[asterisk-commits] dlee: branch dlee/ASTERISK-22685-json-body r402381 - in /team/dlee/ASTERISK-2...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 1 15:09:07 CDT 2013


Author: dlee
Date: Fri Nov  1 15:09:05 2013
New Revision: 402381

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=402381
Log:
Process body parameters

Modified:
    team/dlee/ASTERISK-22685-json-body/include/asterisk/ari.h
    team/dlee/ASTERISK-22685-json-body/include/asterisk/http.h
    team/dlee/ASTERISK-22685-json-body/main/http.c
    team/dlee/ASTERISK-22685-json-body/main/manager.c
    team/dlee/ASTERISK-22685-json-body/res/res_ari.c
    team/dlee/ASTERISK-22685-json-body/res/res_ari_applications.c
    team/dlee/ASTERISK-22685-json-body/res/res_ari_asterisk.c
    team/dlee/ASTERISK-22685-json-body/res/res_ari_bridges.c
    team/dlee/ASTERISK-22685-json-body/res/res_ari_channels.c
    team/dlee/ASTERISK-22685-json-body/res/res_ari_endpoints.c
    team/dlee/ASTERISK-22685-json-body/res/res_ari_playback.c
    team/dlee/ASTERISK-22685-json-body/res/res_ari_recordings.c
    team/dlee/ASTERISK-22685-json-body/res/res_ari_sounds.c
    team/dlee/ASTERISK-22685-json-body/rest-api-templates/param_parsing.mustache
    team/dlee/ASTERISK-22685-json-body/rest-api-templates/res_ari_resource.c.mustache
    team/dlee/ASTERISK-22685-json-body/rest-api-templates/swagger_model.py
    team/dlee/ASTERISK-22685-json-body/tests/test_ari.c

Modified: team/dlee/ASTERISK-22685-json-body/include/asterisk/ari.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/include/asterisk/ari.h?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/include/asterisk/ari.h (original)
+++ team/dlee/ASTERISK-22685-json-body/include/asterisk/ari.h Fri Nov  1 15:09:05 2013
@@ -50,15 +50,16 @@
 
 /*!
  * \brief Callback type for RESTful method handlers.
+ * \param ser TCP/TLS session object
  * \param get_params GET parameters from the HTTP request.
  * \param path_vars Path variables from any wildcard path segments.
  * \param headers HTTP headers from the HTTP requiest.
  * \param[out] response The RESTful response.
  */
-typedef void (*stasis_rest_callback)(struct ast_variable *get_params,
-				     struct ast_variable *path_vars,
-				     struct ast_variable *headers,
-				     struct ast_ari_response *response);
+typedef void (*stasis_rest_callback)(
+	struct ast_tcptls_session_instance *ser,
+	struct ast_variable *get_params, struct ast_variable *path_vars,
+	struct ast_variable *headers, struct ast_ari_response *response);
 
 /*!
  * \brief Handler for a single RESTful path segment.

Modified: team/dlee/ASTERISK-22685-json-body/include/asterisk/http.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/include/asterisk/http.h?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/include/asterisk/http.h (original)
+++ team/dlee/ASTERISK-22685-json-body/include/asterisk/http.h Fri Nov  1 15:09:05 2013
@@ -212,5 +212,17 @@
  */
 struct ast_variable *ast_http_get_post_vars(struct ast_tcptls_session_instance *ser, struct ast_variable *headers);
 
+struct ast_json;
+
+/*!\brief Get JSON from client Request Entity-Body, if content type is
+ *        application/json.
+ * \param ser TCP/TLS session object
+ * \param headers List of HTTP headers
+ * \return Parsed JSON content body
+ * \return \c NULL on error, if no content, or if different content type.
+ * \since 12
+ */
+struct ast_json *ast_http_get_json(
+	struct ast_tcptls_session_instance *ser, struct ast_variable *headers);
 
 #endif /* _ASTERISK_SRV_H */

