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 11262
vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, struct symbol *sym)
41
{
42
        struct vsb *vsb;
43
44 11262
        assert(parent->type == HEADER);
45
46 11262
        if (sym->nlen >= 127) {
47 2
                VSB_printf(tl->sb, "HTTP header (%.20s..) is too long.\n",
48
                    sym->name);
49 2
                VSB_cat(tl->sb, "\nAt: ");
50 2
                vcc_ErrWhere(tl, tl->t);
51
        }
52
53 11262
        AN(sym);
54 11262
        sym->noref = 1;
55 11262
        sym->kind = SYM_VAR;
56 11262
        sym->type = parent->type;
57 11262
        sym->eval = vcc_Eval_Var;
58 11262
        sym->r_methods = parent->r_methods;
59 11262
        sym->w_methods = parent->w_methods;
60 11262
        sym->u_methods = parent->u_methods;
61
62
        /* Create a C-name version of the header name */
63 11262
        vsb = VSB_new_auto();
64 11262
        AN(vsb);
65 11262
        VSB_printf(vsb, "&VGC_%s_", parent->rname);
66 11262
        VCC_PrintCName(vsb, sym->name, NULL);
67 11262
        AZ(VSB_finish(vsb));
68
69
        /* Create the static identifier */
70 11262
        Fh(tl, 0, "static const struct gethdr_s %s =\n", VSB_data(vsb) + 1);
71 22524
        Fh(tl, 0, "    { %s, \"\\%03o%s:\"};\n",
72 11262
            parent->rname, sym->nlen + 1, sym->name);
73
74
        /* Create the symbol r/l values */
75 11262
        sym->rname = TlDup(tl, VSB_data(vsb));
76 11262
        VSB_clear(vsb);
77 11262
        VSB_printf(vsb, "VRT_SetHdr(ctx, %s,", sym->rname);
78 11262
        AZ(VSB_finish(vsb));
79 11262
        sym->lname = TlDup(tl, VSB_data(vsb));
80 11262
        VSB_clear(vsb);
81 11262
        VSB_printf(vsb, "VRT_SetHdr(ctx, %s, vrt_magic_string_unset)",
82
            sym->rname);
83 11262
        AZ(VSB_finish(vsb));
84 11262
        sym->uname = TlDup(tl, VSB_data(vsb));
85 11262
        VSB_destroy(&vsb);
86 11262
}