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
#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_dump_str(root, dst)   ast_json_dump_str_format(root, dst, AST_JSON_COMPACT)
#define ast_json_dump_string(root)   ast_json_dump_string_format(root, AST_JSON_COMPACT)
 Encode a JSON value to a compact string.
#define AST_JSON_ERROR_SOURCE_LENGTH   80
#define AST_JSON_ERROR_TEXT_LENGTH   160
enum  ast_json_encoding_format { AST_JSON_COMPACT, AST_JSON_PRETTY }
 Encoding format type. 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.
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.
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.
char * ast_json_dump_string_format (struct ast_json *root, enum ast_json_encoding_format format)
 Encode a JSON value to a string.
struct ast_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.
struct ast_jsonast_json_load_file (FILE *input, struct ast_json_error *error)
 Parse a FILE into JSON object or array.
struct ast_jsonast_json_load_new_file (const char *path, struct ast_json_error *error)
 Parse file at path into JSON object or array.
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.
struct ast_jsonast_json_load_string (const char *input, struct ast_json_error *error)
 Parse null terminated string into a JSON object or array.
struct ast_jsonast_json_pack (char const *format,...)
 Helper for creating complex JSON values.
struct ast_jsonast_json_vpack (char const *format, va_list ap)
 Helper for creating complex JSON values simply.
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_dialplan_cep (const char *context, const char *exten, int priority)
 Construct a context/exten/priority as JSON.
struct ast_jsonast_json_ipaddr (const struct ast_sockaddr *addr, enum ast_transport transport_type)
 Construct an IP address as JSON.
struct ast_jsonast_json_name_number (const char *name, const char *number)
 Common JSON rendering functions for common 'objects'.
struct ast_jsonast_json_party_id (struct ast_party_id *party)
 Construct an ast_party_id as JSON.
struct ast_json_payloadast_json_payload_create (struct ast_json *json)
 Create an ao2 object to pass json blobs as data payloads for stasis.
struct ast_jsonast_json_timeval (const struct timeval tv, const char *zone)
 Construct a timeval as JSON.
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.
enum  ast_json_type {
  AST_JSON_OBJECT, AST_JSON_ARRAY, AST_JSON_STRING, AST_JSON_INTEGER,
  AST_JSON_REAL, AST_JSON_TRUE, AST_JSON_FALSE, AST_JSON_NULL
}
 Valid types of a JSON element. More...
const char * ast_json_typename (enum ast_json_type type)
 Get the string name for the given type.
enum ast_json_type ast_json_typeof (const struct ast_json *value)
 Get the type of value.

Functions

int ast_json_array_append (struct ast_json *array, struct ast_json *value)
 Append to an array.
int ast_json_array_clear (struct ast_json *array)
 Remove all elements from an array.
struct ast_jsonast_json_array_create (void)
 Create a empty JSON array.
int ast_json_array_extend (struct ast_json *array, struct ast_json *tail)
 Append all elements from tail to array.
struct ast_jsonast_json_array_get (const struct ast_json *array, size_t index)
 Get an element from an array.
int ast_json_array_insert (struct ast_json *array, size_t index, struct ast_json *value)
 Insert into an array.
int ast_json_array_remove (struct ast_json *array, size_t index)
 Remove an element from an array.
int ast_json_array_set (struct ast_json *array, size_t index, struct ast_json *value)
 Change an element in an array.
size_t ast_json_array_size (const struct ast_json *array)
 Get the size of a JSON array.
struct ast_jsonast_json_boolean (int value)
 Get the JSON boolean corresponding to value.
struct ast_jsonast_json_false (void)
 Get the JSON false value.
int ast_json_is_false (const struct ast_json *value)
 Check if value is JSON false.
int ast_json_is_null (const struct ast_json *value)
 Check if value is JSON null.
int ast_json_is_true (const struct ast_json *value)
 Check if value is JSON true.
struct ast_jsonast_json_null (void)
 Get the JSON null value.
struct ast_jsonast_json_true (void)
 Get the JSON true value.
struct ast_jsonast_json_copy (const struct ast_json *value)
 Copy a JSON value, but not its children.
struct ast_jsonast_json_deep_copy (const struct ast_json *value)
 Copy a JSON value, and its children.
int ast_json_equal (const struct ast_json *lhs, const struct ast_json *rhs)
 Compare two JSON objects.
void ast_json_free (void *p)
 Asterisk's custom JSON allocator. Exposed for use by unit tests.
void ast_json_init (void)
 Initialize the JSON library.
void * ast_json_malloc (size_t size)
 Asterisk's custom JSON allocator. Exposed for use by unit tests.
struct ast_jsonast_json_ref (struct ast_json *value)
 Increase refcount on value.
void ast_json_reset_alloc_funcs (void)
 Change alloc funcs back to the resource module defaults.
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().
void ast_json_unref (struct ast_json *value)
 Decrease refcount on value. If refcount reaches zero, value is freed.
struct ast_jsonast_json_integer_create (intmax_t value)
 Create a JSON integer.
intmax_t ast_json_integer_get (const struct ast_json *integer)
 Get the value from a JSON integer.
int ast_json_integer_set (struct ast_json *integer, intmax_t value)
 Set the value of a JSON integer.
struct ast_jsonast_json_real_create (double value)
 Create a JSON real number.
double ast_json_real_get (const struct ast_json *real)
 Get the value from a JSON real number.
int ast_json_real_set (struct ast_json *real, double value)
 Set the value of a JSON real number.
int ast_json_object_clear (struct ast_json *object)
 Delete all elements from a JSON object.
struct ast_jsonast_json_object_create (void)
 Create a new JSON object.
int ast_json_object_del (struct ast_json *object, const char *key)
 Delete a field from a JSON object.
struct ast_jsonast_json_object_get (struct ast_json *object, const char *key)
 Get a field from a JSON object.
struct ast_json_iterast_json_object_iter (struct ast_json *object)
 Get an iterator pointing to the first field in a JSON object.
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.
const char * ast_json_object_iter_key (struct ast_json_iter *iter)
 Get the key from an iterator.
struct ast_json_iterast_json_object_iter_next (struct ast_json *object, struct ast_json_iter *iter)
 Get the next iterator.
int ast_json_object_iter_set (struct ast_json *object, struct ast_json_iter *iter, struct ast_json *value)
 Set the value of the field pointed to by an iterator.
struct ast_jsonast_json_object_iter_value (struct ast_json_iter *iter)
 Get the value from an iterator.
int ast_json_object_set (struct ast_json *object, const char *key, struct ast_json *value)
 Set a field in a JSON object.
size_t ast_json_object_size (struct ast_json *object)
 Get size of JSON object.
int ast_json_object_update (struct ast_json *object, struct ast_json *other)
 Update object with all of the fields of other.
int ast_json_object_update_existing (struct ast_json *object, struct ast_json *other)
 Update existing fields in object with the fields of other.
int ast_json_object_update_missing (struct ast_json *object, struct ast_json *other)
 Add new fields to object with the fields of other.
struct ast_jsonast_json_string_create (const char *value)
 Construct a JSON string from value.
const char * ast_json_string_get (const struct ast_json *string)
 Get the value of a JSON string.
int ast_json_string_set (struct ast_json *string, const char *value)
 Change the value of a JSON string.
struct ast_jsonast_json_stringf (const char *format,...)
 Create a JSON string, printf style.
struct ast_jsonast_json_vstringf (const char *format, va_list args)
 Create a JSON string, vprintf style.


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.4/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.

Thread Safety
Jansson (as of 2.4) provides fairly weak thread safety guarantees. The Asterisk wrapper improves upon that slightly. The remaining refcounting problems are issues when slicing/sharing/mixing instances between JSON objects and arrays, which we avoid.

