40 static regex_t date_regex;
43 #define REGEX_YMD "[0-9]{4}-[01][0-9]-[0-3][0-9]"
47 #define REGEX_HMS "[0-2][0-9]:[0-5][0-9](:[0-6][0-9](.[0-9]+)?)?"
50 #define REGEX_TZ "(Z|[-+][0-2][0-9](:?[0-5][0-9])?)"
53 #define ISO8601_PATTERN "^" REGEX_YMD "(T" REGEX_HMS REGEX_TZ ")?$"
60 ast_log(LOG_ERROR,
"Expected type %s, was NULL\n",
66 if (expected != actual) {
67 ast_log(LOG_ERROR,
"Expected type %s, was %s\n",
74 static int check_range(intmax_t minval, intmax_t maxval,
struct ast_json *json)
78 if (!check_type(json, AST_JSON_INTEGER)) {
84 if (v < minval || maxval < v) {
85 ast_log(LOG_ERROR,
"Value out of range. Expected %jd <= %jd <= %jd\n", minval, v, maxval);
93 return check_type(json, AST_JSON_NULL);
98 return check_type(json, AST_JSON_OBJECT);
104 return check_range(-128, 255, json);
115 ast_log(LOG_ERROR,
"Expected type boolean, was %s\n",
124 return check_range(-2147483648LL, 2147483647LL, json);
130 return check_type(json, AST_JSON_INTEGER);
135 return check_type(json, AST_JSON_REAL);
140 return check_type(json, AST_JSON_REAL);
145 return check_type(json, AST_JSON_STRING);
152 if (!check_type(json, AST_JSON_STRING)) {
156 ast_assert(str != NULL);
157 if (regexec(&date_regex, str, 0, NULL, 0) != 0) {
158 ast_log(LOG_ERROR,
"Date field is malformed: '%s'\n", str);
169 if (!check_type(json, AST_JSON_ARRAY)) {
178 "Array member %zu failed validation\n", i);
186 static int load_module(
void)
189 res = regcomp(&date_regex, ISO8601_PATTERN,
190 REG_EXTENDED | REG_ICASE | REG_NOSUB);
198 static int unload_module(
void)
200 regfree(&date_regex);
204 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER | AST_MODFLAG_GLOBAL_SYMBOLS,
"ARI Model validators",
205 .support_level = AST_MODULE_SUPPORT_CORE,
207 .unload = unload_module,
Asterisk main include file. File version handling, generic pbx functions.
int ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
int ast_ari_validate_long(struct ast_json *json)
Validator for native Swagger long.
ast_json_type
Valid types of a JSON element.
int ast_ari_validate_float(struct ast_json *json)
Validator for native Swagger float.
Generated file - Build validators for ARI model objects.
int ast_ari_validate_byte(struct ast_json *json)
Validator for native Swagger byte.
int ast_ari_validate_double(struct ast_json *json)
Validator for native Swagger double.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
int ast_ari_validate_date(struct ast_json *json)
Validator for native Swagger date.
int ast_ari_validate_object(struct ast_json *json)
Validator for native Swagger object.
int ast_ari_validate_int(struct ast_json *json)
Validator for native Swagger int.
int ast_ari_validate_boolean(struct ast_json *json)
Validator for native Swagger boolean.
enum ast_json_type ast_json_typeof(const struct ast_json *value)
Get the type of value.
Support for logging to various files, console and syslog Configuration in file logger.conf.
Module has failed to load, may be in an inconsistent state.
const char * ast_json_typename(enum ast_json_type type)
Get the string name for the given type.
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
Abstract JSON element (object, array, string, int, ...).
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
int ast_ari_validate_list(struct ast_json *json, int(*fn)(struct ast_json *))
Validator for a Swagger List[]/JSON array.
struct ast_json * ast_json_array_get(const struct ast_json *array, size_t index)
Get an element from an array.
int ast_ari_validate_string(struct ast_json *json)
Validator for native Swagger string.