source: lib/libvcl/vcc_var.c @ fb84ba

Revision fb84ba, 3.8 KB checked in by Poul-Henning Kamp <phk@…>, 4 years ago (diff)

Whitespace cleanup

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

  • Property mode set to 100644
Line 
1/*-
2 * Copyright (c) 2006 Verdens Gang AS
3 * Copyright (c) 2006-2009 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
30#include "config.h"
31
32#include "svnid.h"
33SVNID("$Id$")
34
35#include <stdio.h>
36#include <string.h>
37
38#include "vsb.h"
39
40#include "vcc_priv.h"
41#include "vcc_compile.h"
42#include "libvarnish.h"
43
44/*--------------------------------------------------------------------*/
45
46static struct var *
47HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
48{
49        char *p;
50        struct var *v;
51        int i, l;
52        char buf[258];
53
54        (void)tl;
55
56        v = TlAlloc(tl, sizeof *v);
57        assert(v != NULL);
58        i = t->e - t->b;
59        p = TlAlloc(tl, i + 1);
60        assert(p != NULL);
61        memcpy(p, t->b, i);
62        p[i] = '\0';
63        v->name = p;
64        v->access = V_RW;
65        v->fmt = STRING;
66        v->hdr = vh->hdr;
67        v->methods = vh->methods;
68        l = strlen(v->name + vh->len) + 1;
69
70        bprintf(buf, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")",
71            v->hdr, (unsigned)l, v->name + vh->len);
72        i = strlen(buf);
73        p = TlAlloc(tl, i + 1);
74        memcpy(p, buf, i + 1);
75        v->rname = p;
76
77        bprintf(buf, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ",
78            v->hdr, (unsigned)l, v->name + vh->len);
79        i = strlen(buf);
80        p =  TlAlloc(tl, i + 1);
81        memcpy(p, buf, i + 1);
82        v->lname = p;
83
84        return (v);
85}
86
87/*--------------------------------------------------------------------*/
88
89struct var *
90vcc_FindVar(struct tokenlist *tl, const struct token *t, struct var *vl)
91{
92        struct var *v;
93
94        for (v = vl; v->name != NULL; v++) {
95                if (v->fmt == HEADER  && (t->e - t->b) <= v->len)
96                        continue;
97                if (v->fmt != HEADER  && t->e - t->b != v->len)
98                        continue;
99                if (memcmp(t->b, v->name, v->len))
100                        continue;
101                vcc_AddUses(tl, v);
102                if (v->fmt != HEADER)
103                        return (v);
104                return (HeaderVar(tl, t, v));
105        }
106        vsb_printf(tl->sb, "Unknown variable ");
107        vcc_ErrToken(tl, t);
108        vsb_cat(tl->sb, "\nAt: ");
109        vcc_ErrWhere(tl, t);
110        return (NULL);
111}
112
113/*--------------------------------------------------------------------*/
114
115void
116vcc_VarVal(struct tokenlist *tl, const struct var *vp, const struct token *vt)
117{
118        double d;
119
120        if (vp->fmt == TIME) {
121                vcc_TimeVal(tl, &d);
122                ERRCHK(tl);
123                Fb(tl, 0, "%g", d);
124        } else if (vp->fmt == RTIME) {
125                vcc_RTimeVal(tl, &d);
126                ERRCHK(tl);
127                Fb(tl, 0, "%g", d);
128        } else if (vp->fmt == SIZE) {
129                vcc_SizeVal(tl, &d);
130                ERRCHK(tl);
131                Fb(tl, 0, "%g", d);
132        } else if (vp->fmt == FLOAT) {
133                Fb(tl, 0, "%g", vcc_DoubleVal(tl));
134        } else if (vp->fmt == INT) {
135                Fb(tl, 0, "%u", vcc_UintVal(tl));
136        } else {
137                AN(vt);
138                vsb_printf(tl->sb,
139                    "Variable has incompatible type.\n");
140                vcc_ErrWhere(tl, vt);
141                return;
142        }
143}
Note: See TracBrowser for help on using the repository browser.