Modified: team/dlee/ASTERISK-22685-json-body/main/http.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/main/http.c?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/main/http.c (original)
+++ team/dlee/ASTERISK-22685-json-body/main/http.c Fri Nov  1 15:09:05 2013
@@ -65,6 +65,7 @@
 #include "asterisk/_private.h"
 #include "asterisk/astobj2.h"
 #include "asterisk/netsock2.h"
+#include "asterisk/json.h"
 
 #define MAX_PREFIX 80
 #define DEFAULT_PORT 8088
@@ -607,6 +608,71 @@
 
 #define MAX_POST_CONTENT 1025
 
+struct ast_json *ast_http_get_json(
+	struct ast_tcptls_session_instance *ser, struct ast_variable *headers)
+{
+	int content_length = 0;
+	int res;
+	struct ast_variable *v;
+	struct ast_json *body;
+	RAII_VAR(char *, buf, NULL, ast_free_ptr);
+
+	/* Use errno to distinguish errors from no body */
+	errno = 0;
+
+	for (v = headers; v; v = v->next) {
+		if (!strcasecmp(v->name, "Content-Type")) {
+			if (strcasecmp(v->value, "application/json")) {
+				return NULL;
+			}
+			break;
+		}
+	}
+
+	for (v = headers; v; v = v->next) {
+		if (!strcasecmp(v->name, "Content-Length")) {
+			content_length = atoi(v->value);
+			break;
+		}
+	}
+
+	if (content_length <= 0) {
+		return NULL;
+	}
+
+	if (content_length > MAX_POST_CONTENT - 1) {
+		ast_log(LOG_WARNING,
+			"Excessively long HTTP content. (%d > %d)\n",
+			content_length, MAX_POST_CONTENT);
+		errno = EFBIG;
+		return NULL;
+	}
+
+	buf = ast_malloc(content_length);
+	if (!buf) {
+		return NULL;
+	}
+
+	res = fread(buf, 1, content_length, ser->f);
+	if (res < content_length) {
+		/* Error, distinguishable by ferror() or feof(), but neither
+		 * is good. Treat either one as I/O error */
+		ast_log(LOG_WARNING, "Short HTTP request body (%d < %d)\n",
+			res, content_length);
+		errno = EIO;
+		return NULL;
+	}
+
+	body = ast_json_load_buf(buf, content_length, NULL);
+	if (body == NULL) {
+		/* Failed to parse JSON; treat as an I/O error */
+		errno = EIO;
+		return NULL;
+	}
+
+	return body;
+}
+
 /*
  * get post variables from client Request Entity-Body, if content type is
  * application/x-www-form-urlencoded
@@ -616,8 +682,12 @@
 {
 	int content_length = 0;
 	struct ast_variable *v, *post_vars=NULL, *prev = NULL;
-	char *buf, *var, *val;
+	char *var, *val;
+	RAII_VAR(char *, buf, NULL, ast_free_ptr);
 	int res;
+
+	/* Use errno to distinguish errors from no params */
+	errno = 0;
 
 	for (v = headers; v; v = v->next) {
 		if (!strcasecmp(v->name, "Content-Type")) {
@@ -640,22 +710,25 @@
 	}
 
 	if (content_length > MAX_POST_CONTENT - 1) {
-		ast_log(LOG_WARNING, "Excessively long HTTP content. %d is greater than our max of %d\n",
-				content_length, MAX_POST_CONTENT);
-		ast_http_send(ser, AST_HTTP_POST, 413, "Request Entity Too Large", NULL, NULL, 0, 0);
+		ast_log(LOG_WARNING,
+			"Excessively long HTTP content. (%d > %d)\n",
+			content_length, MAX_POST_CONTENT);
+		errno = EFBIG;
 		return NULL;
 	}
 
 	buf = ast_malloc(content_length + 1);
 	if (!buf) {
+		/* malloc sets errno to ENOMEM */
 		return NULL;
 	}
 
 	res = fread(buf, 1, content_length, ser->f);
 	if (res < content_length) {
 		/* Error, distinguishable by ferror() or feof(), but neither
-		 * is good. */
-		goto done;
+		 * is good. Treat either one as I/O error */
+		errno = EIO;
+		return NULL;
 	}
 	buf[content_length] = '\0';
 
@@ -677,8 +750,6 @@
 		}
 	}
 
