[svn-commits] dlee: branch dlee/ari-event-remodel2 r392360 - in /team/dlee/ari-event-remode...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jun 20 14:53:19 CDT 2013


Author: dlee
Date: Thu Jun 20 14:53:17 2013
New Revision: 392360

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392360
Log:
Validation fixes

Modified:
    team/dlee/ari-event-remodel2/res/res_ari_model.c
    team/dlee/ari-event-remodel2/res/res_stasis_http.c
    team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c
    team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h
    team/dlee/ari-event-remodel2/rest-api-templates/ari_model.c.mustache
    team/dlee/ari-event-remodel2/rest-api-templates/asterisk_processor.py
    team/dlee/ari-event-remodel2/rest-api-templates/swagger_model.py
    team/dlee/ari-event-remodel2/rest-api/api-docs/events.json
    team/dlee/ari-event-remodel2/tests/test_ari_model.c

Modified: team/dlee/ari-event-remodel2/res/res_ari_model.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/res_ari_model.c?view=diff&rev=392360&r1=392359&r2=392360
==============================================================================
--- team/dlee/ari-event-remodel2/res/res_ari_model.c (original)
+++ team/dlee/ari-event-remodel2/res/res_ari_model.c Thu Jun 20 14:53:17 2013
@@ -48,15 +48,23 @@
  * Handles the probably impossible case of a leap second, too */
 #define REGEX_HMS "[0-2][0-9]:[0-5][0-9](:[0-6][0-9](.[0-9]+)?)?"
 
-/* Regex for timezone */
-#define REGEX_TZ "(Z|[-+][0-2][0-9]:[0-5][0-9])"
+/* Regex for timezone: (+|-)hh(:mm), with optional colon. */
+#define REGEX_TZ "(Z|[-+][0-2][0-9](:?[0-5][0-9])?)"
 
 /* REGEX for ISO 8601, the time specifier optional */
 #define ISO8601_PATTERN "^" REGEX_YMD "(T" REGEX_HMS REGEX_TZ ")?$"
 
 static int check_type(struct ast_json *json, enum ast_json_type expected)
 {
-	enum ast_json_type actual = ast_json_typeof(json);
+	enum ast_json_type actual;
+
+	if (!json) {
+		ast_log(LOG_ERROR, "Expected type %s, was NULL\n",
+			ast_json_typename(expected));
+		return 0;
+	}
+
+	actual = ast_json_typeof(json);
 	if (expected != actual) {
 		ast_log(LOG_ERROR, "Expected type %s, was %s\n",
 			ast_json_typename(expected), ast_json_typename(actual));

Modified: team/dlee/ari-event-remodel2/res/res_stasis_http.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/res_stasis_http.c?view=diff&rev=392360&r1=392359&r2=392360
==============================================================================
--- team/dlee/ari-event-remodel2/res/res_stasis_http.c (original)
+++ team/dlee/ari-event-remodel2/res/res_stasis_http.c Thu Jun 20 14:53:17 2013
@@ -324,7 +324,7 @@
 
 void stasis_http_response_no_content(struct stasis_http_response *response)
 {
-	response->message = NULL;
+	response->message = ast_json_null();
 	response->response_code = 204;
 	response->response_text = "No Content";
 }
@@ -386,9 +386,7 @@
 
 	/* Regular OPTIONS response */
 	add_allow_header(handler, response);
-	response->response_code = 204;
-	response->response_text = "No Content";
-	response->message = NULL;
+	stasis_http_response_no_content(response);
 
 	/* Parse CORS headers */
 	for (header = headers; header != NULL; header = header->next) {
@@ -844,11 +842,10 @@
 		return 0;
 	}
 
-	/* Leaving message unset is only allowed for 204 (No Content).
-	 * If you explicitly want to have no content for a different return
+	/* If you explicitly want to have no content for a different return
 	 * code, set message to ast_json_null().
 	 */
-	ast_assert(response.response_code == 204 || response.message != NULL);
+	ast_assert(response.message != NULL);
 	ast_assert(response.response_code > 0);
 
 	ast_str_append(&response_headers, 0, "%s", ast_str_buffer(response.headers));

Modified: team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c?view=diff&rev=392360&r1=392359&r2=392360
==============================================================================
--- team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c (original)
+++ team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c Thu Jun 20 14:53:17 2013
@@ -788,6 +788,7 @@
 	int res = 1;
 	struct ast_json_iter *iter;
 	int has_application = 0;
+	int has_type = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
 		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
@@ -797,6 +798,25 @@
 				ast_json_object_iter_value(iter));
 			if (!prop_res) {
 				ast_log(LOG_ERROR, "ARI ApplicationReplaced field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ApplicationReplaced field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ApplicationReplaced field type failed validation\n");
 				res = 0;
 			}
 		} else
