| 1 | /* |
| 2 | * Copyright (c) 2013-2022 Joris Vink <[email protected]> |
| 3 | * |
| 4 | * Permission to use, copy, modify, and distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include <sys/types.h> |
| 18 | |
| 19 | #include "kore.h"cxx . . $ `<file>/include/kore/kore.h`/ |
| 20 | |
| 21 | TAILQ_HEADcxx . . $ `<external>/2546723208511035544/queue.h:372:9`!(, kore_validator) validatorscxx . . $ validators.; |
| 22 | |
| 23 | void |
| 24 | kore_validator_initcxx . . $ kore_validator_init(49f6e7a06ebc5aa8).(void) |
| 25 | { |
| 26 | TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&validators); |
| 27 | } |
| 28 | |
| 29 | int |
| 30 | kore_validator_addcxx . . $ kore_validator_add(6ab9682c6b532ad5).(const char *name, u_int8_tcxx . . $ u_int8_t# type, const char *arg) |
| 31 | { |
| 32 | int ret; |
| 33 | struct kore_validatorcxx . . $ kore_validator# *val; |
| 34 | |
| 35 | val = kore_malloccxx . . $ kore_malloc(bfcfa4d6b7f7ef64).(sizeof(*val)); |
| 36 | val->typecxx . . $ kore_validator#type. = type; |
| 37 | |
| 38 | switch (val->typecxx . . $ kore_validator#type.) { |
| 39 | case KORE_VALIDATOR_TYPE_REGEXcxx . . $ `include/kore/kore.h:487:9`!: |
| 40 | ret = regcompcxx . . $ regcomp(aa05013d3db24b3e).(&(val->rctxcxx . . $ kore_validator#rctx.), arg, REG_EXTENDEDcxx . . $ `<external>/18190116149591951179/regex.h:310:9`! | REG_NOSUBcxx . . $ `<external>/18190116149591951179/regex.h:323:9`!); |
| 41 | if (ret) { |
| 42 | kore_freecxx . . $ kore_free(5d22bdacc48458e8).(val); |
| 43 | kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_NOTICEcxx . . $ `<external>/6168640806541382331/syslog.h:56:9`!, |
| 44 | "validator %s has bad regex %s (%d)", |
| 45 | name, arg, ret); |
| 46 | return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!); |
| 47 | } |
| 48 | break; |
| 49 | case KORE_VALIDATOR_TYPE_FUNCTIONcxx . . $ `include/kore/kore.h:488:9`!: |
| 50 | val->rcallcxx . . $ kore_validator#rcall. = kore_runtime_getcallcxx . . $ kore_runtime_getcall(b514b5951ac4d62f).(arg); |
| 51 | if (val->rcallcxx . . $ kore_validator#rcall. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 52 | kore_freecxx . . $ kore_free(5d22bdacc48458e8).(val); |
| 53 | kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_NOTICEcxx . . $ `<external>/6168640806541382331/syslog.h:56:9`!, |
| 54 | "validator %s has undefined callback %s", |
| 55 | name, arg); |
| 56 | return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!); |
| 57 | } |
| 58 | break; |
| 59 | default: |
| 60 | kore_freecxx . . $ kore_free(5d22bdacc48458e8).(val); |
| 61 | return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!); |
| 62 | } |
| 63 | |
| 64 | val->argcxx . . $ kore_validator#arg. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(arg); |
| 65 | val->namecxx . . $ kore_validator#name. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(name); |
| 66 | TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&validators, val, list); |
| 67 | |
| 68 | return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!); |
| 69 | } |
| 70 | |
| 71 | int |
| 72 | kore_validator_runcxx . . $ kore_validator_run(5489bcf6244fd69e).(struct http_requestcxx . . $ http_request# *req, const char *name, char *data) |
| 73 | { |
| 74 | struct kore_validatorcxx . . $ kore_validator# *val; |
| 75 | |
| 76 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(val, &validators, list) { |
| 77 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(val->namecxx . . $ kore_validator#name., name)) |
| 78 | continue; |
| 79 | |
| 80 | return (kore_validator_checkcxx . . $ kore_validator_check(a50dfed4c9bd2b00).(req, val, data)); |
| 81 | } |
| 82 | |
| 83 | return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!); |
| 84 | } |
| 85 | |
| 86 | int |
| 87 | kore_validator_checkcxx . . $ kore_validator_check(a50dfed4c9bd2b00).(struct http_requestcxx . . $ http_request# *req, struct kore_validatorcxx . . $ kore_validator# *val, |
| 88 | const void *data) |
| 89 | { |
| 90 | int r; |
| 91 | |
| 92 | switch (val->typecxx . . $ kore_validator#type.) { |
| 93 | case KORE_VALIDATOR_TYPE_REGEXcxx . . $ `include/kore/kore.h:487:9`!: |
| 94 | if (!regexeccxx . . $ regexec(7b724a18a85d26ac).(&(val->rctxcxx . . $ kore_validator#rctx.), data, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0)) |
| 95 | r = KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!; |
| 96 | else |
| 97 | r = KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!; |
| 98 | break; |
| 99 | case KORE_VALIDATOR_TYPE_FUNCTIONcxx . . $ `include/kore/kore.h:488:9`!: |
| 100 | r = kore_runtime_validatorcxx . . $ kore_runtime_validator(4393986cf857ca4).(val->rcallcxx . . $ kore_validator#rcall., req, data); |
| 101 | break; |
| 102 | default: |
| 103 | r = KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!; |
| 104 | kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_NOTICEcxx . . $ `<external>/6168640806541382331/syslog.h:56:9`!, "invalid type %d for validator %s", |
| 105 | val->typecxx . . $ kore_validator#type., val->namecxx . . $ kore_validator#name.); |
| 106 | break; |
| 107 | } |
| 108 | |
| 109 | return (r); |
| 110 | } |
| 111 | |
| 112 | void |
| 113 | kore_validator_reloadcxx . . $ kore_validator_reload(49f6e7a06ebc5aa8).(void) |
| 114 | { |
| 115 | struct kore_validatorcxx . . $ kore_validator# *val; |
| 116 | |
| 117 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(val, &validators, list) { |
| 118 | if (val->typecxx . . $ kore_validator#type. != KORE_VALIDATOR_TYPE_FUNCTIONcxx . . $ `include/kore/kore.h:488:9`!) |
| 119 | continue; |
| 120 | |
| 121 | kore_freecxx . . $ kore_free(5d22bdacc48458e8).(val->rcallcxx . . $ kore_validator#rcall.); |
| 122 | val->rcallcxx . . $ kore_validator#rcall. = kore_runtime_getcallcxx . . $ kore_runtime_getcall(b514b5951ac4d62f).(val->argcxx . . $ kore_validator#arg.); |
| 123 | if (val->rcallcxx . . $ kore_validator#rcall. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 124 | fatalcxx . . $ fatal(f6bc48f0426f26ee).("no function for validator %s found", val->argcxx . . $ kore_validator#arg.); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | struct kore_validatorcxx . . $ kore_validator# * |
| 129 | kore_validator_lookupcxx . . $ kore_validator_lookup(7aee95ef419e76b2).(const char *name) |
| 130 | { |
| 131 | struct kore_validatorcxx . . $ kore_validator# *val; |
| 132 | |
| 133 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(val, &validators, list) { |
| 134 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(val->namecxx . . $ kore_validator#name., name)) |
| 135 | return (val); |
| 136 | } |
| 137 | |
| 138 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 139 | } |