Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures
json.h File Reference

Asterisk JSON abstraction layer. More...

#include "asterisk/netsock2.h"
Include dependency graph for json.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_json_error
 JSON parsing error information. More...
 
struct  ast_json_payload
 

Functions

struct ast_jsonast_json_boolean (int value)
 Get the JSON boolean corresponding to value. More...
 
struct ast_jsonast_json_false (void)
 Get the JSON false value. More...
 
int ast_json_is_array (const struct ast_json *value)
 Check if value is JSON array. More...
 
int ast_json_is_false (const struct ast_json *value)
 Check if value is JSON false. More...
 
int ast_json_is_null (const struct ast_json *value)
 Check if value is JSON null. More...
 
int ast_json_is_object (const struct ast_json *value)
 Check if value is JSON object. More...
 
int ast_json_is_true (const struct ast_json *value)
 Check if value is JSON true. More...
 
struct ast_jsonast_json_null (void)
 Get the JSON null value. More...
 
struct ast_jsonast_json_true (void)
 Get the JSON true value. More...
 
struct ast_jsonast_json_string_create (const char *value)
 Construct a JSON string from value. More...
 
const char * ast_json_string_get (const struct ast_json *string)
 Get the value of a JSON string. More...
 
int ast_json_string_set (struct ast_json *string, const char *value)
 Change the value of a JSON string. More...
 
struct ast_jsonast_json_stringf (const char *format,...)
 Create a JSON string, printf style. More...
 
struct ast_jsonast_json_vstringf (const char *format, va_list args)
 Create a JSON string, vprintf style. More...
 
struct ast_jsonast_json_integer_create (intmax_t value)
 Create a JSON integer. More...
 
intmax_t ast_json_integer_get (const struct ast_json *integer)
 Get the value from a JSON integer. More...
 
int ast_json_integer_set (struct ast_json *integer, intmax_t value)
 Set the value of a JSON integer. More...
 
struct ast_jsonast_json_real_create (double value)
 Create a JSON real number. More...
 
double ast_json_real_get (const struct ast_json *real)
 Get the value from a JSON real number. More...
 
int ast_json_real_set (struct ast_json *real, double value)
 Set the value of a JSON real number. More...
 
int ast_json_array_append (struct ast_json *array, struct ast_json *value)
 Append to an array. More...
 
int ast_json_array_clear (struct ast_json *array)
 Remove all elements from an array. More...
 
struct ast_jsonast_json_array_create (void)
 Create a empty JSON array. More...
 
int ast_json_array_extend (struct ast_json *array, struct ast_json *tail)
 Append all elements from tail to array. More...
 
struct ast_jsonast_json_array_get (const struct ast_json *array, size_t index)
 Get an element from an array. More...
 
int ast_json_array_insert (struct ast_json *array, size_t index, struct ast_json *value)
 Insert into an array. More...
 
int ast_json_array_remove (struct ast_json *array, size_t index)
 Remove an element from an array. More...
 
int ast_json_array_set (struct ast_json *array, size_t index, struct ast_json *value)
 Change an element in an array. More...
 
size_t ast_json_array_size (const struct ast_json *array)
 Get the size of a JSON array. More...
 
struct ast_jsonast_json_copy (const struct ast_json *value)
 Copy a JSON value, but not its children. More...
 
struct ast_jsonast_json_deep_copy (const struct ast_json *value)
 Copy a JSON value, and its children. More...
 
int ast_json_equal (const struct ast_json *lhs, const struct ast_json *rhs)
 Compare two JSON objects. More...
 
int ast_json_utf8_check (const char *str)
 Check the nul terminated string for UTF-8 format. More...
 
int ast_json_utf8_check_len (const char *str, size_t len)
 Check the string of the given length for UTF-8 format. More...
 
#define AST_JSON_UTF8_VALIDATE(str)   (ast_json_utf8_check(str) ? (str) : "")
 Check str for UTF-8 and replace with an empty string if fails the check. More...
 
int ast_json_object_clear (struct ast_json *object)
 Delete all elements from a JSON object. More...
 
struct ast_jsonast_json_object_create (void)
 Create a new JSON object. More...
 
struct ast_jsonast_json_object_create_vars (const struct ast_variable *variables, const char *excludes)
 Create a new JSON object using the given variables. More...
 
int ast_json_object_del (struct ast_json *object, const char *key)
 Delete a field from a JSON object. More...
 
struct ast_jsonast_json_object_get (struct ast_json *object, const char *key)
 Get a field from a JSON object. More...
 
#define ast_json_object_integer_get(object, key)   ast_json_integer_get(ast_json_object_get(object, key))
 Get an integer field from a JSON object. More...
 
struct ast_json_iterast_json_object_iter (struct ast_json *object)
 Get an iterator pointing to the first field in a JSON object. More...
 
struct ast_json_iterast_json_object_iter_at (struct ast_json *object, const char *key)
 Get an iterator pointing to a specified key in object. More...
 
const char * ast_json_object_iter_key (struct ast_json_iter *iter)
 Get the key from an iterator. More...
 
struct ast_json_iterast_json_object_iter_next (struct ast_json *object, struct ast_json_iter *iter)
 Get the next iterator. More...
 
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. More...
 
struct ast_jsonast_json_object_iter_value (struct ast_json_iter *iter)
 Get the value from an iterator. More...
 
#define ast_json_object_real_get(object, key)   ast_json_real_get(ast_json_object_get(object, key))
 Get a double field from a JSON object. More...
 
int ast_json_object_set (struct ast_json *object, const char *key, struct ast_json *value)
 Set a field in a JSON object. More...
 
size_t ast_json_object_size (struct ast_json *object)
 Get size of JSON object. More...
 
#define ast_json_object_string_get(object, key)   ast_json_string_get(ast_json_object_get(object, key))
 Get a string field from a JSON object. More...
 
int ast_json_object_update (struct ast_json *object, struct ast_json *other)
 Update object with all of the fields of other. More...
 
int ast_json_object_update_existing (struct ast_json *object, struct ast_json *other)
 Update existing fields in object with the fields of other. More...
 
int ast_json_object_update_missing (struct ast_json *object, struct ast_json *other)
 Add new fields to object with the fields of other. More...
 
#define ast_json_dump_file(root, output)   ast_json_dump_file_format(root, output, AST_JSON_COMPACT)
 
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. More...
 
#define ast_json_dump_new_file(root, path)   ast_json_dump_new_file_format(root, path, AST_JSON_COMPACT)
 
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. More...
 
#define ast_json_dump_str(root, dst)   ast_json_dump_str_format(root, dst, AST_JSON_COMPACT)
 
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. More...
 
#define ast_json_dump_string(root)   ast_json_dump_string_format(root, AST_JSON_COMPACT)
 Encode a JSON value to a compact string. More...
 
char * ast_json_dump_string_format (struct ast_json *root, enum ast_json_encoding_format format)
 Encode a JSON value to a string. More...
 
#define ast_json_dump_string_sorted(root)   ast_json_dump_string_format(root, AST_JSON_SORTED)
 Encode a JSON value to a string, with its keys sorted. More...
 
enum  ast_json_encoding_format { AST_JSON_COMPACT , AST_JSON_PRETTY , AST_JSON_SORTED }
 Encoding format type. More...
 
#define AST_JSON_ERROR_SOURCE_LENGTH   80
 
#define AST_JSON_ERROR_TEXT_LENGTH   160
 
struct ast_jsonast_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. More...
 
struct ast_jsonast_json_load_file (FILE *input, struct ast_json_error *error)
 Parse a FILE into JSON object or array. More...
 
struct ast_jsonast_json_load_new_file (const char *path, struct ast_json_error *error)
 Parse file at path into JSON object or array. More...
 
struct ast_jsonast_json_load_str (const struct ast_str *input, struct ast_json_error *error)
 Parse ast_str into a JSON object or array. More...
 
struct ast_jsonast_json_load_string (const char *input, struct ast_json_error *error)
 Parse null terminated string into a JSON object or array. More...
 
struct ast_jsonast_json_pack (char const *format,...)
 Helper for creating complex JSON values. More...
 
struct ast_jsonast_json_vpack (char const *format, va_list ap)
 Helper for creating complex JSON values simply. More...
 
enum  ast_json_type {
  AST_JSON_OBJECT , AST_JSON_ARRAY , AST_JSON_STRING , AST_JSON_INTEGER ,
  AST_JSON_REAL , AST_JSON_TRUE , AST_JSON_FALSE , AST_JSON_NULL
}
 Valid types of a JSON element. More...
 
const char * ast_json_typename (enum ast_json_type type)
 Get the string name for the given type. More...
 
enum ast_json_type ast_json_typeof (const struct ast_json *value)
 Get the type of value. More...
 
struct ast_jsonast_json_channel_vars (struct varshead *channelvars)
 Construct a JSON object from a ast_var_t list. More...
 
struct ast_jsonast_json_dialplan_cep (const char *context, const char *exten, int priority)
 Construct a context/exten/priority as JSON. More...
 
struct ast_jsonast_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. More...
 
struct ast_jsonast_json_ipaddr (const struct ast_sockaddr *addr, enum ast_transport transport_type)
 Construct an IP address as JSON. More...
 
struct ast_jsonast_json_name_number (const char *name, const char *number)
 Common JSON rendering functions for common 'objects'. More...
 
struct ast_jsonast_json_party_id (struct ast_party_id *party)
 Construct an ast_party_id as JSON. More...
 
struct ast_json_payloadast_json_payload_create (struct ast_json *json)
 Create an ao2 object to pass json blobs as data payloads for stasis. More...
 
struct ast_jsonast_json_timeval (const struct timeval tv, const char *zone)
 Construct a timeval as JSON. More...
 
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. More...
 
enum  ast_json_to_ast_vars_code { AST_JSON_TO_AST_VARS_CODE_SUCCESS , AST_JSON_TO_AST_VARS_CODE_INVALID_TYPE , AST_JSON_TO_AST_VARS_CODE_OOM }
 
void ast_json_free (void *p)
 Asterisk's custom JSON allocator. Exposed for use by unit tests. More...
 
int ast_json_init (void)
 Initialize the JSON library. More...
 
typedef AST_JSON_INT_T ast_json_int_t
 Primarily used to cast when packing to an "I" type. More...
 
void * ast_json_malloc (size_t size)
 Asterisk's custom JSON allocator. Exposed for use by unit tests. More...
 
struct ast_jsonast_json_ref (struct ast_json *value)
 Increase refcount on value. More...
 
void ast_json_reset_alloc_funcs (void)
 Change alloc funcs back to the resource module defaults. More...
 
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(). More...
 
void ast_json_unref (struct ast_json *value)
 Decrease refcount on value. If refcount reaches zero, value is freed. More...
 

Detailed Description

Asterisk JSON abstraction layer.

Since
12.0.0

This is a very thin wrapper around the Jansson API. For more details on it, see its docs at http://www.digip.org/jansson/doc/2.11/apiref.html.

Rather than provide the multiple ways of doing things that the Jansson API does, the Asterisk wrapper is always reference-stealing, and always NULL safe.

And by always, I mean that the reference is stolen even if the function fails. This avoids lots of conditional logic, and also avoids having to track zillions of local variables when building complex JSON objects. You can instead chain ast_json_* calls together safely and only worry about cleaning up the root object.

In the cases where you have a need to introduce intermediate objects, just wrap them with json_ref() when passing them to other ast_json_*() functions.

Example code
// Example of how to use the Asterisk JSON API
static struct ast_json *foo(void) {
int i, res;
if (!array) { return NULL; }
for (i = 0; i < 10; ++i) {
// NULL safety and object stealing means calls can
// be chained together directly.
if (res != 0) { return NULL; }
}
if (!obj) { return NULL; }
// If you already have an object reference, ast_json_ref()
// can be used inline to bump the ref before passing it along
// to a ref-stealing call
res = ast_json_object_set(obj, "foo", ast_json_ref(array));
if (!res) { return NULL; }
return obj;
}
static int array(struct ast_channel *chan, const char *cmd, char *var, const char *value)
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition: json.c:378
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
Definition: json.c:399
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
Definition: json.c:327
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:362
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:414
#define NULL
Definition: resample.c:96
Abstract JSON element (object, array, string, int, ...).
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m

Definition in file json.h.

Macro Definition Documentation

◆ ast_json_dump_file

#define ast_json_dump_file (   root,
  output 
)    ast_json_dump_file_format(root, output, AST_JSON_COMPACT)

Definition at line 852 of file json.h.

◆ ast_json_dump_new_file

#define ast_json_dump_new_file (   root,
  path 
)    ast_json_dump_new_file_format(root, path, AST_JSON_COMPACT)

Definition at line 866 of file json.h.

◆ ast_json_dump_str

#define ast_json_dump_str (   root,
  dst 
)    ast_json_dump_str_format(root, dst, AST_JSON_COMPACT)

Definition at line 836 of file json.h.

◆ ast_json_dump_string

#define ast_json_dump_string (   root)    ast_json_dump_string_format(root, AST_JSON_COMPACT)

Encode a JSON value to a compact string.

Since
12.0.0

Returned string must be freed by calling ast_json_free().

Parameters
rootJSON value.
Returns
String encoding of root.
Return values
NULLon error.

Definition at line 810 of file json.h.

◆ ast_json_dump_string_sorted

#define ast_json_dump_string_sorted (   root)    ast_json_dump_string_format(root, AST_JSON_SORTED)

