40static void debug(
const char* fmt, ...);
56 debug(
"can't type expression");
129 struct comments comments;
133 arg =
mapGet(expr,
"equal");
136 left =
mapGet(arg,
"left");
139 right =
mapGet(arg,
"right");
145 mapSet(arg, left,
"left");
150 mapSet(arg, right,
"right");
153 equal = eval_equal_expression(left, right);
183 arg =
mapGet(expr,
"not-equal");
186 left =
mapGet(arg,
"left");
189 right =
mapGet(arg,
"right");
195 mapSet(arg, left,
"left");
200 mapSet(arg, right,
"right");
203 equal = eval_equal_expression(left, right);
255 arg =
mapGet(expr,
"and");
258 left =
mapGet(arg,
"left");
261 right =
mapGet(arg,
"right");
263 debug(
"can't get and right branch");
267 mapSet(arg, left,
"left");
272 mapSet(arg, right,
"right");
280 result =
copy(right);
326 left =
mapGet(arg,
"left");
329 right =
mapGet(arg,
"right");
335 mapSet(arg, left,
"left");
340 mapSet(arg, right,
"right");
348 result =
copy(right);
384 arg =
mapGet(expr,
"not");
405 arg =
mapGet(arg,
"equal");
410 mapSet(result, arg,
"not-equal");
417 arg =
mapGet(arg,
"not-equal");
422 mapSet(result, arg,
"equal");
513 arg =
mapGet(expr,
"substring");
516 string =
mapGet(arg,
"expression");
519 offset =
mapGet(arg,
"offset");
528 mapSet(arg,
string,
"expression");
533 mapSet(arg, offset,
"offset");
546 if ((off < 0) || (len < 0))
579 mapSet(arg, right,
"expression");
591 (off == 0) && (len == 1)) {
653 arg =
mapGet(expr,
"suffix");
656 string =
mapGet(arg,
"expression");
665 mapSet(arg,
string,
"expression");
704 arg =
mapGet(expr,
"lowercase");
710 mapSet(expr, arg,
"lowercase");
718 for (i = 0; i < r->
length; i++)
739 arg =
mapGet(expr,
"uppercase");
745 mapSet(expr, arg,
"lowercase");
753 for (i = 0; i < r->
length; i++)
851 arg =
mapGet(expr,
"concat");
854 left =
mapGet(arg,
"left");
857 right =
mapGet(arg,
"right");
863 mapSet(arg, left,
"left");
868 mapSet(arg, right,
"right");
919 arg =
mapGet(expr,
"encode-int8");
925 mapSet(expr, arg,
"encode-int8");
952 arg =
mapGet(expr,
"encode-int16");
958 mapSet(expr, arg,
"encode-int16");
986 arg =
mapGet(expr,
"encode-int32");
992 mapSet(expr, arg,
"encode-int32");
1023 arg =
mapGet(expr,
"gethostbyname");
1027 h = gethostbyname(hostname);
1031 case HOST_NOT_FOUND:
1032 debug(
"gethostbyname: %s: host unknown",
1036 debug(
"gethostbyname: %s: temporary name "
1037 "server failure", hostname);
1040 debug(
"gethostbyname: %s: name server failed",
1044 debug(
"gethostbyname: %s: no A record "
1045 "associated with address", hostname);
1049 for (i = 0; h->h_addr_list[i] != NULL; i++) {
1090 arg =
mapGet(expr,
"binary-to-ascii");
1093 base =
mapGet(arg,
"base");
1096 width =
mapGet(arg,
"width");
1099 separator =
mapGet(arg,
"separator");
1100 if (separator == NULL)
1108 mapSet(arg, base,
"base");
1113 mapSet(arg, width,
"width");
1118 mapSet(arg, separator,
"separator");
1132 if ((b < 2) || (b > 16))
1134 if ((b != 8) && (b != 10) && (b != 16))
1137 if ((w != 8) && (w != 16) && (w != 32))
1159 for (i = 0; i < buf->
length; i++) {
1165 val = (uint8_t)buf->
content[i];
1166 snprintf(num,
sizeof(num), fmt, (
int)val);
1169 }
else if (w == 16) {
1173 if ((buf->
length % 2) != 0)
1189 for (i = 0; i < buf->
length; i += 2) {
1195 memcpy(&val, buf->
content + i, 2);
1197 snprintf(num,
sizeof(num), fmt, (
int)val);
1200 }
else if (w == 32) {
1204 if ((buf->
length % 4) != 0)
1220 for (i = 0; i < buf->
length; i += 4) {
1226 memcpy(&val, buf->
content + i, 4);
1228 snprintf(num,
sizeof(num), fmt,
1280 arg =
mapGet(expr,
"reverse");
1283 width =
mapGet(arg,
"width");
1292 mapSet(arg, width,
"width");
1307 if ((buf->
length % w) != 0)
1312 for (i = 0; i < buf->
length; i += w) {
1340 arg =
mapGet(expr,
"pick-first-value");
1344 for (i = 0; i <
listSize(arg); i++) {
1430 if (gethostname(buf,
sizeof(buf)) != 0) {
1431 debug(
"gethostname fails: %s", strerror(errno));
1457 arg =
mapGet(expr,
"v6relay");
1460 relay =
mapGet(arg,
"relay");
1466 mapSet(arg, relay,
"relay");
1506 arg =
mapGet(expr,
"extract-int8");
1512 mapSet(expr, arg,
"extract-int8");
1538 arg =
mapGet(expr,
"extract-int16");
1544 mapSet(expr, arg,
"extract-int16");
1572 arg =
mapGet(expr,
"extract-int32");
1578 mapSet(expr, arg,
"extract-int32");
1603 arg =
mapGet(expr,
"const-int");
1639 arg =
mapGet(expr,
"add");
1642 left =
mapGet(arg,
"left");
1645 right =
mapGet(arg,
"right");
1651 mapSet(arg, left,
"left");
1656 mapSet(arg, right,
"right");
1688 arg =
mapGet(expr,
"subtract");
1691 left =
mapGet(arg,
"left");
1694 right =
mapGet(arg,
"right");
1700 mapSet(arg, left,
"left");
1705 mapSet(arg, right,
"right");
1737 arg =
mapGet(expr,
"multiply");
1740 left =
mapGet(arg,
"left");
1743 right =
mapGet(arg,
"right");
1749 mapSet(arg, left,
"left");
1754 mapSet(arg, right,
"right");
1786 arg =
mapGet(expr,
"divide");
1789 left =
mapGet(arg,
"left");
1792 right =
mapGet(arg,
"right");
1798 mapSet(arg, left,
"left");
1803 mapSet(arg, right,
"right");
1837 arg =
mapGet(expr,
"remainder");
1840 left =
mapGet(arg,
"left");
1843 right =
mapGet(arg,
"right");
1849 mapSet(arg, left,
"left");
1854 mapSet(arg, right,
"right");
1888 arg =
mapGet(expr,
"binary-and");
1891 left =
mapGet(arg,
"left");
1894 right =
mapGet(arg,
"right");
1900 mapSet(arg, left,
"left");
1905 mapSet(arg, right,
"right");
1937 arg =
mapGet(expr,
"binary-or");
1940 left =
mapGet(arg,
"left");
1943 right =
mapGet(arg,
"right");
1949 mapSet(arg, left,
"left");
1954 mapSet(arg, right,
"right");
1986 arg =
mapGet(expr,
"binary-xor");
1989 left =
mapGet(arg,
"left");
1992 right =
mapGet(arg,
"right");
1998 mapSet(arg, left,
"left");
2003 mapSet(arg, right,
"right");
2035eval_equal_expression(
struct element *left,
struct element *right)
2037 struct element *result = NULL;
2064 ci =
mapGet(right,
"const-int");
2066 debug(
"bad const-int");
2080 ci =
mapGet(left,
"const-int");
2082 debug(
"bad const-int");
2091 lci =
mapGet(left,
"const-int");
2092 rci =
mapGet(right,
"const-int");
2095 debug(
"bad const-int");
2126 cd =
mapGet(right,
"const-data");
2128 debug(
"bad const-data");
2142 cd =
mapGet(left,
"const-data");
2144 debug(
"bad const-data");
2153 lcd =
mapGet(left,
"const-data");
2154 rcd =
mapGet(right,
"const-data");
2157 debug(
"bad const-data");
2182 debug(
"equal between unexpected %s and %s",
2203 if (!left_is_hexa && !right_is_hexa) {
2211 if (left_is_hexa && right_is_hexa) {
2216 if (sleft->
length == 0) {
2217 debug(
"empty const-data");
2244debug(
const char* fmt, ...)
2248 va_start(list, fmt);
2249 vfprintf(stderr, fmt, list);
2250 fprintf(stderr,
"\n");
void concatString(struct string *s, const struct string *a)
isc_boolean_t eqString(const struct string *s, const struct string *o)
struct string * makeString(int l, const char *s)
isc_boolean_t boolValue(const struct element *e)
struct element * copy(struct element *e)
void listRemove(struct element *l, int i)
struct element * createBool(isc_boolean_t b)
struct string * allocString(void)
void appendString(struct string *s, const char *a)
struct element * listGet(struct element *l, int i)
struct string * stringValue(struct element *e)
struct element * createNull(void)
void concat(struct element *l, struct element *o)
isc_boolean_t mapContains(const struct element *m, const char *k)
struct string * hexaValue(struct element *s)
struct element * createInt(int64_t i)
void mapSet(struct element *m, struct element *e, const char *k)
void listSet(struct element *l, struct element *e, int i)
size_t listSize(const struct element *l)
struct element * createMap(void)
struct element * createString(const struct string *s)
void mapRemove(struct element *m, const char *k)
struct element * mapGet(struct element *m, const char *k)
int64_t intValue(const struct element *e)
const char * type2name(int t)
struct string * makeStringExt(int l, const char *s, char fmt)
#define TAILQ_CONCAT(head1, head2)
struct element * eval_boolean_expression(struct element *expr, isc_boolean_t *modifiedp)
struct element * eval_expression(struct element *expr, isc_boolean_t *modifiedp)
struct element * eval_data_expression(struct element *expr, isc_boolean_t *modifiedp)
struct element * eval_numeric_expression(struct element *expr, isc_boolean_t *modifiedp)
int is_boolean_expression(struct expression *expr)
int is_numeric_expression(struct expression *expr)
int is_data_expression(struct expression *expr)