-done:
-	ast_free(buf);
 	return post_vars;
 }
 

Modified: team/dlee/ASTERISK-22685-json-body/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/main/manager.c?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/main/manager.c (original)
+++ team/dlee/ASTERISK-22685-json-body/main/manager.c Fri Nov  1 15:09:05 2013
@@ -6723,6 +6723,20 @@
 		params = ast_http_get_post_vars(ser, headers);
 	}
 
+	if (!params) {
+		switch (errno) {
+		case EFBIG:
+			ast_http_send(ser, AST_HTTP_POST, 413, "Request Entity Too Large", NULL, NULL, 0, 0);
+			break;
+		case ENOMEM:
+			ast_http_send(ser, AST_HTTP_POST, 500, "Internal Server Error", NULL, NULL, 0, 0);
+			break;
+		case EIO:
+			ast_http_send(ser, AST_HTTP_POST, 400, "Bad Request", NULL, NULL, 0, 0);
+			break;
+		}
+	}
+
 	for (v = params; v && m.hdrcount < ARRAY_LEN(m.headers); v = v->next) {
 		hdrlen = strlen(v->name) + strlen(v->value) + 3;
 		m.headers[m.hdrcount] = ast_malloc(hdrlen);

Modified: team/dlee/ASTERISK-22685-json-body/res/res_ari.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/res/res_ari.c?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/res/res_ari.c (original)
+++ team/dlee/ASTERISK-22685-json-body/res/res_ari.c Fri Nov  1 15:09:05 2013
@@ -539,7 +539,7 @@
 		return;
 	}
 