Encode a JSON value to a string, with its keys sorted.

Returned string must be freed by calling ast_json_free().

Parameters
rootJSON value.
Returns
String encoding of root.
Return values
NULLon error.

Definition at line 834 of file json.h.

◆ AST_JSON_ERROR_SOURCE_LENGTH

#define AST_JSON_ERROR_SOURCE_LENGTH   80

Definition at line 881 of file json.h.

◆ AST_JSON_ERROR_TEXT_LENGTH

#define AST_JSON_ERROR_TEXT_LENGTH   160

Definition at line 880 of file json.h.

◆ ast_json_object_integer_get

#define ast_json_object_integer_get (   object,
  key 
)    ast_json_integer_get(ast_json_object_get(object, key))

Get an integer field from a JSON object.

Parameters
objectJSON object.
keyKey of integer field to look up.
Returns
Value of a JSON integer.
Return values
0if integer is not a JSON integer.

Definition at line 609 of file json.h.

◆ ast_json_object_real_get

#define ast_json_object_real_get (   object,
  key 
)    ast_json_real_get(ast_json_object_get(object, key))

Get a double field from a JSON object.

Parameters
objectJSON object.
keyKey of double field to look up.
Returns
Value of a JSON double.
Return values
0if real is not a JSON real number.

Definition at line 618 of file json.h.

◆ ast_json_object_string_get

#define ast_json_object_string_get (   object,
  key 
)    ast_json_string_get(ast_json_object_get(object, key))

Get a string field from a JSON object.

Since
16.3.0
Parameters
objectJSON object.
keyKey of string field to look up.
Returns
String value of given key.
Return values
NULLon error, or key value is not a string.

Definition at line 600 of file json.h.

◆ AST_JSON_UTF8_VALIDATE

#define AST_JSON_UTF8_VALIDATE (   str)    (ast_json_utf8_check(str) ? (str) : "")

Check str for UTF-8 and replace with an empty string if fails the check.

Note
The convenience macro is normally used with ast_json_pack() or a function wrapper that calls ast_json_vpack().

Definition at line 224 of file json.h.

Typedef Documentation

◆ ast_json_int_t

Primarily used to cast when packing to an "I" type.

Definition at line 87 of file json.h.

Enumeration Type Documentation

◆ ast_json_encoding_format

Encoding format type.

Since
12.0.0
Enumerator
AST_JSON_COMPACT 

Compact format, low human readability

AST_JSON_PRETTY 

Formatted for human readability

AST_JSON_SORTED 

Keys sorted alphabetically

Definition at line 790 of file json.h.

791{
792 /*! Compact format, low human readability */
794 /*! Formatted for human readability */
796 /*! Keys sorted alphabetically */
798};
@ AST_JSON_SORTED
Definition: json.h:797
@ AST_JSON_COMPACT
Definition: json.h:793
@ AST_JSON_PRETTY
Definition: json.h:795

◆ ast_json_to_ast_vars_code

Enumerator
AST_JSON_TO_AST_VARS_CODE_SUCCESS 

Conversion successful.

AST_JSON_TO_AST_VARS_CODE_INVALID_TYPE 

Conversion failed because invalid value type supplied.

Note
Only string values allowed.
AST_JSON_TO_AST_VARS_CODE_OOM 

Conversion failed because of allocation failure. (Out Of Memory)

Definition at line 1109 of file json.h.

1109 {
1110 /*! \brief Conversion successful */
1112 /*!
1113 * \brief Conversion failed because invalid value type supplied.
1114 * \note Only string values allowed.
1115 */
1117 /*! \brief Conversion failed because of allocation failure. (Out Of Memory) */
1119};
@ AST_JSON_TO_AST_VARS_CODE_INVALID_TYPE
Conversion failed because invalid value type supplied.
Definition: json.h:1116
@ AST_JSON_TO_AST_VARS_CODE_SUCCESS
Conversion successful.
Definition: json.h:1111
@ AST_JSON_TO_AST_VARS_CODE_OOM
Conversion failed because of allocation failure. (Out Of Memory)
Definition: json.h:1118

◆ ast_json_type

Valid types of a JSON element.

Since
12.0.0
Enumerator
AST_JSON_OBJECT 
AST_JSON_ARRAY 
AST_JSON_STRING 
AST_JSON_INTEGER 
AST_JSON_REAL 
AST_JSON_TRUE 
AST_JSON_FALSE 
AST_JSON_NULL 

Definition at line 162 of file json.h.

163{
172};
@ AST_JSON_STRING
Definition: json.h:166
@ AST_JSON_ARRAY
Definition: json.h:165
@ AST_JSON_NULL
Definition: json.h:171
@ AST_JSON_OBJECT
Definition: json.h:164
@ AST_JSON_FALSE
Definition: json.h:170
@ AST_JSON_REAL
Definition: json.h:168
@ AST_JSON_INTEGER
Definition: json.h:167
@ AST_JSON_TRUE
Definition: json.h:169

Function Documentation

◆ ast_json_array_append()

int ast_json_array_append ( struct ast_json array,
struct ast_json value 
)

Append to an array.

Since
12.0.0
Note
The array steals the value reference even if it returns error; use ast_json_ref() to safely keep a pointer to it.
Parameters
arrayJSON array to modify.
valueNew JSON value to store at the end of array.
Return values
0on success.
-1on error.

Definition at line 378 of file json.c.

379{
380 return json_array_append_new((json_t *)array, (json_t *)value);
381}
int value
Definition: syslog.c:37

References array(), and value.

Referenced by add_format_information_cb(), app_to_json(), append_json(), append_sound_cb(), ast_ari_bridges_list(), ast_ari_channels_list(), ast_ari_endpoints_list(), ast_ari_endpoints_list_by_tech(), ast_ari_recordings_list_stored(), ast_bucket_json(), ast_endpoint_snapshot_to_json(), AST_TEST_DEFINE(), conf_send_event_to_participants(), container_to_json_array(), device_to_json_cb(), generate_filenames_json(), json_array_from_list(), process_log_list(), process_module_list(), report_receive_fax_status(), return_sorcery_object(), rtcp_report_to_json(), s_to_json(), send_start_msg_snapshots(), stasis_app_device_states_to_json(), stasis_app_exec(), stasis_app_mailboxes_to_json(), test_handler(), and units_to_json().

◆ ast_json_array_clear()

int ast_json_array_clear ( struct ast_json array)

Remove all elements from an array.

Since
12.0.0
Parameters
arrayJSON array to clear.
Return values
0on success.
-1on error.

Definition at line 390 of file json.c.

391{
392 return json_array_clear((json_t *)array);
393}

References array().

Referenced by AST_TEST_DEFINE().

◆ ast_json_array_create()

struct ast_json * ast_json_array_create ( void  )

◆ ast_json_array_extend()

int ast_json_array_extend ( struct ast_json array,
struct ast_json tail 
)

Append all elements from tail to array.

Since
12.0.0

The tail argument is not changed, so ast_json_unref() it when you are done with it.

Parameters
arrayJSON array to modify.
tailJSON array with contents to append to array.
Return values
0on success.
-1on error.

Definition at line 394 of file json.c.

395{
396 return json_array_extend((json_t *)array, (json_t *)tail);
397}

References array().

Referenced by AST_TEST_DEFINE().

◆ ast_json_array_get()

struct ast_json * ast_json_array_get ( const struct ast_json array,
size_t  index 
)

◆ ast_json_array_insert()

int ast_json_array_insert ( struct ast_json array,
size_t  index,
struct ast_json value 
)

Insert into an array.

Since
12.0.0
Note
The array steals the value reference even if it returns error; use ast_json_ref() to safely keep a pointer to it.
Parameters
arrayJSON array to modify.
indexZero-based index into array.
valueNew JSON value to store in array at index.
Return values
0on success.
-1on error.

Definition at line 382 of file json.c.

383{
384 return json_array_insert_new((json_t *)array, index, (json_t *)value);
385}

References array(), and value.

Referenced by AST_TEST_DEFINE().

◆ ast_json_array_remove()

int ast_json_array_remove ( struct ast_json array,
size_t  index 
)

Remove an element from an array.

Since
12.0.0
Parameters
arrayJSON array to modify.
indexZero-based index into array.
Return values
0on success.
-1on error.

Definition at line 386 of file json.c.

387{
388 return json_array_remove((json_t *)array, index);
389}

References array().

Referenced by AST_TEST_DEFINE().

◆ ast_json_array_set()

int ast_json_array_set ( struct ast_json array,
size_t  index,
struct ast_json value 
)

Change an element in an array.

Since
12.0.0
Note
The array steals the value reference even if it returns error; use ast_json_ref() to safely keep a pointer to it.
Parameters
arrayJSON array to modify.
indexZero-based index into array.
valueNew JSON value to store in array at index.
Return values
0on success.
-1on error.

Definition at line 374 of file json.c.

375{
376 return json_array_set_new((json_t *)array, index, (json_t *)value);
377}

References array(), and value.

Referenced by AST_TEST_DEFINE().

◆ ast_json_array_size()

size_t ast_json_array_size ( const struct ast_json array)

◆ ast_json_boolean()

struct ast_json * ast_json_boolean ( int  value)

Get the JSON boolean corresponding to value.

Since
12.0.0
Returns
JSON true if value is true (non-zero).
JSON false if value is false (zero).

Definition at line 243 of file json.c.

244{
245 return (struct ast_json *)json_boolean(value);
246}

References value.

Referenced by AST_TEST_DEFINE(), attended_transfer_to_json(), and blind_transfer_to_json().

◆ ast_json_channel_vars()

struct ast_json * ast_json_channel_vars ( struct varshead channelvars)

Construct a JSON object from a ast_var_t list.

Since
14.2.0
Parameters
channelvarsThe list of ast_var_t to represent as JSON
Returns
JSON object with variable names as keys and variable values as values

Definition at line 864 of file json.c.

865{
866 struct ast_json *ret;
867 struct ast_var_t *var;
868
870 AST_LIST_TRAVERSE(channelvars, var, entries) {
872 }
873
874 return ret;
875}
#define var
Definition: ast_expr2f.c:605
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:278
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
Definition: json.c:399
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:414
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
struct ast_var_t::@211 entries

References ast_json_object_create(), ast_json_object_set(), ast_json_string_create(), AST_LIST_TRAVERSE, ast_var_t::entries, and var.

Referenced by ast_channel_snapshot_to_json(), external_media_audiosocket_tcp(), and external_media_rtp_udp().

◆ ast_json_copy()

struct ast_json * ast_json_copy ( const struct ast_json value)

Copy a JSON value, but not its children.

Since
12.0.0

If value is a JSON object or array, its children are shared with the returned copy.

Parameters
valueJSON value to copy.
Returns
Shallow copy of value.
Return values
NULLon error.

Definition at line 637 of file json.c.

638{
639 return (struct ast_json *)json_copy((json_t *)value);
640}

References value.

Referenced by AST_TEST_DEFINE(), channel_blob_to_json(), channel_to_json(), and test_handler().

◆ ast_json_deep_copy()

struct ast_json * ast_json_deep_copy ( const struct ast_json value)

Copy a JSON value, and its children.

Since
12.0.0

If value is a JSON object or array, they are also copied.

Parameters
valueJSON value to copy.
Returns
Deep copy of value.
Return values
NULLon error.

Definition at line 641 of file json.c.

642{
643 return (struct ast_json *)json_deep_copy((json_t *)value);
644}

References value.

Referenced by AST_TEST_DEFINE().

◆ ast_json_dialplan_cep()

struct ast_json * ast_json_dialplan_cep ( const char *  context,
const char *  exten,
int  priority 
)

Construct a context/exten/priority as JSON.

If a NULL is passed for context or exten, or -1 for priority, the fields is set to ast_json_null().

Parameters
contextContext name.
extenExtension.
priorityDialplan priority.
Returns
JSON object with context, exten and priority fields

Definition at line 665 of file json.c.

666{
667 return ast_json_dialplan_cep_app(context, exten, priority, "", "");
668}
static int priority
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.
Definition: json.c:653

References ast_json_dialplan_cep_app(), voicemailpwcheck::context, and priority.

◆ ast_json_dialplan_cep_app()

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.

If a NULL is passed for context or exten or app_name or app_data, or -1 for priority, the fields is set to ast_json_null().

Parameters
contextContext name.
extenExtension.
priorityDialplan priority.
app_nameApplication name.
app_dataApplication argument.
Returns
JSON object with context, exten and priority app_name app_data fields

Definition at line 653 of file json.c.

655{
656 return ast_json_pack("{s: s?, s: s?, s: o, s: s?, s: s?}",
657 "context", context,
658 "exten", exten,
660 "app_name", app_name,
661 "app_data", app_data
662 );
663}
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition: json.c:248
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
Definition: json.c:327
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463

References app_name(), ast_json_integer_create(), ast_json_null(), ast_json_pack(), voicemailpwcheck::context, and priority.

Referenced by ast_channel_snapshot_to_json(), ast_json_dialplan_cep(), and AST_TEST_DEFINE().

◆ ast_json_dump_file_format()

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.

Since
12.0.0
Parameters
rootJSON value.
outputFile to write JSON encoding to.
formatencoding format type.
Return values
0on success.
-1on error. The contents of output are undefined.

Definition at line 526 of file json.c.

