varnish-cache/include/vct.h
1
/*-
2
 * Copyright (c) 2006 Verdens Gang AS
3
 * Copyright (c) 2006-2009 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
31
/* from libvarnish/vct.c */
32
33
#define VCT_SP                  (1<<0)
34
#define VCT_CRLF                (1<<1)
35
#define VCT_LWS                 (VCT_CRLF | VCT_SP)
36
#define VCT_CTL                 (1<<2)
37
#define VCT_ALPHA               (1<<3)
38
#define VCT_SEPARATOR           (1<<4)
39
#define VCT_DIGIT               (1<<5)
40
#define VCT_HEX                 (1<<6)
41
#define VCT_XMLNAMESTART        (1<<7)
42
#define VCT_XMLNAME             (1<<8)
43
#define VCT_TCHAR               (1<<9)
44
#define VCT_ID                  (1<<10)
45
#define VCT_IDENT               (VCT_ALPHA | VCT_DIGIT | VCT_ID)
46
#define VCT_VAR                 (1<<11)
47
#define VCT_VT                  (1<<12)
48
#define VCT_SPACE               (VCT_LWS | VCT_VT)
49
50
extern const uint16_t vct_typtab[256];
51
52
const char *VCT_invalid_name(const char *b, const char *e);
53
54
static inline int
55 3233675
vct_is(int x, uint16_t y)
56
{
57
58 3233675
        x &= 0xff;
59 3233675
        return (vct_typtab[x] & (y));
60
}
61
62
#define vct_issp(x) vct_is(x, VCT_SP)
63
#define vct_ishex(x) vct_is(x, VCT_HEX)
64
#define vct_islws(x) vct_is(x, VCT_LWS)
65
#define vct_isctl(x) vct_is(x, VCT_CTL)
66
#define vct_isspace(x) vct_is(x, VCT_SPACE)
67
#define vct_isdigit(x) vct_is(x, VCT_DIGIT)
68
#define vct_isalpha(x) vct_is(x, VCT_ALPHA)
69
#define vct_isalnum(x) vct_is(x, VCT_ALPHA | VCT_DIGIT)
70
#define vct_issep(x) vct_is(x, VCT_SEPARATOR)
71
#define vct_issepctl(x) vct_is(x, VCT_SEPARATOR | VCT_CTL)
72
#define vct_isident1(x) vct_isalpha(x)
73
#define vct_isident(x) vct_is(x, VCT_IDENT)
74
#define vct_isvar(x) vct_is(x, VCT_IDENT | VCT_VAR)
75
#define vct_isxmlnamestart(x) vct_is(x, VCT_XMLNAMESTART)
76
#define vct_isxmlname(x) vct_is(x, VCT_XMLNAMESTART | VCT_XMLNAME)
77
#define vct_istchar(x) vct_is(x, VCT_ALPHA | VCT_DIGIT | VCT_TCHAR)
78
79
#define vct_iscrlf(p) (((p)[0] == 0x0d && (p)[1] == 0x0a) || (p)[0] == 0x0a)
80
81
/* NB: VCT always operate in ASCII, don't replace 0x0d with \r etc. */
82
#define vct_skipcrlf(p) ((p)[0] == 0x0d && (p)[1] == 0x0a ? 2 : 1)