@@ -812,6 +832,10 @@
 		ast_log(LOG_ERROR, "ARI ApplicationReplaced missing required field application\n");
 		res = 0;
 	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI ApplicationReplaced missing required field type\n");
+		res = 0;
+	}
 
 	return res;
 }
@@ -820,9 +844,40 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_bridge = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI BridgeCreated field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI BridgeCreated field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI BridgeCreated field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("bridge", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_bridge = 1;
@@ -841,6 +896,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI BridgeCreated missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI BridgeCreated missing required field type\n");
+		res = 0;
+	}
 	if (!has_bridge) {
 		ast_log(LOG_ERROR, "ARI BridgeCreated missing required field bridge\n");
 		res = 0;
@@ -853,9 +916,40 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_bridge = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI BridgeDestroyed field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI BridgeDestroyed field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI BridgeDestroyed field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("bridge", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_bridge = 1;
@@ -874,6 +968,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI BridgeDestroyed missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI BridgeDestroyed missing required field type\n");
+		res = 0;
+	}
 	if (!has_bridge) {
 		ast_log(LOG_ERROR, "ARI BridgeDestroyed missing required field bridge\n");
 		res = 0;
@@ -886,10 +988,41 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_bridge = 0;
 	int has_bridge_from = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI BridgeMerged field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI BridgeMerged field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI BridgeMerged field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("bridge", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_bridge = 1;
@@ -918,6 +1051,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI BridgeMerged missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI BridgeMerged missing required field type\n");
+		res = 0;
+	}
 	if (!has_bridge) {
 		ast_log(LOG_ERROR, "ARI BridgeMerged missing required field bridge\n");
 		res = 0;
@@ -934,11 +1075,42 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_caller_presentation = 0;
 	int has_caller_presentation_txt = 0;
 	int has_channel = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelCallerId field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelCallerId field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelCallerId field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("caller_presentation", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_caller_presentation = 1;
@@ -977,6 +1149,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI ChannelCallerId missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI ChannelCallerId missing required field type\n");
+		res = 0;
+	}
 	if (!has_caller_presentation) {
 		ast_log(LOG_ERROR, "ARI ChannelCallerId missing required field caller_presentation\n");
 		res = 0;
@@ -997,9 +1177,40 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_channel = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelCreated field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelCreated field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelCreated field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_channel = 1;
@@ -1018,6 +1229,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI ChannelCreated missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI ChannelCreated missing required field type\n");
+		res = 0;
+	}
 	if (!has_channel) {
 		ast_log(LOG_ERROR, "ARI ChannelCreated missing required field channel\n");
 		res = 0;
@@ -1030,11 +1249,42 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_cause = 0;
 	int has_cause_txt = 0;
 	int has_channel = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelDestroyed field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelDestroyed field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelDestroyed field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("cause", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_cause = 1;
@@ -1073,6 +1323,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI ChannelDestroyed missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI ChannelDestroyed missing required field type\n");
+		res = 0;
+	}
 	if (!has_cause) {
 		ast_log(LOG_ERROR, "ARI ChannelDestroyed missing required field cause\n");
 		res = 0;
@@ -1093,9 +1351,40 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_channel = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelDialplan field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelDialplan field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelDialplan field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_channel = 1;
@@ -1114,6 +1403,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI ChannelDialplan missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI ChannelDialplan missing required field type\n");
+		res = 0;
+	}
 	if (!has_channel) {
 		ast_log(LOG_ERROR, "ARI ChannelDialplan missing required field channel\n");
 		res = 0;
@@ -1126,11 +1423,42 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_channel = 0;
 	int has_digit = 0;
 	int has_duration_ms = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelDtmfReceived field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelDtmfReceived field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelDtmfReceived field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_channel = 1;
@@ -1169,6 +1497,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI ChannelDtmfReceived missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI ChannelDtmfReceived missing required field type\n");
+		res = 0;
+	}
 	if (!has_channel) {
 		ast_log(LOG_ERROR, "ARI ChannelDtmfReceived missing required field channel\n");
 		res = 0;
@@ -1189,9 +1525,40 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_bridge = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelEnteredBridge field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelEnteredBridge field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelEnteredBridge field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("bridge", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_bridge = 1;
@@ -1219,6 +1586,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI ChannelEnteredBridge missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI ChannelEnteredBridge missing required field type\n");
+		res = 0;
+	}
 	if (!has_bridge) {
 		ast_log(LOG_ERROR, "ARI ChannelEnteredBridge missing required field bridge\n");
 		res = 0;
@@ -1231,9 +1606,40 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_channel = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelHangupRequest field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelHangupRequest field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelHangupRequest field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("cause", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			prop_res = ari_validate_int(
@@ -1270,6 +1676,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI ChannelHangupRequest missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI ChannelHangupRequest missing required field type\n");
+		res = 0;
+	}
 	if (!has_channel) {
 		ast_log(LOG_ERROR, "ARI ChannelHangupRequest missing required field channel\n");
 		res = 0;
@@ -1282,10 +1696,41 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_bridge = 0;
 	int has_channel = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelLeftBridge field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelLeftBridge field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelLeftBridge field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("bridge", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_bridge = 1;
@@ -1314,6 +1759,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI ChannelLeftBridge missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI ChannelLeftBridge missing required field type\n");
+		res = 0;
+	}
 	if (!has_bridge) {
 		ast_log(LOG_ERROR, "ARI ChannelLeftBridge missing required field bridge\n");
 		res = 0;
@@ -1330,9 +1783,40 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_channel = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelStateChange field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelStateChange field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelStateChange field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_channel = 1;
@@ -1351,6 +1835,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI ChannelStateChange missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI ChannelStateChange missing required field type\n");
+		res = 0;
+	}
 	if (!has_channel) {
 		ast_log(LOG_ERROR, "ARI ChannelStateChange missing required field channel\n");
 		res = 0;
@@ -1363,10 +1855,41 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_channel = 0;
 	int has_eventname = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelUserevent field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelUserevent field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelUserevent field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_channel = 1;
@@ -1395,6 +1918,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI ChannelUserevent missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI ChannelUserevent missing required field type\n");
+		res = 0;
+	}
 	if (!has_channel) {
 		ast_log(LOG_ERROR, "ARI ChannelUserevent missing required field channel\n");
 		res = 0;
@@ -1411,10 +1942,41 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_value = 0;
 	int has_variable = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelVarset field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelVarset field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI ChannelVarset field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			prop_res = ari_validate_channel(
@@ -1452,6 +2014,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI ChannelVarset missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI ChannelVarset missing required field type\n");
+		res = 0;
+	}
 	if (!has_value) {
 		ast_log(LOG_ERROR, "ARI ChannelVarset missing required field value\n");
 		res = 0;
@@ -1469,6 +2039,79 @@
 	int res = 1;
 	struct ast_json_iter *iter;
 	int has_application = 0;
+	int has_type = 0;
+	const char *discriminator;
+
+	discriminator = ast_json_string_get(ast_json_object_get(json, "type"));
+	if (!discriminator) {
+		ast_log(LOG_ERROR, "ARI Event missing required field type");
+		return 0;
+	}
+
+	if (strcmp("Event", discriminator) == 0) {
+		/* Self type; fall through */
+	} else
+	if (strcmp("ApplicationReplaced", discriminator) == 0) {
+		return ari_validate_application_replaced(json);
+	} else
+	if (strcmp("BridgeCreated", discriminator) == 0) {
+		return ari_validate_bridge_created(json);
+	} else
+	if (strcmp("BridgeDestroyed", discriminator) == 0) {
+		return ari_validate_bridge_destroyed(json);
+	} else
+	if (strcmp("BridgeMerged", discriminator) == 0) {
+		return ari_validate_bridge_merged(json);
+	} else
+	if (strcmp("ChannelCallerId", discriminator) == 0) {
+		return ari_validate_channel_caller_id(json);
+	} else
+	if (strcmp("ChannelCreated", discriminator) == 0) {
+		return ari_validate_channel_created(json);
+	} else
+	if (strcmp("ChannelDestroyed", discriminator) == 0) {
+		return ari_validate_channel_destroyed(json);
+	} else
+	if (strcmp("ChannelDialplan", discriminator) == 0) {
+		return ari_validate_channel_dialplan(json);
+	} else
+	if (strcmp("ChannelDtmfReceived", discriminator) == 0) {
+		return ari_validate_channel_dtmf_received(json);
+	} else
+	if (strcmp("ChannelEnteredBridge", discriminator) == 0) {
+		return ari_validate_channel_entered_bridge(json);
+	} else
+	if (strcmp("ChannelHangupRequest", discriminator) == 0) {
+		return ari_validate_channel_hangup_request(json);
+	} else
+	if (strcmp("ChannelLeftBridge", discriminator) == 0) {
+		return ari_validate_channel_left_bridge(json);
+	} else
+	if (strcmp("ChannelStateChange", discriminator) == 0) {
+		return ari_validate_channel_state_change(json);
+	} else
+	if (strcmp("ChannelUserevent", discriminator) == 0) {
+		return ari_validate_channel_userevent(json);
+	} else
+	if (strcmp("ChannelVarset", discriminator) == 0) {
+		return ari_validate_channel_varset(json);
+	} else
+	if (strcmp("PlaybackFinished", discriminator) == 0) {
+		return ari_validate_playback_finished(json);
+	} else
+	if (strcmp("PlaybackStarted", discriminator) == 0) {
+		return ari_validate_playback_started(json);
+	} else
+	if (strcmp("StasisEnd", discriminator) == 0) {
+		return ari_validate_stasis_end(json);
+	} else
+	if (strcmp("StasisStart", discriminator) == 0) {
+		return ari_validate_stasis_start(json);
+	} else
+	{
+		ast_log(LOG_ERROR, "ARI Event has undocumented subtype %s\n",
+			discriminator);
+	}
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
 		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
@@ -1492,6 +2135,7 @@
 		} else
 		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
+			has_type = 1;
 			prop_res = ari_validate_string(
 				ast_json_object_iter_value(iter));
 			if (!prop_res) {
@@ -1511,6 +2155,10 @@
 		ast_log(LOG_ERROR, "ARI Event missing required field application\n");
 		res = 0;
 	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI Event missing required field type\n");
+		res = 0;
+	}
 
 	return res;
 }
@@ -1519,9 +2167,40 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_playback = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI PlaybackFinished field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI PlaybackFinished field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI PlaybackFinished field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("playback", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_playback = 1;
@@ -1540,6 +2219,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI PlaybackFinished missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI PlaybackFinished missing required field type\n");
+		res = 0;
+	}
 	if (!has_playback) {
 		ast_log(LOG_ERROR, "ARI PlaybackFinished missing required field playback\n");
 		res = 0;
@@ -1552,9 +2239,40 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_playback = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI PlaybackStarted field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI PlaybackStarted field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI PlaybackStarted field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("playback", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_playback = 1;
@@ -1573,6 +2291,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI PlaybackStarted missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI PlaybackStarted missing required field type\n");
+		res = 0;
+	}
 	if (!has_playback) {
 		ast_log(LOG_ERROR, "ARI PlaybackStarted missing required field playback\n");
 		res = 0;
@@ -1585,9 +2311,40 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_channel = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI StasisEnd field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI StasisEnd field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI StasisEnd field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_channel = 1;
@@ -1606,6 +2363,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI StasisEnd missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI StasisEnd missing required field type\n");
+		res = 0;
+	}
 	if (!has_channel) {
 		ast_log(LOG_ERROR, "ARI StasisEnd missing required field channel\n");
 		res = 0;
@@ -1618,10 +2383,41 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
+	int has_application = 0;
+	int has_type = 0;
 	int has_args = 0;
 	int has_channel = 0;
 
 	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_application = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI StasisStart field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			prop_res = ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI StasisStart field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_res;
+			has_type = 1;
+			prop_res = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_res) {
+				ast_log(LOG_ERROR, "ARI StasisStart field type failed validation\n");
+				res = 0;
+			}
+		} else
 		if (strcmp("args", ast_json_object_iter_key(iter)) == 0) {
 			int prop_res;
 			has_args = 1;
@@ -1651,6 +2447,14 @@
 		}
 	}
 
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI StasisStart missing required field application\n");
+		res = 0;
+	}
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI StasisStart missing required field type\n");
+		res = 0;
+	}
 	if (!has_args) {
 		ast_log(LOG_ERROR, "ARI StasisStart missing required field args\n");
 		res = 0;

Modified: team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h?view=diff&rev=392360&r1=392359&r2=392360
==============================================================================
--- team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h (original)
+++ team/dlee/ari-event-remodel2/res/stasis_http/ari_model.h Thu Jun 20 14:53:17 2013
@@ -532,59 +532,115 @@
  * - target_uri: string (required)
  * ApplicationReplaced
  * - application: string (required)
+ * - timestamp: Date
+ * - type: string (required)
  * BridgeCreated
+ * - application: string (required)
+ * - timestamp: Date
+ * - type: string (required)
  * - bridge: Bridge (required)
  * BridgeDestroyed
+ * - application: string (required)
+ * - timestamp: Date
+ * - type: string (required)
  * - bridge: Bridge (required)
  * BridgeMerged
+ * - application: string (required)
+ * - timestamp: Date
+ * - type: string (required)
  * - bridge: Bridge (required)
  * - bridge_from: Bridge (required)
  * ChannelCallerId
+ * - application: string (required)
+ * - timestamp: Date
+ * - type: string (required)
  * - caller_presentation: int (required)
  * - caller_presentation_txt: string (required)
  * - channel: Channel (required)

[... 328 lines stripped ...]



More information about the svn-commits mailing list