527{
528 if (!root || !output) {
529 return -1;
530 }
531 return json_dumpf((json_t *)root, output, dump_flags(format));
532}
static size_t dump_flags(enum ast_json_encoding_format format)
Default flags for JSON encoding.
Definition: json.c:467

References dump_flags().

◆ ast_json_dump_new_file_format()

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.

Since
12.0.0
Parameters
rootJSON value.
pathPath to file to write JSON encoding to.
formatencoding format type.
Return values
0on success.
-1on error. The contents of output are undefined.

Definition at line 533 of file json.c.

534{
535 if (!root || !path) {
536 return -1;
537 }
538 return json_dump_file((json_t *)root, path, dump_flags(format));
539}

References dump_flags().

◆ ast_json_dump_str_format()

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.

Since
12.0.0

If dst is too small, it will be grown as needed.

Parameters
rootJSON value.
dstast_str to store JSON encoding.
formatencoding format type.
Return values
0on success.
-1on error. The contents of dst are undefined.

Definition at line 520 of file json.c.

521{
522 return json_dump_callback((json_t *)root, write_to_ast_str, dst, dump_flags(format));
523}
static int write_to_ast_str(const char *buffer, size_t size, void *data)
Definition: json.c:489

References dump_flags(), and write_to_ast_str().

Referenced by ast_ari_callback().

◆ ast_json_dump_string_format()

char * ast_json_dump_string_format ( struct ast_json root,
enum ast_json_encoding_format  format 
)

Encode a JSON value to a string.

Since
12.0.0

Returned string must be freed by calling ast_json_free().

Parameters
rootJSON value.
formatencoding format type.
Returns
String encoding of root.
Return values
NULLon error.

Definition at line 484 of file json.c.

485{
486 return json_dumps((json_t *)root, dump_flags(format));
487}

References dump_flags().

Referenced by ast_ari_callback(), ast_ari_websocket_session_write(), pack_payload(), send_message(), and stasis_app_message_handler().

◆ ast_json_equal()

int ast_json_equal ( const struct ast_json lhs,
const struct ast_json rhs 
)

Compare two JSON objects.

Since
12.0.0

Two JSON objects are equal if they are of the same type, and their contents are equal.

Parameters
lhsValue to compare.
rhsOther value to compare.
Return values
True(non-zero) if lhs and rhs are equal.
False(zero) if they are not.

Definition at line 357 of file json.c.

358{
359 return json_equal((json_t *)lhs, (json_t *)rhs);
360}

Referenced by AST_TEST_DEFINE(), and test_name_number().

◆ ast_json_false()

struct ast_json * ast_json_false ( void  )

Get the JSON false value.

Since
12.0.0

The returned value is a singleton, and does not need to be ast_json_unref()'ed.

Returns
JSON false.

Definition at line 238 of file json.c.

239{
240 return (struct ast_json *)json_false();
241}

Referenced by AST_TEST_DEFINE().

◆ ast_json_free()

void ast_json_free ( void *  p)

◆ ast_json_init()

int ast_json_init ( void  )

Initialize the JSON library.

Definition at line 726 of file json.c.

727{
728 json_t *version_check;
729
730 /* Setup to use Asterisk custom allocators */
732
733 /* We depend on functionality of jansson-2.11 but don't actually use
734 * any symbols. If we link at runtime to less than 2.11 this json_pack
735 * will return NULL. */
736 version_check = json_pack("{s: o?, s: o*}",
737 "JSON", NULL,
738 "Bourne", NULL);
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");
742 return -1;
743 }
744
745 json_decref(version_check);
746
747 return 0;
748}
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
void ast_json_reset_alloc_funcs(void)
Change alloc funcs back to the resource module defaults.
Definition: json.c:62

References ast_json_reset_alloc_funcs(), ast_log, LOG_ERROR, and NULL.

Referenced by asterisk_daemon().

◆ ast_json_integer_create()

struct ast_json * ast_json_integer_create ( intmax_t  value)

Create a JSON integer.

Since
12.0.0
Parameters
valueValue of the new JSON integer.
Returns
Newly allocated integer.
Return values
NULLon error.

Definition at line 327 of file json.c.

328{
329 return (struct ast_json *)json_integer(value);
330}

References value.

Referenced by alloc_security_event_json_object(), ast_ari_asterisk_get_info(), ast_endpoint_snapshot_to_json(), ast_json_dialplan_cep_app(), ast_rtp_convert_stats_json(), AST_TEST_DEFINE(), dialog_info_generate_body_content(), identify_module(), meetme_stasis_generate_msg(), pack_payload(), and stasis_app_recording_to_json().

◆ ast_json_integer_get()

intmax_t ast_json_integer_get ( const struct ast_json integer)

Get the value from a JSON integer.

Since
12.0.0
Parameters
integerJSON integer.
Returns
Value of a JSON integer.
Return values
0if integer is not a JSON integer.

Definition at line 332 of file json.c.

333{
334 return json_integer_value((json_t *)integer);
335}
INT32 integer
Definition: lpc10.h:80

Referenced by agent_logoff_to_ami(), ast_ari_bridges_play_parse_body(), ast_ari_bridges_play_with_id_parse_body(), ast_ari_bridges_record_parse_body(), ast_ari_channels_continue_in_dialplan_parse_body(), ast_ari_channels_dial_parse_body(), ast_ari_channels_originate_parse_body(), ast_ari_channels_originate_with_id_parse_body(), ast_ari_channels_play_parse_body(), ast_ari_channels_play_with_id_parse_body(), ast_ari_channels_record_parse_body(), ast_ari_channels_send_dtmf_parse_body(), ast_ari_mailboxes_update_parse_body(), AST_TEST_DEFINE(), asterisk_publication_devicestate(), asterisk_publication_mailboxstate(), cc_available_to_ami(), cc_callerrecalling_to_ami(), cc_callerstartmonitoring_to_ami(), cc_callerstopmonitoring_to_ami(), cc_failure_to_ami(), cc_monitorfailed_to_ami(), cc_offertimerstart_to_ami(), cc_recallcomplete_to_ami(), cc_requestacknowledged_to_ami(), cc_requested_to_ami(), cel_generic_cb(), channel_dtmf_end_cb(), channel_hangup_request_cb(), check_range(), dahdichannel_to_ami(), dialog_info_generate_body_content(), dtmf_end_to_json(), handle_local_optimization_begin(), handle_local_optimization_end(), local_message_to_ami(), manager_generic_msg_cb(), manager_json_value_str_append(), meetme_stasis_cb(), parse_node(), queue_agent_cb(), security_event_stasis_cb(), security_event_to_ami_blob(), and talking_stop_to_ami().

◆ ast_json_integer_set()

int ast_json_integer_set ( struct ast_json integer,
intmax_t  value 
)

Set the value of a JSON integer.

Since
12.0.0
Parameters
integerJSON integer to modify.
valueNew value for integer.
Return values
0on success.
-1on error.

Definition at line 337 of file json.c.

338{
339 return json_integer_set((json_t *)integer, value);
340}

References value.

Referenced by AST_TEST_DEFINE().

◆ ast_json_ipaddr()

struct ast_json * ast_json_ipaddr ( const struct ast_sockaddr addr,
enum ast_transport  transport_type 
)

Construct an IP address as JSON.

XXX some comments describing the need for this here

Parameters
addrast_sockaddr to encode
transport_typeast_transport to include in the address string if any. Should just be one.
Returns
JSON string containing the IP address with optional transport information
Return values
NULLon error.

Definition at line 682 of file json.c.