The ast_json_dump_* functions are thread safe for multiple concurrent dumps of the same object, so long as the concurrent dumps start from the same root object. But if an object is shared by other JSON objects/arrays, then concurrent dumps of the outer objects/arrays are not thread safe. This can be avoided by using ast_json_deep_copy() when sharing JSON instances between objects.

The ast_json_ref() and ast_json_unref() functions are thread safe. Since the Asterisk wrapper exclusively uses the reference stealing API, Jansson won't be performing many refcount modifications behind our backs. There are a few exceptions.

The first is the transitive json_decref() that occurs when AST_JSON_OBJECT and AST_JSON_ARRAY instances are deleted. This can be avoided by using ast_json_deep_copy() when sharing JSON instances between objects.

The second is when using the reference borrowing specifier in ast_json_pack() (capital O). This can be avoided by using the reference stealing specifier (lowercase o) and wrapping the JSON object parameter with ast_json_ref() for an explicit ref-bump.

Example code
   // Example of how to use the Asterisk JSON API
   static struct ast_json *foo(void) {
      RAII_VAR(struct ast_json *, array, NULL, ast_json_unref);
      RAII_VAR(struct ast_json *, obj, NULL, ast_json_unref);
      int i, res;

      array = ast_json_array_create();
      if (!array) { return NULL; }

      for (i = 0; i < 10; ++i) {
         // NULL safety and object stealing means calls can
         // be chained together directly.
         res = ast_json_array_append(array,
            ast_json_integer_create(i));
         if (res != 0) { return NULL; }
      }

      obj = ast_json_object_create();
      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@digium.com>

Definition in file json.h.


Define Documentation

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

Definition at line 772 of file json.h.

Referenced by AST_TEST_DEFINE().

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

Definition at line 786 of file json.h.

Referenced by AST_TEST_DEFINE().

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

Definition at line 756 of file json.h.

Referenced by AST_TEST_DEFINE().

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

Encode a JSON value to a compact string.

Since:
12.0.0
Returned string must be freed by calling ast_json_free().

Parameters:
root JSON value.
Returns:
String encoding of root.

NULL on error.

Definition at line 741 of file json.h.

Referenced by ast_ari_events_event_websocket_ws_cb(), ast_cel_create_event(), AST_TEST_DEFINE(), asterisk_publication_send_refresh(), asterisk_publisher_devstate_cb(), asterisk_publisher_mwistate_cb(), rtcp_message_handler(), and sorcery_astdb_create().

#define AST_JSON_ERROR_SOURCE_LENGTH   80

Definition at line 801 of file json.h.

#define AST_JSON_ERROR_TEXT_LENGTH   160

Definition at line 800 of file json.h.


Enumeration Type Documentation

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

00724 {
00725    /*! Compact format, low human readability */
00726    AST_JSON_COMPACT,
00727    /*! Formatted for human readability */
00728    AST_JSON_PRETTY,
00729 };

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

01013                                {
01014    /*! \brief Conversion successful */
01015    AST_JSON_TO_AST_VARS_CODE_SUCCESS,
01016    /*!
01017     * \brief Conversion failed because invalid value type supplied.
01018     * \note Only string values allowed.
01019     */
01020    AST_JSON_TO_AST_VARS_CODE_INVALID_TYPE,
01021    /*! \brief Conversion failed because of allocation failure. (Out Of Memory) */
01022    AST_JSON_TO_AST_VARS_CODE_OOM,
01023 };

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

00187 {
00188    AST_JSON_OBJECT,
00189    AST_JSON_ARRAY,
00190    AST_JSON_STRING,
00191    AST_JSON_INTEGER,
00192    AST_JSON_REAL,
00193    AST_JSON_TRUE,
00194    AST_JSON_FALSE,
00195    AST_JSON_NULL,
00196 };


Function Documentation

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:
array JSON array to modify.
value New JSON value to store at the end of array.
Returns:
0 on success.

-1 on error.

Definition at line 403 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(), container_to_json_array(), device_to_json_cb(), generate_filenames_json(), json_array_from_list(), msg_to_json(), report_receive_fax_status(), rtcp_report_to_json(), s_to_json(), send_start_msg_snapshots(), stasis_app_device_states_to_json(), stasis_app_mailboxes_to_json(), test_handler(), and units_to_json().

00404 {
00405    return json_array_append_new((json_t *)array, (json_t *)value);
00406 }

int ast_json_array_clear ( struct ast_json array  ) 

Remove all elements from an array.

Since:
12.0.0
Parameters:
array JSON array to clear.
Returns:
0 on success.

-1 on error.

Definition at line 415 of file json.c.

Referenced by AST_TEST_DEFINE().

00416 {
00417    return json_array_clear((json_t *)array);
00418 }

struct ast_json* ast_json_array_create ( void   )  [read]

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:
array JSON array to modify.
tail JSON array with contents to append to array.
Returns:
0 on success.

-1 on error.

Definition at line 419 of file json.c.

Referenced by AST_TEST_DEFINE().

00420 {
00421    return json_array_extend((json_t *)array, (json_t *)tail);
00422 }

struct ast_json* ast_json_array_get ( const struct ast_json array,
size_t  index 
) [read]

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:
array JSON array.
index Zero-based index into array.
Returns:
The specified element.

NULL if array not an array.

NULL if index is out of bounds.

Definition at line 395 of file json.c.

Referenced by 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_remove_channel_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().

00396 {
00397    return (struct ast_json *)json_array_get((json_t *)array, index);
00398 }

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:
array JSON array to modify.
index Zero-based index into array.
value New JSON value to store in array at index.
Returns:
0 on success.

-1 on error.

Definition at line 407 of file json.c.

Referenced by AST_TEST_DEFINE().

00408 {
00409    return json_array_insert_new((json_t *)array, index, (json_t *)value);
00410 }

int ast_json_array_remove ( struct ast_json array,
size_t  index 
)

Remove an element from an array.

Since:
12.0.0
Parameters:
array JSON array to modify.
index Zero-based index into array.
Returns:
0 on success.

-1 on error.

Definition at line 411 of file json.c.

Referenced by AST_TEST_DEFINE().

00412 {
00413    return json_array_remove((json_t *)array, index);
00414 }

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:
array JSON array to modify.
index Zero-based index into array.
value New JSON value to store in array at index.
Returns:
0 on success.

-1 on error.

Definition at line 399 of file json.c.

Referenced by AST_TEST_DEFINE().

00400 {
00401    return json_array_set_new((json_t *)array, index, (json_t *)value);
00402 }

size_t ast_json_array_size ( const struct ast_json array  ) 

struct ast_json* ast_json_boolean ( int  value  )  [read]

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

References ast_json_false(), and ast_json_true().

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

00284 {
00285 #if JANSSON_VERSION_HEX >= 0x020400
00286    return (struct ast_json *)json_boolean(value);
00287 #else
00288    return value ? ast_json_true() : ast_json_false();
00289 #endif
00290 }

struct ast_json* ast_json_copy ( const struct ast_json value  )  [read]

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:
value JSON value to copy.
Returns:
Shallow copy of value.

NULL on error.

Definition at line 712 of file json.c.

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

00713 {
00714    return (struct ast_json *)json_copy((json_t *)value);
00715 }

struct ast_json* ast_json_deep_copy ( const struct ast_json value  )  [read]

Copy a JSON value, and its children.

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

Parameters:
value JSON value to copy.
Returns:
Deep copy of value.

NULL on error.

Definition at line 716 of file json.c.

Referenced by AST_TEST_DEFINE().

00717 {
00718    return (struct ast_json *)json_deep_copy((json_t *)value);
00719 }

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

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:
context Context name.
exten Extension.
priority Dialplan priority.
Returns:
JSON object with context, exten and priority fields

Definition at line 728 of file json.c.

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

Referenced by ast_channel_snapshot_to_json(), and AST_TEST_DEFINE().

00729 {
00730    return ast_json_pack("{s: o, s: o, s: o}",
00731               "context", context ? ast_json_string_create(context) : ast_json_null(),
00732               "exten", exten ? ast_json_string_create(exten) : ast_json_null(),
00733               "priority", priority != -1 ? ast_json_integer_create(priority) : ast_json_null());
00734 }

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:
root JSON value.
output File to write JSON encoding to.
format encoding format type.
Returns:
0 on success.

-1 on error. The contents of output are undefined.

Definition at line 594 of file json.c.

References dump_flags(), and SCOPED_JSON_LOCK.

00595 {
00596    /* Jansson's json_dump*, even though it's a read operation, isn't
00597     * thread safe for concurrent reads. Locking is necessary.
00598     * See http://www.digip.org/jansson/doc/2.4/portability.html#thread-safety. */
00599    SCOPED_JSON_LOCK(root);
00600    if (!root || !output) {
00601       return -1;
00602    }
00603    return json_dumpf((json_t *)root, output, dump_flags(format));
00604 }

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:
root JSON value.
path Path to file to write JSON encoding to.
format encoding format type.
Returns:
0 on success.

-1 on error. The contents of output are undefined.

Definition at line 605 of file json.c.

References dump_flags(), and SCOPED_JSON_LOCK.

00606 {
00607    /* Jansson's json_dump*, even though it's a read operation, isn't
00608     * thread safe for concurrent reads. Locking is necessary.
00609     * See http://www.digip.org/jansson/doc/2.4/portability.html#thread-safety. */
00610    SCOPED_JSON_LOCK(root);
00611    if (!root || !path) {
00612       return -1;
00613    }
00614    return json_dump_file((json_t *)root, path, dump_flags(format));
00615 }

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:
root JSON value.
dst ast_str to store JSON encoding.
format encoding format type.
Returns:
0 on success.

-1 on error. The contents of dst are undefined.

Definition at line 584 of file json.c.

References dump_flags(), SCOPED_JSON_LOCK, and write_to_ast_str().

Referenced by ast_ari_callback().

00585 {
00586    /* Jansson's json_dump*, even though it's a read operation, isn't
00587     * thread safe for concurrent reads. Locking is necessary.
00588     * See http://www.digip.org/jansson/doc/2.4/portability.html#thread-safety. */
00589    SCOPED_JSON_LOCK(root);
00590    return json_dump_callback((json_t *)root, write_to_ast_str, dst, dump_flags(format));
00591 }

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:
root JSON value.
format encoding format type.
Returns:
String encoding of root.

NULL on error.

Definition at line 544 of file json.c.

References dump_flags(), and SCOPED_JSON_LOCK.

Referenced by ast_ari_websocket_session_write().

00545 {
00546    /* Jansson's json_dump*, even though it's a read operation, isn't
00547     * thread safe for concurrent reads. Locking is necessary.
00548     * See http://www.digip.org/jansson/doc/2.4/portability.html#thread-safety. */
00549    SCOPED_JSON_LOCK(root);
00550    return json_dumps((json_t *)root, dump_flags(format));
00551 }

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:
lhs Value to compare.
rhs Other value to compare.
Returns:
True (non-zero) if lhs and rhs are equal.

False (zero) if they are not.

Definition at line 382 of file json.c.

Referenced by AST_TEST_DEFINE(), and sorcery_json_equal().

00383 {
00384    return json_equal((json_t *)lhs, (json_t *)rhs);
00385 }

struct ast_json* ast_json_false ( void   )  [read]

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

Referenced by ast_json_boolean(), and AST_TEST_DEFINE().

00279 {
00280    return (struct ast_json *)json_false();
00281 }

void ast_json_free ( void *  p  ) 

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

Since:
12.0.0

Definition at line 166 of file json.c.

References ast_assert, AST_LIST_INSERT_HEAD, ast_log, json_free_list(), json_mem_free(), json_mem::list, LOG_ERROR, and to_json_mem().

Referenced by ast_ari_events_event_websocket_ws_cb(), ast_ari_websocket_session_write(), ast_cel_create_event(), ast_json_reset_alloc_funcs(), asterisk_publication_send_refresh(), asterisk_publisher_devstate_cb(), asterisk_publisher_mwistate_cb(), json_debug_free(), msg_to_json(), rtcp_message_handler(), and sorcery_astdb_create().

00167 {
00168    struct json_mem *mem;
00169    struct json_mem_list *free_list;
00170    mem = to_json_mem(p);
00171 
00172    if (!mem) {
00173       return;
00174    }
00175 
00176    /* Since the unref is holding a lock in mem, we can't free it
00177     * immediately. Store it off on a thread local list to be freed by
00178     * ast_json_unref().
00179     */
00180    free_list = json_free_list();
00181    if (!free_list) {
00182       ast_log(LOG_ERROR, "Error allocating free list\n");
00183       ast_assert(0);
00184       /* It's not ideal to free the memory immediately, but that's the
00185        * best we can do if the threadlocal allocation fails */
00186       json_mem_free(mem);
00187       return;
00188    }
00189 
00190    AST_LIST_INSERT_HEAD(free_list, mem, list);
00191 }

void ast_json_init ( void   ) 

Initialize the JSON library.

Definition at line 792 of file json.c.

References ast_json_reset_alloc_funcs().

Referenced by main().

00793 {
00794    /* Setup to use Asterisk custom allocators */
00795    ast_json_reset_alloc_funcs();
00796 }

struct ast_json* ast_json_integer_create ( intmax_t  value  )  [read]

Create a JSON integer.

Since:
12.0.0
Parameters:
value Value of the new JSON integer.
Returns:
Newly allocated integer.

NULL on error.

Definition at line 352 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(), AST_TEST_DEFINE(), meetme_stasis_generate_msg(), and stasis_app_recording_to_json().

00353 {
00354    return (struct ast_json *)json_integer(value);
00355 }

intmax_t ast_json_integer_get ( const struct ast_json integer  ) 

Get the value from a JSON integer.

Since:
12.0.0
Parameters:
integer JSON integer.
Returns:
Value of a JSON integer.

0 if integer is not a JSON integer.

Definition at line 357 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_originate_parse_body(), ast_ari_channels_originate_with_id_parse_body(), ast_ari_channels_play_parse_body(), ast_ari_channels_play_with_id_parse_body(), ast_ari_channels_record_parse_body(), ast_ari_channels_send_dtmf_parse_body(), ast_ari_mailboxes_update_parse_body(), AST_TEST_DEFINE(), asterisk_publication_devicestate(), asterisk_publication_mailboxstate(), cc_available_to_ami(), cc_callerrecalling_to_ami(), cc_callerstartmonitoring_to_ami(), cc_callerstopmonitoring_to_ami(), cc_failure_to_ami(), cc_monitorfailed_to_ami(), cc_offertimerstart_to_ami(), cc_recallcomplete_to_ami(), cc_requestacknowledged_to_ami(), cc_requested_to_ami(), cel_generic_cb(), channel_dtmf_end_cb(), channel_hangup_request_cb(), check_range(), dahdichannel_to_ami(), 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(), and talking_stop_to_ami().

00358 {
00359    return json_integer_value((json_t *)integer);
00360 }

int ast_json_integer_set ( struct ast_json integer,
intmax_t  value 
)

Set the value of a JSON integer.

Since:
12.0.0
Parameters:
integer JSON integer to modify.
value New value for integer.
Returns:
0 on success.

-1 on error.

Definition at line 362 of file json.c.

Referenced by AST_TEST_DEFINE().

00363 {
00364    return json_integer_set((json_t *)integer, value);
00365 }

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

Construct an IP address as JSON.

XXX some comments describing the need for this here

Parameters:
addr ast_sockaddr to encode
transport_type ast_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 748 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().

00749 {
00750    struct ast_str *string = ast_str_alloca(64);
00751 
00752    if (!string) {
00753       return NULL;
00754    }
00755 
00756    ast_str_set(&string, 0, (ast_sockaddr_is_ipv4(addr) ||
00757       ast_sockaddr_is_ipv4_mapped(addr)) ? "IPV4/" : "IPV6/");
00758 
00759    if (transport_type) {
00760       char *transport_string = NULL;
00761 
00762       /* NOTE: None will be applied if multiple transport types are specified in transport_type */
00763       switch(transport_type) {
00764       case AST_TRANSPORT_UDP:
00765          transport_string = "UDP";
00766          break;
00767       case AST_TRANSPORT_TCP:
00768          transport_string = "TCP";
00769          break;
00770       case AST_TRANSPORT_TLS:
00771          transport_string = "TLS";
00772          break;
00773       case AST_TRANSPORT_WS:
00774          transport_string = "WS";
00775          break;
00776       case AST_TRANSPORT_WSS:
00777          transport_string = "WSS";
00778          break;
00779       }
00780 
00781       if (transport_string) {
00782          ast_str_append(&string, 0, "%s/", transport_string);
00783       }
00784    }
00785 
00786    ast_str_append(&string, 0, "%s", ast_sockaddr_stringify_addr(addr));
00787    ast_str_append(&string, 0, "/%s", ast_sockaddr_stringify_port(addr));
00788 
00789    return ast_json_string_create(ast_str_buffer(string));
00790 }

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

Referenced by AST_TEST_DEFINE().

00303 {
00304    return json_is_false((const json_t *)json);
00305 }

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

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

00308 {
00309    return json_is_null((const json_t *)json);
00310 }

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

Referenced by ast_ari_bridges_record_parse_body(), ast_ari_channels_record_parse_body(), AST_TEST_DEFINE(), channel_hangup_request_cb(), get_admin_header(), and local_message_to_ami().

00298 {
00299    return json_is_true((const json_t *)json);
00300 }

struct ast_json* ast_json_load_buf ( const char *  buffer,
size_t  buflen,
struct ast_json_error error 
) [read]

Parse buffer with known length into a JSON object or array.

Since:
12.0.0
Parameters:
buffer Buffer to parse.
buflen Length of buffer.
[out] error Filled with information on error.
Returns:
Parsed JSON element.

NULL on error.

Definition at line 661 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().

00662 {
00663    json_error_t jansson_error = {};
00664    struct ast_json *r = (struct ast_json *)json_loadb(buffer, buflen, 0, &jansson_error);
00665    copy_error(error, &jansson_error);
00666    return r;
00667 }

struct ast_json* ast_json_load_file ( FILE *  input,
struct ast_json_error error 
) [read]

Parse a FILE into JSON object or array.

Since:
12.0.0
Parameters:
input FILE to parse.
[out] error Filled with information on error.
Returns:
Parsed JSON element.

NULL on error.

Definition at line 668 of file json.c.

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

Referenced by AST_TEST_DEFINE().

00669 {
00670    json_error_t jansson_error = {};
00671    struct ast_json *r = NULL;
00672    if (input != NULL) {
00673       r = (struct ast_json *)json_loadf(input, 0, &jansson_error);
00674       copy_error(error, &jansson_error);
00675    } else {
00676       parse_error(error, "NULL input file", "<null>");
00677    }
00678    return r;
00679 }

struct ast_json* ast_json_load_new_file ( const char *  path,
struct ast_json_error error 
) [read]

Parse file at path into JSON object or array.

Since:
12.0.0
Parameters:
path Path of file to parse.
[out] error Filled with information on error.
Returns:
Parsed JSON element.

NULL on error.

Definition at line 680 of file json.c.

References copy_error().

Referenced by ast_ari_get_docs(), and AST_TEST_DEFINE().

00681 {
00682    json_error_t jansson_error = {};
00683    struct ast_json *r = (struct ast_json *)json_load_file(path, 0, &jansson_error);
00684    copy_error(error, &jansson_error);
00685    return r;
00686 }

struct ast_json* ast_json_load_str ( const struct ast_str input,
struct ast_json_error error 
) [read]

Parse ast_str into a JSON object or array.

Since:
12.0.0
Parameters:
input ast_str to parse.
[out] error Filled with information on error.
Returns:
Parsed JSON element.

NULL on error.

Definition at line 656 of file json.c.

References ast_json_load_string(), and ast_str_buffer().

Referenced by AST_TEST_DEFINE().

00657 {
00658    return ast_json_load_string(ast_str_buffer(input), error);
00659 }

struct ast_json* ast_json_load_string ( const char *  input,
struct ast_json_error error 
) [read]

Parse null terminated string into a JSON object or array.

Since:
12.0.0
Parameters:
input String to parse.
[out] error Filled with information on error.
Returns:
Parsed JSON element.

NULL on error.

Definition at line 643 of file json.c.

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

Referenced by ast_json_load_str(), AST_TEST_DEFINE(), sorcery_astdb_retrieve_fields_common(), sorcery_astdb_retrieve_id(), and sorcery_astdb_retrieve_regex().

00644 {
00645    json_error_t jansson_error = {};
00646    struct ast_json *r = NULL;
00647    if (input != NULL) {
00648       r = (struct ast_json *)json_loads(input, 0, &jansson_error);
00649       copy_error(error, &jansson_error);
00650    } else {
00651       parse_error(error, "NULL input string", "<null>");
00652    }
00653    return r;
00654 }

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

References ast_malloc, ast_mutex_init, json_mem::data, JSON_MAGIC, json_mem::magic, json_mem::mutex, and NULL.

Referenced by ast_json_reset_alloc_funcs(), and json_debug_malloc().

00139 {
00140    struct json_mem *mem = ast_malloc(size + sizeof(*mem));
00141    if (!mem) {
00142       return NULL;
00143    }
00144    mem->magic = JSON_MAGIC;
00145    ast_mutex_init(&mem->mutex);
00146    return mem->data;
00147 }

struct ast_json* ast_json_name_number ( const char *  name,
const char *  number 
) [read]

Common JSON rendering functions for common 'objects'.

Simple name/number pair.

Parameters:
name Name
number Number
Returns:
NULL if error (non-UTF8 characters, NULL inputs, etc.)

JSON object with name and number fields

Definition at line 721 of file json.c.

References ast_json_pack().

Referenced by ast_channel_snapshot_to_json(), and AST_TEST_DEFINE().

00722 {
00723    return ast_json_pack("{s: s, s: s}",
00724               "name", name,
00725               "number", number);
00726 }

struct ast_json* ast_json_null ( void   )  [read]

int ast_json_object_clear ( struct ast_json object  ) 

Delete all elements from a JSON object.

Since:
12.0.0
Parameters:
object JSON object to clear.
Returns:
0 on success.

-1 on error.

Definition at line 447 of file json.c.

Referenced by AST_TEST_DEFINE().

00448 {
00449    return json_object_clear((json_t *)object);
00450 }

struct ast_json* ast_json_object_create ( void   )  [read]

Create a new JSON object.

Since:
12.0.0
Returns:
Newly allocated object.

NULL on error.

Definition at line 424 of file json.c.

Referenced by alloc_security_event_json_object(), ast_ari_asterisk_get_info(), ast_bucket_file_json(), ast_sorcery_objectset_json_create(), AST_TEST_DEFINE(), channel_blob_to_json(), multi_user_event_to_json(), publish_acl_change(), s_to_json(), sorcery_objectset_to_json(), stun_monitor_request(), and units_to_json().

00425 {
00426    return (struct ast_json *)json_object();
00427 }

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

Delete a field from a JSON object.

Since:
12.0.0
Parameters:
object JSON object to modify.
key Key of field to delete.
Returns:
0 on success, or -1 if key does not exist.

Definition at line 443 of file json.c.

Referenced by ast_ari_get_docs(), and AST_TEST_DEFINE().

00444 {
00445    return json_object_del((json_t *)object, key);
00446 }

struct ast_json* ast_json_object_get ( struct ast_json object,
const char *  key 
) [read]

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:
object JSON object.
key Key of field to look up.
Returns:
Value with given key.

NULL on error.

Definition at line 432 of file json.c.

References NULL.

Referenced by agent_login_to_ami(), agent_logoff_to_ami(), app_handler(), app_to_json(), append_event_str_single(), append_json_single(), ast_ari_applications_subscribe_parse_body(), ast_ari_applications_unsubscribe_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_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_channels_continue_in_dialplan_parse_body(), ast_ari_channels_get_channel_var_parse_body(), ast_ari_channels_hangup_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_json_object_update_existing(), ast_json_object_update_missing(), 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_moh_start_cb(), confbridge_publish_manager_event(), confbridge_talking_cb(), create_sound_blob(), dahdichannel_to_ami(), dial_to_json(), dtmf_end_to_json(), get_admin_header(), get_blob_variable(), handle_dial_message(), handle_local_optimization_begin(), handle_local_optimization_end(), 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(), peerstatus_to_ami(), playback_to_json(), queue_agent_cb(), recording_to_json(), rtcp_message_handler(), rtcp_report_to_ami(), security_event_stasis_cb(), security_event_to_ami_blob(), send_start_msg_snapshots(), session_timeout_to_ami(), sorcery_json_equal(), stasis_start_to_json(), subscription_persistence_event_cb(), system_registry_to_ami(), talking_stop_to_ami(), and varset_to_ami().

00433 {
00434    if (!key) {
00435       return NULL;
00436    }
00437    return (struct ast_json *)json_object_get((json_t *)object, key);
00438 }

struct ast_json_iter* ast_json_object_iter ( struct ast_json object  )  [read]

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:
object JSON object.
Returns:
Iterator to the first field in object.

NULL object is empty.

NULL on error.

Definition at line 510 of file json.c.

Referenced by ast_ari_validate_application(), ast_ari_validate_application_replaced(), ast_ari_validate_asterisk_info(), 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_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_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_mailbox(), ast_ari_validate_message(), ast_ari_validate_missing_params(), ast_ari_validate_playback(), 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_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_text_message_variable(), ast_ari_validate_variable(), ast_json_object_update_existing(), ast_json_object_update_missing(), ast_json_to_ast_variables(), AST_TEST_DEFINE(), manager_json_to_ast_str(), sorcery_json_equal(), and sorcery_json_to_objectset().

00511 {
00512    return json_object_iter((json_t *)object);
00513 }

struct ast_json_iter* ast_json_object_iter_at ( struct ast_json object,
const char *  key 
) [read]

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:
object JSON object to iterate.
key Key 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 514 of file json.c.

Referenced by AST_TEST_DEFINE().

00515 {
00516    return json_object_iter_at((json_t *)object, key);
00517 }

const char* ast_json_object_iter_key ( struct ast_json_iter iter  ) 

Get the key from an iterator.

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

Definition at line 522 of file json.c.

Referenced by ast_ari_validate_application(), ast_ari_validate_application_replaced(), ast_ari_validate_asterisk_info(), 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_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_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_mailbox(), ast_ari_validate_message(), ast_ari_validate_missing_params(), ast_ari_validate_playback(), 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_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_text_message_variable(), ast_ari_validate_variable(), ast_json_object_update_existing(), ast_json_object_update_missing(), ast_json_to_ast_variables(), AST_TEST_DEFINE(), manager_json_to_ast_str(), sorcery_json_equal(), and sorcery_json_to_objectset().

00523 {
00524    return json_object_iter_key(iter);
00525 }

struct ast_json_iter* ast_json_object_iter_next ( struct ast_json object,
struct ast_json_iter iter 
) [read]

Get the next iterator.

Since:
12.0.0
Parameters:
object JSON object iter was obtained from.
iter JSON object iterator.
Returns:
Iterator to next field in object.

NULL if iter was the last field.

Definition at line 518 of file json.c.

Referenced by ast_ari_validate_application(), ast_ari_validate_application_replaced(), ast_ari_validate_asterisk_info(), 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_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_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_mailbox(), ast_ari_validate_message(), ast_ari_validate_missing_params(), ast_ari_validate_playback(), 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_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_text_message_variable(), ast_ari_validate_variable(), ast_json_object_update_existing(), ast_json_object_update_missing(), ast_json_to_ast_variables(), AST_TEST_DEFINE(), manager_json_to_ast_str(), sorcery_json_equal(), and sorcery_json_to_objectset().

00519 {
00520    return json_object_iter_next((json_t *)object, iter);
00521 }

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:
object JSON object iter was obtained from.
iter JSON object iterator.
value JSON value to store in 's field.
Returns:
0 on success.

-1 on error.

Definition at line 530 of file json.c.

Referenced by AST_TEST_DEFINE().

00531 {
00532    return json_object_iter_set_new((json_t *)object, iter, (json_t *)value);
00533 }

struct ast_json* ast_json_object_iter_value ( struct ast_json_iter iter  )  [read]

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:
iter JSON object iterator.
Returns:
Value of the field iter points to.

Definition at line 526 of file json.c.

Referenced by ast_ari_validate_application(), ast_ari_validate_application_replaced(), ast_ari_validate_asterisk_info(), 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_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_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_mailbox(), ast_ari_validate_message(), ast_ari_validate_missing_params(), ast_ari_validate_playback(), 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_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_text_message_variable(), ast_ari_validate_variable(), ast_json_object_update_existing(), ast_json_object_update_missing(), ast_json_to_ast_variables(), AST_TEST_DEFINE(), manager_json_to_ast_str(), sorcery_json_equal(), and sorcery_json_to_objectset().

00527 {
00528    return (struct ast_json *)json_object_iter_value(iter);
00529 }

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

size_t ast_json_object_size ( struct ast_json object  ) 

Get size of JSON object.

Since:
12.0.0
Parameters:
object JSON object.
Returns:
Size of object.

Zero of object is not a JSON object.

Definition at line 428 of file json.c.

Referenced by AST_TEST_DEFINE().

00429 {
00430    return json_object_size((json_t *)object);
00431 }

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:
object JSON object to modify.
other JSON object to copy into object.
Returns:
0 on success.

-1 on error.

Definition at line 451 of file json.c.

Referenced by AST_TEST_DEFINE(), cc_publish(), meetme_stasis_generate_msg(), and send_conf_stasis().

00452 {
00453    return json_object_update((json_t *)object, (json_t *)other);
00454 }

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:
object JSON object to modify.
other JSON object to copy into object.
Returns:
0 on success.

-1 on error.

Definition at line 455 of file json.c.

References ast_json_object_get(), ast_json_object_iter(), ast_json_object_iter_key(), ast_json_object_iter_next(), ast_json_object_iter_value(), ast_json_object_set(), ast_json_ref(), NULL, and value.

Referenced by AST_TEST_DEFINE().

00456 {
00457 #if JANSSON_VERSION_HEX >= 0x020300
00458    return json_object_update_existing((json_t *)object, (json_t *)other);
00459 #else
00460    struct ast_json_iter *iter = ast_json_object_iter(other);
00461    int ret = 0;
00462 
00463    if (object == NULL || other == NULL) {
00464       return -1;
00465    }
00466 
00467    while (iter != NULL && ret == 0) {
00468       const char *key = ast_json_object_iter_key(iter);
00469 
00470       if (ast_json_object_get(object, key) != NULL) {
00471          struct ast_json *value = ast_json_object_iter_value(iter);
00472 
00473          if (!value || ast_json_object_set(object, key, ast_json_ref(value))) {
00474             ret = -1;
00475          }
00476       }
00477       iter = ast_json_object_iter_next(other, iter);
00478    }
00479    return ret;
00480 #endif
00481 }

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:
object JSON object to modify.
other JSON object to copy into object.
Returns:
0 on success.

-1 on error.

Definition at line 482 of file json.c.

References ast_json_object_get(), ast_json_object_iter(), ast_json_object_iter_key(), ast_json_object_iter_next(), ast_json_object_iter_value(), ast_json_object_set(), ast_json_ref(), NULL, and value.

Referenced by AST_TEST_DEFINE().

00483 {
00484 #if JANSSON_VERSION_HEX >= 0x020300
00485    return json_object_update_missing((json_t *)object, (json_t *)other);
00486 #else
00487    struct ast_json_iter *iter = ast_json_object_iter(other);
00488    int ret = 0;
00489 
00490    if (object == NULL || other == NULL) {
00491       return -1;
00492    }
00493 
00494    while (iter != NULL && ret == 0) {
00495       const char *key = ast_json_object_iter_key(iter);
00496 
00497       if (ast_json_object_get(object, key) == NULL) {
00498          struct ast_json *value = ast_json_object_iter_value(iter);
00499 
00500          if (!value || ast_json_object_set(object, key, ast_json_ref(value))) {
00501             ret = -1;
00502          }
00503       }
00504       iter = ast_json_object_iter_next(other, iter);
00505    }
00506    return ret;
00507 #endif
00508 }

struct ast_json* ast_json_pack ( char const *  format,
  ... 
) [read]

Helper for creating complex JSON values.

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

Definition at line 688 of file json.c.

References args, and ast_json_vpack().

Referenced by __expire_registry(), __iax2_poke_noanswer(), add_format_information_cb(), agi_handle_command(), analog_publish_channel_alarm_clear(), analog_publish_dnd_state(), app_send_end_msg(), app_to_json(), app_update(), association_to_json(), ast_ari_asterisk_get_global_var(), ast_ari_asterisk_get_info(), ast_ari_channels_get_channel_var(), ast_ari_response_error(), ast_ari_websocket_events_event_websocket(), 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_publish_dial_internal(), ast_channel_publish_varset(), ast_channel_snapshot_to_json(), ast_endpoint_snapshot_to_json(), ast_json_dialplan_cep(), ast_json_name_number(), ast_json_party_id(), ast_manager_publish_event(), ast_queue_hangup_with_cause(), ast_queue_hold(), ast_rtcp_read(), ast_rtcp_write_report(), 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(), 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_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(), create_sound_blob(), currency_to_json(), d_to_json(), dial_to_json(), dtmf_end_to_json(), e_to_json(), expire_register(), 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(), meetme_stasis_generate_msg(), message_received_handler(), moh_post_start(), msg_to_json(), notify_new_message(), parse_register_contact(), persistent_endpoint_update_state(), phase_e_handler(), playback_to_json(), publish_async_exec_end(), publish_channel_alarm(), publish_channel_alarm_clear(), publish_dahdichannel(), publish_dnd_state(), publish_format_update(), publish_fully_booted(), publish_hangup_handler_message(), publish_local_bridge_message(), publish_qualify_peer_done(), publish_reload_message(), 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(), ring_entry(), rna(), rtcp_report_to_json(), s_to_json(), send_agent_complete(), send_agent_login(), send_agent_logoff(), send_conf_stasis(), 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_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(), try_calling(), unhold_to_json(), unload_module(), update_registry(), and userevent_exec().

00689 {
00690    struct ast_json *ret;
00691    va_list args;
00692    va_start(args, format);
00693    ret = ast_json_vpack(format, args);
00694    va_end(args);
00695    return ret;
00696 }

struct ast_json* ast_json_party_id ( struct ast_party_id party  )  [read]

Construct an ast_party_id as JSON.

Since:
12.0.0
Parameters:
party The 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 853 of file json.c.

References ast_describe_caller_presentation(), ast_json_object_set(), ast_json_pack(), ast_json_ref(), ast_json_unref(), ast_party_id_presentation(), json_party_name(), json_party_number(), json_party_subaddress(), ast_party_id::name, NULL, ast_party_id::number, RAII_VAR, ast_party_id::subaddress, ast_party_subaddress::valid, ast_party_name::valid, and ast_party_number::valid.

00854 {
00855    RAII_VAR(struct ast_json *, json_party_id, NULL, ast_json_unref);
00856    int pres;
00857 
00858    /* Combined party presentation */
00859    pres = ast_party_id_presentation(party);
00860    json_party_id = ast_json_pack("{s: i, s: s}",
00861       "presentation", pres,
00862       "presentation_txt", ast_describe_caller_presentation(pres));
00863    if (!json_party_id) {
00864       return NULL;
00865    }
00866 
00867    /* Party number */
00868    if (party->number.valid && ast_json_object_set(json_party_id, "number", json_party_number(&party->number))) {
00869       return NULL;
00870    }
00871 
00872    /* Party name */
00873    if (party->name.valid && ast_json_object_set(json_party_id, "name", json_party_name(&party->name))) {
00874       return NULL;
00875    }
00876 
00877    /* Party subaddress */
00878    if (party->subaddress.valid && ast_json_object_set(json_party_id, "subaddress", json_party_subaddress(&party->subaddress))) {
00879       return NULL;
00880    }
00881 
00882    return ast_json_ref(json_party_id);
00883 }

struct ast_json_payload* ast_json_payload_create ( struct ast_json json  )  [read]

Create an ao2 object to pass json blobs as data payloads for stasis.

Since:
12.0.0
Parameters:
json the ast_json blob we are loading
Return values:
NULL if we fail to alloc it
pointer to the ast_json_payload created

Definition at line 804 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_format_update(), publish_reload_message(), queue_publish_member_blob(), and stun_monitor_request().

00805 {
00806    struct ast_json_payload *payload;
00807 
00808    if (!(payload = ao2_alloc(sizeof(*payload), json_payload_destructor))) {
00809       return NULL;
00810    }
00811 
00812    ast_json_ref(json);
00813    payload->json = json;
00814 
00815    return payload;
00816 }

struct ast_json* ast_json_real_create ( double  value  )  [read]

Create a JSON real number.

Since:
12.0.0
Parameters:
value Value of the new JSON real number.
Returns:
Newly allocated real number.

NULL on error.

Definition at line 367 of file json.c.

Referenced by ast_ari_asterisk_get_info().

00368 {
00369    return (struct ast_json *)json_real(value);
00370 }

double ast_json_real_get ( const struct ast_json real  ) 

Get the value from a JSON real number.

Since:
12.0.0
Parameters:
real JSON real number.
Returns:
Value of a JSON real number.

0 if real is not a JSON real number.

Definition at line 372 of file json.c.

Referenced by rtcp_report_to_ami().

00373 {
00374    return json_real_value((json_t *)real);
00375 }

int ast_json_real_set ( struct ast_json real,
double  value 
)

Set the value of a JSON real number.

Since:
12.0.0
Parameters:
integer JSON real number to modify.
value New value for real.
Returns:
0 on success.

-1 on error.

Definition at line 377 of file json.c.

00378 {
00379    return json_real_set((json_t *)real, value);
00380 }

struct ast_json* ast_json_ref ( struct ast_json value  )  [read]

Increase refcount on value.

Since:
12.0.0
Parameters:
value JSON value to reference.
Returns:
The given value.
Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 203 of file json.c.

References SCOPED_JSON_LOCK.

Referenced by alloc_security_event_json_object(), aoc_publish_blob(), app_to_json(), 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_events_event_websocket(), ast_ari_websocket_session_read(), ast_bridge_blob_create(), ast_bridge_snapshot_to_json(), ast_bucket_file_json(), ast_bucket_json(), ast_channel_snapshot_to_json(), ast_endpoint_blob_create(), ast_endpoint_snapshot_to_json(), ast_json_object_update_existing(), ast_json_object_update_missing(), ast_json_party_id(), 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_TEST_DEFINE(), attended_transfer_to_json(), channel_blob_to_json(), container_to_json_array(), create_channel_blob_message(), create_sound_blob(), generate_filenames_json(), json_array_from_list(), multi_user_event_to_json(), phase_e_handler(), send_start_msg_snapshots(), stasis_app_playback_to_json(), stasis_app_recording_to_json(), and stasis_app_user_event().

00204 {
00205    /* Jansson refcounting is non-atomic; lock it. */
00206    SCOPED_JSON_LOCK(json);
00207    json_incref((json_t *)json);
00208    return json;
00209 }

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

References ast_json_free(), and ast_json_malloc().

Referenced by ast_json_init(), and json_test_cleanup().

00199 {
00200    json_set_alloc_funcs(ast_json_malloc, ast_json_free);
00201 }

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_fn Custom allocation function.
free_fn Matching free function.

Definition at line 193 of file json.c.

Referenced by json_test_init().

00194 {
00195    json_set_alloc_funcs(malloc_fn, free_fn);
00196 }

struct ast_json* ast_json_string_create ( const char *  value  )  [read]

const char* ast_json_string_get ( const struct ast_json string  ) 

Get the value of a JSON string.

Since:
12.0.0
Parameters:
string JSON string.
Returns:
Value of the string.

NULL on error.

Definition at line 317 of file json.c.

Referenced by agent_login_to_ami(), agent_logoff_to_ami(), app_handler(), append_event_str_single(), append_json_single(), ast_ari_applications_subscribe_parse_body(), ast_ari_applications_unsubscribe_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_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_channels_continue_in_dialplan_parse_body(), ast_ari_channels_get_channel_var_parse_body(), ast_ari_channels_hangup_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_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_moh_start_cb(), confbridge_publish_manager_event(), confbridge_talking_cb(), dahdichannel_to_ami(), dtmf_end_to_json(), get_blob_variable(), handle_dial_message(), 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(), peerstatus_to_ami(), playback_to_json(), queue_agent_cb(), recording_to_json(), rtcp_message_handler(), rtcp_report_to_ami(), session_timeout_to_ami(), sorcery_json_to_objectset(), subscription_persistence_event_cb(), system_registry_to_ami(), and varset_to_ami().

00318 {
00319    return json_string_value((json_t *)string);
00320 }

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:
string JSON string to modify.
value New value to store in string.
Returns:
0 on success.

-1 on error.

Definition at line 322 of file json.c.

Referenced by AST_TEST_DEFINE().

00323 {
00324    return json_string_set((json_t *)string, value);
00325 }

struct ast_json* ast_json_stringf ( const char *  format,
  ... 
) [read]

Create a JSON string, printf style.

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

Parameters:
format printf style format string.
Returns:
Newly allocated string.

NULL on error.

Definition at line 327 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().

00328 {
00329    struct ast_json *ret;
00330    va_list args;
00331    va_start(args, format);
00332    ret = ast_json_vstringf(format, args);
00333    va_end(args);
00334    return ret;
00335 }

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

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:
tv timeval to encode.
zone Text 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 736 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(), ast_ari_asterisk_get_info(), ast_bridge_merge_message_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(), dial_to_json(), dtmf_end_to_json(), hold_to_json(), message_received_handler(), multi_user_event_to_json(), send_device_state(), send_start_msg_snapshots(), simple_bridge_channel_event(), simple_bridge_event(), simple_channel_event(), simple_endpoint_event(), stasis_end_to_json(), and unhold_to_json().

00737 {
00738    char buf[AST_ISO8601_LEN];
00739    struct ast_tm tm = {};
00740 
00741    ast_localtime(&tv, &tm, zone);
00742 
00743    ast_strftime(buf, sizeof(buf),AST_ISO8601_FORMAT, &tm);
00744 
00745    return ast_json_string_create(buf);
00746 }

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_variables The JSON blob containing the variable
variables An 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 885 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, ast_variable_new(), ast_variables_destroy(), NULL, and value.

Referenced by json_to_ast_variables().

00886 {
00887    struct ast_json_iter *it_json_var;
00888 
00889    *variables = NULL;
00890 
00891    for (it_json_var = ast_json_object_iter(json_variables); it_json_var;
00892       it_json_var = ast_json_object_iter_next(json_variables, it_json_var)) {
00893       struct ast_variable *new_var;
00894       const char *key = ast_json_object_iter_key(it_json_var);
00895       const char *value;
00896       struct ast_json *json_value;
00897 
00898       if (ast_strlen_zero(key)) {
00899          continue;
00900       }
00901 
00902       json_value = ast_json_object_iter_value(it_json_var);
00903       if (ast_json_typeof(json_value) != AST_JSON_STRING) {
00904          /* Error: Only strings allowed */
00905          ast_variables_destroy(*variables);
00906          *variables = NULL;
00907          return AST_JSON_TO_AST_VARS_CODE_INVALID_TYPE;
00908       }
00909       value = ast_json_string_get(json_value);
00910       /* Should never be NULL.  Otherwise, how could it be a string type? */
00911       ast_assert(value != NULL);
00912       if (!value) {
00913          /* To be safe. */
00914          continue;
00915       }
00916       new_var = ast_variable_new(key, value, "");
00917       if (!new_var) {
00918          /* Error: OOM */
00919          ast_variables_destroy(*variables);
00920          *variables = NULL;
00921          return AST_JSON_TO_AST_VARS_CODE_OOM;
00922       }
00923 
00924       ast_variable_list_append(variables, new_var);
00925    }
00926 
00927    return AST_JSON_TO_AST_VARS_CODE_SUCCESS;
00928 }

struct ast_json* ast_json_true ( void   )  [read]

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

Referenced by ast_json_boolean(), and AST_TEST_DEFINE().

00274 {
00275    return (struct ast_json *)json_true();
00276 }

const char* ast_json_typename ( enum ast_json_type  type  ) 

Get the string name for the given type.

Since:
12.0.0
Parameters:
type Type to convert to string.
Returns:
Simple string for the type name (object, array, string, etc.)

"?" for invalid types.

Definition at line 256 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().

00257 {
00258    switch (type) {
00259    case AST_JSON_OBJECT: return "object";
00260    case AST_JSON_ARRAY: return "array";
00261    case AST_JSON_STRING: return "string";
00262    case AST_JSON_INTEGER: return "integer";
00263    case AST_JSON_REAL: return "real";
00264    case AST_JSON_TRUE: return "boolean";
00265    case AST_JSON_FALSE: return "boolean";
00266    case AST_JSON_NULL: return "null";
00267    }
00268    ast_assert(0);
00269    return "?";
00270 }

enum ast_json_type ast_json_typeof ( const struct ast_json value  ) 

Get the type of value.

Since:
12.0.0
Parameters:
value Value to query.
Returns:
Type of value.

Definition at line 239 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_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_remove_channel_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(), and manager_json_value_str_append().

00240 {
00241    int r = json_typeof((json_t*)json);
00242    switch(r) {
00243    case JSON_OBJECT: return AST_JSON_OBJECT;
00244    case JSON_ARRAY: return AST_JSON_ARRAY;
00245    case JSON_STRING: return AST_JSON_STRING;
00246    case JSON_INTEGER: return AST_JSON_INTEGER;
00247    case JSON_REAL: return AST_JSON_REAL;
00248    case JSON_TRUE: return AST_JSON_TRUE;
00249    case JSON_FALSE: return AST_JSON_FALSE;
00250    case JSON_NULL: return AST_JSON_NULL;
00251    }
00252    ast_assert(0); /* Unexpect return from json_typeof */
00253    return r;
00254 }

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.
Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 211 of file json.c.

References AST_LIST_REMOVE_HEAD, json_free_list(), json_mem_free(), json_mem::list, and SCOPED_JSON_LOCK.

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_send_end_msg(), app_to_json(), app_update(), ari_bridges_play_found(), ari_bridges_play_new(), ast_aoc_manager_event(), ast_ari_applications_get_cb(), ast_ari_applications_list(), ast_ari_applications_list_cb(), ast_ari_applications_subscribe(), ast_ari_applications_subscribe_cb(), ast_ari_applications_unsubscribe(), ast_ari_applications_unsubscribe_cb(), ast_ari_asterisk_get_global_var(), ast_ari_asterisk_get_global_var_cb(), ast_ari_asterisk_get_info(), ast_ari_asterisk_get_info_cb(), ast_ari_asterisk_set_global_var_cb(), ast_ari_bridges_add_channel_cb(), ast_ari_bridges_create_cb(), ast_ari_bridges_create_with_id_cb(), ast_ari_bridges_destroy_cb(), ast_ari_bridges_get_cb(), ast_ari_bridges_list(), ast_ari_bridges_list_cb(), ast_ari_bridges_play_cb(), ast_ari_bridges_play_with_id_cb(), ast_ari_bridges_record(), ast_ari_bridges_record_cb(), ast_ari_bridges_remove_channel_cb(), ast_ari_bridges_start_moh_cb(), ast_ari_bridges_stop_moh_cb(), ast_ari_callback(), ast_ari_channels_answer_cb(), ast_ari_channels_continue_in_dialplan_cb(), ast_ari_channels_get_cb(), ast_ari_channels_get_channel_var(), ast_ari_channels_get_channel_var_cb(), ast_ari_channels_hangup_cb(), ast_ari_channels_hold_cb(), ast_ari_channels_list(), ast_ari_channels_list_cb(), ast_ari_channels_mute_cb(), ast_ari_channels_originate_cb(), ast_ari_channels_originate_with_id_cb(), ast_ari_channels_play_cb(), ast_ari_channels_play_with_id_cb(), ast_ari_channels_record_cb(), ast_ari_channels_redirect_cb(), ast_ari_channels_ring_cb(), ast_ari_channels_ring_stop_cb(), ast_ari_channels_send_dtmf_cb(), ast_ari_channels_set_channel_var_cb(), ast_ari_channels_snoop_channel_cb(), ast_ari_channels_snoop_channel_with_id_cb(), ast_ari_channels_start_moh_cb(), ast_ari_channels_start_silence_cb(), ast_ari_channels_stop_moh_cb(), ast_ari_channels_stop_silence_cb(), ast_ari_channels_unhold_cb(), ast_ari_channels_unmute_cb(), ast_ari_device_states_delete_cb(), ast_ari_device_states_get_cb(), ast_ari_device_states_list_cb(), ast_ari_device_states_update_cb(), ast_ari_endpoints_get_cb(), ast_ari_endpoints_list(), ast_ari_endpoints_list_by_tech(), ast_ari_endpoints_list_by_tech_cb(), ast_ari_endpoints_list_cb(), ast_ari_endpoints_send_message_cb(), ast_ari_endpoints_send_message_to_endpoint_cb(), ast_ari_events_user_event_cb(), ast_ari_mailboxes_delete_cb(), ast_ari_mailboxes_get_cb(), ast_ari_mailboxes_list_cb(), ast_ari_mailboxes_update_cb(), ast_ari_playbacks_control_cb(), ast_ari_playbacks_get_cb(), ast_ari_playbacks_stop_cb(), ast_ari_recordings_cancel_cb(), ast_ari_recordings_copy_stored_cb(), ast_ari_recordings_delete_stored_cb(), ast_ari_recordings_get_live_cb(), ast_ari_recordings_get_stored_cb(), ast_ari_recordings_list_stored(), ast_ari_recordings_list_stored_cb(), ast_ari_recordings_mute_cb(), ast_ari_recordings_pause_cb(), ast_ari_recordings_stop_cb(), ast_ari_recordings_unmute_cb(), ast_ari_recordings_unpause_cb(), ast_ari_response_error(), ast_ari_sounds_get_cb(), ast_ari_sounds_list_cb(), ast_ari_websocket_events_event_websocket(), ast_ari_websocket_session_read(), ast_bridge_channel_write_hold(), ast_bridge_merge_message_to_json(), ast_bridge_publish_enter(), ast_bridge_snapshot_to_json(), ast_bucket_file_json(), ast_bucket_json(), ast_cel_publish_event(), ast_channel_publish_dial_internal(), ast_channel_publish_varset(), ast_channel_snapshot_to_json(), ast_endpoint_snapshot_to_json(), ast_json_party_id(), ast_manager_publish_event(), ast_queue_hangup_with_cause(), ast_queue_hold(), ast_rtcp_read(), ast_rtcp_write_report(), ast_softhangup(), ast_sorcery_objectset_json_create(), 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(), 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_channel_state_change(), cel_dial_cb(), cel_local_cb(), cel_parking_cb(), cel_pickup_cb(), celgenuserevent_exec(), channel_blob_dtor(), channel_blob_to_json(), charge_to_json(), conf_handle_talker_cb(), conf_run(), container_to_json_array(), create_sound_blob(), dial_to_json(), endpoint_blob_dtor(), expire_register(), 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(), meetme_stasis_generate_msg(), moh_post_start(), multi_channel_blob_dtor(), multi_object_blob_dtor(), multi_user_event_to_json(), mwi_blob_dtor(), notify_new_message(), parse_register_contact(), persistent_endpoint_update_state(), phase_e_handler(), playback_publish(), publish_acl_change(), publish_async_exec_end(), publish_channel_alarm(), publish_channel_alarm_clear(), publish_chanspy_message(), publish_dahdichannel(), publish_dnd_state(), publish_format_update(), publish_fully_booted(), publish_hangup_handler_message(), publish_local_bridge_message(), publish_qualify_peer_done(), publish_reload_message(), 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(), ring_entry(), rna(), rtcp_message_handler(), rtcp_message_payload_dtor(), rtcp_report_to_json(), s_to_json(), send_agent_complete(), send_agent_login(), send_agent_logoff(), send_conf_stasis(), 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_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_regex(), sorcery_objectset_to_json(), start_message_blob_dtor(), 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(), talk_detect_audiohook_cb(), try_calling(), unload_module(), update_registry(), and userevent_exec().

00212 {
00213    struct json_mem_list *free_list;
00214    struct json_mem *mem;
00215 
00216    if (!json) {
00217       return;
00218    }
00219 
00220    /* Jansson refcounting is non-atomic; lock it. */
00221    {
00222       SCOPED_JSON_LOCK(json);
00223 
00224       json_decref((json_t *) json);
00225    }
00226 
00227    /* Now free any objects that were ast_json_free()'s while the lock was
00228     * held */
00229    free_list = json_free_list();
00230    if (!free_list) {
00231       return;
00232    }
00233 
00234    while ((mem = AST_LIST_REMOVE_HEAD(free_list, list))) {
00235       json_mem_free(mem);
00236    }
00237 }

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

Helper for creating complex JSON values simply.

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

Definition at line 697 of file json.c.

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

Referenced by ast_json_pack().

00698 {
00699    json_error_t error;
00700    struct ast_json *r = NULL;
00701    if (format) {
00702       r = (struct ast_json *)json_vpack_ex(&error, 0, format, ap);
00703       if (!r && !ast_strlen_zero(error.text)) {
00704          ast_log(LOG_ERROR,
00705             "Error building JSON from '%s': %s.\n",
00706             format, error.text);
00707       }
00708    }
00709    return r;
00710 }

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

Create a JSON string, vprintf style.

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

Parameters:
format printf style format string.
Returns:
Newly allocated string.

NULL on error.

Definition at line 337 of file json.c.

References ast_free, ast_vasprintf, NULL, and str.

Referenced by ast_ari_response_error(), and ast_json_stringf().

00338 {
00339    char *str = NULL;
00340    json_t *ret = NULL;
00341 
00342    if (format) {
00343       int err = ast_vasprintf(&str, format, args);
00344       if (err > 0) {
00345          ret = json_string(str);
00346          ast_free(str);
00347       }
00348    }
00349    return (struct ast_json *)ret;
00350 }


Generated on Thu Apr 16 06:31:46 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6