| Code Coverage: vinyl-cache/lib/libvinylapi/vxp.h |
| |
| 82217aa4fc7094b3610340078afaf78cd95a8ec9 |
| |
| 0 |
|
/*- |
| 1 |
|
* Copyright (c) 2006 Verdens Gang AS |
| 2 |
|
* Copyright (c) 2006-2015 Varnish Software AS |
| 3 |
|
* All rights reserved. |
| 4 |
|
* |
| 5 |
|
* Author: Martin Blix Grydeland <martin@varnish-software.com> |
| 6 |
|
* |
| 7 |
|
* SPDX-License-Identifier: BSD-2-Clause |
| 8 |
|
* |
| 9 |
|
* Redistribution and use in source and binary forms, with or without |
| 10 |
|
* modification, are permitted provided that the following conditions |
| 11 |
|
* are met: |
| 12 |
|
* 1. Redistributions of source code must retain the above copyright |
| 13 |
|
* notice, this list of conditions and the following disclaimer. |
| 14 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 15 |
|
* notice, this list of conditions and the following disclaimer in the |
| 16 |
|
* documentation and/or other materials provided with the distribution. |
| 17 |
|
* |
| 18 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 19 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
| 22 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 24 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 25 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 26 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 27 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 |
|
* SUCH DAMAGE. |
| 29 |
|
* |
| 30 |
|
*/ |
| 31 |
|
|
| 32 |
|
#include "vxp_tokens.h" |
| 33 |
|
|
| 34 |
4359 |
#define isword(c) (isalpha(c) || isdigit(c) || (c) == '_' || (c) == '-' || \ |
| 35 |
4359 |
(c) == '+' || (c) == '.' || (c) == '*') |
| 36 |
|
|
| 37 |
13 |
#define PF(t) (int)((t)->e - (t)->b), (t)->b |
| 38 |
|
|
| 39 |
|
/* From vex_fixed_token.c */ |
| 40 |
|
unsigned vxp_fixed_token(const char *p, const char **q); |
| 41 |
|
extern const char * const vxp_tnames[256]; |
| 42 |
|
|
| 43 |
|
struct membit { |
| 44 |
|
VTAILQ_ENTRY(membit) list; |
| 45 |
|
void *ptr; |
| 46 |
|
}; |
| 47 |
|
|
| 48 |
|
struct token { |
| 49 |
|
unsigned tok; |
| 50 |
|
const char *b; |
| 51 |
|
const char *e; |
| 52 |
|
VTAILQ_ENTRY(token) list; |
| 53 |
|
char *dec; |
| 54 |
|
}; |
| 55 |
|
|
| 56 |
|
struct vxp { |
| 57 |
|
unsigned magic; |
| 58 |
|
#define VXP_MAGIC 0x59C7F6AC |
| 59 |
|
|
| 60 |
|
const char *b; |
| 61 |
|
const char *e; |
| 62 |
|
|
| 63 |
|
VTAILQ_HEAD(, token) tokens; |
| 64 |
|
VTAILQ_HEAD(, membit) membits; |
| 65 |
|
struct token *t; |
| 66 |
|
|
| 67 |
|
unsigned vex_options; |
| 68 |
|
unsigned vre_options; |
| 69 |
|
|
| 70 |
|
struct vsb *sb; |
| 71 |
|
int err; |
| 72 |
|
}; |
| 73 |
|
|
| 74 |
|
struct vex_lhs { |
| 75 |
|
/* Left-hand-side of a vex expression. Stores the information |
| 76 |
|
about which records and what parts of those records the |
| 77 |
|
expression should be applied to */ |
| 78 |
|
unsigned magic; |
| 79 |
|
#define VEX_LHS_MAGIC 0x1AD3D78D |
| 80 |
|
struct vbitmap *tags; |
| 81 |
|
char *prefix; |
| 82 |
|
int prefixlen; |
| 83 |
|
int field; |
| 84 |
|
int level; |
| 85 |
|
int level_pm; |
| 86 |
|
unsigned taglist; |
| 87 |
|
int64_t vxid; |
| 88 |
|
}; |
| 89 |
|
|
| 90 |
|
enum vex_rhs_e { |
| 91 |
|
VEX__UNSET, |
| 92 |
|
VEX_INT, |
| 93 |
|
VEX_FLOAT, |
| 94 |
|
VEX_STRING, |
| 95 |
|
VEX_REGEX, |
| 96 |
|
}; |
| 97 |
|
|
| 98 |
|
struct vex_rhs { |
| 99 |
|
/* Right-hand-side of a vex expression. Stores the value that the |
| 100 |
|
records from LHS should be matched against */ |
| 101 |
|
unsigned magic; |
| 102 |
|
#define VEX_RHS_MAGIC 0x3F109965 |
| 103 |
|
enum vex_rhs_e type; |
| 104 |
|
int64_t val_int; |
| 105 |
|
double val_float; |
| 106 |
|
char *val_string; |
| 107 |
|
size_t val_stringlen; |
| 108 |
|
vre_t *val_regex; |
| 109 |
|
}; |
| 110 |
|
|
| 111 |
|
struct vex { |
| 112 |
|
unsigned magic; |
| 113 |
|
#define VEX_MAGIC 0xC7DB792D |
| 114 |
|
unsigned tok; |
| 115 |
|
unsigned options; |
| 116 |
|
struct vex *a, *b; |
| 117 |
|
struct vex_lhs *lhs; |
| 118 |
|
struct vex_rhs *rhs; |
| 119 |
|
}; |
| 120 |
|
|
| 121 |
|
/* VXP internals */ |
| 122 |
|
|
| 123 |
1660 |
#define ERRCHK(tl) do { if ((tl)->err) return; } while (0) |
| 124 |
|
#define ExpectErr(a, b) \ |
| 125 |
249 |
do { vxp__Expect(a, b); ERRCHK(a); } while (0) |
| 126 |
|
#define SkipToken(a, b) \ |
| 127 |
10 |
do { vxp__Expect(a, b); ERRCHK(a); vxp_NextToken(a); } while (0) |
| 128 |
|
|
| 129 |
|
void vxp__Expect(struct vxp *vxp, unsigned tok); |
| 130 |
|
void vxp_ErrWhere(struct vxp *vxp, const struct token *t, int tokoff); |
| 131 |
|
void vxp_NextToken(struct vxp *vxp); |
| 132 |
|
void * vxp_Alloc(struct vxp *vxp, unsigned len); |
| 133 |
|
void vxp_Lexer(struct vxp *vxp); |
| 134 |
|
struct vex * vxp_Parse(struct vxp *vxp); |
| 135 |
|
|
| 136 |
|
/* API internal interface */ |
| 137 |
274 |
#define VEX_OPT_CASELESS (1 << 0) |
| 138 |
|
struct vex * vex_New(const char *query, struct vsb *sb, unsigned options); |
| 139 |
|
void vex_Free(struct vex **pvex); |
| 140 |
|
|
| 141 |
|
/* Debug routines */ |
| 142 |
|
#ifdef VXP_DEBUG |
| 143 |
|
void vxp_PrintTokens(const struct vxp *vxp); |
| 144 |
|
void vex_PrintTree(const struct vex *vex); |
| 145 |
|
#endif /* VXP_DEBUG */ |