683{
684 struct ast_str *string = ast_str_alloca(64);
685
686 if (!string) {
687 return NULL;
688 }
689
690 ast_str_set(&string, 0, (ast_sockaddr_is_ipv4(addr) ||
691 ast_sockaddr_is_ipv4_mapped(addr)) ? "IPV4/" : "IPV6/");
692
693 if (transport_type) {
694 char *transport_string = NULL;
695
696 /* NOTE: None will be applied if multiple transport types are specified in transport_type */
697 switch(transport_type) {
699 transport_string = "UDP";
700 break;
702 transport_string = "TCP";
703 break;
705 transport_string = "TLS";
706 break;
707 case AST_TRANSPORT_WS:
708 transport_string = "WS";
709 break;
711 transport_string = "WSS";
712 break;
713 }
714
715 if (transport_string) {
716 ast_str_append(&string, 0, "%s/", transport_string);
717 }
718 }
719
720 ast_str_append(&string, 0, "%s", ast_sockaddr_stringify_addr(addr));
721 ast_str_append(&string, 0, "/%s", ast_sockaddr_stringify_port(addr));
722
724}
@ AST_TRANSPORT_WSS
Definition: netsock2.h:64
@ AST_TRANSPORT_WS
Definition: netsock2.h:63
@ AST_TRANSPORT_UDP
Definition: netsock2.h:60
@ AST_TRANSPORT_TLS
Definition: netsock2.h:62
@ AST_TRANSPORT_TCP
Definition: netsock2.h:61
static char * ast_sockaddr_stringify_port(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return a port only.
Definition: netsock2.h:358
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:286
int ast_sockaddr_is_ipv4(const struct ast_sockaddr *addr)
Determine if the address is an IPv4 address.
Definition: netsock2.c:497
int ast_sockaddr_is_ipv4_mapped(const struct ast_sockaddr *addr)
Determine if this is an IPv4-mapped IPv6 address.
Definition: netsock2.c:507
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define ast_str_alloca(init_len)
Definition: strings.h:848
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113
Support for dynamic strings.
Definition: strings.h:623

References ast_json_string_create(), ast_sockaddr_is_ipv4(), ast_sockaddr_is_ipv4_mapped(), ast_sockaddr_stringify_addr(), ast_sockaddr_stringify_port(), ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_set(), AST_TRANSPORT_TCP, AST_TRANSPORT_TLS, AST_TRANSPORT_UDP, AST_TRANSPORT_WS, AST_TRANSPORT_WSS, and NULL.

Referenced by add_ip_json_object().

◆ ast_json_is_array()

int ast_json_is_array ( const struct ast_json value)

Check if value is JSON array.

Since
12.0.0
Return values
True(non-zero) if value == ast_json_array().
False(zero) otherwise..

Definition at line 253 of file json.c.

254{
255 return json_is_array((const json_t *)json);
256}

◆ ast_json_is_false()

int ast_json_is_false ( const struct ast_json value)

Check if value is JSON false.

Since
12.0.0
Return values
True(non-zero) if value == ast_json_false().
False(zero) otherwise.

Definition at line 268 of file json.c.

269{
270 return json_is_false((const json_t *)json);
271}

Referenced by AST_TEST_DEFINE().

◆ ast_json_is_null()

int ast_json_is_null ( const struct ast_json value)

Check if value is JSON null.

Since
12.0.0
Return values
True(non-zero) if value == ast_json_false().
False(zero) otherwise.

Definition at line 273 of file json.c.

274{
275 return json_is_null((const json_t *)json);
276}

Referenced by aoc_publish_blob(), ast_ari_callback(), ast_manager_str_from_json_object(), AST_TEST_DEFINE(), and channel_blob_to_json().

◆ ast_json_is_object()

int ast_json_is_object ( const struct ast_json value)

Check if value is JSON object.

Since
12.0.0
Return values
True(non-zero) if value == ast_json_object().
False(zero) otherwise..

Definition at line 258 of file json.c.

259{
260 return json_is_object((const json_t *)json);
261}

Referenced by json_decode_read().

◆ ast_json_is_true()

int ast_json_is_true ( const struct ast_json value)

Check if value is JSON true.

Since
12.0.0
Return values
True(non-zero) if value == ast_json_true().
False(zero) otherwise..

Definition at line 263 of file json.c.

264{
265 return json_is_true((const json_t *)json);
266}

Referenced by ast_ari_bridges_add_channel_parse_body(), ast_ari_bridges_record_parse_body(), ast_ari_channels_record_parse_body(), ast_ari_endpoints_refer_parse_body(), ast_ari_endpoints_refer_to_endpoint_parse_body(), AST_TEST_DEFINE(), channel_hangup_request_cb(), channel_mixmonitor_mute_cb(), get_bool_header(), local_message_to_ami(), and parse_node().

◆ ast_json_load_buf()

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.

Since
12.0.0
Parameters
bufferBuffer to parse.
buflenLength of buffer.
[out]errorFilled with information on error.
Returns
Parsed JSON element.
Return values
NULLon error.

Definition at line 585 of file json.c.

586{
587 json_error_t jansson_error = {};
588 struct ast_json *r = (struct ast_json *)json_loadb(buffer, buflen, 0, &jansson_error);
589 copy_error(error, &jansson_error);
590 return r;
591}
static void copy_error(struct ast_json_error *error, const json_error_t *jansson_error)
Copy Jansson error struct to ours.
Definition: json.c:544
int error(const char *format,...)
Definition: utils/frame.c:999

References copy_error(), and error().

Referenced by ast_ari_websocket_session_read(), ast_http_get_json(), AST_TEST_DEFINE(), asterisk_publication_devicestate_state_change(), asterisk_publication_mwi_state_change(), message_json_deserialize(), and speech_test_server_handle_request().

◆ ast_json_load_file()

struct ast_json * ast_json_load_file ( FILE *  input,
struct ast_json_error error 
)

Parse a FILE into JSON object or array.

Since
12.0.0
Parameters
inputFILE to parse.
[out]errorFilled with information on error.
Returns
Parsed JSON element.
Return values
NULLon error.

Definition at line 592 of file json.c.

593{
594 json_error_t jansson_error = {};
595 struct ast_json *r = NULL;
596 if (input != NULL) {
597 r = (struct ast_json *)json_loadf(input, 0, &jansson_error);
598 copy_error(error, &jansson_error);
599 } else {
600 parse_error(error, "NULL input file", "<null>");
601 }
602 return r;
603}
static int input(yyscan_t yyscanner)
Definition: ast_expr2f.c:1570
static void parse_error(struct ast_json_error *error, const char *text, const char *source)
Definition: json.c:556

References copy_error(), error(), input(), NULL, and parse_error().

Referenced by AST_TEST_DEFINE().

◆ ast_json_load_new_file()

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.

Since
12.0.0
Parameters
pathPath of file to parse.
[out]errorFilled with information on error.
Returns
Parsed JSON element.
Return values
NULLon error.

Definition at line 604 of file json.c.

605{
606 json_error_t jansson_error = {};
607 struct ast_json *r = (struct ast_json *)json_load_file(path, 0, &jansson_error);
608 copy_error(error, &jansson_error);
609 return r;
610}

References copy_error(), and error().

Referenced by ast_ari_get_docs(), and AST_TEST_DEFINE().

◆ ast_json_load_str()

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.

Since
12.0.0
Parameters
inputast_str to parse.
[out]errorFilled with information on error.
Returns
Parsed JSON element.
Return values
NULLon error.

Definition at line 580 of file json.c.

581{
583}
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.
Definition: json.c:567

References ast_json_load_string(), ast_str_buffer(), error(), and input().

Referenced by AST_TEST_DEFINE(), and json_decode_read().

◆ ast_json_load_string()

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.

Since
12.0.0
Parameters
inputString to parse.
[out]errorFilled with information on error.
Returns
Parsed JSON element.
Return values
NULLon error.

Definition at line 567 of file json.c.

568{
569 json_error_t jansson_error = {};
570 struct ast_json *r = NULL;
571 if (input != NULL) {
572 r = (struct ast_json *)json_loads(input, 0, &jansson_error);
573 copy_error(error, &jansson_error);
574 } else {
575 parse_error(error, "NULL input string", "<null>");
576 }
577 return r;
578}

References copy_error(), error(), input(), NULL, and parse_error().

Referenced by ast_json_load_str(), ast_stir_shaken_vs_verify(), AST_TEST_DEFINE(), fetch_access_token(), fetch_google_access_token(), persistence_generator_data_str2struct(), sorcery_astdb_retrieve_fields_common(), sorcery_astdb_retrieve_id(), sorcery_astdb_retrieve_prefix(), and sorcery_astdb_retrieve_regex().

◆ ast_json_malloc()

void * ast_json_malloc ( size_t  size)

Asterisk's custom JSON allocator. Exposed for use by unit tests.

Since
12.0.0

Definition at line 47 of file json.c.

48{
49 return ast_malloc(size);
50}
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191

References ast_malloc.

Referenced by ast_json_reset_alloc_funcs(), and json_debug_malloc().

◆ ast_json_name_number()

struct ast_json * ast_json_name_number ( const char *  name,
const char *  number 
)

Common JSON rendering functions for common 'objects'.

Simple name/number pair.

Parameters
nameName
numberNumber
Returns
JSON object with name and number fields
Return values
NULLon error (non-UTF8 characters, NULL inputs, etc.)

Definition at line 646 of file json.c.

647{
648 return ast_json_pack("{s: s, s: s}",
650 "number", AST_JSON_UTF8_VALIDATE(number));
651}
static const char name[]
Definition: format_mp3.c:68
#define AST_JSON_UTF8_VALIDATE(str)
Check str for UTF-8 and replace with an empty string if fails the check.
Definition: json.h:224
Number structure.
Definition: app_followme.c:154

References ast_json_pack(), AST_JSON_UTF8_VALIDATE, and name.

Referenced by ast_channel_snapshot_to_json(), and test_name_number().

◆ ast_json_null()

struct ast_json * ast_json_null ( void  )

◆ ast_json_object_clear()

int ast_json_object_clear ( struct ast_json object)

Delete all elements from a JSON object.

Since
12.0.0
Parameters
objectJSON object to clear.
Return values
0on success.
-1on error.

Definition at line 422 of file json.c.

423{
424 return json_object_clear((json_t *)object);
425}

Referenced by AST_TEST_DEFINE().

◆ ast_json_object_create()

struct ast_json * ast_json_object_create ( void  )

◆ ast_json_object_create_vars()

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.

Parameters
variablesA list of Asterisk variables
excludesComma separated string of variable names to exclude (optional)
Returns
Newly allocated object.
Return values
NULLon error.

Definition at line 877 of file json.c.

878{
879 const struct ast_variable *i;
880 struct ast_json *obj;
881
883 if (!obj) {
884 return NULL;
885 }
886
887 for (i = variables; i; i = i->next) {
888 if (!excludes || !ast_in_delimited_string(i->name, excludes, ',')) {
890 }
891 }
892
893 return obj;
894}
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'.
Definition: strings.c:433
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next

References ast_in_delimited_string(), ast_json_object_create(), ast_json_object_set(), ast_json_string_create(), ast_variable::name, ast_variable::next, NULL, and ast_variable::value.

Referenced by AST_TEST_DEFINE().

◆ ast_json_object_del()

int ast_json_object_del ( struct ast_json object,
const char *  key 
)

Delete a field from a JSON object.

Since
12.0.0
Parameters
objectJSON object to modify.
keyKey of field to delete.
Return values
0on success, or -1 if key does not exist.

Definition at line 418 of file json.c.

419{
420 return json_object_del((json_t *)object, key);
421}

Referenced by ast_ari_get_docs(), AST_TEST_DEFINE(), bridge_to_json(), and channel_to_json().

◆ ast_json_object_get()

struct ast_json * ast_json_object_get ( struct ast_json object,
const char *  key 
)

Get a field from a JSON object.

Since
12.0.0

The returned element is a borrowed reference; use ast_json_ref() to safely keep a pointer to it.

Parameters
objectJSON object.
keyKey of field to look up.
Returns
Value with given key.
Return values
NULLon error.

Definition at line 407 of file json.c.

408{
409 if (!key) {
410 return NULL;
411 }
412 return (struct ast_json *)json_object_get((json_t *)object, key);
413}

References NULL.

Referenced by agent_login_to_ami(), agent_logoff_to_ami(), allocate_subscription(), app_event_filter_set(), app_send(), app_to_json(), append_event_str_single(), append_json_single(), assign_uuid(), ast_ari_applications_subscribe_parse_body(), ast_ari_applications_unsubscribe_parse_body(), ast_ari_asterisk_add_log_parse_body(), ast_ari_asterisk_get_global_var_parse_body(), ast_ari_asterisk_get_info_parse_body(), ast_ari_asterisk_set_global_var_parse_body(), ast_ari_asterisk_update_object(), ast_ari_bridges_add_channel_parse_body(), ast_ari_bridges_create_parse_body(), ast_ari_bridges_create_with_id_parse_body(), ast_ari_bridges_play_parse_body(), ast_ari_bridges_play_with_id_parse_body(), ast_ari_bridges_record_parse_body(), ast_ari_bridges_remove_channel_parse_body(), ast_ari_bridges_start_moh_parse_body(), ast_ari_callback(), ast_ari_channels_continue_in_dialplan_parse_body(), ast_ari_channels_create(), ast_ari_channels_create_parse_body(), ast_ari_channels_dial_parse_body(), ast_ari_channels_external_media(), ast_ari_channels_external_media_parse_body(), ast_ari_channels_get_channel_var_parse_body(), ast_ari_channels_hangup_parse_body(), ast_ari_channels_move_parse_body(), ast_ari_channels_mute_parse_body(), ast_ari_channels_originate(), ast_ari_channels_originate_parse_body(), ast_ari_channels_originate_with_id(), ast_ari_channels_originate_with_id_parse_body(), ast_ari_channels_play_parse_body(), ast_ari_channels_play_with_id_parse_body(), ast_ari_channels_record_parse_body(), ast_ari_channels_redirect_parse_body(), ast_ari_channels_send_dtmf_parse_body(), ast_ari_channels_set_channel_var_parse_body(), ast_ari_channels_snoop_channel_parse_body(), ast_ari_channels_snoop_channel_with_id_parse_body(), ast_ari_channels_start_moh_parse_body(), ast_ari_channels_unmute_parse_body(), ast_ari_device_states_update_parse_body(), ast_ari_endpoints_refer_parse_body(), ast_ari_endpoints_refer_to_endpoint_parse_body(), ast_ari_endpoints_send_message(), ast_ari_endpoints_send_message_parse_body(), ast_ari_endpoints_send_message_to_endpoint(), ast_ari_endpoints_send_message_to_endpoint_parse_body(), ast_ari_events_user_event(), ast_ari_events_user_event_parse_body(), ast_ari_get_docs(), ast_ari_mailboxes_update_parse_body(), ast_ari_playbacks_control_parse_body(), ast_ari_recordings_copy_stored_parse_body(), ast_ari_sounds_list_parse_body(), ast_ari_validate_event(), ast_ari_validate_message(), ast_endpoint_snapshot_to_json(), ast_stir_shaken_vs_verify(), AST_TEST_DEFINE(), asterisk_publication_devicestate(), asterisk_publication_devicestate_state_change(), asterisk_publication_mailboxstate(), asterisk_publication_mwi_state_change(), cc_available_to_ami(), cc_callerrecalling_to_ami(), cc_callerstartmonitoring_to_ami(), cc_callerstopmonitoring_to_ami(), cc_failure_to_ami(), cc_monitorfailed_to_ami(), cc_offertimerstart_to_ami(), cc_recallcomplete_to_ami(), cc_requestacknowledged_to_ami(), cc_requested_to_ami(), cel_generic_cb(), channel_dial_cb(), channel_dtmf_begin_cb(), channel_dtmf_end_cb(), channel_enter_cb(), channel_fax_cb(), channel_hangup_handler_cb(), channel_hangup_request_cb(), channel_hold_cb(), channel_mixmonitor_mute_cb(), channel_moh_start_cb(), conf_send_event_to_participants(), confbridge_publish_manager_event(), confbridge_talking_cb(), contactstatus_to_ami(), contactstatus_to_json(), create_sound_blob(), dahdichannel_to_ami(), dial_to_json(), dtmf_end_to_json(), fetch_access_token(), fetch_google_access_token(), get_blob_variable(), get_bool_header(), handle_dial_message(), handle_local_optimization_begin(), handle_local_optimization_end(), handle_masquerade(), handle_request_set(), handle_response_get(), handle_response_setup(), handler(), hold_to_json(), json_decode_read(), local_message_to_ami(), manager_generic_msg_cb(), meetme_stasis_cb(), multi_user_event_to_ami(), multi_user_event_to_json(), mwi_app_event_cb(), mwi_startup_event_cb(), parse_node(), parse_refer_json(), peerstatus_to_ami(), playback_to_json(), queue_agent_cb(), recording_to_json(), rtcp_message_handler(), rtcp_report_to_ami(), security_event_stasis_cb(), security_event_to_ami_blob(), send_start_msg_snapshots(), speech_test_server_get(), speech_test_server_set(), speech_test_server_setup(), startup_event_cb(), stasis_app_exec(), stasis_app_message_handler(), stasis_end_to_json(), stasis_start_to_json(), subscription_persistence_event_cb(), system_registry_to_ami(), talking_stop_to_ami(), and varset_to_ami().

◆ ast_json_object_iter()

struct ast_json_iter * ast_json_object_iter ( struct ast_json object)

Get an iterator pointing to the first field in a JSON object.

Since
12.0.0

The order of the fields in an object are not specified. However, iterating forward from this iterator will cover all fields in object. Adding or removing fields from object may invalidate its iterators.

Parameters
objectJSON object.
Returns
Iterator to the first field in object.
Return values
NULLobject is empty. on error.

Definition at line 439 of file json.c.

440{
441 return json_object_iter((json_t *)object);
442}

Referenced by ast_ari_validate_application(), ast_ari_validate_application_move_failed(), ast_ari_validate_application_replaced(), ast_ari_validate_asterisk_info(), ast_ari_validate_asterisk_ping(), ast_ari_validate_bridge(), ast_ari_validate_bridge_attended_transfer(), ast_ari_validate_bridge_blind_transfer(), ast_ari_validate_bridge_created(), ast_ari_validate_bridge_destroyed(), ast_ari_validate_bridge_merged(), ast_ari_validate_bridge_video_source_changed(), ast_ari_validate_build_info(), ast_ari_validate_caller_id(), ast_ari_validate_channel(), ast_ari_validate_channel_caller_id(), ast_ari_validate_channel_connected_line(), ast_ari_validate_channel_created(), ast_ari_validate_channel_destroyed(), ast_ari_validate_channel_dialplan(), ast_ari_validate_channel_dtmf_received(), ast_ari_validate_channel_entered_bridge(), ast_ari_validate_channel_hangup_request(), ast_ari_validate_channel_hold(), ast_ari_validate_channel_left_bridge(), ast_ari_validate_channel_state_change(), ast_ari_validate_channel_talking_finished(), ast_ari_validate_channel_talking_started(), ast_ari_validate_channel_tone_detected(), ast_ari_validate_channel_unhold(), ast_ari_validate_channel_userevent(), ast_ari_validate_channel_varset(), ast_ari_validate_config_info(), ast_ari_validate_config_tuple(), ast_ari_validate_contact_info(), ast_ari_validate_contact_status_change(), ast_ari_validate_device_state(), ast_ari_validate_device_state_changed(), ast_ari_validate_dial(), ast_ari_validate_dialed(), ast_ari_validate_dialplan_cep(), ast_ari_validate_endpoint(), ast_ari_validate_endpoint_state_change(), ast_ari_validate_event(), ast_ari_validate_format_lang_pair(), ast_ari_validate_live_recording(), ast_ari_validate_log_channel(), ast_ari_validate_mailbox(), ast_ari_validate_message(), ast_ari_validate_missing_params(), ast_ari_validate_module(), ast_ari_validate_peer(), ast_ari_validate_peer_status_change(), ast_ari_validate_playback(), ast_ari_validate_playback_continuing(), ast_ari_validate_playback_finished(), ast_ari_validate_playback_started(), ast_ari_validate_recording_failed(), ast_ari_validate_recording_finished(), ast_ari_validate_recording_started(), ast_ari_validate_rtpstat(), ast_ari_validate_set_id(), ast_ari_validate_sound(), ast_ari_validate_stasis_end(), ast_ari_validate_stasis_start(), ast_ari_validate_status_info(), ast_ari_validate_stored_recording(), ast_ari_validate_system_info(), ast_ari_validate_text_message(), ast_ari_validate_text_message_received(), ast_ari_validate_variable(), ast_json_to_ast_variables(), AST_TEST_DEFINE(), handle_request_set(), handle_response_get(), and manager_json_to_ast_str().

◆ ast_json_object_iter_at()

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.

Since
12.0.0

Iterating forward from this iterator may not to cover all elements in object.

Parameters
objectJSON object to iterate.
keyKey of field to lookup.
Returns
Iterator pointing to the field with the given key.
Return values
NULLif key does not exist. on error.

Definition at line 443 of file json.c.

444{
445 return json_object_iter_at((json_t *)object, key);
446}

Referenced by AST_TEST_DEFINE(), message_json_is_request(), message_json_is_response(), and message_json_name().

◆ ast_json_object_iter_key()

const char * ast_json_object_iter_key ( struct ast_json_iter iter)

Get the key from an iterator.

Since
12.0.0
Parameters
iterJSON object iterator.
Returns
Key of the field iter points to.

Definition at line 451 of file json.c.

452{
453 return json_object_iter_key(iter);
454}

Referenced by ast_ari_validate_application(), ast_ari_validate_application_move_failed(), ast_ari_validate_application_replaced(), ast_ari_validate_asterisk_info(), ast_ari_validate_asterisk_ping(), ast_ari_validate_bridge(), ast_ari_validate_bridge_attended_transfer(), ast_ari_validate_bridge_blind_transfer(), ast_ari_validate_bridge_created(), ast_ari_validate_bridge_destroyed(), ast_ari_validate_bridge_merged(), ast_ari_validate_bridge_video_source_changed(), ast_ari_validate_build_info(), ast_ari_validate_caller_id(), ast_ari_validate_channel(), ast_ari_validate_channel_caller_id(), ast_ari_validate_channel_connected_line(), ast_ari_validate_channel_created(), ast_ari_validate_channel_destroyed(), ast_ari_validate_channel_dialplan(), ast_ari_validate_channel_dtmf_received(), ast_ari_validate_channel_entered_bridge(), ast_ari_validate_channel_hangup_request(), ast_ari_validate_channel_hold(), ast_ari_validate_channel_left_bridge(), ast_ari_validate_channel_state_change(), ast_ari_validate_channel_talking_finished(), ast_ari_validate_channel_talking_started(), ast_ari_validate_channel_tone_detected(), ast_ari_validate_channel_unhold(), ast_ari_validate_channel_userevent(), ast_ari_validate_channel_varset(), ast_ari_validate_config_info(), ast_ari_validate_config_tuple(), ast_ari_validate_contact_info(), ast_ari_validate_contact_status_change(), ast_ari_validate_device_state(), ast_ari_validate_device_state_changed(), ast_ari_validate_dial(), ast_ari_validate_dialed(), ast_ari_validate_dialplan_cep(), ast_ari_validate_endpoint(), ast_ari_validate_endpoint_state_change(), ast_ari_validate_event(), ast_ari_validate_format_lang_pair(), ast_ari_validate_live_recording(), ast_ari_validate_log_channel(), ast_ari_validate_mailbox(), ast_ari_validate_message(), ast_ari_validate_missing_params(), ast_ari_validate_module(), ast_ari_validate_peer(), ast_ari_validate_peer_status_change(), ast_ari_validate_playback(), ast_ari_validate_playback_continuing(), ast_ari_validate_playback_finished(), ast_ari_validate_playback_started(), ast_ari_validate_recording_failed(), ast_ari_validate_recording_finished(), ast_ari_validate_recording_started(), ast_ari_validate_rtpstat(), ast_ari_validate_set_id(), ast_ari_validate_sound(), ast_ari_validate_stasis_end(), ast_ari_validate_stasis_start(), ast_ari_validate_status_info(), ast_ari_validate_stored_recording(), ast_ari_validate_system_info(), ast_ari_validate_text_message(), ast_ari_validate_text_message_received(), ast_ari_validate_variable(), ast_json_to_ast_variables(), AST_TEST_DEFINE(), handle_request_set(), handle_response_get(), handle_setting(), and manager_json_to_ast_str().

◆ ast_json_object_iter_next()

struct ast_json_iter * ast_json_object_iter_next ( struct ast_json object,
struct ast_json_iter iter 
)

Get the next iterator.

Since
12.0.0
Parameters
objectJSON object iter was obtained from.
iterJSON object iterator.
Returns
Iterator to next field in object.
Return values
NULLif iter was the last field.

Definition at line 447 of file json.c.

448{
449 return json_object_iter_next((json_t *)object, iter);
450}

Referenced by ast_ari_validate_application(), ast_ari_validate_application_move_failed(), ast_ari_validate_application_replaced(), ast_ari_validate_asterisk_info(), ast_ari_validate_asterisk_ping(), ast_ari_validate_bridge(), ast_ari_validate_bridge_attended_transfer(), ast_ari_validate_bridge_blind_transfer(), ast_ari_validate_bridge_created(), ast_ari_validate_bridge_destroyed(), ast_ari_validate_bridge_merged(), ast_ari_validate_bridge_video_source_changed(), ast_ari_validate_build_info(), ast_ari_validate_caller_id(), ast_ari_validate_channel(), ast_ari_validate_channel_caller_id(), ast_ari_validate_channel_connected_line(), ast_ari_validate_channel_created(), ast_ari_validate_channel_destroyed(), ast_ari_validate_channel_dialplan(), ast_ari_validate_channel_dtmf_received(), ast_ari_validate_channel_entered_bridge(), ast_ari_validate_channel_hangup_request(), ast_ari_validate_channel_hold(), ast_ari_validate_channel_left_bridge(), ast_ari_validate_channel_state_change(), ast_ari_validate_channel_talking_finished(), ast_ari_validate_channel_talking_started(), ast_ari_validate_channel_tone_detected(), ast_ari_validate_channel_unhold(), ast_ari_validate_channel_userevent(), ast_ari_validate_channel_varset(), ast_ari_validate_config_info(), ast_ari_validate_config_tuple(), ast_ari_validate_contact_info(), ast_ari_validate_contact_status_change(), ast_ari_validate_device_state(), ast_ari_validate_device_state_changed(), ast_ari_validate_dial(), ast_ari_validate_dialed(), ast_ari_validate_dialplan_cep(), ast_ari_validate_endpoint(), ast_ari_validate_endpoint_state_change(), ast_ari_validate_event(), ast_ari_validate_format_lang_pair(), ast_ari_validate_live_recording(), ast_ari_validate_log_channel(), ast_ari_validate_mailbox(), ast_ari_validate_message(), ast_ari_validate_missing_params(), ast_ari_validate_module(), ast_ari_validate_peer(), ast_ari_validate_peer_status_change(), ast_ari_validate_playback(), ast_ari_validate_playback_continuing(), ast_ari_validate_playback_finished(), ast_ari_validate_playback_started(), ast_ari_validate_recording_failed(), ast_ari_validate_recording_finished(), ast_ari_validate_recording_started(), ast_ari_validate_rtpstat(), ast_ari_validate_set_id(), ast_ari_validate_sound(), ast_ari_validate_stasis_end(), ast_ari_validate_stasis_start(), ast_ari_validate_status_info(), ast_ari_validate_stored_recording(), ast_ari_validate_system_info(), ast_ari_validate_text_message(), ast_ari_validate_text_message_received(), ast_ari_validate_variable(), ast_json_to_ast_variables(), AST_TEST_DEFINE(), and manager_json_to_ast_str().

◆ ast_json_object_iter_set()

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.

Since
12.0.0
Note
The object steals the value reference even if it returns error; use ast_json_ref() to safely keep a pointer to it.
Parameters
objectJSON object iter was obtained from.
iterJSON object iterator.
valueJSON value to store in iter's field.
Return values
0on success.
-1on error.

Definition at line 459 of file json.c.

460{
461 return json_object_iter_set_new((json_t *)object, iter, (json_t *)value);
462}

References value.

Referenced by AST_TEST_DEFINE().

◆ ast_json_object_iter_value()

struct ast_json * ast_json_object_iter_value ( struct ast_json_iter iter)

Get the value from an iterator.

Since
12.0.0

The returned element is a borrowed reference; use ast_json_ref() to safely keep a pointer to it.

Parameters
iterJSON object iterator.
Returns
Value of the field iter points to.

Definition at line 455 of file json.c.

456{
457 return (struct ast_json *)json_object_iter_value(iter);
458}

Referenced by ast_ari_validate_application(), ast_ari_validate_application_move_failed(), ast_ari_validate_application_replaced(), ast_ari_validate_asterisk_info(), ast_ari_validate_asterisk_ping(), ast_ari_validate_bridge(), ast_ari_validate_bridge_attended_transfer(), ast_ari_validate_bridge_blind_transfer(), ast_ari_validate_bridge_created(), ast_ari_validate_bridge_destroyed(), ast_ari_validate_bridge_merged(), ast_ari_validate_bridge_video_source_changed(), ast_ari_validate_build_info(), ast_ari_validate_caller_id(), ast_ari_validate_channel(), ast_ari_validate_channel_caller_id(), ast_ari_validate_channel_connected_line(), ast_ari_validate_channel_created(), ast_ari_validate_channel_destroyed(), ast_ari_validate_channel_dialplan(), ast_ari_validate_channel_dtmf_received(), ast_ari_validate_channel_entered_bridge(), ast_ari_validate_channel_hangup_request(), ast_ari_validate_channel_hold(), ast_ari_validate_channel_left_bridge(), ast_ari_validate_channel_state_change(), ast_ari_validate_channel_talking_finished(), ast_ari_validate_channel_talking_started(), ast_ari_validate_channel_tone_detected(), ast_ari_validate_channel_unhold(), ast_ari_validate_channel_userevent(), ast_ari_validate_channel_varset(), ast_ari_validate_config_info(), ast_ari_validate_config_tuple(), ast_ari_validate_contact_info(), ast_ari_validate_contact_status_change(), ast_ari_validate_device_state(), ast_ari_validate_device_state_changed(), ast_ari_validate_dial(), ast_ari_validate_dialplan_cep(), ast_ari_validate_endpoint(), ast_ari_validate_endpoint_state_change(), ast_ari_validate_event(), ast_ari_validate_format_lang_pair(), ast_ari_validate_live_recording(), ast_ari_validate_log_channel(), ast_ari_validate_mailbox(), ast_ari_validate_message(), ast_ari_validate_missing_params(), ast_ari_validate_module(), ast_ari_validate_peer(), ast_ari_validate_peer_status_change(), ast_ari_validate_playback(), ast_ari_validate_playback_continuing(), ast_ari_validate_playback_finished(), ast_ari_validate_playback_started(), ast_ari_validate_recording_failed(), ast_ari_validate_recording_finished(), ast_ari_validate_recording_started(), ast_ari_validate_rtpstat(), ast_ari_validate_set_id(), ast_ari_validate_sound(), ast_ari_validate_stasis_end(), ast_ari_validate_stasis_start(), ast_ari_validate_status_info(), ast_ari_validate_stored_recording(), ast_ari_validate_system_info(), ast_ari_validate_text_message(), ast_ari_validate_text_message_received(), ast_ari_validate_variable(), ast_json_to_ast_variables(), AST_TEST_DEFINE(), handle_results(), handle_setting(), manager_json_to_ast_str(), and message_json_name().

◆ ast_json_object_set()

int ast_json_object_set ( struct ast_json object,
const char *  key,
struct ast_json value 
)

Set a field in a JSON object.

Since
12.0.0
Note
The object steals the value reference even if it returns error; use ast_json_ref() to safely keep a pointer to it.
Parameters
objectJSON object to modify.
keyKey of field to set.
valueJSON value to set for field.
Return values
0on success.
-1on error.

Definition at line 414 of file json.c.

415{
416 return json_object_set_new((json_t *)object, key, (json_t *)value);
417}

References value.

Referenced by add_ip_json_object(), add_json_object(), alloc_security_event_json_object(), app_send(), ast_ari_asterisk_get_info(), ast_ari_get_docs(), ast_bridge_snapshot_to_json(), ast_bucket_file_json(), ast_bucket_json(), ast_channel_snapshot_to_json(), ast_endpoint_snapshot_to_json(), ast_json_channel_vars(), ast_json_object_create_vars(), ast_rtp_convert_stats_json(), ast_sip_subscription_set_persistence_data(), ast_sorcery_objectset_json_create(), AST_TEST_DEFINE(), attended_transfer_to_json(), blind_transfer_to_json(), channel_blob_to_json(), custom_fields_to_params(), devices_to_json(), dial_to_json(), external_media_audiosocket_tcp(), external_media_rtp_udp(), handler(), identify_module(), launch_asyncagi(), meetme_stasis_generate_msg(), message_json_error_msg_set(), message_json_id_set(), msg_to_json(), multi_user_event_to_json(), publish_acl_change(), recording_publish(), speech_test_server_get(), speech_test_server_set(), speech_test_server_setup(), stasis_app_event_filter_to_json(), stasis_app_message_handler(), stasis_app_recording_to_json(), stasis_app_user_event(), stasis_start_to_json(), sub_bridge_update_handler(), units_to_json(), and userevent_exec().

◆ ast_json_object_size()

size_t ast_json_object_size ( struct ast_json object)

Get size of JSON object.

Since
12.0.0
Parameters
objectJSON object.
Returns
Size of object.
Return values
Zeroof object is not a JSON object.

Definition at line 403 of file json.c.

404{
405 return json_object_size((json_t *)object);
406}

Referenced by app_event_filter_set(), and AST_TEST_DEFINE().

◆ ast_json_object_update()

int ast_json_object_update ( struct ast_json object,
struct ast_json other 
)

Update object with all of the fields of other.

Since
12.0.0

All of the fields of other are copied into object, overwriting existing keys. The other object is not changed, so ast_json_unref() it when you are done with it.

Parameters
objectJSON object to modify.
otherJSON object to copy into object.
Return values
0on success.
-1on error.

Definition at line 426 of file json.c.

427{
428 return json_object_update((json_t *)object, (json_t *)other);
429}

Referenced by AST_TEST_DEFINE(), cc_publish(), channel_to_json(), meetme_stasis_generate_msg(), message_json_construct2(), peerstatus_to_json(), send_conf_stasis(), and send_conf_stasis_snapshots().

◆ ast_json_object_update_existing()

int ast_json_object_update_existing ( struct ast_json object,
struct ast_json other 
)

Update existing fields in object with the fields of other.

Since
12.0.0

Like ast_json_object_update(), but only existing fields are updated. No new fields will get added. The other object is not changed, so ast_json_unref() it when you are done with it.

Parameters
objectJSON object to modify.
otherJSON object to copy into object.
Return values
0on success.
-1on error.

Definition at line 430 of file json.c.

431{
432 return json_object_update_existing((json_t *)object, (json_t *)other);
433}

Referenced by AST_TEST_DEFINE().

◆ ast_json_object_update_missing()

int ast_json_object_update_missing ( struct ast_json object,
struct ast_json other 
)

Add new fields to object with the fields of other.

Since
12.0.0

Like ast_json_object_update(), but only missing fields are added. No existing fields will be modified. The other object is not changed, so ast_json_unref() it when you are done with it.

Parameters
objectJSON object to modify.
otherJSON object to copy into object.
Return values
0on success.
-1on error.

Definition at line 434 of file json.c.

435{
436 return json_object_update_missing((json_t *)object, (json_t *)other);
437}

Referenced by AST_TEST_DEFINE().

◆ ast_json_pack()

struct ast_json * ast_json_pack ( char const *  format,
  ... 
)

Helper for creating complex JSON values.

Since
12.0.0

See original Jansson docs at http://www.digip.org/jansson/doc/2.11/apiref.html#apiref-pack for more details.

Definition at line 612 of file json.c.

613{
614 struct ast_json *ret;
615 va_list args;
616 va_start(args, format);
617 ret = ast_json_vpack(format, args);
618 va_end(args);
619 return ret;
620}
struct ast_json * ast_json_vpack(char const *format, va_list ap)
Helper for creating complex JSON values simply.
Definition: json.c:621
const char * args

References args, and ast_json_vpack().

Referenced by __expire_registry(), __iax2_poke_noanswer(), add_format_information_cb(), agi_handle_command(), analog_publish_channel_alarm_clear(), analog_publish_dnd_state(), app_send_end_msg(), app_to_json(), app_update(), association_to_json(), ast_ari_asterisk_get_global_var(), ast_ari_asterisk_get_info(), ast_ari_asterisk_ping(), ast_ari_channels_get_channel_var(), ast_ari_response_error(), ast_bridge_channel_write_hold(), ast_bridge_merge_message_to_json(), ast_bridge_publish_enter(), ast_bridge_snapshot_to_json(), ast_cel_publish_event(), ast_cel_publish_user_event(), ast_channel_move(), ast_channel_publish_dial_internal(), ast_channel_publish_varset(), ast_channel_snapshot_to_json(), ast_endpoint_snapshot_to_json(), ast_json_dialplan_cep_app(), ast_json_name_number(), ast_json_party_id(), ast_manager_publish_event(), ast_queue_hangup_with_cause(), ast_queue_hold(), ast_rtcp_calculate_sr_rr_statistics(), ast_rtcp_interpret(), ast_sip_persistent_endpoint_publish_contact_state(), ast_sip_persistent_endpoint_update_state(), ast_softhangup(), ast_system_publish_registry(), AST_TEST_DEFINE(), asterisk_publication_send_refresh(), asterisk_publisher_devstate_cb(), asterisk_publisher_mwistate_cb(), attended_transfer_to_json(), beanstalk_put(), blind_transfer_to_json(), cc_publish(), cc_publish_available(), cc_publish_callerrecalling(), cc_publish_callerstartmonitoring(), cc_publish_callerstopmonitoring(), cc_publish_failure(), cc_publish_monitorfailed(), cc_publish_offertimerstart(), cc_publish_recallcomplete(), cc_publish_requestacknowledged(), cc_publish_requested(), cel_attended_transfer_cb(), cel_blind_transfer_cb(), cel_bridge_enter_cb(), cel_bridge_leave_cb(), cel_bs_put(), cel_channel_state_change(), cel_dial_cb(), cel_local_optimization_cb_helper(), cel_parking_cb(), cel_pickup_cb(), celgenuserevent_exec(), channel_callerid(), channel_connected_line(), channel_destroyed_event(), channel_dialplan(), charge_to_json(), conf_handle_talker_cb(), confbridge_handle_atxfer(), contactstatus_to_json(), create_sound_blob(), currency_to_json(), d_to_json(), dial_to_json(), dtmf_end_to_json(), e_to_json(), format_log_json(), handler(), hold_to_json(), join_queue(), json_party_name(), json_party_number(), json_party_subaddress(), launch_asyncagi(), leave_queue(), load_module(), local_optimization_finished_cb(), local_optimization_started_cb(), mailbox_to_json(), manager_mute_mixmonitor(), meetme_stasis_generate_msg(), message_json_construct2(), message_received_handler(), moh_post_start(), msg_to_json(), notify_new_message(), pack_bridge_and_channels(), peerstatus_to_json(), playback_to_json(), process_log_list(), process_module_list(), publish_async_exec_end(), publish_channel_alarm(), publish_channel_alarm_clear(), publish_cluster_discovery_to_stasis_full(), publish_dahdichannel(), publish_dnd_state(), publish_format_update(), publish_fully_booted(), publish_hangup_handler_message(), publish_load_message_type(), publish_local_bridge_message(), publish_span_alarm(), publish_span_alarm_clear(), queue_member_blob_create(), really_quit(), record_abandoned(), recording_to_json(), report_fax_status(), report_receive_fax_status(), report_send_fax_status(), reset_user_pw(), return_sorcery_object(), ring_entry(), rna(), rtcp_report_to_json(), s_to_json(), send_agent_complete(), send_agent_login(), send_agent_logoff(), send_conf_stasis(), send_conf_stasis_snapshots(), send_device_state(), send_dtmf_begin_event(), send_dtmf_end_event(), send_join_event(), send_leave_event(), send_mute_event(), send_start_msg_snapshots(), send_unmute_event(), simple_bridge_channel_event(), simple_bridge_event(), simple_channel_event(), simple_endpoint_event(), socket_process_helper(), speech_aeap_engine_create(), speech_aeap_get(), speech_aeap_set(), speech_test_server_get(), speech_test_server_handle_request(), stasis_app_device_state_to_json(), stasis_app_exec(), stasis_app_playback_to_json(), stasis_app_recording_to_json(), stasis_app_stored_recording_to_json(), stasis_app_user_event(), stasis_end_to_json(), stasis_start_to_json(), status_to_json(), talk_detect_audiohook_cb(), test_name_number(), try_calling(), unhold_to_json(), update_registry(), and userevent_exec().

◆ ast_json_party_id()

struct ast_json * ast_json_party_id ( struct ast_party_id party)

Construct an ast_party_id as JSON.

Since
12.0.0
Parameters
partyThe party ID to represent as JSON.
Returns
JSON object with name, number and subaddress objects for those that are valid in the party ID

Definition at line 805 of file json.c.

806{
807 int pres = ast_party_id_presentation(party);
808
809 /* Combined party presentation */
810 return ast_json_pack("{s: i, s: s, s: o*, s: o*, s: o*}",
811 "presentation", pres,
812 "presentation_txt", ast_describe_caller_presentation(pres),
813 "number", json_party_number(&party->number),
814 "name", json_party_name(&party->name),
815 "subaddress", json_party_subaddress(&party->subaddress));
816}
const char * ast_describe_caller_presentation(int data)
Convert caller ID pres value to explanatory string.
Definition: callerid.c:1364
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
Definition: channel.c:1840
static struct ast_json * json_party_name(struct ast_party_name *name)
Definition: json.c:782
static struct ast_json * json_party_subaddress(struct ast_party_subaddress *subaddress)
Definition: json.c:794
static struct ast_json * json_party_number(struct ast_party_number *number)
Definition: json.c:770
struct ast_party_subaddress subaddress
Subscriber subaddress.
Definition: channel.h:346
struct ast_party_name name
Subscriber name.
Definition: channel.h:342
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:344

References ast_describe_caller_presentation(), ast_json_pack(), ast_party_id_presentation(), json_party_name(), json_party_number(), json_party_subaddress(), ast_party_id::name, ast_party_id::number, and ast_party_id::subaddress.

◆ ast_json_payload_create()

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.

Since
12.0.0
Parameters
jsonthe ast_json blob we are loading
Returns
pointer to the ast_json_payload created
Return values
NULLif we fail to alloc it

Definition at line 756 of file json.c.

757{
758 struct ast_json_payload *payload;
759
760 if (!(payload = ao2_alloc(sizeof(*payload), json_payload_destructor))) {
761 return NULL;
762 }
763
765 payload->json = json;
766
767 return payload;
768}
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
struct ast_json * ast_json_ref(struct ast_json *json)
Increase refcount on value.
Definition: json.c:67
static void json_payload_destructor(void *obj)
Definition: json.c:750
struct ast_json * json
Definition: json.h:1083

References ao2_alloc, ast_json_ref(), ast_json_payload::json, json_payload_destructor(), and NULL.

Referenced by ast_manager_publish_event(), ast_system_publish_registry(), cc_publish(), handle_security_event(), publish_acl_change(), publish_cluster_discovery_to_stasis_full(), publish_format_update(), publish_load_message_type(), queue_publish_member_blob(), and stun_monitor_request().

◆ ast_json_real_create()

struct ast_json * ast_json_real_create ( double  value)

Create a JSON real number.

Since
12.0.0
Parameters
valueValue of the new JSON real number.
Returns
Newly allocated real number.
Return values
NULLon error.

Definition at line 342 of file json.c.

343{
344 return (struct ast_json *)json_real(value);
345}

References value.

Referenced by ast_ari_asterisk_get_info(), and ast_rtp_convert_stats_json().

◆ ast_json_real_get()

double ast_json_real_get ( const struct ast_json real)

Get the value from a JSON real number.

Since
12.0.0
Parameters
realJSON real number.
Returns
Value of a JSON real number.
Return values
0if real is not a JSON real number.

Definition at line 347 of file json.c.

348{
349 return json_real_value((json_t *)real);
350}
float real
Definition: lpc10.h:79

Referenced by parse_node(), and rtcp_report_to_ami().

◆ ast_json_real_set()

int ast_json_real_set ( struct ast_json real,
double  value 
)

Set the value of a JSON real number.

Since
12.0.0
Parameters
realJSON real number to modify.
valueNew value for real.
Return values
0on success.
-1on error.

Definition at line 352 of file json.c.

353{
354 return json_real_set((json_t *)real, value);
355}

References value.

◆ ast_json_ref()

struct ast_json * ast_json_ref ( struct ast_json value)

Increase refcount on value.

Since
12.0.0
Parameters
valueJSON value to reference.
Returns
The given value.

Definition at line 67 of file json.c.

68{
69 json_incref((json_t *)json);
70 return json;
71}

Referenced by alloc_security_event_json_object(), allocate_subscription(), aoc_publish_blob(), app_event_filter_set(), ari_bridges_play_found(), ari_bridges_play_new(), ast_ari_applications_list(), ast_ari_applications_subscribe(), ast_ari_applications_unsubscribe(), ast_ari_asterisk_get_global_var(), ast_ari_asterisk_get_info(), ast_ari_bridges_list(), ast_ari_bridges_record(), ast_ari_channels_get_channel_var(), ast_ari_channels_list(), ast_ari_endpoints_list(), ast_ari_endpoints_list_by_tech(), ast_ari_recordings_list_stored(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_websocket_session_read(), ast_bridge_blob_create(), ast_bridge_blob_create_from_snapshots(), ast_bucket_file_json(), ast_bucket_json(), ast_cel_publish_event(), ast_endpoint_blob_create(), ast_json_payload_create(), ast_manager_publish_event(), ast_multi_channel_blob_create(), ast_multi_object_blob_create(), ast_mwi_blob_create(), ast_rtp_publish_rtcp_message(), ast_sip_subscription_set_persistence_data(), AST_TEST_DEFINE(), attended_transfer_to_json(), create_channel_blob_message(), create_sound_blob(), generate_filenames_json(), json_array_from_list(), message_json_construct1(), message_received_handler(), multi_user_event_to_json(), publish_load_message_type(), report_receive_fax_status(), return_sorcery_object(), speech_test_server_set(), speech_test_server_setup(), stasis_app_event_filter_to_json(), stasis_app_message_handler(), stasis_app_playback_to_json(), stasis_app_recording_to_json(), and stasis_app_user_event().

◆ ast_json_reset_alloc_funcs()

void ast_json_reset_alloc_funcs ( void  )

Change alloc funcs back to the resource module defaults.

Since
12.0.0

If you use ast_json_set_alloc_funcs() to temporarily change the allocator functions (i.e., from in a unit test), this function sets them back to ast_malloc() and ast_free().

Definition at line 62 of file json.c.

63{
64 json_set_alloc_funcs(ast_json_malloc, ast_json_free);
65}
void ast_json_free(void *p)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
Definition: json.c:52
void * ast_json_malloc(size_t size)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
Definition: json.c:47

References ast_json_free(), and ast_json_malloc().

Referenced by ast_json_init(), and json_test_cleanup().

◆ ast_json_set_alloc_funcs()

void ast_json_set_alloc_funcs ( void *(*)(size_t)  malloc_fn,
void(*)(void *)  free_fn 
)

Set custom allocators instead of the standard ast_malloc() and ast_free().

Since
12.0.0

This is used by the unit tests to do JSON specific memory leak detection. Since it affects all users of the JSON library, shouldn't normally be used.

Parameters
malloc_fnCustom allocation function.
free_fnMatching free function.

Definition at line 57 of file json.c.

58{
59 json_set_alloc_funcs(malloc_fn, free_fn);
60}

Referenced by json_test_init().

◆ ast_json_string_create()

struct ast_json * ast_json_string_create ( const char *  value)

◆ ast_json_string_get()

const char * ast_json_string_get ( const struct ast_json string)

Get the value of a JSON string.

Since
12.0.0
Parameters
stringJSON string.
Returns
Value of the string.
Return values
NULLon error.

Definition at line 283 of file json.c.

284{
285 return json_string_value((json_t *)string);
286}

Referenced by agent_login_to_ami(), agent_logoff_to_ami(), app_send(), append_event_str_single(), append_json_single(), assign_uuid(), ast_ari_applications_subscribe_parse_body(), ast_ari_applications_unsubscribe_parse_body(), ast_ari_asterisk_add_log_parse_body(), ast_ari_asterisk_get_global_var_parse_body(), ast_ari_asterisk_get_info_parse_body(), ast_ari_asterisk_set_global_var_parse_body(), ast_ari_asterisk_update_object(), ast_ari_bridges_add_channel_parse_body(), ast_ari_bridges_create_parse_body(), ast_ari_bridges_create_with_id_parse_body(), ast_ari_bridges_play_parse_body(), ast_ari_bridges_play_with_id_parse_body(), ast_ari_bridges_record_parse_body(), ast_ari_bridges_remove_channel_parse_body(), ast_ari_bridges_start_moh_parse_body(), ast_ari_callback(), ast_ari_channels_continue_in_dialplan_parse_body(), ast_ari_channels_create_parse_body(), ast_ari_channels_dial_parse_body(), ast_ari_channels_external_media_parse_body(), ast_ari_channels_get_channel_var_parse_body(), ast_ari_channels_hangup_parse_body(), ast_ari_channels_move_parse_body(), ast_ari_channels_mute_parse_body(), ast_ari_channels_originate_parse_body(), ast_ari_channels_originate_with_id_parse_body(), ast_ari_channels_play_parse_body(), ast_ari_channels_play_with_id_parse_body(), ast_ari_channels_record_parse_body(), ast_ari_channels_redirect_parse_body(), ast_ari_channels_send_dtmf_parse_body(), ast_ari_channels_set_channel_var_parse_body(), ast_ari_channels_snoop_channel_parse_body(), ast_ari_channels_snoop_channel_with_id_parse_body(), ast_ari_channels_start_moh_parse_body(), ast_ari_channels_unmute_parse_body(), ast_ari_device_states_update_parse_body(), ast_ari_endpoints_refer_parse_body(), ast_ari_endpoints_refer_to_endpoint_parse_body(), ast_ari_endpoints_send_message_parse_body(), ast_ari_endpoints_send_message_to_endpoint_parse_body(), ast_ari_events_user_event_parse_body(), ast_ari_playbacks_control_parse_body(), ast_ari_recordings_copy_stored_parse_body(), ast_ari_sounds_list_parse_body(), ast_ari_validate_date(), ast_ari_validate_event(), ast_ari_validate_message(), ast_json_to_ast_variables(), AST_TEST_DEFINE(), asterisk_publication_devicestate(), asterisk_publication_devicestate_state_change(), asterisk_publication_mailboxstate(), asterisk_publication_mwi_state_change(), cc_available_to_ami(), cc_callerrecalling_to_ami(), cc_callerstartmonitoring_to_ami(), cc_callerstopmonitoring_to_ami(), cc_failure_to_ami(), cc_monitorfailed_to_ami(), cc_offertimerstart_to_ami(), cc_recallcomplete_to_ami(), cc_requestacknowledged_to_ami(), cc_requested_to_ami(), cel_generic_cb(), channel_dial_cb(), channel_dtmf_begin_cb(), channel_dtmf_end_cb(), channel_enter_cb(), channel_fax_cb(), channel_hangup_handler_cb(), channel_hold_cb(), channel_mixmonitor_mute_cb(), channel_moh_start_cb(), confbridge_publish_manager_event(), confbridge_talking_cb(), contactstatus_to_ami(), contactstatus_to_json(), dahdichannel_to_ami(), dial_to_json(), dtmf_end_to_json(), fetch_access_token(), fetch_google_access_token(), get_blob_variable(), handle_dial_message(), handle_masquerade(), handle_setting(), hold_to_json(), local_message_to_ami(), manager_generic_msg_cb(), manager_json_value_str_append(), meetme_stasis_cb(), message_json_name(), multi_user_event_to_ami(), mwi_app_event_cb(), mwi_startup_event_cb(), parse_node(), parse_refer_json(), peerstatus_to_ami(), playback_to_json(), queue_agent_cb(), recording_to_json(), rtcp_message_handler(), rtcp_report_to_ami(), speech_test_server_get(), startup_event_cb(), stasis_app_message_handler(), subscription_persistence_event_cb(), system_registry_to_ami(), and varset_to_ami().

◆ ast_json_string_set()

int ast_json_string_set ( struct ast_json string,
const char *  value 
)

Change the value of a JSON string.

Since
12.0.0

The given value must be a valid ASCII or UTF-8 encoded string.

Parameters
stringJSON string to modify.
valueNew value to store in string.
Return values
0on success.
-1on error.

Definition at line 288 of file json.c.

289{
290 return json_string_set((json_t *)string, value);
291}

References value.

Referenced by AST_TEST_DEFINE(), and conf_send_event_to_participants().

◆ ast_json_stringf()

struct ast_json * ast_json_stringf ( const char *  format,
  ... 
)

Create a JSON string, printf style.

Since
12.0.0

The formatted value must be a valid ASCII or UTF-8 encoded string.

Parameters
formatprintf style format string.
Returns
Newly allocated string.
Return values
NULLon error.

Definition at line 293 of file json.c.

294{
295 struct ast_json *ret;
296 va_list args;
297 va_start(args, format);
298 ret = ast_json_vstringf(format, args);
299 va_end(args);
300 return ret;
301}
struct ast_json * ast_json_vstringf(const char *format, va_list args)
Create a JSON string, vprintf style.
Definition: json.c:303

References args, and ast_json_vstringf().

Referenced by add_json_object(), alloc_security_event_json_object(), ast_ari_get_docs(), AST_TEST_DEFINE(), and units_to_json().

◆ ast_json_timeval()

struct ast_json * ast_json_timeval ( const struct timeval  tv,
const char *  zone 
)

Construct a timeval as JSON.

JSON does not define a standard date format (boo), but the de facto standard is to use ISO 8601 formatted string. We build a millisecond resolution string from the timeval

Parameters
tvtimeval to encode.
zoneText string of a standard system zoneinfo file. If NULL, the system localtime will be used.
Returns
JSON string with ISO 8601 formatted date/time.
Return values
NULLon error.

Definition at line 670 of file json.c.

671{
672 char buf[AST_ISO8601_LEN];
673 struct ast_tm tm = {};
674
675 ast_localtime(&tv, &tm, zone);
676
677 ast_strftime(buf, sizeof(buf),AST_ISO8601_FORMAT, &tm);
678
680}
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_ISO8601_LEN
Max length of an null terminated, millisecond resolution, ISO8601 timestamp string.
Definition: localtime.h:105
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition: localtime.c:1739
#define AST_ISO8601_FORMAT
ast_strftime for ISO8601 formatting timestamps.
Definition: localtime.h:103
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...
Definition: localtime.c:2524

References AST_ISO8601_FORMAT, AST_ISO8601_LEN, ast_json_string_create(), ast_localtime(), ast_strftime(), and buf.

Referenced by add_json_object(), alloc_security_event_json_object(), app_send_end_msg(), app_update(), ast_ari_asterisk_get_info(), ast_ari_asterisk_ping(), ast_bridge_merge_message_to_json(), ast_bridge_snapshot_to_json(), ast_channel_snapshot_to_json(), AST_TEST_DEFINE(), attended_transfer_to_json(), blind_transfer_to_json(), channel_blob_to_json(), channel_callerid(), channel_connected_line(), channel_destroyed_event(), channel_dialplan(), contactstatus_to_json(), dial_to_json(), dtmf_end_to_json(), hold_to_json(), message_received_handler(), multi_user_event_to_json(), pack_bridge_and_channels(), peerstatus_to_json(), playback_to_json(), recording_to_json(), send_device_state(), send_start_msg_snapshots(), simple_bridge_channel_event(), simple_bridge_event(), simple_channel_event(), simple_endpoint_event(), stasis_app_exec(), and unhold_to_json().

◆ ast_json_to_ast_variables()

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.

Since
12.5.0
Parameters
json_variablesThe JSON blob containing the variable
variablesAn out reference to the variables to populate.
struct ast_json *json_variables = ast_json_pack("[ { s: s } ]", "foo", "bar");
struct ast_variable *variables = NULL;
int res;
res = ast_json_to_ast_variables(json_variables, &variables);
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
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.
Definition: json.c:818
Returns
Conversion enum ast_json_to_ast_vars_code status

Definition at line 818 of file json.c.

819{
820 struct ast_json_iter *it_json_var;
821 struct ast_variable *tail = NULL;
822
823 *variables = NULL;
824
825 for (it_json_var = ast_json_object_iter(json_variables); it_json_var;
826 it_json_var = ast_json_object_iter_next(json_variables, it_json_var)) {
827 struct ast_variable *new_var;
828 const char *key = ast_json_object_iter_key(it_json_var);
829 const char *value;
830 struct ast_json *json_value;
831
832 if (ast_strlen_zero(key)) {
833 continue;
834 }
835
836 json_value = ast_json_object_iter_value(it_json_var);
837 if (ast_json_typeof(json_value) != AST_JSON_STRING) {
838 /* Error: Only strings allowed */
839 ast_variables_destroy(*variables);
840 *variables = NULL;
842 }
843 value = ast_json_string_get(json_value);
844 /* Should never be NULL. Otherwise, how could it be a string type? */
846 if (!value) {
847 /* To be safe. */
848 continue;
849 }
850 new_var = ast_variable_new(key, value, "");
851 if (!new_var) {
852 /* Error: OOM */
853 ast_variables_destroy(*variables);
854 *variables = NULL;
856 }
857
858 tail = ast_variable_list_append_hint(variables, tail, new_var);
859 }
860
862}
#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.
Definition: main/config.c:647
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1262
enum ast_json_type ast_json_typeof(const struct ast_json *json)
Get the type of value.
Definition: json.c:78
struct ast_json * ast_json_object_iter_value(struct ast_json_iter *iter)
Get the value from an iterator.
Definition: json.c:455
struct ast_json_iter * ast_json_object_iter_next(struct ast_json *object, struct ast_json_iter *iter)
Get the next iterator.
Definition: json.c:447
struct ast_json_iter * ast_json_object_iter(struct ast_json *object)
Get an iterator pointing to the first field in a JSON object.
Definition: json.c:439
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:283
const char * ast_json_object_iter_key(struct ast_json_iter *iter)
Get the key from an iterator.
Definition: json.c:451
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Iterator for JSON object key/values.
#define ast_assert(a)
Definition: utils.h:739

References ast_assert, ast_json_object_iter(), ast_json_object_iter_key(), ast_json_object_iter_next(), ast_json_object_iter_value(), AST_JSON_STRING, ast_json_string_get(), AST_JSON_TO_AST_VARS_CODE_INVALID_TYPE, AST_JSON_TO_AST_VARS_CODE_OOM, AST_JSON_TO_AST_VARS_CODE_SUCCESS, ast_json_typeof(), ast_strlen_zero(), ast_variable_list_append_hint(), ast_variable_new, ast_variables_destroy(), NULL, and value.

Referenced by json_to_ast_variables(), sorcery_astdb_retrieve_fields_common(), sorcery_astdb_retrieve_id(), sorcery_astdb_retrieve_prefix(), and sorcery_astdb_retrieve_regex().

◆ ast_json_true()

struct ast_json * ast_json_true ( void  )

Get the JSON true value.

Since
12.0.0

The returned value is a singleton, and does not need to be ast_json_unref()'ed.

Returns
JSON true.

Definition at line 233 of file json.c.

234{
235 return (struct ast_json *)json_true();
236}

Referenced by AST_TEST_DEFINE().

◆ ast_json_typename()

const char * ast_json_typename ( enum ast_json_type  type)

Get the string name for the given type.

Since
12.0.0
Parameters
typeType to convert to string.
Returns
Simple string for the type name (object, array, string, etc.)
Return values
?for invalid types.

Definition at line 95 of file json.c.

96{
97 switch (type) {
98 case AST_JSON_OBJECT: return "object";
99 case AST_JSON_ARRAY: return "array";
100 case AST_JSON_STRING: return "string";
101 case AST_JSON_INTEGER: return "integer";
102 case AST_JSON_REAL: return "real";
103 case AST_JSON_TRUE: return "boolean";
104 case AST_JSON_FALSE: return "boolean";
105 case AST_JSON_NULL: return "null";
106 }
107 ast_assert(0);
108 return "?";
109}
static const char type[]
Definition: chan_ooh323.c:109

References ast_assert, AST_JSON_ARRAY, AST_JSON_FALSE, AST_JSON_INTEGER, AST_JSON_NULL, AST_JSON_OBJECT, AST_JSON_REAL, AST_JSON_STRING, AST_JSON_TRUE, and type.

Referenced by ast_ari_validate_boolean(), and check_type().

◆ ast_json_typeof()

enum ast_json_type ast_json_typeof ( const struct ast_json value)

◆ ast_json_unref()

void ast_json_unref ( struct ast_json value)

Decrease refcount on value. If refcount reaches zero, value is freed.

Since
12.0.0
Note
It is safe to pass NULL to this function.

Definition at line 73 of file json.c.

74{
75 json_decref((json_t *) json);
76}

Referenced by __expire_registry(), __iax2_poke_noanswer(), agi_handle_command(), alloc_security_event_json_object(), analog_publish_channel_alarm_clear(), analog_publish_dnd_state(), aoc_event_blob_dtor(), app_data_dtor(), app_dtor(), app_event_filter_set(), app_send_end_msg(), app_to_json(), app_update(), ari_bridges_play_found(), ari_bridges_play_new(), ast_aoc_manager_event(), ast_ari_applications_list(), ast_ari_applications_subscribe(), ast_ari_applications_unsubscribe(), ast_ari_asterisk_get_global_var(), ast_ari_asterisk_get_info(), ast_ari_asterisk_get_module(), ast_ari_asterisk_list_log_channels(), ast_ari_bridges_list(), ast_ari_bridges_record(), ast_ari_callback(), ast_ari_channels_get_channel_var(), ast_ari_channels_list(), ast_ari_endpoints_list(), ast_ari_endpoints_list_by_tech(), ast_ari_recordings_list_stored(), ast_ari_response_error(), ast_ari_sounds_list(), ast_ari_websocket_events_event_websocket_established(), ast_ari_websocket_session_read(), ast_bridge_channel_write_hold(), ast_bridge_merge_message_to_json(), ast_bridge_publish_enter(), ast_bucket_file_json(), ast_bucket_json(), ast_cel_publish_event(), ast_cel_publish_user_event(), ast_channel_move(), ast_channel_publish_dial_internal(), ast_channel_publish_varset(), ast_endpoint_snapshot_to_json(), ast_manager_publish_event(), ast_queue_hangup_with_cause(), ast_queue_hold(), ast_rtcp_calculate_sr_rr_statistics(), ast_rtcp_interpret(), ast_rtp_convert_stats_json(), ast_sip_persistent_endpoint_publish_contact_state(), ast_sip_persistent_endpoint_update_state(), ast_sip_subscription_set_persistence_data(), ast_softhangup(), ast_sorcery_objectset_json_create(), ast_stir_shaken_vs_verify(), ast_system_publish_registry(), AST_TEST_DEFINE(), asterisk_publication_devicestate_state_change(), asterisk_publication_mwi_state_change(), asterisk_publication_send_refresh(), asterisk_publisher_devstate_cb(), asterisk_publisher_mwistate_cb(), attended_transfer_to_json(), beanstalk_put(), blind_transfer_to_json(), bridge_blob_dtor(), cc_publish(), cc_publish_available(), cc_publish_callerrecalling(), cc_publish_callerstartmonitoring(), cc_publish_callerstopmonitoring(), cc_publish_failure(), cc_publish_monitorfailed(), cc_publish_offertimerstart(), cc_publish_recallcomplete(), cc_publish_requestacknowledged(), cc_publish_requested(), cel_attended_transfer_cb(), cel_blind_transfer_cb(), cel_bridge_enter_cb(), cel_bridge_leave_cb(), cel_bs_put(), cel_channel_state_change(), cel_dial_cb(), cel_local_optimization_cb_helper(), cel_parking_cb(), cel_pickup_cb(), celgenuserevent_exec(), channel_blob_dtor(), channel_blob_to_json(), channel_to_json(), conf_handle_talker_cb(), conf_run(), conf_send_event_to_participants(), confbridge_handle_atxfer(), contactstatus_to_json(), container_to_json_array(), create_sound_blob(), destroy_subscription(), dial_to_json(), endpoint_blob_dtor(), event_session_shutdown(), event_session_update_websocket(), fetch_access_token(), fetch_google_access_token(), format_log_json(), generate_filenames_json(), handle_msg_cb(), handle_security_event(), join_queue(), json_array_from_list(), json_decode_read(), json_payload_destructor(), launch_asyncagi(), leave_queue(), local_optimization_finished_cb(), local_optimization_started_cb(), manager_mute_mixmonitor(), meetme_stasis_generate_msg(), message_json_construct2(), message_json_destruct(), message_received_handler(), moh_post_start(), msg_to_json(), multi_channel_blob_dtor(), multi_object_blob_dtor(), mwi_blob_dtor(), notify_new_message(), pack_payload(), peerstatus_to_json(), playback_publish(), publish_acl_change(), publish_async_exec_end(), publish_channel_alarm(), publish_channel_alarm_clear(), publish_chanspy_message(), publish_cluster_discovery_to_stasis_full(), publish_dahdichannel(), publish_dnd_state(), publish_format_update(), publish_fully_booted(), publish_hangup_handler_message(), publish_load_message_type(), publish_local_bridge_message(), publish_span_alarm(), publish_span_alarm_clear(), queue_publish_member_blob(), really_quit(), record_abandoned(), recording_publish(), report_fax_status(), report_receive_fax_status(), report_send_fax_status(), reset_user_pw(), response_free(), return_sorcery_object(), ring_entry(), rna(), rtcp_message_handler(), rtcp_message_payload_dtor(), rtcp_report_to_json(), send_agent_complete(), send_agent_login(), send_agent_logoff(), send_conf_stasis(), send_conf_stasis_snapshots(), send_device_state(), send_dtmf_begin_event(), send_dtmf_end_event(), send_join_event(), send_leave_event(), send_mute_event(), send_talking_event(), send_unmute_event(), simple_bridge_channel_event(), socket_process_helper(), sorcery_astdb_create(), sorcery_astdb_retrieve_fields_common(), sorcery_astdb_retrieve_id(), sorcery_astdb_retrieve_prefix(), sorcery_astdb_retrieve_regex(), speech_test_server_handle_request(), start_message_blob_dtor(), stasis_app_exec(), stasis_app_mailboxes_to_json(), stasis_app_playback_to_json(), stasis_app_recording_to_json(), stasis_app_user_event(), stasis_start_to_json(), stun_monitor_request(), sub_bridge_update_handler(), sub_channel_update_handler(), sub_endpoint_update_handler(), subscription_persistence_destroy(), talk_detect_audiohook_cb(), test_name_number(), try_calling(), unload_module(), update_registry(), and userevent_exec().

◆ ast_json_utf8_check()

int ast_json_utf8_check ( const char *  str)

Check the nul terminated string for UTF-8 format.

Since
13.12.0
Parameters
strString to check.
Return values
0if not UTF-8 encoded or str is NULL.
1if UTF-8 encoded.

Definition at line 228 of file json.c.

229{
230 return str ? ast_json_utf8_check_len(str, strlen(str)) : 0;
231}
const char * str
Definition: app_jack.c:147
int ast_json_utf8_check_len(const char *str, size_t len)
Check the string of the given length for UTF-8 format.
Definition: json.c:186

References ast_json_utf8_check_len(), and str.

◆ ast_json_utf8_check_len()

int ast_json_utf8_check_len ( const char *  str,
size_t  len 
)

Check the string of the given length for UTF-8 format.

Since
13.12.0
Parameters
strString to check.
lenLength of string to check.
Return values
0if not UTF-8 encoded or str is NULL.
1if UTF-8 encoded.

Definition at line 186 of file json.c.

187{
188 size_t pos;
189 size_t count;
190 int res = 1;
191
192 if (!str) {
193 return 0;
194 }
195
196 /*
197 * Since the json library does not make the check function
198 * public we recreate/copy the function in our interface
199 * module.
200 *
201 * Loop ported from libjansson utf.c:utf8_check_string()
202 */
203 for (pos = 0; pos < len; pos += count) {
204 count = json_utf8_check_first(str[pos]);
205 if (count == 0) {
206 res = 0;
207 break;
208 } else if (count > 1) {
209 if (count > len - pos) {
210 /* UTF-8 needs more than we have left in the string. */
211 res = 0;
212 break;
213 }
214
215 if (!json_utf8_check_full(&str[pos], count)) {
216 res = 0;
217 break;
218 }
219 }
220 }
221
222 if (!res) {
223 ast_debug(1, "String '%.*s' is not UTF-8 for json conversion\n", (int) len, str);
224 }
225 return res;
226}
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_debug(level,...)
Log a DEBUG message.
static size_t json_utf8_check_full(const char *str, size_t len)
Definition: json.c:144
static size_t json_utf8_check_first(char byte)
Definition: json.c:112

References ast_debug, json_utf8_check_first(), json_utf8_check_full(), len(), and str.

Referenced by ast_json_utf8_check().

◆ ast_json_vpack()

struct ast_json * ast_json_vpack ( char const *  format,
va_list  ap 
)

Helper for creating complex JSON values simply.

Since
12.0.0

See original Jansson docs at http://www.digip.org/jansson/doc/2.11/apiref.html#apiref-pack for more details.

Definition at line 621 of file json.c.

622{
623 json_error_t error;
624 struct ast_json *r = NULL;
625 if (format) {
626 r = (struct ast_json *)json_vpack_ex(&error, 0, format, ap);
627 if (!r && !ast_strlen_zero(error.text)) {
629 "Error building JSON from '%s': %s.\n",
630 format, error.text);
632 }
633 }
634 return r;
635}
void ast_log_backtrace(void)
Log a backtrace of the current thread's execution stack to the Asterisk log.
Definition: logger.c:2510

References ast_log, ast_log_backtrace(), ast_strlen_zero(), error(), LOG_ERROR, and NULL.

Referenced by ast_json_pack().

◆ ast_json_vstringf()

struct ast_json * ast_json_vstringf ( const char *  format,
va_list  args 
)

Create a JSON string, vprintf style.

Since
12.0.0

The formatted value must be a valid ASCII or UTF-8 encoded string.

Parameters
formatprintf style format string.
args
Returns
Newly allocated string.
Return values
NULLon error.

Definition at line 303 of file json.c.

304{
305 json_t *ret = NULL;
306
307 if (format) {
308 /* json_pack was not introduced until jansson-2.0 so Asterisk could never
309 * be compiled against older versions. The version check can never match
310 * anything older than 2.12. */
311#if defined(HAVE_JANSSON_BUNDLED) || JANSSON_MAJOR_VERSION > 2 || JANSSON_MINOR_VERSION > 11
312 ret = json_vsprintf(format, args);
313#else
314 char *str = NULL;
315 int err = ast_vasprintf(&str, format, args);
316
317 if (err >= 0) {
318 ret = json_string(str);
319 ast_free(str);
320 }
321#endif
322 }
323
324 return (struct ast_json *)ret;
325}
#define ast_vasprintf(ret, fmt, ap)
A wrapper for vasprintf()
Definition: astmm.h:278

References args, ast_free, ast_vasprintf, NULL, and str.

Referenced by ast_ari_response_error(), and ast_json_stringf().