source: lib/libvcl/vcc_var.c @ 22edaa

Revision 22edaa, 3.0 KB checked in by Dag Erling Smørgrav <des@…>, 6 years ago (diff)

Revert r3072, which was a no-op.
Add "config.h" where it's missing.

git-svn-id:  http://www.varnish-cache.org/svn/trunk/varnish-cache@3336 d4fa192b-c00b-0410-8231-f00ffab90ce4

  • Property mode set to 100644
Line 
1/*-
2 * Copyright (c) 2006 Verdens Gang AS
3 * Copyright (c) 2006-2008 Linpro 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 * $Id$
30 */
31
32#include "config.h"
33
34#include <stdio.h>
35#include <string.h>
36
37#include "vsb.h"
38
39#include "vcc_priv.h"
40#include "vcc_compile.h"
41#include "libvarnish.h"
42
43/*--------------------------------------------------------------------*/
44
45static struct var *
46HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
47{
48        char *p;
49        struct var *v;
50        int i;
51
52        (void)tl;
53
54        v = TlAlloc(tl, sizeof *v);
55        assert(v != NULL);
56        i = t->e - t->b;
57        p = TlAlloc(tl, i + 1);
58        assert(p != NULL);
59        memcpy(p, t->b, i);
60        p[i] = '\0';
61        v->name = p;
62        v->access = V_RW;
63        v->fmt = STRING;
64        v->hdr = vh->hdr;
65        v->methods = vh->methods;
66        asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", v->hdr,
67            (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len);
68        AN(p);
69        TlFree(tl, p);
70        v->rname = p;
71        asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", v->hdr,
72            (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len);
73        AN(p);
74        TlFree(tl, p);
75        v->lname = p;
76        return (v);
77}
78
79/*--------------------------------------------------------------------*/
80
81struct var *
82vcc_FindVar(struct tokenlist *tl, const struct token *t, struct var *vl)
83{
84        struct var *v;
85
86        for (v = vl; v->name != NULL; v++) {
87                if (v->fmt == HEADER  && (t->e - t->b) <= v->len)
88                        continue;
89                if (v->fmt != HEADER  && t->e - t->b != v->len)
90                        continue;
91                if (memcmp(t->b, v->name, v->len))
92                        continue;
93                vcc_AddUses(tl, v);
94                if (v->fmt != HEADER)
95                        return (v);
96                return (HeaderVar(tl, t, v));
97        }
98        vsb_printf(tl->sb, "Unknown variable ");
99        vcc_ErrToken(tl, t);
100        vsb_cat(tl->sb, "\nAt: ");
101        vcc_ErrWhere(tl, t);
102        return (NULL);
103}
104
Note: See TracBrowser for help on using the repository browser.