59 json_set_alloc_funcs(malloc_fn, free_fn);
69 json_incref((json_t *)json);
75 json_decref((json_t *) json);
80 int r = json_typeof((json_t*)json);
114 unsigned char ch = (
unsigned char) byte;
120 if (0x80 <= ch && ch <= 0xBF) {
124 }
else if (ch == 0xC0 || ch == 0xC1) {
127 }
else if (0xC2 <= ch && ch <= 0xDF) {
130 }
else if (0xE0 <= ch && ch <= 0xEF) {
133 }
else if (0xF0 <= ch && ch <= 0xF4) {
148 unsigned char ch = (
unsigned char) str[0];
152 }
else if (len == 3) {
154 }
else if (len == 4) {
160 for (pos = 1; pos <
len; ++pos) {
161 ch = (
unsigned char) str[pos];
162 if (ch < 0x80 || ch > 0xBF) {
167 value = (value << 6) + (ch & 0x3F);
170 if (value > 0x10FFFF) {
173 }
else if (0xD800 <= value && value <= 0xDFFF) {
176 }
else if ((len == 2 && value < 0x80)
177 || (len == 3 && value < 0x800)
178 || (len == 4 && value < 0x10000)) {
203 for (pos = 0; pos <
len; pos += count) {
208 }
else if (count > 1) {
209 if (count > len - pos) {
223 ast_debug(1,
"String '%.*s' is not UTF-8 for json conversion\n", (
int) len, str);
235 return (
struct ast_json *)json_true();
240 return (
struct ast_json *)json_false();
245 return (
struct ast_json *)json_boolean(value);
250 return (
struct ast_json *)json_null();
255 return json_is_true((
const json_t *)json);
260 return json_is_false((
const json_t *)json);
265 return json_is_null((
const json_t *)json);
270 return (
struct ast_json *)json_string(value);
275 return json_string_value((json_t *)
string);
280 return json_string_set((json_t *)
string, value);
287 va_start(args, format);
301 #if defined(HAVE_JANSSON_BUNDLED) || JANSSON_MAJOR_VERSION > 2 || JANSSON_MINOR_VERSION > 11 302 ret = json_vsprintf(format, args);
308 ret = json_string(str);
319 return (
struct ast_json *)json_integer(value);
324 return json_integer_value((json_t *)integer);
329 return json_integer_set((json_t *)integer, value);
334 return (
struct ast_json *)json_real(value);
339 return json_real_value((json_t *)real);
344 return json_real_set((json_t *)real, value);
349 return json_equal((json_t *)lhs, (json_t *)rhs);
354 return (
struct ast_json *)json_array();
358 return json_array_size((json_t *)array);
362 return (
struct ast_json *)json_array_get((json_t *)array, index);
366 return json_array_set_new((json_t *)array, index, (json_t *)value);
370 return json_array_append_new((json_t *)array, (json_t *)value);
374 return json_array_insert_new((json_t *)array, index, (json_t *)value);
378 return json_array_remove((json_t *)array, index);
382 return json_array_clear((json_t *)array);
386 return json_array_extend((json_t *)array, (json_t *)tail);
391 return (
struct ast_json *)json_object();
395 return json_object_size((json_t *)
object);
402 return (
struct ast_json *)json_object_get((json_t *)
object, key);
406 return json_object_set_new((json_t *)
object, key, (json_t *)value);
410 return json_object_del((json_t *)
object, key);
414 return json_object_clear((json_t *)
object);
418 return json_object_update((json_t *)
object, (json_t *)other);
422 return json_object_update_existing((json_t *)
object, (json_t *)other);
426 return json_object_update_missing((json_t *)
object, (json_t *)other);
431 return json_object_iter((json_t *)
object);
435 return json_object_iter_at((json_t *)
object, key);
439 return json_object_iter_next((json_t *)
object, iter);
443 return json_object_iter_key(iter);
447 return (
struct ast_json *)json_object_iter_value(iter);
451 return json_object_iter_set_new((json_t *)
object, iter, (json_t *)value);
460 JSON_INDENT(2) | JSON_PRESERVE_ORDER : JSON_COMPACT;
465 return json_dumps((json_t *)root,
dump_flags(format));
480 while (remaining < size + 1) {
507 if (!root || !output) {
510 return json_dumpf((json_t *)root, output,
dump_flags(format));
514 if (!root || !path) {
517 return json_dump_file((json_t *)root, path,
dump_flags(format));
525 if (error && jansson_error) {
526 error->
line = jansson_error->line;
527 error->
column = jansson_error->column;
528 error->
position = jansson_error->position;
541 strncpy(error->
text, text,
sizeof(error->
text));
542 strncpy(error->
source, source,
sizeof(error->
text));
548 json_error_t jansson_error = {};
551 r = (
struct ast_json *)json_loads(input, 0, &jansson_error);
566 json_error_t jansson_error = {};
567 struct ast_json *r = (
struct ast_json *)json_loadb(buffer, buflen, 0, &jansson_error);
573 json_error_t jansson_error = {};
576 r = (
struct ast_json *)json_loadf(input, 0, &jansson_error);
585 json_error_t jansson_error = {};
586 struct ast_json *r = (
struct ast_json *)json_load_file(path, 0, &jansson_error);
595 va_start(args, format);
605 r = (
struct ast_json *)json_vpack_ex(&error, 0, format, ap);
608 "Error building JSON from '%s': %s.\n",
618 return (
struct ast_json *)json_copy((json_t *)value);
622 return (
struct ast_json *)json_deep_copy((json_t *)value);
639 "app_name", app_name,
672 if (transport_type) {
673 char *transport_string =
NULL;
676 switch(transport_type) {
678 transport_string =
"UDP";
681 transport_string =
"TCP";
684 transport_string =
"TLS";
687 transport_string =
"WS";
690 transport_string =
"WSS";
694 if (transport_string) {
707 json_t *version_check;
715 version_check = json_pack(
"{s: o?, s: o*}",
718 if (!version_check) {
719 ast_log(
LOG_ERROR,
"There was a problem finding jansson 2.11 runtime libraries.\n" 720 "Please rebuild Asterisk using ./configure --with-jansson-bundled.\n");
724 json_decref(version_check);
751 if (!number->
valid) {
756 "plan", number->
plan,
775 if (!subaddress->
valid) {
780 "type", subaddress->
type,
790 "presentation", pres,
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
struct ast_json * ast_json_vpack(char const *format, va_list ap)
Helper for creating complex JSON values simply.
Information needed to identify an endpoint in a call.
int presentation
Q.931 encoded presentation-indicator encoded field.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
static char exten[AST_MAX_EXTENSION]
int ast_json_utf8_check_len(const char *str, size_t len)
Check the string of the given length for UTF-8 format.
struct ast_json * ast_json_object_iter_value(struct ast_json_iter *iter)
Get the value from an iterator.
char * str
Subscriber phone number (Malloced)
struct ast_json * ast_json_ref(struct ast_json *json)
Increase refcount on value.
struct ast_json * ast_json_load_str(const struct ast_str *input, struct ast_json_error *error)
Parse ast_str into a JSON object or array.
Asterisk main include file. File version handling, generic pbx functions.
static void json_payload_destructor(void *obj)
size_t ast_json_object_size(struct ast_json *object)
Get size of JSON object.
int ast_json_object_clear(struct ast_json *object)
Delete all elements from a JSON object.
int presentation
Q.931 presentation-indicator and screening-indicator encoded fields.
static struct ast_json * json_party_subaddress(struct ast_party_subaddress *subaddress)
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
void * ast_json_malloc(size_t size)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
char text[AST_JSON_ERROR_TEXT_LENGTH]
const char * ast_describe_caller_presentation(int data)
Convert caller ID pres value to explanatory string.
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Time-related functions and macros.
struct ast_party_name name
Subscriber name.
int ast_json_array_extend(struct ast_json *array, struct ast_json *tail)
Append all elements from tail to array.
Iterator for JSON object key/values.
int ast_json_array_set(struct ast_json *array, size_t index, struct ast_json *value)
Change an element in an array.
struct ast_json * ast_json_copy(const struct ast_json *value)
Copy a JSON value, but not its children.
#define ast_str_make_space(buf, new_len)
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
void ast_json_reset_alloc_funcs(void)
Change alloc funcs back to the resource module defaults.
static struct ast_json * json_party_number(struct ast_party_number *number)
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Structure for variables, used for configurations and for channel variables.
ast_json_type
Valid types of a JSON element.
int ast_json_object_iter_set(struct ast_json *object, struct ast_json_iter *iter, struct ast_json *value)
Set the value of the field pointed to by an iterator.
int ast_json_dump_file_format(struct ast_json *root, FILE *output, enum ast_json_encoding_format format)
Encode a JSON value to a FILE.
int char_set
Character set the name is using.
char * str
Subscriber name (Malloced)
#define AST_ISO8601_LEN
Max length of an null terminated, millisecond resolution, ISO8601 timestamp string.
int ast_json_is_false(const struct ast_json *json)
Check if value is JSON false.
struct ast_json * ast_json_channel_vars(struct varshead *channelvars)
Construct a JSON object from a ast_var_t list.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
unsigned char valid
TRUE if the subaddress information is valid/present.
static size_t json_utf8_check_full(const char *str, size_t len)
#define ast_str_alloca(init_len)
#define ast_vasprintf(ret, fmt, ap)
A wrapper for vasprintf()
struct ast_json * ast_json_load_file(FILE *input, struct ast_json_error *error)
Parse a FILE into JSON object or array.
char * str
Malloced subaddress string.
char * ast_json_dump_string_format(struct ast_json *root, enum ast_json_encoding_format format)
Encode a JSON value to a string.
static int input(yyscan_t yyscanner)
Socket address structure.
unsigned char odd_even_indicator
TRUE if odd number of address signals.
struct ast_json * ast_json_dialplan_cep_app(const char *context, const char *exten, int priority, const char *app_name, const char *app_data)
Construct a context/exten/priority/application/application_data as JSON.
JSON parsing error information.
struct ast_json * ast_json_null(void)
Get the JSON null value.
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
#define ast_strlen_zero(foo)
void ast_log_backtrace(void)
Log a backtrace of the current thread's execution stack to the Asterisk log.
int ast_json_array_clear(struct ast_json *array)
Remove all elements from an array.
Conversion failed because invalid value type supplied.
struct ast_json * ast_json_true(void)
Get the JSON true value.
Custom localtime functions for multiple timezones.
struct ast_json * ast_json_name_number(const char *name, const char *number)
Common JSON rendering functions for common 'objects'.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
static char * ast_sockaddr_stringify_port(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return a port only.
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
struct ast_json * ast_json_load_string(const char *input, struct ast_json_error *error)
Parse null terminated string into a JSON object or array.
#define ast_debug(level,...)
Log a DEBUG message.
General Asterisk PBX channel definitions.
Asterisk JSON abstraction layer.
#define AST_ISO8601_FORMAT
ast_strftime for ISO8601 formatting timestamps.
struct ast_json * ast_json_load_new_file(const char *path, struct ast_json_error *error)
Parse file at path into JSON object or array.
char * ast_str_append_substr(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc)
Append a non-NULL terminated substring to the end of a dynamic string.
struct ast_json * ast_json_stringf(const char *format,...)
Create a JSON string, printf style.
int ast_json_array_insert(struct ast_json *array, size_t index, struct ast_json *value)
Insert into an array.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
static void parse_error(struct ast_json_error *error, const char *text, const char *source)
#define ast_malloc(len)
A wrapper for malloc()
struct ast_json * ast_json_load_buf(const char *buffer, size_t buflen, struct ast_json_error *error)
Parse buffer with known length into a JSON object or array.
#define ast_variable_new(name, value, filename)
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
struct ast_json * ast_json_array_get(const struct ast_json *array, size_t index)
Get an element from an array.
enum ast_json_to_ast_vars_code ast_json_to_ast_variables(struct ast_json *json_variables, struct ast_variable **variables)
Convert a ast_json list of key/value pair tuples into a ast_variable list.
struct ast_variable * ast_variable_list_append_hint(struct ast_variable **head, struct ast_variable *search_hint, struct ast_variable *new_var)
Appends a variable list to the end of another list.
struct ast_json_payload * ast_json_payload_create(struct ast_json *json)
Create an ao2 object to pass json blobs as data payloads for stasis.
int ast_json_array_remove(struct ast_json *array, size_t index)
Remove an element from an array.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
const char * ast_json_object_iter_key(struct ast_json_iter *iter)
Get the key from an iterator.
static struct ast_json * json_party_name(struct ast_party_name *name)
struct ast_party_subaddress subaddress
Subscriber subaddress.
int ast_json_utf8_check(const char *str)
Check the nul terminated string for UTF-8 format.
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
void ast_json_free(void *p)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
static void copy_error(struct ast_json_error *error, const json_error_t *jansson_error)
Copy Jansson error struct to ours.
static int array(struct ast_channel *chan, const char *cmd, char *var, const char *value)
int plan
Q.931 Type-Of-Number and Numbering-Plan encoded fields.
struct ast_json * ast_json_dialplan_cep(const char *context, const char *exten, int priority)
Construct a context/exten/priority as JSON.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
enum ast_json_type ast_json_typeof(const struct ast_json *json)
Get the type of value.
void ast_json_set_alloc_funcs(void *(*malloc_fn)(size_t), void(*free_fn)(void *))
Set custom allocators instead of the standard ast_malloc() and ast_free().
const char * app_name(struct ast_app *app)
#define ao2_alloc(data_size, destructor_fn)
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
int ast_json_object_update_missing(struct ast_json *object, struct ast_json *other)
Add new fields to object with the fields of other.
int ast_json_equal(const struct ast_json *lhs, const struct ast_json *rhs)
Compare two JSON objects.
Conversion failed because of allocation failure. (Out Of Memory)
struct ast_var_t::@249 entries
int ast_sockaddr_is_ipv4_mapped(const struct ast_sockaddr *addr)
Determine if this is an IPv4-mapped IPv6 address.
int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm)
Special version of strftime(3) that handles fractions of a second. Takes the same arguments as strfti...
void ast_json_unref(struct ast_json *json)
Decrease refcount on value. If refcount reaches zero, value is freed.
int ast_json_integer_set(struct ast_json *integer, intmax_t value)
Set the value of a JSON integer.
struct ast_json * ast_json_ipaddr(const struct ast_sockaddr *addr, enum ast_transport transport_type)
Construct an IP address as JSON.
struct ast_json * ast_json_real_create(double value)
Create a JSON real number.
struct ast_json * ast_json_vstringf(const char *format, va_list args)
Create a JSON string, vprintf style.
double ast_json_real_get(const struct ast_json *real)
Get the value from a JSON real number.
struct ast_json_iter * ast_json_object_iter_next(struct ast_json *object, struct ast_json_iter *iter)
Get the next iterator.
char source[AST_JSON_ERROR_TEXT_LENGTH]
int type
Q.931 subaddress type.
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
int ast_json_string_set(struct ast_json *string, const char *value)
Change the value of a JSON string.
struct ast_json_iter * ast_json_object_iter(struct ast_json *object)
Get an iterator pointing to the first field in a JSON object.
static size_t json_utf8_check_first(char byte)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Information needed to specify a number in a call.
int ast_sockaddr_is_ipv4(const struct ast_sockaddr *addr)
Determine if the address is an IPv4 address.
struct ast_json * ast_json_deep_copy(const struct ast_json *value)
Copy a JSON value, and its children.
Abstract JSON element (object, array, string, int, ...).
const char * ast_json_typename(enum ast_json_type type)
Get the string name for the given type.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
int error(const char *format,...)
int ast_json_is_true(const struct ast_json *json)
Check if value is JSON true.
int ast_json_is_null(const struct ast_json *json)
Check if value is JSON null.
unsigned char valid
TRUE if the name information is valid/present.
static char context[AST_MAX_CONTEXT]
Information needed to specify a subaddress in a call.
static int write_to_ast_str(const char *buffer, size_t size, void *data)
struct ast_json * ast_json_false(void)
Get the JSON false value.
struct ast_json * ast_json_boolean(int value)
Get the JSON boolean corresponding to value.
int ast_json_real_set(struct ast_json *real, double value)
Set the value of a JSON real number.
int ast_json_dump_new_file_format(struct ast_json *root, const char *path, enum ast_json_encoding_format format)
Encode a JSON value to a file at the given location.
Asterisk module definitions.
static snd_pcm_format_t format
struct ast_json_iter * ast_json_object_iter_at(struct ast_json *object, const char *key)
Get an iterator pointing to a specified key in object.
int ast_json_object_update(struct ast_json *object, struct ast_json *other)
Update object with all of the fields of other.
ast_json_to_ast_vars_code
Information needed to specify a name in a call.
#define AST_JSON_UTF8_VALIDATE(str)
Check str for UTF-8 and replace with an empty string if fails the check.
int ast_json_object_update_existing(struct ast_json *object, struct ast_json *other)
Update existing fields in object with the fields of other.
int ast_json_init(void)
Initialize the JSON library.
unsigned char valid
TRUE if the number information is valid/present.
const char * ast_party_name_charset_describe(int data)
Convert ast_party_name.char_set value to explanatory string.
int ast_json_object_del(struct ast_json *object, const char *key)
Delete a field from a JSON object.
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
struct ast_json * ast_json_party_id(struct ast_party_id *party)
Construct an ast_party_id as JSON.
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
static size_t dump_flags(enum ast_json_encoding_format format)
Default flags for JSON encoding.
ast_json_encoding_format
Encoding format type.
int ast_json_dump_str_format(struct ast_json *root, struct ast_str **dst, enum ast_json_encoding_format format)
Encode a JSON value to an ast_str.
struct ast_party_number number
Subscriber phone number.