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) {
170 if (
value > 0x10FFFF) {
173 }
else if (0xD800 <=
value &&
value <= 0xDFFF) {
176 }
else if ((
len == 2 &&
value < 0x80)
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();
250 return (
struct ast_json *)json_null();
255 return json_is_array((
const json_t *)json);
260 return json_is_object((
const json_t *)json);
265 return json_is_true((
const json_t *)json);
270 return json_is_false((
const json_t *)json);
275 return json_is_null((
const json_t *)json);
285 return json_string_value((json_t *)
string);
290 return json_string_set((json_t *)
string,
value);
297 va_start(
args, format);
311#if defined(HAVE_JANSSON_BUNDLED) || JANSSON_MAJOR_VERSION > 2 || JANSSON_MINOR_VERSION > 11
312 ret = json_vsprintf(format,
args);
318 ret = json_string(
str);
334 return json_integer_value((json_t *)
integer);
349 return json_real_value((json_t *)
real);
354 return json_real_set((json_t *)
real,
value);
359 return json_equal((json_t *)lhs, (json_t *)rhs);
364 return (
struct ast_json *)json_array();
368 return json_array_size((json_t *)
array);
372 return (
struct ast_json *)json_array_get((json_t *)
array, index);
376 return json_array_set_new((json_t *)
array, index, (json_t *)
value);
380 return json_array_append_new((json_t *)
array, (json_t *)
value);
384 return json_array_insert_new((json_t *)
array, index, (json_t *)
value);
388 return json_array_remove((json_t *)
array, index);
392 return json_array_clear((json_t *)
array);
396 return json_array_extend((json_t *)
array, (json_t *)tail);
401 return (
struct ast_json *)json_object();
405 return json_object_size((json_t *)
object);
412 return (
struct ast_json *)json_object_get((json_t *)
object, key);
416 return json_object_set_new((json_t *)
object, key, (json_t *)
value);
420 return json_object_del((json_t *)
object, key);
424 return json_object_clear((json_t *)
object);
428 return json_object_update((json_t *)
object, (json_t *)other);
432 return json_object_update_existing((json_t *)
object, (json_t *)other);
436 return json_object_update_missing((json_t *)
object, (json_t *)other);
441 return json_object_iter((json_t *)
object);
445 return json_object_iter_at((json_t *)
object, key);
449 return json_object_iter_next((json_t *)
object, iter);
453 return json_object_iter_key(iter);
457 return (
struct ast_json *)json_object_iter_value(iter);
461 return json_object_iter_set_new((json_t *)
object, iter, (json_t *)
value);
469 size_t jansson_dump_flags;
472 jansson_dump_flags = JSON_INDENT(2);
474 jansson_dump_flags = JSON_COMPACT;
478 jansson_dump_flags |= JSON_SORT_KEYS;
481 return jansson_dump_flags;
486 return json_dumps((json_t *)root,
dump_flags(format));
501 while (remaining < size + 1) {
528 if (!root || !output) {
531 return json_dumpf((json_t *)root, output,
dump_flags(format));
535 if (!root || !path) {
538 return json_dump_file((json_t *)root, path,
dump_flags(format));
546 if (
error && jansson_error) {
547 error->line = jansson_error->line;
548 error->column = jansson_error->column;
549 error->position = jansson_error->position;
563 strncpy(
error->source, source,
sizeof(
error->text));
569 json_error_t jansson_error = {};
587 json_error_t jansson_error = {};
588 struct ast_json *r = (
struct ast_json *)json_loadb(buffer, buflen, 0, &jansson_error);
594 json_error_t jansson_error = {};
606 json_error_t jansson_error = {};
607 struct ast_json *r = (
struct ast_json *)json_load_file(path, 0, &jansson_error);
616 va_start(
args, format);
629 "Error building JSON from '%s': %s.\n",
693 if (transport_type) {
694 char *transport_string =
NULL;
697 switch(transport_type) {
699 transport_string =
"UDP";
702 transport_string =
"TCP";
705 transport_string =
"TLS";
708 transport_string =
"WS";
711 transport_string =
"WSS";
715 if (transport_string) {
728 json_t *version_check;
736 version_check = json_pack(
"{s: o?, s: o*}",
739 if (!version_check) {
740 ast_log(
LOG_ERROR,
"There was a problem finding jansson 2.11 runtime libraries.\n"
741 "Please rebuild Asterisk using ./configure --with-jansson-bundled.\n");
745 json_decref(version_check);
778 "presentation",
number->presentation,
790 "presentation",
name->presentation,
796 if (!subaddress->
valid) {
801 "type", subaddress->
type,
811 "presentation", pres,
887 for (i = variables; i; i = i->
next) {
static int input(yyscan_t yyscanner)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_vasprintf(ret, fmt, ap)
A wrapper for vasprintf()
#define ast_malloc(len)
A wrapper for malloc()
#define ao2_alloc(data_size, destructor_fn)
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
const char * ast_describe_caller_presentation(int data)
Convert caller ID pres value to explanatory string.
const char * ast_party_name_charset_describe(int data)
Convert ast_party_name.char_set value to explanatory string.
General Asterisk PBX channel definitions.
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
static int array(struct ast_channel *chan, const char *cmd, char *var, const char *value)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_variable_new(name, value, filename)
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.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
#define ast_debug(level,...)
Log a DEBUG message.
void ast_log_backtrace(void)
Log a backtrace of the current thread's execution stack to the Asterisk log.
int ast_json_array_remove(struct ast_json *array, size_t index)
Remove an element from an array.
enum ast_json_type ast_json_typeof(const struct ast_json *json)
Get the type of value.
int ast_json_object_clear(struct ast_json *object)
Delete all elements from a JSON object.
static struct ast_json * json_party_name(struct ast_party_name *name)
int ast_json_is_true(const struct ast_json *json)
Check if value is JSON true.
struct ast_json * ast_json_false(void)
Get the JSON false value.
struct ast_json * ast_json_ipaddr(const struct ast_sockaddr *addr, enum ast_transport transport_type)
Construct an IP address as JSON.
static struct ast_json * json_party_subaddress(struct ast_party_subaddress *subaddress)
struct ast_json * ast_json_object_iter_value(struct ast_json_iter *iter)
Get the value from an iterator.
struct ast_json * ast_json_dialplan_cep(const char *context, const char *exten, int priority)
Construct a context/exten/priority as JSON.
struct ast_json * ast_json_deep_copy(const struct ast_json *value)
Copy a JSON value, and its children.
int ast_json_array_clear(struct ast_json *array)
Remove all elements from an array.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
int ast_json_object_update_missing(struct ast_json *object, struct ast_json *other)
Add new fields to object with the fields of other.
struct ast_json * ast_json_null(void)
Get the JSON null value.
void ast_json_free(void *p)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
struct ast_json_iter * ast_json_object_iter_next(struct ast_json *object, struct ast_json_iter *iter)
Get the next iterator.
int ast_json_array_set(struct ast_json *array, size_t index, struct ast_json *value)
Change an element in an array.
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
void ast_json_unref(struct ast_json *json)
Decrease refcount on value. If refcount reaches zero, value is freed.
int ast_json_equal(const struct ast_json *lhs, const struct ast_json *rhs)
Compare two JSON objects.
size_t ast_json_object_size(struct ast_json *object)
Get size of JSON object.
struct ast_json * ast_json_ref(struct ast_json *json)
Increase refcount on value.
static void json_payload_destructor(void *obj)
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
int ast_json_is_false(const struct ast_json *json)
Check if value is JSON false.
struct ast_json * ast_json_array_get(const struct ast_json *array, size_t index)
Get an element from an array.
struct ast_json * ast_json_name_number(const char *name, const char *number)
Common JSON rendering functions for common 'objects'.
const char * ast_json_typename(enum ast_json_type type)
Get the string name for the given type.
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_integer_set(struct ast_json *integer, intmax_t value)
Set the value of a JSON integer.
int ast_json_is_null(const struct ast_json *json)
Check if value is JSON null.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
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_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
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.
struct ast_json * ast_json_boolean(int value)
Get the JSON boolean corresponding to value.
static size_t json_utf8_check_full(const char *str, size_t len)
static int write_to_ast_str(const char *buffer, size_t size, void *data)
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
struct ast_json * ast_json_vstringf(const char *format, va_list args)
Create a JSON string, vprintf style.
struct ast_json * ast_json_stringf(const char *format,...)
Create a JSON string, printf style.
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.
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
struct ast_json * ast_json_party_id(struct ast_party_id *party)
Construct an ast_party_id as JSON.
void * ast_json_malloc(size_t size)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
static size_t json_utf8_check_first(char byte)
void ast_json_reset_alloc_funcs(void)
Change alloc funcs back to the resource module defaults.
struct ast_json * ast_json_object_create_vars(const struct ast_variable *variables, const char *excludes)
Create a new JSON object using the given variables.
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_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.
struct ast_json * ast_json_true(void)
Get the JSON true value.
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.
static struct ast_json * json_party_number(struct ast_party_number *number)
int ast_json_object_del(struct ast_json *object, const char *key)
Delete a field from a JSON object.
struct ast_json_iter * ast_json_object_iter(struct ast_json *object)
Get an iterator pointing to the first field in a JSON object.
int ast_json_array_extend(struct ast_json *array, struct ast_json *tail)
Append all elements from tail to array.
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.
static void copy_error(struct ast_json_error *error, const json_error_t *jansson_error)
Copy Jansson error struct to ours.
int ast_json_utf8_check_len(const char *str, size_t len)
Check the string of the given length for UTF-8 format.
static void parse_error(struct ast_json_error *error, const char *text, const char *source)
int ast_json_real_set(struct ast_json *real, double value)
Set the value of a JSON real number.
struct ast_json * ast_json_load_file(FILE *input, struct ast_json_error *error)
Parse a FILE into JSON object or array.
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.
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.
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
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.
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.
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.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
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().
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.
int ast_json_init(void)
Initialize the JSON library.
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
int ast_json_is_array(const struct ast_json *json)
Check if value is JSON array.
struct ast_json * ast_json_channel_vars(struct varshead *channelvars)
Construct a JSON object from a ast_var_t list.
char * ast_json_dump_string_format(struct ast_json *root, enum ast_json_encoding_format format)
Encode a JSON value to a string.
struct ast_json * ast_json_copy(const struct ast_json *value)
Copy a JSON value, but not its children.
struct ast_json * ast_json_real_create(double value)
Create a JSON real number.
int ast_json_is_object(const struct ast_json *json)
Check if value is JSON object.
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.
int ast_json_utf8_check(const char *str)
Check the nul terminated string for UTF-8 format.
struct ast_json * ast_json_vpack(char const *format, va_list ap)
Helper for creating complex JSON values simply.
int ast_json_object_update(struct ast_json *object, struct ast_json *other)
Update object with all of the fields of other.
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
double ast_json_real_get(const struct ast_json *real)
Get the value from a JSON real number.
int ast_json_string_set(struct ast_json *string, const char *value)
Change the value of a JSON string.
static size_t dump_flags(enum ast_json_encoding_format format)
Default flags for JSON encoding.
Asterisk JSON abstraction layer.
ast_json_type
Valid types of a JSON element.
ast_json_encoding_format
Encoding format type.
#define AST_JSON_UTF8_VALIDATE(str)
Check str for UTF-8 and replace with an empty string if fails the check.
ast_json_to_ast_vars_code
@ AST_JSON_TO_AST_VARS_CODE_INVALID_TYPE
Conversion failed because invalid value type supplied.
@ AST_JSON_TO_AST_VARS_CODE_SUCCESS
Conversion successful.
@ AST_JSON_TO_AST_VARS_CODE_OOM
Conversion failed because of allocation failure. (Out Of Memory)
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Custom localtime functions for multiple timezones.
#define AST_ISO8601_LEN
Max length of an null terminated, millisecond resolution, ISO8601 timestamp string.
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
#define AST_ISO8601_FORMAT
ast_strftime for ISO8601 formatting timestamps.
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...
Asterisk module definitions.
static char * ast_sockaddr_stringify_port(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return a port only.
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
int ast_sockaddr_is_ipv4(const struct ast_sockaddr *addr)
Determine if the address is an IPv4 address.
int ast_sockaddr_is_ipv4_mapped(const struct ast_sockaddr *addr)
Determine if this is an IPv4-mapped IPv6 address.
const char * app_name(struct ast_app *app)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
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.
#define ast_str_alloca(init_len)
int ast_in_delimited_string(const char *needle, const char *haystack, char delim)
Check if there is an exact match for 'needle' between delimiters in 'haystack'.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
#define ast_str_make_space(buf, new_len)
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
JSON parsing error information.
Iterator for JSON object key/values.
Abstract JSON element (object, array, string, int, ...).
Information needed to identify an endpoint in a call.
struct ast_party_subaddress subaddress
Subscriber subaddress.
struct ast_party_name name
Subscriber name.
struct ast_party_number number
Subscriber phone number.
Information needed to specify a name in a call.
Information needed to specify a number in a call.
Information needed to specify a subaddress in a call.
unsigned char odd_even_indicator
TRUE if odd number of address signals.
unsigned char valid
TRUE if the subaddress information is valid/present.
char * str
Malloced subaddress string.
int type
Q.931 subaddress type.
Socket address structure.
Support for dynamic strings.
struct ast_var_t::@211 entries
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
Time-related functions and macros.
int error(const char *format,...)