summaryrefslogtreecommitdiff
path: root/include/asterisk/json.h
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2013-04-22 14:58:53 +0000
committerDavid M. Lee <dlee@digium.com>2013-04-22 14:58:53 +0000
commit1c21b8575bfd70b98b1102fd3dd09fc0bc335e14 (patch)
tree9a6ef6074e545ad2768bc1994e1a233fc1443729 /include/asterisk/json.h
parent1871017cc6bd2e2ce7c638eeb6813e982377a521 (diff)
This patch adds a RESTful HTTP interface to Asterisk.
The API itself is documented using Swagger, a lightweight mechanism for documenting RESTful API's using JSON. This allows us to use swagger-ui to provide executable documentation for the API, generate client bindings in different languages, and generate a lot of the boilerplate code for implementing the RESTful bindings. The API docs live in the rest-api/ directory. The RESTful bindings are generated from the Swagger API docs using a set of Mustache templates. The code generator is written in Python, and uses Pystache. Pystache has no dependencies, and be installed easily using pip. Code generation code lives in rest-api-templates/. The generated code reduces a lot of boilerplate when it comes to handling HTTP requests. It also helps us have greater consistency in the REST API. (closes issue ASTERISK-20891) Review: https://reviewboard.asterisk.org/r/2376/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@386232 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk/json.h')
-rw-r--r--include/asterisk/json.h34
1 files changed, 29 insertions, 5 deletions
diff --git a/include/asterisk/json.h b/include/asterisk/json.h
index 62e21293b..d06416f58 100644
--- a/include/asterisk/json.h
+++ b/include/asterisk/json.h
@@ -586,16 +586,33 @@ int ast_json_object_iter_set(struct ast_json *object, struct ast_json_iter *iter
/*!@{*/
/*!
+ * \brief Encoding format type.
+ * \since 12.0.0
+ */
+enum ast_json_encoding_format
+{
+ /*! Compact format, low human readability */
+ AST_JSON_COMPACT,
+ /*! Formatted for human readability */
+ AST_JSON_PRETTY,
+};
+
+#define ast_json_dump_string(root) ast_json_dump_string_format(root, AST_JSON_COMPACT)
+
+/*!
* \brief Encode a JSON value to a string.
* \since 12.0.0
*
* Returned string must be freed by calling ast_free().
*
- * \param JSON value.
+ * \param root JSON value.
+ * \param format encoding format type.
* \return String encoding of \a root.
* \return \c NULL on error.
*/
-char *ast_json_dump_string(struct ast_json *root);
+char *ast_json_dump_string_format(struct ast_json *root, enum ast_json_encoding_format format);
+
+#define ast_json_dump_str(root, dst) ast_json_dump_str_format(root, dst, AST_JSON_COMPACT)
/*!
* \brief Encode a JSON value to an \ref ast_str.
@@ -605,10 +622,13 @@ char *ast_json_dump_string(struct ast_json *root);
*
* \param root JSON value.
* \param dst \ref ast_str to store JSON encoding.
+ * \param format encoding format type.
* \return 0 on success.
* \return -1 on error. The contents of \a dst are undefined.
*/
-int ast_json_dump_str(struct ast_json *root, struct ast_str **dst);
+int ast_json_dump_str_format(struct ast_json *root, struct ast_str **dst, enum ast_json_encoding_format format);
+
+#define ast_json_dump_file(root, output) ast_json_dump_file_format(root, output, AST_JSON_COMPACT)
/*!
* \brief Encode a JSON value to a \c FILE.
@@ -616,10 +636,13 @@ int ast_json_dump_str(struct ast_json *root, struct ast_str **dst);
*
* \param root JSON value.
* \param output File to write JSON encoding to.
+ * \param format encoding format type.
* \return 0 on success.
* \return -1 on error. The contents of \a output are undefined.
*/
-int ast_json_dump_file(struct ast_json *root, FILE *output);
+int ast_json_dump_file_format(struct ast_json *root, FILE *output, enum ast_json_encoding_format format);
+
+#define ast_json_dump_new_file(root, path) ast_json_dump_new_file_format(root, path, AST_JSON_COMPACT)
/*!
* \brief Encode a JSON value to a file at the given location.
@@ -627,10 +650,11 @@ int ast_json_dump_file(struct ast_json *root, FILE *output);
*
* \param root JSON value.
* \param path Path to file to write JSON encoding to.
+ * \param format encoding format type.
* \return 0 on success.
* \return -1 on error. The contents of \a output are undefined.
*/
-int ast_json_dump_new_file(struct ast_json *root, const char *path);
+int ast_json_dump_new_file_format(struct ast_json *root, const char *path, enum ast_json_encoding_format format);
#define AST_JSON_ERROR_TEXT_LENGTH 160
#define AST_JSON_ERROR_SOURCE_LENGTH 80