Asterisk - The Open Source Telephony Project  18.5.0
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_true (void)
 Get the JSON true value. More...
 
struct ast_jsonast_json_false (void)
 Get the JSON false value. More...
 
struct ast_jsonast_json_boolean (int value)
 Get the JSON boolean corresponding to value. More...
 
struct ast_jsonast_json_null (void)
 Get the JSON null value. More...
 
int ast_json_is_true (const struct ast_json *value)
 Check if value is JSON true. 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...
 
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...
 
struct ast_jsonast_json_array_create (void)
 Create a empty JSON 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_array_get (const struct ast_json *array, size_t index)
 Get 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...
 
int ast_json_array_append (struct ast_json *array, struct ast_json *value)
 Append to 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_clear (struct ast_json *array)
 Remove all elements from an array. More...
 
int ast_json_array_extend (struct ast_json *array, struct ast_json *tail)
 Append all elements from tail to array. More...
 
int ast_json_equal (const struct ast_json *lhs, const struct ast_json *rhs)
 Compare two JSON objects. 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...
 
typedef AST_JSON_INT_T ast_json_int_t
 Primarily used to cast when packing to an "I" type. More...
 
int ast_json_init (void)
 Initialize the JSON library. 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_reset_alloc_funcs (void)
 Change alloc funcs back to the resource module defaults. More...
 
void * ast_json_malloc (size_t size)
 Asterisk's custom JSON allocator. Exposed for use by unit tests. More...
 
void ast_json_free (void *p)
 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_unref (struct ast_json *value)
 Decrease refcount on value. If refcount reaches zero, value is freed. 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...
 
enum ast_json_type ast_json_typeof (const struct ast_json *value)
 Get the type of value. More...
 
const char * ast_json_typename (enum ast_json_type type)
 Get the string name for the given type. 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_utf8_check_len (const char *str, size_t len)
 Check the string of the given length for UTF-8 format. More...
 
int ast_json_utf8_check (const char *str)
 Check the nul terminated string for UTF-8 format. 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...
 
struct ast_jsonast_json_object_create (void)
 Create a new JSON object. More...
 
size_t ast_json_object_size (struct ast_json *object)
 Get size of JSON object. More...
 
struct ast_jsonast_json_object_get (struct ast_json *object, const char *key)
 Get a 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...
 
int ast_json_object_del (struct ast_json *object, const char *key)
 Delete a field from a JSON object. More...
 
int ast_json_object_clear (struct ast_json *object)
 Delete all elements 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...
 
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...
 
struct ast_json_iterast_json_object_iter_next (struct ast_json *object, struct ast_json_iter *iter)
 Get the next iterator. More...
 
const char * ast_json_object_iter_key (struct ast_json_iter *iter)
 Get the key from an iterator. More...
 
struct ast_jsonast_json_object_iter_value (struct ast_json_iter *iter)
 Get the value from an 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...
 
#define ast_json_dump_string(root)   ast_json_dump_string_format(root, AST_JSON_COMPACT)
 Encode a JSON value to a compact string. More...
 
#define ast_json_dump_str(root, dst)   ast_json_dump_str_format(root, dst, AST_JSON_COMPACT)
 
#define ast_json_dump_file(root, output)   ast_json_dump_file_format(root, output, AST_JSON_COMPACT)
 
#define ast_json_dump_new_file(root, path)   ast_json_dump_new_file_format(root, path, AST_JSON_COMPACT)
 
#define AST_JSON_ERROR_TEXT_LENGTH   160
 
#define AST_JSON_ERROR_SOURCE_LENGTH   80
 
enum  ast_json_encoding_format { AST_JSON_COMPACT, AST_JSON_PRETTY }
 Encoding format type. 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...
 
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...
 
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...
 
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...
 
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_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_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_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_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 }
 
struct ast_jsonast_json_name_number (const char *name, const char *number)
 Common JSON rendering functions for common 'objects'. More...
 
struct ast_jsonast_json_timeval (const struct timeval tv, const char *zone)
 Construct a timeval 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_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_dialplan_cep (const char *context, const char *exten, int priority)
 Construct a context/exten/priority 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_party_id (struct ast_party_id *party)
 Construct an ast_party_id 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...
 
struct ast_jsonast_json_channel_vars (struct varshead *channelvars)
 Construct a JSON object from a ast_var_t list. 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;
}
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 794 of file json.h.

Referenced by AST_TEST_DEFINE().

◆ 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 808 of file json.h.

Referenced by AST_TEST_DEFINE().

◆ ast_json_dump_str

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

Definition at line 778 of file json.h.

Referenced by AST_TEST_DEFINE().

◆ ast_json_dump_string

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

◆ AST_JSON_ERROR_SOURCE_LENGTH

#define AST_JSON_ERROR_SOURCE_LENGTH   80

Definition at line 823 of file json.h.

◆ AST_JSON_ERROR_TEXT_LENGTH

#define AST_JSON_ERROR_TEXT_LENGTH   160

Definition at line 822 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.
NULL on error, or key value is not a string.

Definition at line 573 of file json.h.

Referenced by app_event_filter_matched(), and app_event_filter_set().

◆ 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.

