varnish-cache/lib/libvcc/vcc_var.c
1
/*-
2
 * Copyright (c) 2006 Verdens Gang AS
3
 * Copyright (c) 2006-2011 Varnish Software AS
4
 * All rights reserved.
5
 *
6
 * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
 * SUCH DAMAGE.
28
 */
29
30
#include "config.h"
31
32
#include <stdlib.h>
33
#include <string.h>
34
35
#include "vcc_compile.h"
36
37
/*--------------------------------------------------------------------*/
38
39
void v_matchproto_(sym_wildcard_t)
40 22840
vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, struct symbol *sym)
41
{
42
        struct vsb *vsb;
43
44 22840
        assert(parent->type == HEADER);
45
46 22840
        if (sym->nlen >= 127) {
47 4
                VSB_printf(tl->sb, "HTTP header (%.20s..) is too long.\n",
48
                    sym->name);
49 4
                VSB_cat(tl->sb, "\nAt: ");
50 4
                vcc_ErrWhere(tl, tl->t);
51
        }
52
53 22840
        AN(sym);
54 22840
        sym->noref = 1;
55 22840
        sym->kind = SYM_VAR;
56 22840
        sym->type = parent->type;
57 22840
        sym->eval = vcc_Eval_Var;
58 22840
        sym->r_methods = parent->r_methods;
59 22840
        sym->w_methods = parent->w_methods;
60 22840
        sym->u_methods = parent->u_methods;
61
62
        /* Create a C-name version of the header name */
63 22840
        vsb = VSB_new_auto();
64 22840
        AN(vsb);
65 22840
        VSB_printf(vsb, "&VGC_%s_", parent->rname);
66 22840
        VCC_PrintCName(vsb, sym->name, NULL);
67 22840
        AZ(VSB_finish(vsb));
68
69
        /* Create the static identifier */
70 22840
        Fh(tl, 0, "static const struct gethdr_s %s =\n", VSB_data(vsb) + 1);
71 45680
        Fh(tl, 0, "    { %s, \"\\%03o%s:\"};\n",
72 22840
            parent->rname, sym->nlen + 1, sym->name);
73
74
        /* Create the symbol r/l values */
75 22840
        sym->rname = TlDup(tl, VSB_data(vsb));
76 22840
        VSB_clear(vsb);
77 22840
        VSB_printf(vsb, "VRT_SetHdr(ctx, %s,", sym->rname);
78 22840
        AZ(VSB_finish(vsb));
79 22840
        sym->lname = TlDup(tl, VSB_data(vsb));
80 22840
        VSB_clear(vsb);
81 22840
        VSB_printf(vsb, "VRT_SetHdr(ctx, %s, vrt_magic_string_unset)",
82
            sym->rname);
83 22840
        AZ(VSB_finish(vsb));
84 22840
        sym->uname = TlDup(tl, VSB_data(vsb));
85 22840
        VSB_destroy(&vsb);
86 22840
}