| | varnish-cache/lib/libvcc/vcc_var.c |
| 0 |
|
/*- |
| 1 |
|
* Copyright (c) 2006 Verdens Gang AS |
| 2 |
|
* Copyright (c) 2006-2011 Varnish Software AS |
| 3 |
|
* All rights reserved. |
| 4 |
|
* |
| 5 |
|
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk> |
| 6 |
|
* |
| 7 |
|
* SPDX-License-Identifier: BSD-2-Clause |
| 8 |
|
* |
| 9 |
|
* Redistribution and use in source and binary forms, with or without |
| 10 |
|
* modification, are permitted provided that the following conditions |
| 11 |
|
* are met: |
| 12 |
|
* 1. Redistributions of source code must retain the above copyright |
| 13 |
|
* notice, this list of conditions and the following disclaimer. |
| 14 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 15 |
|
* notice, this list of conditions and the following disclaimer in the |
| 16 |
|
* documentation and/or other materials provided with the distribution. |
| 17 |
|
* |
| 18 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 19 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
| 22 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 24 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 26 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 27 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 |
|
* SUCH DAMAGE. |
| 29 |
|
*/ |
| 30 |
|
|
| 31 |
|
#include "config.h" |
| 32 |
|
|
| 33 |
|
#include <stdlib.h> |
| 34 |
|
#include <string.h> |
| 35 |
|
|
| 36 |
|
#include "vcc_compile.h" |
| 37 |
|
|
| 38 |
|
#include "vct.h" |
| 39 |
|
|
| 40 |
|
/*--------------------------------------------------------------------*/ |
| 41 |
|
|
| 42 |
|
void |
| 43 |
1305377 |
vcc_Header_Fh(const struct vcc *tl, const struct symbol *sym) |
| 44 |
|
{ |
| 45 |
|
const struct symbol *parent; |
| 46 |
|
|
| 47 |
1305377 |
AN(tl); |
| 48 |
1305377 |
AN(sym); |
| 49 |
1305377 |
AZ(sym->wildcard); |
| 50 |
1305377 |
assert(sym->type == HEADER); |
| 51 |
|
|
| 52 |
1305377 |
parent = sym->eval_priv; |
| 53 |
1305377 |
AN(parent); |
| 54 |
1305377 |
AN(parent->wildcard); |
| 55 |
1305377 |
assert(parent->type == HEADER); |
| 56 |
|
|
| 57 |
|
/* Create the static identifier */ |
| 58 |
1305377 |
Fh(tl, 0, "static const struct gethdr_s %s =\n", sym->rname + 1); |
| 59 |
1305377 |
Fh(tl, 0, " { %s, HDR(\"%s\")};\n", parent->rname, sym->name); |
| 60 |
1305377 |
} |
| 61 |
|
|
| 62 |
|
/*--------------------------------------------------------------------*/ |
| 63 |
|
|
| 64 |
|
void v_matchproto_(sym_wildcard_t) |
| 65 |
2023620 |
vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, struct symbol *sym) |
| 66 |
|
{ |
| 67 |
|
struct vsb *vsb; |
| 68 |
|
const char *p; |
| 69 |
|
|
| 70 |
2023620 |
AN(sym); |
| 71 |
2023620 |
assert(parent->type == HEADER); |
| 72 |
|
|
| 73 |
2023620 |
if (strlen(sym->name) >= 127) { |
| 74 |
58 |
VSB_printf(tl->sb, "HTTP header (%.20s..) is too long.\n", |
| 75 |
29 |
sym->name); |
| 76 |
29 |
tl->err = 1; |
| 77 |
29 |
return; |
| 78 |
|
} |
| 79 |
|
|
| 80 |
27376174 |
for (p = sym->name; *p != '\0'; p++) { |
| 81 |
25352612 |
if (!vct_istchar(*p)) { |
| 82 |
29 |
VSB_cat(tl->sb, "Invalid character '"); |
| 83 |
29 |
VSB_quote(tl->sb, p, 1, VSB_QUOTE_PLAIN); |
| 84 |
29 |
VSB_cat(tl->sb, "' in header name.\n"); |
| 85 |
29 |
tl->err = 1; |
| 86 |
29 |
return; |
| 87 |
|
} |
| 88 |
25352583 |
} |
| 89 |
|
|
| 90 |
2023562 |
sym->noref = 1; |
| 91 |
2023562 |
sym->kind = SYM_VAR; |
| 92 |
2023562 |
sym->type = parent->type; |
| 93 |
2023562 |
sym->eval = vcc_Eval_Var; |
| 94 |
2023562 |
sym->eval_priv = parent; |
| 95 |
2023562 |
sym->r_methods = parent->r_methods; |
| 96 |
2023562 |
sym->w_methods = parent->w_methods; |
| 97 |
2023562 |
sym->u_methods = parent->u_methods; |
| 98 |
|
|
| 99 |
|
/* Create a C-name version of the header name */ |
| 100 |
2023562 |
vsb = VSB_new_auto(); |
| 101 |
2023562 |
AN(vsb); |
| 102 |
2023562 |
VSB_printf(vsb, "&VGC_%s_", parent->rname); |
| 103 |
2023562 |
VCC_PrintCName(vsb, sym->name, NULL); |
| 104 |
2023562 |
AZ(VSB_finish(vsb)); |
| 105 |
|
|
| 106 |
|
/* Create the symbol r/l values */ |
| 107 |
2023562 |
sym->rname = TlDup(tl, VSB_data(vsb)); |
| 108 |
|
|
| 109 |
2023562 |
if (sym->w_methods) { |
| 110 |
2023301 |
VSB_clear(vsb); |
| 111 |
2023301 |
VSB_printf(vsb, "VRT_SetHdr(ctx, %s,", sym->rname); |
| 112 |
2023301 |
AZ(VSB_finish(vsb)); |
| 113 |
2023301 |
sym->lname = TlDup(tl, VSB_data(vsb)); |
| 114 |
2023301 |
} |
| 115 |
|
|
| 116 |
2023562 |
if (sym->u_methods) { |
| 117 |
2023301 |
VSB_clear(vsb); |
| 118 |
2023301 |
VSB_printf(vsb, "VRT_UnsetHdr(ctx, %s)", sym->rname); |
| 119 |
2023301 |
AZ(VSB_finish(vsb)); |
| 120 |
2023301 |
sym->uname = TlDup(tl, VSB_data(vsb)); |
| 121 |
2023301 |
} |
| 122 |
2023562 |
VSB_destroy(&vsb); |
| 123 |
|
|
| 124 |
2023562 |
if (sym->lorev > 0) |
| 125 |
1305058 |
vcc_Header_Fh(tl, sym); |
| 126 |
2023620 |
} |