Referenced by association_to_json(), ast_json_name_number(), channel_dialplan(), currency_to_json(), json_party_name(), json_party_number(), json_party_subaddress(), phase_e_handler(), report_fax_status(), report_receive_fax_status(), report_send_fax_status(), and set_channel_variables().

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

Definition at line 745 of file json.h.

746 {
747  /*! Compact format, low human readability */
749  /*! Formatted for human readability */
751 };

◆ 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 1051 of file json.h.

1051  {
1052  /*! \brief Conversion successful */
1054  /*!
1055  * \brief Conversion failed because invalid value type supplied.
1056  * \note Only string values allowed.
1057  */
1059  /*! \brief Conversion failed because of allocation failure. (Out Of Memory) */
1061 };
Conversion failed because invalid value type supplied.
Definition: json.h:1058
Conversion successful.
Definition: json.h:1053
Conversion failed because of allocation failure. (Out Of Memory)
Definition: json.h:1060

◆ 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.

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.
Returns
0 on success.
-1 on error.

Definition at line 368 of file json.c.

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().

369 {
370  return json_array_append_new((json_t *)array, (json_t *)value);
371 }

◆ 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.
Returns
0 on success.
-1 on error.

Definition at line 380 of file json.c.

Referenced by AST_TEST_DEFINE().

381 {
382  return json_array_clear((json_t *)array);
383 }

◆ 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.
Returns
0 on success.
-1 on error.

Definition at line 384 of file json.c.

Referenced by AST_TEST_DEFINE().

385 {
386  return json_array_extend((json_t *)array, (json_t *)tail);
387 }

◆ ast_json_array_get()

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

Get an element from an array.

Since
12.0.0

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

Parameters
arrayJSON array.
indexZero-based index into array.
Returns
The specified element.
NULL if array not an array.
NULL if index is out of bounds.

Definition at line 360 of file json.c.

Referenced by app_event_filter_matched(), app_event_filter_set(), ast_ari_applications_subscribe_parse_body(), ast_ari_applications_unsubscribe_parse_body(), ast_ari_asterisk_get_info_parse_body(), ast_ari_asterisk_update_object(), ast_ari_bridges_add_channel_parse_body(), ast_ari_bridges_play_parse_body(), ast_ari_bridges_play_with_id_parse_body(), ast_ari_bridges_remove_channel_parse_body(), ast_ari_channels_play_parse_body(), ast_ari_channels_play_with_id_parse_body(), ast_ari_events_user_event_parse_body(), ast_ari_validate_list(), AST_TEST_DEFINE(), channel_fax_cb(), and manager_json_to_ast_str().

361 {
362  return (struct ast_json *)json_array_get((json_t *)array, index);
363 }
Abstract JSON element (object, array, string, int, ...).

◆ 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.
Returns
0 on success.
-1 on error.

Definition at line 372 of file json.c.

Referenced by AST_TEST_DEFINE().

373 {
374  return json_array_insert_new((json_t *)array, index, (json_t *)value);
375 }

◆ 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.
Returns
0 on success.
-1 on error.

Definition at line 376 of file json.c.

Referenced by AST_TEST_DEFINE().

377 {
378  return json_array_remove((json_t *)array, index);
379 }

◆ 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.
Returns
0 on success.
-1 on error.

Definition at line 364 of file json.c.

Referenced by AST_TEST_DEFINE().

365 {
366  return json_array_set_new((json_t *)array, index, (json_t *)value);
367 }

◆ 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.

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

244 {
245  return (struct ast_json *)json_boolean(value);
246 }
int value
Definition: syslog.c:37
Abstract JSON element (object, array, string, int, ...).

◆ 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 843 of file json.c.

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

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

844 {
845  struct ast_json *ret;
846  struct ast_var_t *var;
847 
848  ret = ast_json_object_create();
849  AST_LIST_TRAVERSE(channelvars, var, entries) {
851  }
852 
853  return ret;
854 }
#define var
Definition: ast_expr2f.c:614
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
Definition: json.c:389
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:404
char name[0]
Definition: chanvars.h:31
char * value
Definition: chanvars.h:30
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
struct ast_var_t::@249 entries
Abstract JSON element (object, array, string, int, ...).
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268

◆ 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.
NULL on error.

Definition at line 616 of file json.c.

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

617 {
618  return (struct ast_json *)json_copy((json_t *)value);
619 }
Abstract JSON element (object, array, string, int, ...).

◆ 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.
NULL on error.

Definition at line 620 of file json.c.

Referenced by AST_TEST_DEFINE(), and stir_shaken_verify_json().

621 {
622  return (struct ast_json *)json_deep_copy((json_t *)value);
623 }
Abstract JSON element (object, array, string, int, ...).

◆ 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 644 of file json.c.

References ast_json_dialplan_cep_app().