-	callback(get_params, path_vars, headers, response);
+	callback(ser, get_params, path_vars, headers, response);
 	if (response->message == NULL && response->response_code == 0) {
 		/* Really should not happen */
 		ast_log(LOG_ERROR, "ARI %s %s not implemented\n",

Modified: team/dlee/ASTERISK-22685-json-body/res/res_ari_applications.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/res/res_ari_applications.c?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/res/res_ari_applications.c (original)
+++ team/dlee/ASTERISK-22685-json-body/res/res_ari_applications.c Fri Nov  1 15:09:05 2013
@@ -59,6 +59,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_applications_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -108,6 +109,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_application_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -165,6 +167,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_application_subscribe_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -272,6 +275,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_application_unsubscribe_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {

Modified: team/dlee/ASTERISK-22685-json-body/res/res_ari_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/res/res_ari_asterisk.c?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/res/res_ari_asterisk.c (original)
+++ team/dlee/ASTERISK-22685-json-body/res/res_ari_asterisk.c Fri Nov  1 15:09:05 2013
@@ -59,6 +59,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_asterisk_echo_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -68,6 +69,20 @@
 	int code;
 #endif /* AST_DEVMODE */
 
+	args.anything = ast_http_get_json(ser, headers);
+	if (!args.anything) {
+		switch (errno) {
+		case EFBIG:
+			ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
+			goto fin;
+		case ENOMEM:
+			ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
+			goto fin;
+		case EIO:
+			ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
+			goto fin;
+		}
+	}
 	ast_ari_asterisk_echo(headers, &args, response);
 #if defined(AST_DEVMODE)
 	code = response->response_code;
@@ -109,6 +124,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_asterisk_info_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -207,6 +223,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_global_var_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -264,6 +281,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_set_global_var_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {

Modified: team/dlee/ASTERISK-22685-json-body/res/res_ari_bridges.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/res/res_ari_bridges.c?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/res/res_ari_bridges.c (original)
+++ team/dlee/ASTERISK-22685-json-body/res/res_ari_bridges.c Fri Nov  1 15:09:05 2013
@@ -59,6 +59,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_bridges_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -108,6 +109,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_new_bridge_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -164,6 +166,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_bridge_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -221,6 +224,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_delete_bridge_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -278,6 +282,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_add_channel_to_bridge_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -389,6 +394,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_remove_channel_from_bridge_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -497,6 +503,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_moh_start_bridge_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -561,6 +568,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_moh_stop_bridge_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -619,6 +627,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_play_on_bridge_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -692,6 +701,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_record_bridge_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {

Modified: team/dlee/ASTERISK-22685-json-body/res/res_ari_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/res/res_ari_channels.c?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/res/res_ari_channels.c (original)
+++ team/dlee/ASTERISK-22685-json-body/res/res_ari_channels.c Fri Nov  1 15:09:05 2013
@@ -59,6 +59,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_channels_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -108,6 +109,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_originate_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -186,6 +188,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_channel_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -243,6 +246,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_delete_channel_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -307,6 +311,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_continue_in_dialplan_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -377,6 +382,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_answer_channel_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -435,6 +441,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_ring_channel_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -493,6 +500,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_send_dtmfchannel_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -570,6 +578,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_mute_channel_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -634,6 +643,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_unmute_channel_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -698,6 +708,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_hold_channel_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -756,6 +767,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_unhold_channel_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -814,6 +826,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_moh_start_channel_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -878,6 +891,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_moh_stop_channel_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -936,6 +950,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_play_on_channel_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -1009,6 +1024,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_record_channel_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -1093,6 +1109,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_channel_var_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -1158,6 +1175,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_set_channel_var_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {

Modified: team/dlee/ASTERISK-22685-json-body/res/res_ari_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/res/res_ari_endpoints.c?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/res/res_ari_endpoints.c (original)
+++ team/dlee/ASTERISK-22685-json-body/res/res_ari_endpoints.c Fri Nov  1 15:09:05 2013
@@ -59,6 +59,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_endpoints_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -108,6 +109,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_endpoints_by_tech_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -164,6 +166,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_endpoint_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {

Modified: team/dlee/ASTERISK-22685-json-body/res/res_ari_playback.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/res/res_ari_playback.c?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/res/res_ari_playback.c (original)
+++ team/dlee/ASTERISK-22685-json-body/res/res_ari_playback.c Fri Nov  1 15:09:05 2013
@@ -59,6 +59,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_playback_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -116,6 +117,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_stop_playback_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -173,6 +175,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_control_playback_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {

Modified: team/dlee/ASTERISK-22685-json-body/res/res_ari_recordings.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/res/res_ari_recordings.c?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/res/res_ari_recordings.c (original)
+++ team/dlee/ASTERISK-22685-json-body/res/res_ari_recordings.c Fri Nov  1 15:09:05 2013
@@ -59,6 +59,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_stored_recordings_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -108,6 +109,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_stored_recording_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -165,6 +167,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_delete_stored_recording_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -222,6 +225,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_live_recording_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -279,6 +283,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_cancel_recording_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -336,6 +341,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_stop_recording_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -393,6 +399,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_pause_recording_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -451,6 +458,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_unpause_recording_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -509,6 +517,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_mute_recording_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -567,6 +576,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_unmute_recording_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {

Modified: team/dlee/ASTERISK-22685-json-body/res/res_ari_sounds.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/res/res_ari_sounds.c?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/res/res_ari_sounds.c (original)
+++ team/dlee/ASTERISK-22685-json-body/res/res_ari_sounds.c Fri Nov  1 15:09:05 2013
@@ -59,6 +59,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_sounds_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {
@@ -118,6 +119,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_get_stored_sound_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {

Modified: team/dlee/ASTERISK-22685-json-body/rest-api-templates/param_parsing.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/rest-api-templates/param_parsing.mustache?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/rest-api-templates/param_parsing.mustache (original)
+++ team/dlee/ASTERISK-22685-json-body/rest-api-templates/param_parsing.mustache Fri Nov  1 15:09:05 2013
@@ -83,3 +83,19 @@
 		{}
 	}
 {{/has_path_parameters}}
+{{#body_parameter}}
+	args.{{c_name}} = ast_http_get_json(ser, headers);
+	if (!args.{{c_name}}) {
+		switch (errno) {
+		case EFBIG:
+			ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
+			goto fin;
+		case ENOMEM:
+			ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
+			goto fin;
+		case EIO:
+			ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
+			goto fin;
+		}
+	}
+{{/body_parameter}}

Modified: team/dlee/ASTERISK-22685-json-body/rest-api-templates/res_ari_resource.c.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/rest-api-templates/res_ari_resource.c.mustache?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/rest-api-templates/res_ari_resource.c.mustache (original)
+++ team/dlee/ASTERISK-22685-json-body/rest-api-templates/res_ari_resource.c.mustache Fri Nov  1 15:09:05 2013
@@ -74,6 +74,7 @@
  * \param[out] response Response to the HTTP request.
  */
 static void ast_ari_{{c_nickname}}_cb(
+	struct ast_tcptls_session_instance *ser,
 	struct ast_variable *get_params, struct ast_variable *path_vars,
 	struct ast_variable *headers, struct ast_ari_response *response)
 {

Modified: team/dlee/ASTERISK-22685-json-body/rest-api-templates/swagger_model.py
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/rest-api-templates/swagger_model.py?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/rest-api-templates/swagger_model.py (original)
+++ team/dlee/ASTERISK-22685-json-body/rest-api-templates/swagger_model.py Fri Nov  1 15:09:05 2013
@@ -377,8 +377,9 @@
         if self.is_websocket:
             self.websocket_protocol = op_json.get('websocketProtocol')
             if self.http_method != 'GET':
-                raise ValueError(
-                    "upgrade: websocket is only valid on GET operations")
+                raise SwaggerError(
+                    "upgrade: websocket is only valid on GET operations",
+                    context)
 
         params_json = op_json.get('parameters') or []
         self.parameters = [
@@ -394,6 +395,14 @@
         self.has_header_parameters = self.header_parameters and True
         self.has_parameters = self.has_query_parameters or \
             self.has_path_parameters or self.has_header_parameters
+
+        # Body param is different, since there's at most one
+        self.body_parameter = [
+            p for p in self.parameters if p.is_type('body')]
+        if len(self.body_parameter) > 1:
+            raise SwaggerError("Cannot have more than one body param", context)
+        self.body_parameter = self.body_parameter and self.body_parameter[0]
+
         self.summary = op_json.get('summary')
         self.notes = op_json.get('notes')
         err_json = op_json.get('errorResponses') or []

Modified: team/dlee/ASTERISK-22685-json-body/tests/test_ari.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22685-json-body/tests/test_ari.c?view=diff&rev=402381&r1=402380&r2=402381
==============================================================================
--- team/dlee/ASTERISK-22685-json-body/tests/test_ari.c (original)
+++ team/dlee/ASTERISK-22685-json-body/tests/test_ari.c Fri Nov  1 15:09:05 2013
@@ -95,10 +95,11 @@
  * Macro to reduce the handler definition boiler-plate.
  */
 #define HANDLER(name, response_code)					\
-	static void name(struct ast_variable *get_params,		\
-			 struct ast_variable *path_vars,		\
-			 struct ast_variable *headers,			\
-			 struct ast_ari_response *response)		\
+	static void name(struct ast_tcptls_session_instance *ser,	\
+		struct ast_variable *get_params,			\
+		struct ast_variable *path_vars,				\
+		struct ast_variable *headers,				\
+		struct ast_ari_response *response)			\
 	{								\
 		handler(#name, response_code, get_params, path_vars, headers, response); \
 	}




More information about the asterisk-commits mailing list