1 1.1 christos /* $NetBSD: print.c,v 1.3 2022/04/03 01:10:59 christos Exp $ */ 2 1.1 christos 3 1.1 christos /* 4 1.3 christos * Copyright (C) 2017-2022 Internet Systems Consortium, Inc. ("ISC") 5 1.1 christos * 6 1.1 christos * Permission to use, copy, modify, and distribute this software for any 7 1.1 christos * purpose with or without fee is hereby granted, provided that the above 8 1.1 christos * copyright notice and this permission notice appear in all copies. 9 1.1 christos * 10 1.1 christos * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES 11 1.1 christos * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 1.1 christos * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR 13 1.1 christos * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 1.1 christos * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 1.1 christos * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT 16 1.1 christos * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 1.1 christos * 18 1.1 christos * Internet Systems Consortium, Inc. 19 1.3 christos * PO Box 360 20 1.3 christos * Newmarket, NH 03857 USA 21 1.1 christos * <info (at) isc.org> 22 1.1 christos * https://www.isc.org/ 23 1.1 christos * 24 1.1 christos */ 25 1.1 christos 26 1.1 christos #include <sys/cdefs.h> 27 1.1 christos __RCSID("$NetBSD: print.c,v 1.3 2022/04/03 01:10:59 christos Exp $"); 28 1.1 christos 29 1.1 christos #include "keama.h" 30 1.1 christos 31 1.1 christos #include <sys/errno.h> 32 1.1 christos #include <sys/types.h> 33 1.1 christos #include <arpa/inet.h> 34 1.1 christos #include <ctype.h> 35 1.1 christos #include <netdb.h> 36 1.1 christos #include <stdarg.h> 37 1.1 christos #include <stdio.h> 38 1.1 christos #include <string.h> 39 1.1 christos #include <unistd.h> 40 1.1 christos 41 1.1 christos static void debug(const char* fmt, ...); 42 1.1 christos 43 1.1 christos const char * 44 1.1 christos print_expression(struct element *expr, isc_boolean_t *lose) 45 1.1 christos { 46 1.1 christos if (expr->type == ELEMENT_BOOLEAN) 47 1.1 christos return print_boolean_expression(expr, lose); 48 1.1 christos if (expr->type == ELEMENT_INTEGER) 49 1.1 christos return print_numeric_expression(expr, lose); 50 1.1 christos if (expr->type == ELEMENT_STRING) 51 1.1 christos return print_data_expression(expr, lose); 52 1.3 christos 53 1.1 christos if (is_boolean_expression(expr)) 54 1.1 christos return print_boolean_expression(expr, lose); 55 1.1 christos if (is_numeric_expression(expr)) 56 1.1 christos return print_numeric_expression(expr, lose); 57 1.1 christos if (is_data_expression(expr)) 58 1.1 christos return print_data_expression(expr, lose); 59 1.1 christos *lose = ISC_TRUE; 60 1.1 christos return "???"; 61 1.1 christos } 62 1.1 christos 63 1.1 christos const char * 64 1.1 christos print_boolean_expression(struct element *expr, isc_boolean_t *lose) 65 1.1 christos { 66 1.1 christos struct string *result; 67 1.1 christos 68 1.1 christos if (expr->type == ELEMENT_BOOLEAN) { 69 1.1 christos if (boolValue(expr)) 70 1.1 christos return "true"; 71 1.1 christos else 72 1.1 christos return "false"; 73 1.1 christos } 74 1.1 christos 75 1.1 christos /* 76 1.1 christos * From is_boolean_expression 77 1.1 christos */ 78 1.1 christos if (expr->type != ELEMENT_MAP) { 79 1.1 christos *lose = ISC_TRUE; 80 1.1 christos return "???"; 81 1.1 christos } 82 1.1 christos result = allocString(); 83 1.1 christos 84 1.1 christos /* check */ 85 1.1 christos if (mapContains(expr, "check")) { 86 1.1 christos struct element *name; 87 1.1 christos 88 1.1 christos appendString(result, "check "); 89 1.1 christos name = mapGet(expr, "check"); 90 1.1 christos if ((name == NULL) || (name->type != ELEMENT_STRING)) { 91 1.1 christos *lose = ISC_TRUE; 92 1.1 christos appendString(result, "???"); 93 1.1 christos } else 94 1.1 christos concatString(result, stringValue(name)); 95 1.1 christos return result->content; 96 1.1 christos } 97 1.1 christos 98 1.1 christos /* exists */ 99 1.1 christos if (mapContains(expr, "exists")) { 100 1.1 christos struct element *arg; 101 1.1 christos struct element *universe; 102 1.1 christos struct element *name; 103 1.1 christos 104 1.1 christos appendString(result, "exists "); 105 1.1 christos arg = mapGet(expr, "exists"); 106 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 107 1.1 christos *lose = ISC_TRUE; 108 1.1 christos appendString(result, "???"); 109 1.1 christos return result->content; 110 1.1 christos } 111 1.1 christos universe = mapGet(arg, "universe"); 112 1.1 christos if ((universe == NULL) || (universe->type != ELEMENT_STRING)) { 113 1.1 christos *lose = ISC_TRUE; 114 1.1 christos appendString(result, "???"); 115 1.1 christos return result->content; 116 1.1 christos } 117 1.1 christos concatString(result, stringValue(universe)); 118 1.1 christos appendString(result, "."); 119 1.1 christos name = mapGet(arg, "name"); 120 1.1 christos if ((name == NULL) || (name->type != ELEMENT_STRING)) { 121 1.1 christos *lose = ISC_TRUE; 122 1.1 christos appendString(result, "???"); 123 1.1 christos return result->content; 124 1.1 christos } 125 1.1 christos concatString(result, stringValue(name)); 126 1.1 christos return result->content; 127 1.1 christos } 128 1.1 christos 129 1.1 christos /* variable-exists */ 130 1.1 christos if (mapContains(expr, "variable-exists")) { 131 1.1 christos struct element *name; 132 1.1 christos 133 1.1 christos appendString(result, "variable-exists "); 134 1.1 christos name = mapGet(expr, "variable-exists"); 135 1.1 christos if ((name == NULL) || (name->type != ELEMENT_STRING)) { 136 1.1 christos *lose = ISC_TRUE; 137 1.1 christos appendString(result, "???"); 138 1.1 christos } else 139 1.1 christos concatString(result, stringValue(name)); 140 1.1 christos return result->content; 141 1.1 christos } 142 1.1 christos 143 1.1 christos /* equal */ 144 1.1 christos if (mapContains(expr, "equal")) { 145 1.1 christos struct element *arg; 146 1.1 christos struct element *left; 147 1.1 christos struct element *right; 148 1.1 christos isc_boolean_t add_parenthesis; 149 1.1 christos 150 1.1 christos appendString(result, "equal "); 151 1.1 christos arg = mapGet(expr, "equal"); 152 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 153 1.1 christos *lose = ISC_TRUE; 154 1.1 christos appendString(result, "???"); 155 1.1 christos return result->content; 156 1.1 christos } 157 1.1 christos left = mapGet(arg, "left"); 158 1.1 christos if (left == NULL) { 159 1.1 christos *lose = ISC_TRUE; 160 1.1 christos appendString(result, "???"); 161 1.1 christos return result->content; 162 1.1 christos } 163 1.1 christos result = allocString(); 164 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_equal, 165 1.1 christos left) < 0); 166 1.1 christos if (add_parenthesis) 167 1.1 christos appendString(result, "("); 168 1.1 christos appendString(result, print_expression(left, lose)); 169 1.1 christos if (add_parenthesis) 170 1.1 christos appendString(result, ")"); 171 1.1 christos appendString(result, " = "); 172 1.1 christos right = mapGet(arg, "right"); 173 1.1 christos if (right == NULL) { 174 1.1 christos *lose = ISC_TRUE; 175 1.1 christos appendString(result, "???"); 176 1.1 christos return result->content; 177 1.1 christos } 178 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_equal, 179 1.1 christos right) < 0); 180 1.1 christos if (add_parenthesis) 181 1.1 christos appendString(result, "("); 182 1.1 christos appendString(result, print_expression(right, lose)); 183 1.1 christos if (add_parenthesis) 184 1.1 christos appendString(result, ")"); 185 1.1 christos return result->content; 186 1.1 christos } 187 1.1 christos 188 1.1 christos /* not-equal */ 189 1.1 christos if (mapContains(expr, "not-equal")) { 190 1.1 christos struct element *arg; 191 1.1 christos struct element *left; 192 1.1 christos struct element *right; 193 1.1 christos isc_boolean_t add_parenthesis; 194 1.1 christos 195 1.1 christos appendString(result, "not-equal "); 196 1.1 christos arg = mapGet(expr, "not-equal"); 197 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 198 1.1 christos *lose = ISC_TRUE; 199 1.1 christos appendString(result, "???"); 200 1.1 christos return result->content; 201 1.1 christos } 202 1.1 christos left = mapGet(arg, "left"); 203 1.1 christos if (left == NULL) { 204 1.1 christos *lose = ISC_TRUE; 205 1.1 christos appendString(result, "???"); 206 1.1 christos return result->content; 207 1.1 christos } 208 1.1 christos result = allocString(); 209 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_not_equal, 210 1.1 christos left) < 0); 211 1.1 christos if (add_parenthesis) 212 1.1 christos appendString(result, "("); 213 1.1 christos appendString(result, print_expression(left, lose)); 214 1.1 christos if (add_parenthesis) 215 1.1 christos appendString(result, ")"); 216 1.1 christos appendString(result, " != "); 217 1.1 christos right = mapGet(arg, "right"); 218 1.1 christos if (right == NULL) { 219 1.1 christos *lose = ISC_TRUE; 220 1.1 christos appendString(result, "???"); 221 1.1 christos return result->content; 222 1.1 christos } 223 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_not_equal, 224 1.1 christos right) < 0); 225 1.1 christos if (add_parenthesis) 226 1.1 christos appendString(result, "("); 227 1.1 christos appendString(result, print_expression(right, lose)); 228 1.1 christos if (add_parenthesis) 229 1.1 christos appendString(result, ")"); 230 1.1 christos return result->content; 231 1.1 christos } 232 1.1 christos 233 1.1 christos /* regex-match */ 234 1.1 christos if (mapContains(expr, "regex-match")) { 235 1.1 christos struct element *arg; 236 1.1 christos struct element *left; 237 1.1 christos struct element *right; 238 1.1 christos isc_boolean_t add_parenthesis; 239 1.1 christos 240 1.1 christos appendString(result, "regex-match "); 241 1.1 christos arg = mapGet(expr, "regex-match"); 242 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 243 1.1 christos *lose = ISC_TRUE; 244 1.1 christos appendString(result, "???"); 245 1.1 christos return result->content; 246 1.1 christos } 247 1.1 christos left = mapGet(arg, "left"); 248 1.1 christos if (left == NULL) { 249 1.1 christos *lose = ISC_TRUE; 250 1.1 christos appendString(result, "???"); 251 1.1 christos return result->content; 252 1.1 christos } 253 1.1 christos result = allocString(); 254 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_regex_match, 255 1.1 christos left) < 0); 256 1.1 christos if (add_parenthesis) 257 1.1 christos appendString(result, "("); 258 1.1 christos appendString(result, print_expression(left, lose)); 259 1.1 christos if (add_parenthesis) 260 1.1 christos appendString(result, ")"); 261 1.1 christos appendString(result, " ~= "); 262 1.1 christos right = mapGet(arg, "right"); 263 1.1 christos if (right == NULL) { 264 1.1 christos *lose = ISC_TRUE; 265 1.1 christos appendString(result, "???"); 266 1.1 christos return result->content; 267 1.1 christos } 268 1.1 christos appendString(result, print_expression(right, lose)); 269 1.1 christos return result->content; 270 1.1 christos } 271 1.1 christos 272 1.1 christos /* iregex-match */ 273 1.1 christos if (mapContains(expr, "iregex-match")) { 274 1.1 christos struct element *arg; 275 1.1 christos struct element *left; 276 1.1 christos struct element *right; 277 1.1 christos isc_boolean_t add_parenthesis; 278 1.1 christos 279 1.1 christos appendString(result, "iregex-match "); 280 1.1 christos arg = mapGet(expr, "iregex-match"); 281 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 282 1.1 christos *lose = ISC_TRUE; 283 1.1 christos appendString(result, "???"); 284 1.1 christos return result->content; 285 1.1 christos } 286 1.1 christos left = mapGet(arg, "left"); 287 1.1 christos if (left == NULL) { 288 1.1 christos *lose = ISC_TRUE; 289 1.1 christos appendString(result, "???"); 290 1.1 christos return result->content; 291 1.1 christos } 292 1.1 christos result = allocString(); 293 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_iregex_match, 294 1.1 christos left) < 0); 295 1.1 christos if (add_parenthesis) 296 1.1 christos appendString(result, "("); 297 1.1 christos appendString(result, print_expression(left, lose)); 298 1.1 christos if (add_parenthesis) 299 1.1 christos appendString(result, ")"); 300 1.1 christos appendString(result, " ~~ "); 301 1.1 christos right = mapGet(arg, "right"); 302 1.1 christos if (right == NULL) { 303 1.1 christos *lose = ISC_TRUE; 304 1.1 christos appendString(result, "???"); 305 1.1 christos return result->content; 306 1.1 christos } 307 1.1 christos appendString(result, print_expression(right, lose)); 308 1.1 christos return result->content; 309 1.1 christos } 310 1.1 christos 311 1.1 christos /* and */ 312 1.1 christos if (mapContains(expr, "and")) { 313 1.1 christos struct element *arg; 314 1.1 christos struct element *left; 315 1.1 christos struct element *right; 316 1.1 christos isc_boolean_t add_parenthesis; 317 1.1 christos 318 1.1 christos appendString(result, "and "); 319 1.1 christos arg = mapGet(expr, "and"); 320 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 321 1.1 christos *lose = ISC_TRUE; 322 1.1 christos appendString(result, "???"); 323 1.1 christos return result->content; 324 1.1 christos } 325 1.1 christos left = mapGet(arg, "left"); 326 1.1 christos if (left == NULL) { 327 1.1 christos *lose = ISC_TRUE; 328 1.1 christos appendString(result, "???"); 329 1.1 christos return result->content; 330 1.1 christos } 331 1.1 christos result = allocString(); 332 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_and, 333 1.1 christos left) < 0); 334 1.1 christos if (add_parenthesis) 335 1.1 christos appendString(result, "("); 336 1.1 christos appendString(result, print_expression(left, lose)); 337 1.1 christos if (add_parenthesis) 338 1.1 christos appendString(result, ")"); 339 1.1 christos appendString(result, " and "); 340 1.1 christos right = mapGet(arg, "right"); 341 1.1 christos if (right == NULL) { 342 1.1 christos *lose = ISC_TRUE; 343 1.1 christos appendString(result, "???"); 344 1.1 christos return result->content; 345 1.1 christos } 346 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_and, 347 1.1 christos right) < 0); 348 1.1 christos if (add_parenthesis) 349 1.1 christos appendString(result, "("); 350 1.1 christos appendString(result, print_expression(right, lose)); 351 1.1 christos if (add_parenthesis) 352 1.1 christos appendString(result, ")"); 353 1.1 christos return result->content; 354 1.1 christos } 355 1.1 christos 356 1.1 christos /* or */ 357 1.1 christos if (mapContains(expr, "or")) { 358 1.1 christos struct element *arg; 359 1.1 christos struct element *left; 360 1.1 christos struct element *right; 361 1.1 christos isc_boolean_t add_parenthesis; 362 1.1 christos 363 1.1 christos appendString(result, "or "); 364 1.1 christos arg = mapGet(expr, "or"); 365 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 366 1.1 christos *lose = ISC_TRUE; 367 1.1 christos appendString(result, "???"); 368 1.1 christos return result->content; 369 1.1 christos } 370 1.1 christos left = mapGet(arg, "left"); 371 1.1 christos if (left == NULL) { 372 1.1 christos *lose = ISC_TRUE; 373 1.1 christos appendString(result, "???"); 374 1.1 christos return result->content; 375 1.1 christos } 376 1.1 christos result = allocString(); 377 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_or, 378 1.1 christos left) < 0); 379 1.1 christos if (add_parenthesis) 380 1.1 christos appendString(result, "("); 381 1.1 christos appendString(result, print_expression(left, lose)); 382 1.1 christos if (add_parenthesis) 383 1.1 christos appendString(result, ")"); 384 1.1 christos appendString(result, " or "); 385 1.1 christos right = mapGet(arg, "right"); 386 1.1 christos if (right == NULL) { 387 1.1 christos *lose = ISC_TRUE; 388 1.1 christos appendString(result, "???"); 389 1.1 christos return result->content; 390 1.1 christos } 391 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_or, 392 1.1 christos right) < 0); 393 1.1 christos if (add_parenthesis) 394 1.1 christos appendString(result, "("); 395 1.1 christos appendString(result, print_expression(right, lose)); 396 1.1 christos if (add_parenthesis) 397 1.1 christos appendString(result, ")"); 398 1.1 christos return result->content; 399 1.1 christos } 400 1.1 christos 401 1.1 christos /* not */ 402 1.1 christos if (mapContains(expr, "not")) { 403 1.1 christos struct element *arg; 404 1.1 christos isc_boolean_t add_parenthesis; 405 1.1 christos 406 1.1 christos appendString(result, "not "); 407 1.1 christos arg = mapGet(expr, "not"); 408 1.1 christos if (arg == NULL) { 409 1.1 christos *lose = ISC_TRUE; 410 1.1 christos appendString(result, "???"); 411 1.1 christos return result->content; 412 1.1 christos } 413 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_not, 414 1.1 christos arg) < 0); 415 1.1 christos if (add_parenthesis) 416 1.1 christos appendString(result, "("); 417 1.1 christos appendString(result, print_expression(arg, lose)); 418 1.1 christos if (add_parenthesis) 419 1.1 christos appendString(result, ")"); 420 1.1 christos return result->content; 421 1.1 christos } 422 1.1 christos 423 1.1 christos /* known */ 424 1.1 christos if (mapContains(expr, "known")) { 425 1.1 christos return "known"; 426 1.1 christos } 427 1.1 christos 428 1.1 christos /* static */ 429 1.1 christos if (mapContains(expr, "static")) { 430 1.1 christos return "static"; 431 1.1 christos } 432 1.1 christos 433 1.1 christos /* variable-reference */ 434 1.1 christos if (mapContains(expr, "variable-reference")) { 435 1.1 christos struct element *name; 436 1.1 christos 437 1.1 christos appendString(result, "variable-reference "); 438 1.1 christos name = mapGet(expr, "variable-reference"); 439 1.1 christos if ((name == NULL) || (name->type != ELEMENT_STRING)) { 440 1.1 christos *lose = ISC_TRUE; 441 1.1 christos appendString(result, "???"); 442 1.1 christos return result->content; 443 1.1 christos } 444 1.1 christos return stringValue(name)->content; 445 1.1 christos } 446 1.1 christos 447 1.1 christos /* funcall */ 448 1.1 christos if (mapContains(expr, "funcall")) { 449 1.1 christos struct element *arg; 450 1.1 christos struct element *name; 451 1.1 christos struct element *args; 452 1.1 christos size_t i; 453 1.1 christos 454 1.1 christos appendString(result, "funcall "); 455 1.1 christos arg = mapGet(expr, "funcall"); 456 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 457 1.1 christos *lose = ISC_TRUE; 458 1.1 christos appendString(result, "???"); 459 1.1 christos return result->content; 460 1.1 christos } 461 1.1 christos name = mapGet(arg, "name"); 462 1.1 christos if ((name == NULL) || (name->type != ELEMENT_STRING)) { 463 1.1 christos *lose = ISC_TRUE; 464 1.1 christos appendString(result, "???"); 465 1.1 christos return result->content; 466 1.1 christos } 467 1.1 christos result = allocString(); 468 1.1 christos concatString(result, stringValue(name)); 469 1.1 christos appendString(result, "("); 470 1.1 christos args = mapGet(arg, "arguments"); 471 1.1 christos if ((args == NULL) || (args->type != ELEMENT_LIST)) { 472 1.1 christos *lose = ISC_TRUE; 473 1.1 christos appendString(result, "???" ")"); 474 1.1 christos return result->content; 475 1.1 christos } 476 1.1 christos for (i = 0; i < listSize(args); i++) { 477 1.1 christos struct element *item; 478 1.1 christos 479 1.1 christos if (i != 0) 480 1.1 christos appendString(result, ", "); 481 1.1 christos item = listGet(args, i); 482 1.1 christos if (item == NULL) { 483 1.1 christos debug("funcall null argument %u", 484 1.1 christos (unsigned)i); 485 1.1 christos *lose = ISC_TRUE; 486 1.1 christos appendString(result, "???"); 487 1.1 christos continue; 488 1.1 christos } 489 1.1 christos appendString(result, print_expression(item, lose)); 490 1.1 christos } 491 1.1 christos appendString(result, ")"); 492 1.1 christos return result->content; 493 1.1 christos } 494 1.1 christos 495 1.1 christos *lose = ISC_TRUE; 496 1.1 christos appendString(result, "???"); 497 1.1 christos return result->content; 498 1.1 christos } 499 1.1 christos 500 1.1 christos const char * 501 1.1 christos print_data_expression(struct element *expr, isc_boolean_t *lose) 502 1.1 christos { 503 1.1 christos struct string *result; 504 1.1 christos 505 1.1 christos if (expr->type == ELEMENT_STRING) 506 1.1 christos return quote(stringValue(expr))->content; 507 1.1 christos 508 1.1 christos /* 509 1.1 christos * From is_data_expression 510 1.1 christos */ 511 1.1 christos if (expr->type != ELEMENT_MAP) { 512 1.1 christos *lose = ISC_TRUE; 513 1.1 christos return "???"; 514 1.1 christos } 515 1.1 christos result = allocString(); 516 1.1 christos 517 1.1 christos /* substring */ 518 1.1 christos if (mapContains(expr, "substring")) { 519 1.1 christos struct element *arg; 520 1.1 christos struct element *string; 521 1.1 christos struct element *offset; 522 1.1 christos struct element *length; 523 1.1 christos 524 1.1 christos appendString(result, "substring("); 525 1.1 christos arg = mapGet(expr, "substring"); 526 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 527 1.1 christos *lose = ISC_TRUE; 528 1.1 christos appendString(result, "???" ")"); 529 1.1 christos return result->content; 530 1.1 christos } 531 1.1 christos string = mapGet(arg, "expression"); 532 1.1 christos if (string == NULL) { 533 1.1 christos *lose = ISC_TRUE; 534 1.1 christos appendString(result, "???" ")"); 535 1.1 christos return result->content; 536 1.1 christos } 537 1.1 christos appendString(result, print_data_expression(string, lose)); 538 1.1 christos appendString(result, ", "); 539 1.1 christos offset = mapGet(arg, "offset"); 540 1.1 christos if (offset == NULL) { 541 1.1 christos *lose = ISC_TRUE; 542 1.1 christos appendString(result, "???" ")"); 543 1.1 christos return result->content; 544 1.1 christos } 545 1.1 christos appendString(result, print_numeric_expression(offset, lose)); 546 1.1 christos appendString(result, ", "); 547 1.1 christos length = mapGet(arg, "length"); 548 1.1 christos if (length == NULL) { 549 1.1 christos *lose = ISC_TRUE; 550 1.1 christos appendString(result, "???" ")"); 551 1.1 christos return result->content; 552 1.1 christos } 553 1.1 christos appendString(result, print_numeric_expression(length, lose)); 554 1.1 christos appendString(result, ")"); 555 1.1 christos return result->content; 556 1.1 christos } 557 1.1 christos 558 1.1 christos /* suffix */ 559 1.1 christos if (mapContains(expr, "suffix")) { 560 1.1 christos struct element *arg; 561 1.1 christos struct element *string; 562 1.1 christos struct element *length; 563 1.1 christos 564 1.1 christos appendString(result, "suffix("); 565 1.1 christos arg = mapGet(expr, "suffix"); 566 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 567 1.1 christos *lose = ISC_TRUE; 568 1.1 christos appendString(result, "???" ")"); 569 1.1 christos return result->content; 570 1.1 christos } 571 1.1 christos string = mapGet(arg, "expression"); 572 1.1 christos if (string == NULL) { 573 1.1 christos *lose = ISC_TRUE; 574 1.1 christos appendString(result, "???" ")"); 575 1.1 christos return result->content; 576 1.1 christos } 577 1.1 christos appendString(result, print_data_expression(string, lose)); 578 1.1 christos appendString(result, ", "); 579 1.1 christos length = mapGet(arg, "length"); 580 1.1 christos if (length == NULL) { 581 1.1 christos *lose = ISC_TRUE; 582 1.1 christos appendString(result, "???" ")"); 583 1.1 christos return result->content; 584 1.1 christos } 585 1.1 christos appendString(result, print_numeric_expression(length, lose)); 586 1.1 christos appendString(result, ")"); 587 1.1 christos return result->content; 588 1.1 christos } 589 1.1 christos 590 1.1 christos /* lowercase */ 591 1.1 christos if (mapContains(expr, "lowercase")) { 592 1.1 christos struct element *arg; 593 1.1 christos 594 1.1 christos appendString(result, "lowercase("); 595 1.1 christos arg = mapGet(expr, "lowercase"); 596 1.1 christos if (arg == NULL) { 597 1.1 christos *lose = ISC_TRUE; 598 1.1 christos appendString(result, "???" ")"); 599 1.1 christos return result->content; 600 1.1 christos } 601 1.1 christos appendString(result, print_data_expression(arg, lose)); 602 1.1 christos appendString(result, ")"); 603 1.1 christos return result->content; 604 1.1 christos } 605 1.1 christos 606 1.1 christos /* uppercase */ 607 1.1 christos if (mapContains(expr, "uppercase")) { 608 1.1 christos struct element *arg; 609 1.1 christos 610 1.1 christos appendString(result, "uppercase("); 611 1.1 christos arg = mapGet(expr, "uppercase"); 612 1.1 christos if (arg == NULL) { 613 1.1 christos *lose = ISC_TRUE; 614 1.1 christos appendString(result, "???" ")"); 615 1.1 christos return result->content; 616 1.1 christos } 617 1.1 christos appendString(result, print_data_expression(arg, lose)); 618 1.1 christos appendString(result, ")"); 619 1.1 christos return result->content; 620 1.1 christos } 621 1.1 christos 622 1.1 christos /* option */ 623 1.1 christos if (mapContains(expr, "option")) { 624 1.1 christos struct element *arg; 625 1.1 christos struct element *universe; 626 1.1 christos struct element *name; 627 1.1 christos 628 1.1 christos appendString(result, "option "); 629 1.1 christos arg = mapGet(expr, "option"); 630 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 631 1.1 christos *lose = ISC_TRUE; 632 1.1 christos appendString(result, "???"); 633 1.1 christos return result->content; 634 1.1 christos } 635 1.1 christos universe = mapGet(arg, "universe"); 636 1.1 christos if ((universe == NULL) || (universe->type != ELEMENT_STRING)) { 637 1.1 christos *lose = ISC_TRUE; 638 1.1 christos appendString(result, "???"); 639 1.1 christos return result->content; 640 1.1 christos } 641 1.1 christos concatString(result, stringValue(universe)); 642 1.1 christos appendString(result, "."); 643 1.1 christos name = mapGet(arg, "name"); 644 1.1 christos if ((name == NULL) || (name->type != ELEMENT_STRING)) { 645 1.1 christos *lose = ISC_TRUE; 646 1.1 christos appendString(result, "???"); 647 1.1 christos return result->content; 648 1.1 christos } 649 1.1 christos concatString(result, stringValue(name)); 650 1.1 christos return result->content; 651 1.1 christos } 652 1.1 christos 653 1.1 christos /* hardware */ 654 1.1 christos if (mapContains(expr, "hardware")) 655 1.1 christos return "hardware"; 656 1.1 christos 657 1.1 christos /* hw-type */ 658 1.1 christos if (mapContains(expr, "hw-type")) 659 1.1 christos return "hw-type"; 660 1.1 christos 661 1.1 christos /* hw-address */ 662 1.1 christos if (mapContains(expr, "hw-address")) 663 1.1 christos return "hw-address"; 664 1.1 christos 665 1.1 christos /* const-data */ 666 1.1 christos if (mapContains(expr, "const-data")) { 667 1.1 christos struct element *arg; 668 1.1 christos 669 1.1 christos arg = mapGet(expr, "const-data"); 670 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_STRING)) { 671 1.1 christos *lose = ISC_TRUE; 672 1.1 christos appendString(result, "???"); 673 1.1 christos return result->content; 674 1.1 christos } 675 1.1 christos concatString(result, stringValue(arg)); 676 1.1 christos return result->content; 677 1.1 christos } 678 1.1 christos 679 1.1 christos /* packet */ 680 1.1 christos if (mapContains(expr, "packet")) { 681 1.1 christos struct element *arg; 682 1.1 christos struct element *offset; 683 1.1 christos struct element *length; 684 1.1 christos 685 1.1 christos appendString(result, "packet("); 686 1.1 christos arg = mapGet(expr, "packet"); 687 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 688 1.1 christos *lose = ISC_TRUE; 689 1.1 christos appendString(result, "???" ")"); 690 1.1 christos return result->content; 691 1.1 christos } 692 1.1 christos offset = mapGet(arg, "offset"); 693 1.1 christos if (offset == NULL) { 694 1.1 christos *lose = ISC_TRUE; 695 1.1 christos appendString(result, "???" ")"); 696 1.1 christos return result->content; 697 1.1 christos } 698 1.1 christos appendString(result, print_numeric_expression(offset, lose)); 699 1.1 christos appendString(result, ", "); 700 1.1 christos length = mapGet(arg, "length"); 701 1.1 christos if (length == NULL) { 702 1.1 christos *lose = ISC_TRUE; 703 1.1 christos appendString(result, "???" ")"); 704 1.1 christos return result->content; 705 1.1 christos } 706 1.1 christos appendString(result, print_numeric_expression(length, lose)); 707 1.1 christos appendString(result, ")"); 708 1.1 christos return result->content; 709 1.1 christos } 710 1.1 christos 711 1.1 christos /* concat */ 712 1.1 christos if (mapContains(expr, "concat")) { 713 1.1 christos struct element *arg; 714 1.1 christos struct element *left; 715 1.1 christos struct element *right; 716 1.1 christos 717 1.1 christos appendString(result, "concat("); 718 1.1 christos arg = mapGet(expr, "concat"); 719 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 720 1.1 christos *lose = ISC_TRUE; 721 1.1 christos appendString(result, "???" ")"); 722 1.1 christos return result->content; 723 1.1 christos } 724 1.1 christos left = mapGet(arg, "left"); 725 1.1 christos if (left == NULL) { 726 1.1 christos *lose = ISC_TRUE; 727 1.1 christos appendString(result, "???" ")"); 728 1.1 christos return result->content; 729 1.1 christos } 730 1.1 christos appendString(result, print_data_expression(left, lose)); 731 1.1 christos appendString(result, ", "); 732 1.1 christos right = mapGet(arg, "right"); 733 1.1 christos if (right == NULL) { 734 1.1 christos *lose = ISC_TRUE; 735 1.1 christos appendString(result, "???" ")"); 736 1.1 christos return result->content; 737 1.1 christos } 738 1.1 christos appendString(result, print_data_expression(right, lose)); 739 1.1 christos appendString(result, ")"); 740 1.1 christos return result->content; 741 1.1 christos } 742 1.1 christos 743 1.1 christos /* encapsulate */ 744 1.1 christos if (mapContains(expr, "encapsulate")) { 745 1.1 christos struct element *arg; 746 1.1 christos 747 1.1 christos appendString(result, "encapsulate "); 748 1.1 christos arg = mapGet(expr, "encapsulate"); 749 1.1 christos if (arg == NULL) { 750 1.1 christos *lose = ISC_TRUE; 751 1.1 christos appendString(result, "???"); 752 1.1 christos return result->content; 753 1.1 christos } 754 1.1 christos appendString(result, print_data_expression(arg, lose)); 755 1.1 christos return result->content; 756 1.1 christos } 757 1.1 christos 758 1.1 christos /* encode-int8 */ 759 1.1 christos if (mapContains(expr, "encode-int8")) { 760 1.1 christos struct element *arg; 761 1.1 christos 762 1.1 christos appendString(result, "encode-int("); 763 1.1 christos arg = mapGet(expr, "encode-int8"); 764 1.1 christos if (arg == NULL) { 765 1.1 christos *lose = ISC_TRUE; 766 1.1 christos appendString(result, "???, 8)"); 767 1.1 christos return result->content; 768 1.1 christos } 769 1.1 christos appendString(result, print_numeric_expression(arg, lose)); 770 1.1 christos appendString(result, ", 8)"); 771 1.1 christos return result->content; 772 1.1 christos } 773 1.1 christos 774 1.1 christos /* encode-int16 */ 775 1.1 christos if (mapContains(expr, "encode-int16")) { 776 1.1 christos struct element *arg; 777 1.1 christos 778 1.1 christos appendString(result, "encode-int("); 779 1.1 christos arg = mapGet(expr, "encode-int16"); 780 1.1 christos if (arg == NULL) { 781 1.1 christos *lose = ISC_TRUE; 782 1.1 christos appendString(result, "???, 16)"); 783 1.1 christos return result->content; 784 1.1 christos } 785 1.1 christos appendString(result, print_numeric_expression(arg, lose)); 786 1.1 christos appendString(result, ", 16)"); 787 1.1 christos return result->content; 788 1.1 christos } 789 1.1 christos 790 1.1 christos /* encode-int32 */ 791 1.1 christos if (mapContains(expr, "encode-int32")) { 792 1.1 christos struct element *arg; 793 1.1 christos 794 1.1 christos appendString(result, "encode-int("); 795 1.1 christos arg = mapGet(expr, "encode-int32"); 796 1.1 christos if (arg == NULL) { 797 1.1 christos *lose = ISC_TRUE; 798 1.1 christos appendString(result, "???, 32)"); 799 1.1 christos return result->content; 800 1.1 christos } 801 1.1 christos appendString(result, print_numeric_expression(arg, lose)); 802 1.1 christos appendString(result, ", 32)"); 803 1.1 christos return result->content; 804 1.1 christos } 805 1.1 christos 806 1.1 christos /* gethostbyname */ 807 1.1 christos if (mapContains(expr, "gethostbyname")) { 808 1.1 christos struct element *arg; 809 1.1 christos 810 1.1 christos appendString(result, "gethostbyname("); 811 1.1 christos arg = mapGet(expr, "gethostbyname"); 812 1.1 christos if (arg == NULL) { 813 1.1 christos *lose = ISC_TRUE; 814 1.1 christos appendString(result, "???"); 815 1.1 christos return result->content; 816 1.1 christos } 817 1.1 christos appendString(result, print_data_expression(arg, lose)); 818 1.1 christos appendString(result, ")"); 819 1.1 christos return result->content; 820 1.1 christos } 821 1.1 christos 822 1.1 christos /* binary-to-ascii */ 823 1.1 christos if (mapContains(expr, "binary-to-ascii")) { 824 1.1 christos struct element *arg; 825 1.1 christos struct element *base; 826 1.1 christos struct element *width; 827 1.1 christos struct element *separator; 828 1.1 christos struct element *buffer; 829 1.3 christos 830 1.1 christos appendString(result, "binary-to-ascii("); 831 1.1 christos arg = mapGet(expr, "binary-to-ascii"); 832 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 833 1.1 christos *lose = ISC_TRUE; 834 1.1 christos appendString(result, "???" ")"); 835 1.1 christos return result->content; 836 1.1 christos } 837 1.1 christos base = mapGet(arg, "base"); 838 1.1 christos if (base == NULL) { 839 1.1 christos *lose = ISC_TRUE; 840 1.1 christos appendString(result, "???" ")"); 841 1.1 christos return result->content; 842 1.1 christos } 843 1.1 christos appendString(result, print_numeric_expression(base, lose)); 844 1.1 christos appendString(result, ", "); 845 1.1 christos width = mapGet(arg, "width"); 846 1.1 christos if (width == NULL) { 847 1.1 christos *lose = ISC_TRUE; 848 1.1 christos appendString(result, "???" ")"); 849 1.1 christos return result->content; 850 1.1 christos } 851 1.1 christos appendString(result, print_numeric_expression(width, lose)); 852 1.1 christos appendString(result, ", "); 853 1.1 christos separator = mapGet(arg, "separator"); 854 1.1 christos if (separator == NULL) { 855 1.1 christos *lose = ISC_TRUE; 856 1.1 christos appendString(result, "???" ")"); 857 1.1 christos return result->content; 858 1.1 christos } 859 1.1 christos appendString(result, print_data_expression(separator, lose)); 860 1.1 christos appendString(result, ", "); 861 1.1 christos buffer = mapGet(arg, "buffer"); 862 1.1 christos if (buffer == NULL) { 863 1.1 christos *lose = ISC_TRUE; 864 1.1 christos appendString(result, "???" ")"); 865 1.1 christos return result->content; 866 1.1 christos } 867 1.1 christos appendString(result, print_data_expression(buffer, lose)); 868 1.1 christos appendString(result, ")"); 869 1.1 christos return result->content; 870 1.1 christos } 871 1.1 christos 872 1.1 christos /* filename */ 873 1.1 christos if (mapContains(expr, "filename")) 874 1.1 christos return "filename"; 875 1.1 christos 876 1.1 christos /* server-name */ 877 1.1 christos if (mapContains(expr, "server-name")) 878 1.1 christos return "server-name"; 879 1.1 christos 880 1.1 christos /* reverse */ 881 1.1 christos if (mapContains(expr, "reverse")) { 882 1.1 christos struct element *arg; 883 1.1 christos struct element *width; 884 1.1 christos struct element *buffer; 885 1.3 christos 886 1.1 christos appendString(result, "reverse("); 887 1.1 christos arg = mapGet(expr, "reverse"); 888 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 889 1.1 christos *lose = ISC_TRUE; 890 1.1 christos appendString(result, "???" ")"); 891 1.1 christos return result->content; 892 1.1 christos } 893 1.1 christos width = mapGet(arg, "width"); 894 1.1 christos if (width == NULL) { 895 1.1 christos *lose = ISC_TRUE; 896 1.1 christos appendString(result, "???" ")"); 897 1.1 christos return result->content; 898 1.1 christos } 899 1.1 christos appendString(result, print_numeric_expression(width, lose)); 900 1.1 christos appendString(result, ", "); 901 1.1 christos buffer = mapGet(arg, "buffer"); 902 1.1 christos if (buffer == NULL) { 903 1.1 christos *lose = ISC_TRUE; 904 1.1 christos appendString(result, "???" ")"); 905 1.1 christos return result->content; 906 1.1 christos } 907 1.1 christos appendString(result, print_data_expression(buffer, lose)); 908 1.1 christos appendString(result, ")"); 909 1.1 christos return result->content; 910 1.1 christos } 911 1.1 christos 912 1.1 christos /* pick-first-value */ 913 1.1 christos if (mapContains(expr, "pick-first-value")) { 914 1.1 christos struct element *arg; 915 1.1 christos size_t i; 916 1.1 christos 917 1.1 christos appendString(result, "pick-first-value("); 918 1.1 christos arg = mapGet(expr, "pick-first-value"); 919 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_LIST)) { 920 1.1 christos *lose = ISC_TRUE; 921 1.1 christos appendString(result, "???" ")"); 922 1.1 christos return result->content; 923 1.1 christos } 924 1.1 christos for (i = 0; i < listSize(arg); i++) { 925 1.1 christos struct element *item; 926 1.1 christos 927 1.1 christos if (i != 0) 928 1.1 christos appendString(result, ", "); 929 1.1 christos item = listGet(arg, i); 930 1.1 christos if (item == NULL) { 931 1.1 christos *lose = ISC_TRUE; 932 1.1 christos appendString(result, "???"); 933 1.1 christos continue; 934 1.1 christos } 935 1.1 christos appendString(result, 936 1.1 christos print_data_expression(item, lose)); 937 1.1 christos } 938 1.1 christos appendString(result, ")"); 939 1.1 christos return result->content; 940 1.1 christos } 941 1.1 christos 942 1.1 christos /* host-decl-name */ 943 1.1 christos if (mapContains(expr, "host-decl-name")) 944 1.1 christos return "host-decl-name"; 945 1.1 christos 946 1.1 christos /* leased-address */ 947 1.1 christos if (mapContains(expr, "leased-address")) 948 1.1 christos return "leased-address"; 949 1.1 christos 950 1.1 christos /* config-option */ 951 1.1 christos if (mapContains(expr, "config-option")) { 952 1.1 christos struct element *arg; 953 1.1 christos struct element *universe; 954 1.1 christos struct element *name; 955 1.1 christos 956 1.1 christos appendString(result, "config-option "); 957 1.1 christos arg = mapGet(expr, "config-option"); 958 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 959 1.1 christos *lose = ISC_TRUE; 960 1.1 christos appendString(result, "???"); 961 1.1 christos return result->content; 962 1.1 christos } 963 1.1 christos universe = mapGet(arg, "universe"); 964 1.1 christos if ((universe == NULL) || (universe->type != ELEMENT_STRING)) { 965 1.1 christos *lose = ISC_TRUE; 966 1.1 christos appendString(result, "???"); 967 1.1 christos return result->content; 968 1.1 christos } 969 1.1 christos concatString(result, stringValue(universe)); 970 1.1 christos appendString(result, "."); 971 1.1 christos name = mapGet(arg, "name"); 972 1.1 christos if ((name == NULL) || (name->type != ELEMENT_STRING)) { 973 1.1 christos *lose = ISC_TRUE; 974 1.1 christos appendString(result, "???"); 975 1.1 christos return result->content; 976 1.1 christos } 977 1.1 christos concatString(result, stringValue(name)); 978 1.1 christos return result->content; 979 1.1 christos } 980 1.1 christos 981 1.1 christos /* null */ 982 1.1 christos if (mapContains(expr, "null")) 983 1.1 christos return "null"; 984 1.1 christos 985 1.1 christos /* gethostname */ 986 1.1 christos if (mapContains(expr, "gethostname")) 987 1.1 christos return "gethostname"; 988 1.1 christos 989 1.1 christos /* v6relay */ 990 1.1 christos if (mapContains(expr, "v6relay")) { 991 1.1 christos struct element *arg; 992 1.1 christos struct element *relay; 993 1.1 christos struct element *option; 994 1.3 christos 995 1.1 christos 996 1.1 christos appendString(result, "v6relay("); 997 1.1 christos arg = mapGet(expr, "v6relay"); 998 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 999 1.1 christos *lose = ISC_TRUE; 1000 1.1 christos appendString(result, "???" ")"); 1001 1.1 christos return result->content; 1002 1.1 christos } 1003 1.1 christos relay = mapGet(arg, "relay"); 1004 1.1 christos if (relay == NULL) { 1005 1.1 christos *lose = ISC_TRUE; 1006 1.1 christos appendString(result, "???" ")"); 1007 1.1 christos return result->content; 1008 1.1 christos } 1009 1.1 christos appendString(result, print_numeric_expression(relay, lose)); 1010 1.1 christos appendString(result, ", "); 1011 1.1 christos option = mapGet(arg, "relay-option"); 1012 1.1 christos if (option == NULL) { 1013 1.1 christos *lose = ISC_TRUE; 1014 1.1 christos appendString(result, "???" ")"); 1015 1.1 christos return result->content; 1016 1.1 christos } 1017 1.1 christos appendString(result, print_data_expression(option, lose)); 1018 1.1 christos appendString(result, ")"); 1019 1.1 christos return result->content; 1020 1.1 christos } 1021 1.1 christos 1022 1.1 christos *lose = ISC_TRUE; 1023 1.1 christos appendString(result, "???"); 1024 1.1 christos return result->content; 1025 1.1 christos } 1026 1.1 christos 1027 1.1 christos const char * 1028 1.1 christos print_numeric_expression(struct element *expr, isc_boolean_t *lose) 1029 1.1 christos { 1030 1.1 christos struct string *result; 1031 1.1 christos 1032 1.1 christos if (expr->type == ELEMENT_INTEGER) { 1033 1.1 christos char buf[20]; 1034 1.1 christos 1035 1.1 christos snprintf(buf, sizeof(buf), "%lld", (long long)intValue(expr)); 1036 1.1 christos result = makeString(-1, buf); 1037 1.1 christos return result->content; 1038 1.1 christos } 1039 1.1 christos 1040 1.1 christos /* 1041 1.1 christos * From is_numeric_expression 1042 1.1 christos */ 1043 1.1 christos if (expr->type != ELEMENT_MAP) { 1044 1.1 christos *lose = ISC_TRUE; 1045 1.1 christos return "???"; 1046 1.1 christos } 1047 1.1 christos result = allocString(); 1048 1.1 christos 1049 1.1 christos /* extract-int8 */ 1050 1.1 christos if (mapContains(expr, "extract-int8")) { 1051 1.1 christos struct element *arg; 1052 1.1 christos 1053 1.1 christos appendString(result, "extract-int("); 1054 1.1 christos arg = mapGet(expr, "extract-int8"); 1055 1.1 christos if (arg == NULL) { 1056 1.1 christos *lose = ISC_TRUE; 1057 1.1 christos appendString(result, "???, 8)"); 1058 1.1 christos return result->content; 1059 1.1 christos } 1060 1.1 christos appendString(result, print_data_expression(arg, lose)); 1061 1.1 christos appendString(result, ", 8)"); 1062 1.1 christos return result->content; 1063 1.1 christos } 1064 1.1 christos 1065 1.1 christos /* extract-int16 */ 1066 1.1 christos if (mapContains(expr, "extract-int16")) { 1067 1.1 christos struct element *arg; 1068 1.1 christos 1069 1.1 christos appendString(result, "extract-int("); 1070 1.1 christos arg = mapGet(expr, "extract-int16"); 1071 1.1 christos if (arg == NULL) { 1072 1.1 christos *lose = ISC_TRUE; 1073 1.1 christos appendString(result, "???, 16)"); 1074 1.1 christos return result->content; 1075 1.1 christos } 1076 1.1 christos appendString(result, print_data_expression(arg, lose)); 1077 1.1 christos appendString(result, ", 16)"); 1078 1.1 christos return result->content; 1079 1.1 christos } 1080 1.1 christos 1081 1.1 christos /* extract-int32 */ 1082 1.1 christos if (mapContains(expr, "extract-int32")) { 1083 1.1 christos struct element *arg; 1084 1.1 christos 1085 1.1 christos appendString(result, "extract-int("); 1086 1.1 christos arg = mapGet(expr, "extract-int32"); 1087 1.1 christos if (arg == NULL) { 1088 1.1 christos *lose = ISC_TRUE; 1089 1.1 christos appendString(result, "???, 32)"); 1090 1.1 christos return result->content; 1091 1.1 christos } 1092 1.1 christos appendString(result, print_data_expression(arg, lose)); 1093 1.1 christos appendString(result, ", 32)"); 1094 1.1 christos return result->content; 1095 1.1 christos } 1096 1.1 christos 1097 1.1 christos /* const-int */ 1098 1.1 christos if (mapContains(expr, "const-int")) { 1099 1.1 christos struct element *arg; 1100 1.1 christos char buf[20]; 1101 1.1 christos 1102 1.1 christos arg = mapGet(expr, "const-int"); 1103 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_INTEGER)) { 1104 1.1 christos *lose = ISC_TRUE; 1105 1.1 christos appendString(result, "???"); 1106 1.1 christos return result->content; 1107 1.1 christos } 1108 1.1 christos snprintf(buf, sizeof(buf), "%lld", (long long)intValue(arg)); 1109 1.1 christos result = makeString(-1, buf); 1110 1.1 christos return result->content; 1111 1.1 christos } 1112 1.1 christos 1113 1.1 christos /* lease-time */ 1114 1.1 christos if (mapContains(expr, "lease-time")) 1115 1.1 christos return "lease-time"; 1116 1.1 christos 1117 1.1 christos /* add */ 1118 1.1 christos if (mapContains(expr, "add")) { 1119 1.1 christos struct element *arg; 1120 1.1 christos struct element *left; 1121 1.1 christos struct element *right; 1122 1.1 christos isc_boolean_t add_parenthesis; 1123 1.1 christos 1124 1.1 christos appendString(result, "add "); 1125 1.1 christos arg = mapGet(expr, "add"); 1126 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 1127 1.1 christos *lose = ISC_TRUE; 1128 1.1 christos appendString(result, "???"); 1129 1.1 christos return result->content; 1130 1.1 christos } 1131 1.1 christos left = mapGet(arg, "left"); 1132 1.1 christos if (left == NULL) { 1133 1.1 christos *lose = ISC_TRUE; 1134 1.1 christos appendString(result, "???"); 1135 1.1 christos return result->content; 1136 1.1 christos } 1137 1.1 christos result = allocString(); 1138 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_add, 1139 1.1 christos left) < 0); 1140 1.1 christos if (add_parenthesis) 1141 1.1 christos appendString(result, "("); 1142 1.1 christos appendString(result, print_expression(left, lose)); 1143 1.1 christos if (add_parenthesis) 1144 1.1 christos appendString(result, ")"); 1145 1.1 christos appendString(result, " + "); 1146 1.1 christos right = mapGet(arg, "right"); 1147 1.1 christos if (right == NULL) { 1148 1.1 christos *lose = ISC_TRUE; 1149 1.1 christos appendString(result, "???"); 1150 1.1 christos return result->content; 1151 1.1 christos } 1152 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_add, 1153 1.1 christos right) < 0); 1154 1.1 christos if (add_parenthesis) 1155 1.1 christos appendString(result, "("); 1156 1.1 christos appendString(result, print_expression(right, lose)); 1157 1.1 christos if (add_parenthesis) 1158 1.1 christos appendString(result, ")"); 1159 1.1 christos return result->content; 1160 1.1 christos } 1161 1.1 christos 1162 1.1 christos /* subtract */ 1163 1.1 christos if (mapContains(expr, "subtract")) { 1164 1.1 christos struct element *arg; 1165 1.1 christos struct element *left; 1166 1.1 christos struct element *right; 1167 1.1 christos isc_boolean_t add_parenthesis; 1168 1.1 christos 1169 1.1 christos appendString(result, "subtract "); 1170 1.1 christos arg = mapGet(expr, "subtract"); 1171 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 1172 1.1 christos *lose = ISC_TRUE; 1173 1.1 christos appendString(result, "???"); 1174 1.1 christos return result->content; 1175 1.1 christos } 1176 1.1 christos left = mapGet(arg, "left"); 1177 1.1 christos if (left == NULL) { 1178 1.1 christos *lose = ISC_TRUE; 1179 1.1 christos appendString(result, "???"); 1180 1.1 christos return result->content; 1181 1.1 christos } 1182 1.1 christos result = allocString(); 1183 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_subtract, 1184 1.1 christos left) < 0); 1185 1.1 christos if (add_parenthesis) 1186 1.1 christos appendString(result, "("); 1187 1.1 christos appendString(result, print_expression(left, lose)); 1188 1.1 christos if (add_parenthesis) 1189 1.1 christos appendString(result, ")"); 1190 1.1 christos appendString(result, " - "); 1191 1.1 christos right = mapGet(arg, "right"); 1192 1.1 christos if (right == NULL) { 1193 1.1 christos *lose = ISC_TRUE; 1194 1.1 christos appendString(result, "???"); 1195 1.1 christos return result->content; 1196 1.1 christos } 1197 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_subtract, 1198 1.1 christos right) < 0); 1199 1.1 christos if (add_parenthesis) 1200 1.1 christos appendString(result, "("); 1201 1.1 christos appendString(result, print_expression(right, lose)); 1202 1.1 christos if (add_parenthesis) 1203 1.1 christos appendString(result, ")"); 1204 1.1 christos return result->content; 1205 1.1 christos } 1206 1.1 christos 1207 1.1 christos /* multiply */ 1208 1.1 christos if (mapContains(expr, "multiply")) { 1209 1.1 christos struct element *arg; 1210 1.1 christos struct element *left; 1211 1.1 christos struct element *right; 1212 1.1 christos isc_boolean_t add_parenthesis; 1213 1.1 christos 1214 1.1 christos appendString(result, "multiply "); 1215 1.1 christos arg = mapGet(expr, "multiply"); 1216 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 1217 1.1 christos *lose = ISC_TRUE; 1218 1.1 christos appendString(result, "???"); 1219 1.1 christos return result->content; 1220 1.1 christos } 1221 1.1 christos left = mapGet(arg, "left"); 1222 1.1 christos if (left == NULL) { 1223 1.1 christos *lose = ISC_TRUE; 1224 1.1 christos appendString(result, "???"); 1225 1.1 christos return result->content; 1226 1.1 christos } 1227 1.1 christos result = allocString(); 1228 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_multiply, 1229 1.1 christos left) < 0); 1230 1.1 christos if (add_parenthesis) 1231 1.1 christos appendString(result, "("); 1232 1.1 christos appendString(result, print_expression(left, lose)); 1233 1.1 christos if (add_parenthesis) 1234 1.1 christos appendString(result, ")"); 1235 1.1 christos appendString(result, " * "); 1236 1.1 christos right = mapGet(arg, "right"); 1237 1.1 christos if (right == NULL) { 1238 1.1 christos *lose = ISC_TRUE; 1239 1.1 christos appendString(result, "???"); 1240 1.1 christos return result->content; 1241 1.1 christos } 1242 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_multiply, 1243 1.1 christos right) < 0); 1244 1.1 christos if (add_parenthesis) 1245 1.1 christos appendString(result, "("); 1246 1.1 christos appendString(result, print_expression(right, lose)); 1247 1.1 christos if (add_parenthesis) 1248 1.1 christos appendString(result, ")"); 1249 1.1 christos return result->content; 1250 1.1 christos } 1251 1.1 christos 1252 1.1 christos /* divide */ 1253 1.1 christos if (mapContains(expr, "divide")) { 1254 1.1 christos struct element *arg; 1255 1.1 christos struct element *left; 1256 1.1 christos struct element *right; 1257 1.1 christos isc_boolean_t add_parenthesis; 1258 1.1 christos 1259 1.1 christos appendString(result, "divide "); 1260 1.1 christos arg = mapGet(expr, "divide"); 1261 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 1262 1.1 christos *lose = ISC_TRUE; 1263 1.1 christos appendString(result, "???"); 1264 1.1 christos return result->content; 1265 1.1 christos } 1266 1.1 christos left = mapGet(arg, "left"); 1267 1.1 christos if (left == NULL) { 1268 1.1 christos *lose = ISC_TRUE; 1269 1.1 christos appendString(result, "???"); 1270 1.1 christos return result->content; 1271 1.1 christos } 1272 1.1 christos result = allocString(); 1273 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_divide, 1274 1.1 christos left) < 0); 1275 1.1 christos if (add_parenthesis) 1276 1.1 christos appendString(result, "("); 1277 1.1 christos appendString(result, print_expression(left, lose)); 1278 1.1 christos if (add_parenthesis) 1279 1.1 christos appendString(result, ")"); 1280 1.1 christos appendString(result, " / "); 1281 1.1 christos right = mapGet(arg, "right"); 1282 1.1 christos if (right == NULL) { 1283 1.1 christos *lose = ISC_TRUE; 1284 1.1 christos appendString(result, "???"); 1285 1.1 christos return result->content; 1286 1.1 christos } 1287 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_divide, 1288 1.1 christos right) < 0); 1289 1.1 christos if (add_parenthesis) 1290 1.1 christos appendString(result, "("); 1291 1.1 christos appendString(result, print_expression(right, lose)); 1292 1.1 christos if (add_parenthesis) 1293 1.1 christos appendString(result, ")"); 1294 1.1 christos return result->content; 1295 1.1 christos } 1296 1.1 christos 1297 1.1 christos /* remainder */ 1298 1.1 christos if (mapContains(expr, "remainder")) { 1299 1.1 christos struct element *arg; 1300 1.1 christos struct element *left; 1301 1.1 christos struct element *right; 1302 1.1 christos isc_boolean_t add_parenthesis; 1303 1.1 christos 1304 1.1 christos appendString(result, "remainder "); 1305 1.1 christos arg = mapGet(expr, "remainder"); 1306 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 1307 1.1 christos *lose = ISC_TRUE; 1308 1.1 christos appendString(result, "???"); 1309 1.1 christos return result->content; 1310 1.1 christos } 1311 1.1 christos left = mapGet(arg, "left"); 1312 1.1 christos if (left == NULL) { 1313 1.1 christos *lose = ISC_TRUE; 1314 1.1 christos appendString(result, "???"); 1315 1.1 christos return result->content; 1316 1.1 christos } 1317 1.1 christos result = allocString(); 1318 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_remainder, 1319 1.1 christos left) < 0); 1320 1.1 christos if (add_parenthesis) 1321 1.1 christos appendString(result, "("); 1322 1.1 christos appendString(result, print_expression(left, lose)); 1323 1.1 christos if (add_parenthesis) 1324 1.1 christos appendString(result, ")"); 1325 1.1 christos appendString(result, " % "); 1326 1.1 christos right = mapGet(arg, "right"); 1327 1.1 christos if (right == NULL) { 1328 1.1 christos *lose = ISC_TRUE; 1329 1.1 christos appendString(result, "???"); 1330 1.1 christos return result->content; 1331 1.1 christos } 1332 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_remainder, 1333 1.1 christos right) < 0); 1334 1.1 christos if (add_parenthesis) 1335 1.1 christos appendString(result, "("); 1336 1.1 christos appendString(result, print_expression(right, lose)); 1337 1.1 christos if (add_parenthesis) 1338 1.1 christos appendString(result, ")"); 1339 1.1 christos return result->content; 1340 1.1 christos } 1341 1.1 christos 1342 1.1 christos /* binary-and */ 1343 1.1 christos if (mapContains(expr, "binary-and")) { 1344 1.1 christos struct element *arg; 1345 1.1 christos struct element *left; 1346 1.1 christos struct element *right; 1347 1.1 christos isc_boolean_t add_parenthesis; 1348 1.1 christos 1349 1.1 christos appendString(result, "binary-and "); 1350 1.1 christos arg = mapGet(expr, "binary-and"); 1351 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 1352 1.1 christos *lose = ISC_TRUE; 1353 1.1 christos appendString(result, "???"); 1354 1.1 christos return result->content; 1355 1.1 christos } 1356 1.1 christos left = mapGet(arg, "left"); 1357 1.1 christos if (left == NULL) { 1358 1.1 christos *lose = ISC_TRUE; 1359 1.1 christos appendString(result, "???"); 1360 1.1 christos return result->content; 1361 1.1 christos } 1362 1.1 christos result = allocString(); 1363 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_binary_and, 1364 1.1 christos left) < 0); 1365 1.1 christos if (add_parenthesis) 1366 1.1 christos appendString(result, "("); 1367 1.1 christos appendString(result, print_expression(left, lose)); 1368 1.1 christos if (add_parenthesis) 1369 1.1 christos appendString(result, ")"); 1370 1.1 christos appendString(result, " & "); 1371 1.1 christos right = mapGet(arg, "right"); 1372 1.1 christos if (right == NULL) { 1373 1.1 christos *lose = ISC_TRUE; 1374 1.1 christos appendString(result, "???"); 1375 1.1 christos return result->content; 1376 1.1 christos } 1377 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_binary_and, 1378 1.1 christos right) < 0); 1379 1.1 christos if (add_parenthesis) 1380 1.1 christos appendString(result, "("); 1381 1.1 christos appendString(result, print_expression(right, lose)); 1382 1.1 christos if (add_parenthesis) 1383 1.1 christos appendString(result, ")"); 1384 1.1 christos return result->content; 1385 1.1 christos } 1386 1.1 christos 1387 1.1 christos /* binary-or */ 1388 1.1 christos if (mapContains(expr, "binary-or")) { 1389 1.1 christos struct element *arg; 1390 1.1 christos struct element *left; 1391 1.1 christos struct element *right; 1392 1.1 christos isc_boolean_t add_parenthesis; 1393 1.1 christos 1394 1.1 christos appendString(result, "binary-or "); 1395 1.1 christos arg = mapGet(expr, "binary-or"); 1396 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 1397 1.1 christos *lose = ISC_TRUE; 1398 1.1 christos appendString(result, "???"); 1399 1.1 christos return result->content; 1400 1.1 christos } 1401 1.1 christos left = mapGet(arg, "left"); 1402 1.1 christos if (left == NULL) { 1403 1.1 christos *lose = ISC_TRUE; 1404 1.1 christos appendString(result, "???"); 1405 1.1 christos return result->content; 1406 1.1 christos } 1407 1.1 christos result = allocString(); 1408 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_binary_or, 1409 1.1 christos left) < 0); 1410 1.1 christos if (add_parenthesis) 1411 1.1 christos appendString(result, "("); 1412 1.1 christos appendString(result, print_expression(left, lose)); 1413 1.1 christos if (add_parenthesis) 1414 1.1 christos appendString(result, ")"); 1415 1.1 christos appendString(result, " | "); 1416 1.1 christos right = mapGet(arg, "right"); 1417 1.1 christos if (right == NULL) { 1418 1.1 christos *lose = ISC_TRUE; 1419 1.1 christos appendString(result, "???"); 1420 1.1 christos return result->content; 1421 1.1 christos } 1422 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_binary_or, 1423 1.1 christos right) < 0); 1424 1.1 christos if (add_parenthesis) 1425 1.1 christos appendString(result, "("); 1426 1.1 christos appendString(result, print_expression(right, lose)); 1427 1.1 christos if (add_parenthesis) 1428 1.1 christos appendString(result, ")"); 1429 1.1 christos return result->content; 1430 1.1 christos } 1431 1.1 christos 1432 1.1 christos /* binary-xor */ 1433 1.1 christos if (mapContains(expr, "binary-xor")) { 1434 1.1 christos struct element *arg; 1435 1.1 christos struct element *left; 1436 1.1 christos struct element *right; 1437 1.1 christos isc_boolean_t add_parenthesis; 1438 1.1 christos 1439 1.1 christos appendString(result, "binary-xor "); 1440 1.1 christos arg = mapGet(expr, "binary-xor"); 1441 1.1 christos if ((arg == NULL) || (arg->type != ELEMENT_MAP)) { 1442 1.1 christos *lose = ISC_TRUE; 1443 1.1 christos appendString(result, "???"); 1444 1.1 christos return result->content; 1445 1.1 christos } 1446 1.1 christos left = mapGet(arg, "left"); 1447 1.1 christos if (left == NULL) { 1448 1.1 christos *lose = ISC_TRUE; 1449 1.1 christos appendString(result, "???"); 1450 1.1 christos return result->content; 1451 1.1 christos } 1452 1.1 christos result = allocString(); 1453 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_binary_xor, 1454 1.1 christos left) < 0); 1455 1.1 christos if (add_parenthesis) 1456 1.1 christos appendString(result, "("); 1457 1.1 christos appendString(result, print_expression(left, lose)); 1458 1.1 christos if (add_parenthesis) 1459 1.1 christos appendString(result, ")"); 1460 1.1 christos appendString(result, " ^ "); 1461 1.1 christos right = mapGet(arg, "right"); 1462 1.1 christos if (right == NULL) { 1463 1.1 christos *lose = ISC_TRUE; 1464 1.1 christos appendString(result, "???"); 1465 1.1 christos return result->content; 1466 1.1 christos } 1467 1.1 christos add_parenthesis = ISC_TF(expr_precedence(expr_binary_xor, 1468 1.1 christos right) < 0); 1469 1.1 christos if (add_parenthesis) 1470 1.1 christos appendString(result, "("); 1471 1.1 christos appendString(result, print_expression(right, lose)); 1472 1.1 christos if (add_parenthesis) 1473 1.1 christos appendString(result, ")"); 1474 1.1 christos return result->content; 1475 1.1 christos } 1476 1.1 christos 1477 1.1 christos /* client-state */ 1478 1.1 christos if (mapContains(expr, "client-state")) 1479 1.1 christos return "client-state"; 1480 1.1 christos 1481 1.1 christos *lose = ISC_TRUE; 1482 1.1 christos appendString(result, "???"); 1483 1.1 christos return result->content; 1484 1.1 christos } 1485 1.1 christos 1486 1.1 christos static void 1487 1.1 christos debug(const char* fmt, ...) 1488 1.1 christos { 1489 1.1 christos va_list list; 1490 1.1 christos 1491 1.1 christos va_start(list, fmt); 1492 1.1 christos vfprintf(stderr, fmt, list); 1493 1.1 christos fprintf(stderr, "\n"); 1494 1.1 christos va_end(list); 1495 1.1 christos } 1496