645 {
647 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
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:632
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ 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 632 of file json.c.

References ast_json_integer_create(), ast_json_null(), and ast_json_pack().

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

634 {
635  return ast_json_pack("{s: s?, s: s?, s: o, s: s?, s: s?}",
636  "context", context,
637  "exten", exten,
638  "priority", priority != -1 ? ast_json_integer_create(priority) : ast_json_null(),
639  "app_name", app_name,
640  "app_data", app_data
641  );
642 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
static int priority
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:591
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
Definition: json.c:317

◆ 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.
Returns
0 on success.
-1 on error. The contents of output are undefined.

Definition at line 505 of file json.c.

References dump_flags().

506 {
507  if (!root || !output) {
508  return -1;
509  }
510  return json_dumpf((json_t *)root, output, dump_flags(format));
511 }
static snd_pcm_format_t format
Definition: chan_alsa.c:102
static size_t dump_flags(enum ast_json_encoding_format format)
Default flags for JSON encoding.
Definition: json.c:457

◆ 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.
Returns
0 on success.
-1 on error. The contents of output are undefined.

Definition at line 512 of file json.c.

References dump_flags().

513 {
514  if (!root || !path) {
515  return -1;
516  }
517  return json_dump_file((json_t *)root, path, dump_flags(format));
518 }
static snd_pcm_format_t format
Definition: chan_alsa.c:102
static size_t dump_flags(enum ast_json_encoding_format format)
Default flags for JSON encoding.
Definition: json.c:457

◆ 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.
Returns
0 on success.
-1 on error. The contents of dst are undefined.

Definition at line 499 of file json.c.

References dump_flags(), and write_to_ast_str().

Referenced by ast_ari_callback().

500 {
501  return json_dump_callback((json_t *)root, write_to_ast_str, dst, dump_flags(format));
502 }
static int write_to_ast_str(const char *buffer, size_t size, void *data)
Definition: json.c:468
static snd_pcm_format_t format
Definition: chan_alsa.c:102
static size_t dump_flags(enum ast_json_encoding_format format)
Default flags for JSON encoding.
Definition: json.c:457

◆ 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.
NULL on error.

Definition at line 463 of file json.c.

References dump_flags().

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

464 {
465  return json_dumps((json_t *)root, dump_flags(format));
466 }
static snd_pcm_format_t format
Definition: chan_alsa.c:102
static size_t dump_flags(enum ast_json_encoding_format format)
Default flags for JSON encoding.
Definition: json.c:457

◆ 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.
Returns
True (non-zero) if lhs and rhs are equal.
False (zero) if they are not.

Definition at line 347 of file json.c.

Referenced by AST_TEST_DEFINE(), and test_name_number().

348 {
349  return json_equal((json_t *)lhs, (json_t *)rhs);
350 }

◆ 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.

Referenced by AST_TEST_DEFINE().

239 {
240  return (struct ast_json *)json_false();
241 }
Abstract JSON element (object, array, string, int, ...).

◆ ast_json_free()

void ast_json_free ( void *  p)

◆ ast_json_init()

int ast_json_init ( void  )

Initialize the JSON library.

Definition at line 705 of file json.c.

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

Referenced by asterisk_daemon().

706 {
707  json_t *version_check;
708 
709  /* Setup to use Asterisk custom allocators */
711 
712  /* We depend on functionality of jansson-2.11 but don't actually use
713  * any symbols. If we link at runtime to less than 2.11 this json_pack
714  * will return NULL. */
715  version_check = json_pack("{s: o?, s: o*}",
716  "JSON", NULL,
717  "Bourne", NULL);
718  if (!version_check) {
719  ast_log(LOG_ERROR, "There was a problem finding jansson 2.11 runtime libraries.\n"
720  "Please rebuild Asterisk using ./configure --with-jansson-bundled.\n");
721  return -1;
722  }
723 
724  json_decref(version_check);
725 
726  return 0;
727 }
void ast_json_reset_alloc_funcs(void)
Change alloc funcs back to the resource module defaults.
Definition: json.c:62
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285

◆ 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.
NULL on error.

Definition at line 317 of file json.c.

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(), stasis_app_recording_to_json(), and stir_shaken_add_iat().

318 {
319  return (struct ast_json *)json_integer(value);
320 }
int value
Definition: syslog.c:37
Abstract JSON element (object, array, string, int, ...).

◆ 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.
0 if integer is not a JSON integer.

Definition at line 322 of file json.c.

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(), compare_timestamp(), 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(), queue_agent_cb(), security_event_stasis_cb(), security_event_to_ami_blob(), talking_stop_to_ami(), and test_suite_event_to_ami().

323 {
324  return json_integer_value((json_t *)integer);
325 }

◆ 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.
Returns
0 on success.
-1 on error.

Definition at line 327 of file json.c.

Referenced by AST_TEST_DEFINE().

328 {
329  return json_integer_set((json_t *)integer, value);
330 }
int value
Definition: syslog.c:37

◆ 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
NULL on error.

Definition at line 661 of file json.c.

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().

662 {
663  struct ast_str *string = ast_str_alloca(64);
664 
665  if (!string) {
666  return NULL;
667  }
668 
669  ast_str_set(&string, 0, (ast_sockaddr_is_ipv4(addr) ||
670  ast_sockaddr_is_ipv4_mapped(addr)) ? "IPV4/" : "IPV6/");
671 
672  if (transport_type) {
673  char *transport_string = NULL;
674 
675  /* NOTE: None will be applied if multiple transport types are specified in transport_type */
676  switch(transport_type) {
677  case AST_TRANSPORT_UDP:
678  transport_string = "UDP";
679  break;
680  case AST_TRANSPORT_TCP:
681  transport_string = "TCP";
682  break;
683  case AST_TRANSPORT_TLS:
684  transport_string = "TLS";
685  break;
686  case AST_TRANSPORT_WS:
687  transport_string = "WS";
688  break;
689  case AST_TRANSPORT_WSS:
690  transport_string = "WSS";
691  break;
692  }
693 
694  if (transport_string) {
695  ast_str_append(&string, 0, "%s/", transport_string);
696  }
697  }
698 
699  ast_str_append(&string, 0, "%s", ast_sockaddr_stringify_addr(addr));
700  ast_str_append(&string, 0, "/%s", ast_sockaddr_stringify_port(addr));
701 
702  return ast_json_string_create(ast_str_buffer(string));
703 }
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:290
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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:1091
#define ast_str_alloca(init_len)
Definition: strings.h:800
#define NULL
Definition: resample.c:96
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:1065
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:362
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
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_sockaddr_is_ipv4(const struct ast_sockaddr *addr)
Determine if the address is an IPv4 address.
Definition: netsock2.c:497
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268

◆ ast_json_is_false()

int ast_json_is_false ( const struct ast_json value)

Check if value is JSON false.

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

Definition at line 258 of file json.c.

Referenced by AST_TEST_DEFINE().

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

◆ ast_json_is_null()

int ast_json_is_null ( const struct ast_json value)

Check if value is JSON null.

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

Definition at line 263 of file json.c.

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

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

◆ ast_json_is_true()

int ast_json_is_true ( const struct ast_json value)

Check if value is JSON true.

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

Definition at line 253 of file json.c.

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

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

◆ 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.
NULL on error.

Definition at line 564 of file json.c.

References copy_error().

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

565 {
566  json_error_t jansson_error = {};
567  struct ast_json *r = (struct ast_json *)json_loadb(buffer, buflen, 0, &jansson_error);
568  copy_error(error, &jansson_error);
569  return r;
570 }
static void copy_error(struct ast_json_error *error, const json_error_t *jansson_error)
Copy Jansson error struct to ours.
Definition: json.c:523
Abstract JSON element (object, array, string, int, ...).

◆ 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.
NULL on error.

Definition at line 571 of file json.c.

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

Referenced by AST_TEST_DEFINE().

572 {
573  json_error_t jansson_error = {};
574  struct ast_json *r = NULL;
575  if (input != NULL) {
576  r = (struct ast_json *)json_loadf(input, 0, &jansson_error);
577  copy_error(error, &jansson_error);
578  } else {
579  parse_error(error, "NULL input file", "<null>");
580  }
581  return r;
582 }
#define NULL
Definition: resample.c:96
static int input(yyscan_t yyscanner)
Definition: ast_expr2f.c:1584
static void parse_error(struct ast_json_error *error, const char *text, const char *source)
Definition: json.c:535
static void copy_error(struct ast_json_error *error, const json_error_t *jansson_error)
Copy Jansson error struct to ours.
Definition: json.c:523
Abstract JSON element (object, array, string, int, ...).

◆ 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.
NULL on error.

Definition at line 583 of file json.c.

References copy_error().

Referenced by ast_ari_get_docs(), and AST_TEST_DEFINE().

584 {
585  json_error_t jansson_error = {};
586  struct ast_json *r = (struct ast_json *)json_load_file(path, 0, &jansson_error);
587  copy_error(error, &jansson_error);
588  return r;
589 }
static void copy_error(struct ast_json_error *error, const json_error_t *jansson_error)
Copy Jansson error struct to ours.
Definition: json.c:523
Abstract JSON element (object, array, string, int, ...).

◆ 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.
NULL on error.

Definition at line 559 of file json.c.

References ast_json_load_string(), and ast_str_buffer().

Referenced by AST_TEST_DEFINE().

560 {
561  return ast_json_load_string(ast_str_buffer(input), error);
562 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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:546

◆ 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.
NULL on error.

Definition at line 546 of file json.c.

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

Referenced by ast_json_load_str(), ast_stir_shaken_verify(), AST_TEST_DEFINE(), compare_caller_id(), compare_timestamp(), fetch_access_token(), fetch_google_access_token(), get_attestation_from_payload(), persistence_generator_data_str2struct(), sorcery_astdb_retrieve_fields_common(), sorcery_astdb_retrieve_id(), sorcery_astdb_retrieve_prefix(), and sorcery_astdb_retrieve_regex().

547 {
548  json_error_t jansson_error = {};
549  struct ast_json *r = NULL;
550  if (input != NULL) {
551  r = (struct ast_json *)json_loads(input, 0, &jansson_error);
552  copy_error(error, &jansson_error);
553  } else {
554  parse_error(error, "NULL input string", "<null>");
555  }
556  return r;
557 }
#define NULL
Definition: resample.c:96
static int input(yyscan_t yyscanner)
Definition: ast_expr2f.c:1584
static void parse_error(struct ast_json_error *error, const char *text, const char *source)
Definition: json.c:535
static void copy_error(struct ast_json_error *error, const json_error_t *jansson_error)
Copy Jansson error struct to ours.
Definition: json.c:523
Abstract JSON element (object, array, string, int, ...).

◆ 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.

References ast_malloc.

Referenced by ast_json_reset_alloc_funcs(), and json_debug_malloc().

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

◆ 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
NULL if error (non-UTF8 characters, NULL inputs, etc.)
JSON object with name and number fields

Definition at line 625 of file json.c.

References ast_json_pack(), and AST_JSON_UTF8_VALIDATE.

Referenced by ast_channel_snapshot_to_json(), and test_name_number().

626 {
627  return ast_json_pack("{s: s, s: s}",
628  "name", AST_JSON_UTF8_VALIDATE(name),
629  "number", AST_JSON_UTF8_VALIDATE(number));
630 }
Number structure.
Definition: app_followme.c:154
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
static const char name[]
Definition: cdr_mysql.c:74
#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

◆ 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.
Returns
0 on success.
-1 on error.

Definition at line 412 of file json.c.

Referenced by AST_TEST_DEFINE().

413 {
414  return json_object_clear((json_t *)object);
415 }

◆ ast_json_object_create()

struct ast_json* ast_json_object_create ( void  )

◆ 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.
Returns
0 on success, or -1 if key does not exist.

Definition at line 408 of file json.c.

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

409 {
410  return json_object_del((json_t *)object, key);
411 }

◆ 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.
NULL on error.

Definition at line 397 of file json.c.

References NULL.

Referenced by add_identity_header(), 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_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_sign(), 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(), compare_caller_id(), compare_timestamp(), 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_attestation_from_payload(), get_blob_variable(), get_bool_header(), handle_dial_message(), handle_local_optimization_begin(), handle_local_optimization_end(), handle_masquerade(), handler(), hold_to_json(), 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(), peerstatus_to_ami(), playback_to_json(), queue_agent_cb(), recording_to_json(), registry_message_cb(), rtcp_message_handler(), rtcp_report_to_ami(), security_event_stasis_cb(), security_event_to_ami_blob(), send_start_msg_snapshots(), session_timeout_to_ami(), startup_event_cb(), stasis_app_exec(), stasis_app_message_handler(), stasis_end_to_json(), stasis_start_to_json(), stir_shaken_add_attest(), stir_shaken_add_iat(), stir_shaken_add_origid(), stir_shaken_add_x5u(), stir_shaken_verify_json(), subscription_persistence_event_cb(), system_registry_to_ami(), talking_stop_to_ami(), test_suite_event_to_ami(), and varset_to_ami().

398 {
399  if (!key) {
400  return NULL;
401  }
402  return (struct ast_json *)json_object_get((json_t *)object, key);
403 }
#define NULL
Definition: resample.c:96
Abstract JSON element (object, array, string, int, ...).

◆ 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.
NULL object is empty.
NULL on error.

Definition at line 429 of file json.c.

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_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().

430 {
431  return json_object_iter((json_t *)object);
432 }

◆ 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.
NULL if key does not exist.
NULL on error.

Definition at line 433 of file json.c.

Referenced by AST_TEST_DEFINE().

434 {
435  return json_object_iter_at((json_t *)object, key);
436 }

◆ 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 441 of file json.c.

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_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().

442 {
443  return json_object_iter_key(iter);
444 }

◆ 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.
NULL if iter was the last field.

Definition at line 437 of file json.c.

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_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().

438 {
439  return json_object_iter_next((json_t *)object, iter);
440 }

◆ 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 's field.
Returns
0 on success.
-1 on error.

Definition at line 449 of file json.c.

Referenced by AST_TEST_DEFINE().

450 {
451  return json_object_iter_set_new((json_t *)object, iter, (json_t *)value);
452 }

◆ 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 445 of file json.c.

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_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(), and manager_json_to_ast_str().

446 {
447  return (struct ast_json *)json_object_iter_value(iter);
448 }
Abstract JSON element (object, array, string, int, ...).

◆ 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.
Returns
0 on success.
-1 on error.

Definition at line 404 of file json.c.

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_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(), devices_to_json(), dial_to_json(), external_media_audiosocket_tcp(), external_media_rtp_udp(), handler(), identify_module(), launch_asyncagi(), meetme_stasis_generate_msg(), msg_to_json(), multi_user_event_to_json(), publish_acl_change(), recording_publish(), stasis_app_event_filter_to_json(), stasis_app_message_handler(), stasis_app_recording_to_json(), stasis_app_user_event(), stasis_start_to_json(), stir_shaken_add_attest(), stir_shaken_add_iat(), stir_shaken_add_origid(), stir_shaken_add_x5u(), sub_bridge_update_handler(), units_to_json(), and userevent_exec().

405 {
406  return json_object_set_new((json_t *)object, key, (json_t *)value);
407 }

◆ 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.
Zero of object is not a JSON object.

Definition at line 393 of file json.c.

Referenced by app_event_filter_set(), and AST_TEST_DEFINE().

394 {
395  return json_object_size((json_t *)object);
396 }

◆ 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.
Returns
0 on success.
-1 on error.

Definition at line 416 of file json.c.

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

417 {
418  return json_object_update((json_t *)object, (json_t *)other);
419 }

◆ 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.
Returns
0 on success.
-1 on error.

Definition at line 420 of file json.c.

Referenced by AST_TEST_DEFINE().

421 {
422  return json_object_update_existing((json_t *)object, (json_t *)other);
423 }

◆ 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.
Returns
0 on success.
-1 on error.

Definition at line 424 of file json.c.

Referenced by AST_TEST_DEFINE().

425 {
426  return json_object_update_missing((json_t *)object, (json_t *)other);
427 }

◆ 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 591 of file json.c.

References args, and ast_json_vpack().

Referenced by __ast_test_suite_event_notify(), __expire_registry(), __iax2_poke_noanswer(), add_format_information_cb(), add_identity_header(), 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_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_cb(), 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(), expire_register(), format_log_json(), handle_response_peerpoke(), 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_received_handler(), moh_post_start(), msg_to_json(), notify_new_message(), pack_bridge_and_channels(), parse_register_contact(), peerstatus_to_json(), phase_e_handler(), 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_qualify_peer_done(), publish_span_alarm(), publish_span_alarm_clear(), queue_member_blob_create(), really_quit(), record_abandoned(), recording_to_json(), register_verify(), report_fax_status(), report_receive_fax_status(), report_send_fax_status(), 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_session_timeout(), send_start_msg_snapshots(), send_unmute_event(), simple_bridge_channel_event(), simple_bridge_event(), simple_channel_event(), simple_endpoint_event(), sip_poke_noanswer(), skinny_register(), skinny_session_cleanup(), socket_process_helper(), 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(), unload_module(), update_registry(), and userevent_exec().

592 {
593  struct ast_json *ret;
594  va_list args;
595  va_start(args, format);
596  ret = ast_json_vpack(format, args);
597  va_end(args);
598  return ret;
599 }
struct ast_json * ast_json_vpack(char const *format, va_list ap)
Helper for creating complex JSON values simply.
Definition: json.c:600
const char * args
Abstract JSON element (object, array, string, int, ...).
static snd_pcm_format_t format
Definition: chan_alsa.c:102

◆ 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 784 of file json.c.

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.

785 {
786  int pres = ast_party_id_presentation(party);
787 
788  /* Combined party presentation */
789  return ast_json_pack("{s: i, s: s, s: o*, s: o*, s: o*}",
790  "presentation", pres,
791  "presentation_txt", ast_describe_caller_presentation(pres),
792  "number", json_party_number(&party->number),
793  "name", json_party_name(&party->name),
794  "subaddress", json_party_subaddress(&party->subaddress));
795 }
static struct ast_json * json_party_subaddress(struct ast_party_subaddress *subaddress)
Definition: json.c:773
const char * ast_describe_caller_presentation(int data)
Convert caller ID pres value to explanatory string.
Definition: callerid.c:1164
struct ast_party_name name
Subscriber name.
Definition: channel.h:341
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
Definition: channel.c:1821
static struct ast_json * json_party_number(struct ast_party_number *number)
Definition: json.c:749
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
static struct ast_json * json_party_name(struct ast_party_name *name)
Definition: json.c:761
struct ast_party_subaddress subaddress
Subscriber subaddress.
Definition: channel.h:345
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:343

◆ 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
Return values
NULLif we fail to alloc it
pointerto the ast_json_payload created

Definition at line 735 of file json.c.

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().

736 {
737  struct ast_json_payload *payload;
738 
739  if (!(payload = ao2_alloc(sizeof(*payload), json_payload_destructor))) {
740  return NULL;
741  }
742 
743  ast_json_ref(json);
744  payload->json = json;
745 
746  return payload;
747 }
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:729
struct ast_json * json
Definition: json.h:1025
#define NULL
Definition: resample.c:96
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411

◆ 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.
NULL on error.

Definition at line 332 of file json.c.

Referenced by ast_ari_asterisk_get_info(), and ast_rtp_convert_stats_json().

333 {
334  return (struct ast_json *)json_real(value);
335 }
int value
Definition: syslog.c:37
Abstract JSON element (object, array, string, int, ...).

◆ 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.
0 if real is not a JSON real number.

Definition at line 337 of file json.c.

Referenced by rtcp_report_to_ami().

338 {
339  return json_real_value((json_t *)real);
340 }

◆ 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
integerJSON real number to modify.
valueNew value for real.
Returns
0 on success.
-1 on error.

Definition at line 342 of file json.c.

343 {
344  return json_real_set((json_t *)real, value);
345 }
int value
Definition: syslog.c:37

◆ 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.

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_received_handler(), multi_user_event_to_json(), phase_e_handler(), publish_load_message_type(), report_receive_fax_status(), return_sorcery_object(), 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().

68 {
69  json_incref((json_t *)json);
70  return json;
71 }
struct ast_json * json
Definition: json.h:1025

◆ 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.

References ast_json_free(), and ast_json_malloc().

Referenced by ast_json_init(), and json_test_cleanup().

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

◆ 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.

Referenced by json_test_init().

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

◆ 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.
NULL on error.

Definition at line 273 of file json.c.

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_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_stir_shaken_sign(), 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(), compare_caller_id(), 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_attestation_from_payload(), get_blob_variable(), handle_dial_message(), handle_masquerade(), hold_to_json(), local_message_to_ami(), manager_generic_msg_cb(), manager_json_value_str_append(), meetme_stasis_cb(), multi_user_event_to_ami(), mwi_app_event_cb(), mwi_startup_event_cb(), peerstatus_to_ami(), playback_to_json(), queue_agent_cb(), recording_to_json(), registry_message_cb(), rtcp_message_handler(), rtcp_report_to_ami(), session_timeout_to_ami(), startup_event_cb(), stasis_app_message_handler(), stir_shaken_verify_json(), subscription_persistence_event_cb(), system_registry_to_ami(), test_suite_event_to_ami(), and varset_to_ami().

274 {
275  return json_string_value((json_t *)string);
276 }

◆ 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.
Returns
0 on success.
-1 on error.

Definition at line 278 of file json.c.

Referenced by AST_TEST_DEFINE(), and conf_send_event_to_participants().

279 {
280  return json_string_set((json_t *)string, value);
281 }
int value
Definition: syslog.c:37

◆ 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.
NULL on error.

Definition at line 283 of file json.c.

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().

284 {
285  struct ast_json *ret;
286  va_list args;
287  va_start(args, format);
288  ret = ast_json_vstringf(format, args);
289  va_end(args);
290  return ret;
291 }
const char * args
struct ast_json * ast_json_vstringf(const char *format, va_list args)
Create a JSON string, vprintf style.
Definition: json.c:293
Abstract JSON element (object, array, string, int, ...).
static snd_pcm_format_t format
Definition: chan_alsa.c:102

◆ 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.
NULL on error.

Definition at line 649 of file json.c.

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().

650 {
651  char buf[AST_ISO8601_LEN];
652  struct ast_tm tm = {};
653 
654  ast_localtime(&tv, &tm, zone);
655 
656  ast_strftime(buf, sizeof(buf),AST_ISO8601_FORMAT, &tm);
657 
658  return ast_json_string_create(buf);
659 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
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_LEN
Max length of an null terminated, millisecond resolution, ISO8601 timestamp string.
Definition: localtime.h:105
#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
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268

◆ 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);
Returns
Conversion enum ast_json_to_ast_vars_code status

Definition at line 797 of file json.c.

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().

798 {
799  struct ast_json_iter *it_json_var;
800  struct ast_variable *tail = NULL;
801 
802  *variables = NULL;
803 
804  for (it_json_var = ast_json_object_iter(json_variables); it_json_var;
805  it_json_var = ast_json_object_iter_next(json_variables, it_json_var)) {
806  struct ast_variable *new_var;
807  const char *key = ast_json_object_iter_key(it_json_var);
808  const char *value;
809  struct ast_json *json_value;
810 
811  if (ast_strlen_zero(key)) {
812  continue;
813  }
814 
815  json_value = ast_json_object_iter_value(it_json_var);
816  if (ast_json_typeof(json_value) != AST_JSON_STRING) {
817  /* Error: Only strings allowed */
818  ast_variables_destroy(*variables);
819  *variables = NULL;
821  }
822  value = ast_json_string_get(json_value);
823  /* Should never be NULL. Otherwise, how could it be a string type? */
824  ast_assert(value != NULL);
825  if (!value) {
826  /* To be safe. */
827  continue;
828  }
829  new_var = ast_variable_new(key, value, "");
830  if (!new_var) {
831  /* Error: OOM */
832  ast_variables_destroy(*variables);
833  *variables = NULL;
835  }
836 
837  tail = ast_variable_list_append_hint(variables, tail, new_var);
838  }
839 
841 }
struct ast_json * ast_json_object_iter_value(struct ast_json_iter *iter)
Get the value from an iterator.
Definition: json.c:445
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
Iterator for JSON object key/values.
Structure for variables, used for configurations and for channel variables.
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
#define ast_strlen_zero(foo)
Definition: strings.h:52
Conversion failed because invalid value type supplied.
Definition: json.h:1058
#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:648
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
const char * ast_json_object_iter_key(struct ast_json_iter *iter)
Get the key from an iterator.
Definition: json.c:441
Conversion successful.
Definition: json.h:1053
enum ast_json_type ast_json_typeof(const struct ast_json *json)
Get the type of value.
Definition: json.c:78
Conversion failed because of allocation failure. (Out Of Memory)
Definition: json.h:1060
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:437
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:429
Abstract JSON element (object, array, string, int, ...).

◆ 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.

Referenced by AST_TEST_DEFINE().

234 {
235  return (struct ast_json *)json_true();
236 }
Abstract JSON element (object, array, string, int, ...).

◆ 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.)
"?" for invalid types.

Definition at line 95 of file json.c.

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

Referenced by ast_ari_validate_boolean(), and check_type().

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
#define ast_assert(a)
Definition: utils.h:695

◆ ast_json_typeof()

enum ast_json_type ast_json_typeof ( const struct ast_json value)

Get the type of value.

Since
12.0.0
Parameters
valueValue to query.
Returns
Type of value.

Definition at line 78 of file json.c.

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

Referenced by app_event_filter_set(), ast_ari_applications_subscribe_parse_body(), ast_ari_applications_unsubscribe_parse_body(), ast_ari_asterisk_get_info_parse_body(), ast_ari_bridges_add_channel_parse_body(), ast_ari_bridges_play_parse_body(), ast_ari_bridges_play_with_id_parse_body(), ast_ari_bridges_remove_channel_parse_body(), ast_ari_channels_play_parse_body(), ast_ari_channels_play_with_id_parse_body(), ast_ari_events_user_event_parse_body(), ast_ari_validate_boolean(), ast_json_to_ast_variables(), AST_TEST_DEFINE(), check_type(), manager_json_to_ast_str(), manager_json_value_str_append(), and pack_bridge_and_channels().

79 {
80  int r = json_typeof((json_t*)json);
81  switch(r) {
82  case JSON_OBJECT: return AST_JSON_OBJECT;
83  case JSON_ARRAY: return AST_JSON_ARRAY;
84  case JSON_STRING: return AST_JSON_STRING;
85  case JSON_INTEGER: return AST_JSON_INTEGER;
86  case JSON_REAL: return AST_JSON_REAL;
87  case JSON_TRUE: return AST_JSON_TRUE;
88  case JSON_FALSE: return AST_JSON_FALSE;
89  case JSON_NULL: return AST_JSON_NULL;
90  }
91  ast_assert(0); /* Unexpect return from json_typeof */
92  return r;
93 }
#define ast_assert(a)
Definition: utils.h:695

◆ 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.

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_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_payload_free(), 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_cb(), 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(), expire_register(), fetch_access_token(), fetch_google_access_token(), format_log_json(), generate_filenames_json(), handle_msg_cb(), handle_response_peerpoke(), handle_security_event(), join_queue(), json_array_from_list(), json_payload_destructor(), launch_asyncagi(), leave_queue(), local_optimization_finished_cb(), local_optimization_started_cb(), manager_mute_mixmonitor(), meetme_stasis_generate_msg(), message_received_handler(), moh_post_start(), msg_to_json(), multi_channel_blob_dtor(), multi_object_blob_dtor(), mwi_blob_dtor(), notify_new_message(), parse_register_contact(), peerstatus_to_json(), phase_e_handler(), 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_qualify_peer_done(), publish_span_alarm(), publish_span_alarm_clear(), queue_publish_member_blob(), really_quit(), record_abandoned(), recording_publish(), register_verify(), report_fax_status(), report_receive_fax_status(), report_send_fax_status(), 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_session_timeout(), send_talking_event(), send_unmute_event(), simple_bridge_channel_event(), sip_poke_noanswer(), skinny_register(), skinny_session_cleanup(), socket_process_helper(), sorcery_astdb_create(), sorcery_astdb_retrieve_fields_common(), sorcery_astdb_retrieve_id(), sorcery_astdb_retrieve_prefix(), sorcery_astdb_retrieve_regex(), 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_default_handler(), sub_endpoint_update_handler(), subscription_persistence_destroy(), talk_detect_audiohook_cb(), test_name_number(), test_suite_message_payload_dtor(), try_calling(), unload_module(), update_registry(), and userevent_exec().

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

◆ 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.

References ast_json_utf8_check_len().

229 {
230  return str ? ast_json_utf8_check_len(str, strlen(str)) : 0;
231 }
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
const char * str
Definition: app_jack.c:147

◆ 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.

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

Referenced by ast_json_utf8_check().

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 size_t json_utf8_check_full(const char *str, size_t len)
Definition: json.c:144
const char * str
Definition: app_jack.c:147
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static size_t json_utf8_check_first(char byte)
Definition: json.c:112

◆ 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 600 of file json.c.

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

Referenced by ast_json_pack().

601 {
602  json_error_t error;
603  struct ast_json *r = NULL;
604  if (format) {
605  r = (struct ast_json *)json_vpack_ex(&error, 0, format, ap);
606  if (!r && !ast_strlen_zero(error.text)) {
608  "Error building JSON from '%s': %s.\n",
609  format, error.text);
611  }
612  }
613  return r;
614 }
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
void ast_log_backtrace(void)
Log a backtrace of the current thread&#39;s execution stack to the Asterisk log.
Definition: logger.c:2158
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
Abstract JSON element (object, array, string, int, ...).
int error(const char *format,...)
Definition: utils/frame.c:999
static snd_pcm_format_t format
Definition: chan_alsa.c:102

◆ 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.
Returns
Newly allocated string.
NULL on error.

Definition at line 293 of file json.c.

References ast_free, ast_vasprintf, NULL, and str.

Referenced by ast_ari_response_error(), and ast_json_stringf().

294 {
295  json_t *ret = NULL;
296 
297  if (format) {
298  /* json_pack was not introduced until jansson-2.0 so Asterisk could never
299  * be compiled against older versions. The version check can never match
300  * anything older than 2.12. */
301 #if defined(HAVE_JANSSON_BUNDLED) || JANSSON_MAJOR_VERSION > 2 || JANSSON_MINOR_VERSION > 11
302  ret = json_vsprintf(format, args);
303 #else
304  char *str = NULL;
305  int err = ast_vasprintf(&str, format, args);
306 
307  if (err >= 0) {
308  ret = json_string(str);
309  ast_free(str);
310  }
311 #endif
312  }
313 
314  return (struct ast_json *)ret;
315 }
#define ast_vasprintf(ret, fmt, ap)
A wrapper for vasprintf()
Definition: astmm.h:280
const char * str
Definition: app_jack.c:147
const char * args
#define NULL
Definition: resample.c:96
#define ast_free(a)
Definition: astmm.h:182
Abstract JSON element (object, array, string, int, ...).
static snd_pcm_format_t format
Definition: chan_alsa.c:102