[asterisk-commits] dlee: branch dlee/ASTERISK-22451-ari-subscribe r398805 - in /team/dlee/ASTERI...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 11 08:47:54 CDT 2013


Author: dlee
Date: Wed Sep 11 08:47:52 2013
New Revision: 398805

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=398805
Log:
Passes validation

Modified:
    team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.c
    team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.h
    team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c
    team/dlee/ASTERISK-22451-ari-subscribe/rest-api/api-docs/applications.json

Modified: team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.c?view=diff&rev=398805&r1=398804&r2=398805
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.c Wed Sep 11 08:47:52 2013
@@ -3366,41 +3366,17 @@
 {
 	int res = 1;
 	struct ast_json_iter *iter;
-	int has_bridge_ids = 0;
-	int has_channel_ids = 0;
-	int has_endpoint_ids = 0;
-
-	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
-		if (strcmp("bridge_ids", ast_json_object_iter_key(iter)) == 0) {
-			int prop_is_valid;
-			has_bridge_ids = 1;
+	int has_event_sources = 0;
+
+	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("event_sources", ast_json_object_iter_key(iter)) == 0) {
+			int prop_is_valid;
+			has_event_sources = 1;
 			prop_is_valid = ast_ari_validate_list(
 				ast_json_object_iter_value(iter),
 				ast_ari_validate_string);
 			if (!prop_is_valid) {
-				ast_log(LOG_ERROR, "ARI Application field bridge_ids failed validation\n");
-				res = 0;
-			}
-		} else
-		if (strcmp("channel_ids", ast_json_object_iter_key(iter)) == 0) {
-			int prop_is_valid;
-			has_channel_ids = 1;
-			prop_is_valid = ast_ari_validate_list(
-				ast_json_object_iter_value(iter),
-				ast_ari_validate_string);
-			if (!prop_is_valid) {
-				ast_log(LOG_ERROR, "ARI Application field channel_ids failed validation\n");
-				res = 0;
-			}
-		} else
-		if (strcmp("endpoint_ids", ast_json_object_iter_key(iter)) == 0) {
-			int prop_is_valid;
-			has_endpoint_ids = 1;
-			prop_is_valid = ast_ari_validate_list(
-				ast_json_object_iter_value(iter),
-				ast_ari_validate_string);
-			if (!prop_is_valid) {
-				ast_log(LOG_ERROR, "ARI Application field endpoint_ids failed validation\n");
+				ast_log(LOG_ERROR, "ARI Application field event_sources failed validation\n");
 				res = 0;
 			}
 		} else
@@ -3412,18 +3388,8 @@
 		}
 	}
 
-	if (!has_bridge_ids) {
-		ast_log(LOG_ERROR, "ARI Application missing required field bridge_ids\n");
-		res = 0;
-	}
-
-	if (!has_channel_ids) {
-		ast_log(LOG_ERROR, "ARI Application missing required field channel_ids\n");
-		res = 0;
-	}
-
-	if (!has_endpoint_ids) {
-		ast_log(LOG_ERROR, "ARI Application missing required field endpoint_ids\n");
+	if (!has_event_sources) {
+		ast_log(LOG_ERROR, "ARI Application missing required field event_sources\n");
 		res = 0;
 	}
 

Modified: team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.h?view=diff&rev=398805&r1=398804&r2=398805
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.h (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/ari/ari_model_validators.h Wed Sep 11 08:47:52 2013
@@ -1091,9 +1091,7 @@
  * - args: List[string] (required)
  * - channel: Channel (required)
  * Application
- * - bridge_ids: List[string] (required)
- * - channel_ids: List[string] (required)
- * - endpoint_ids: List[string] (required)
+ * - event_sources: List[string] (required)
  */
 
 #endif /* _ASTERISK_ARI_MODEL_H */

Modified: team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c?view=diff&rev=398805&r1=398804&r2=398805
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c Wed Sep 11 08:47:52 2013
@@ -52,6 +52,12 @@
 	char name[];
 };
 
+enum forward_type {
+	FORWARD_CHANNEL,
+	FORWARD_BRIDGE,
+	FORWARD_ENDPOINT,
+};
+
 /*! Subscription info for a particular channel/bridge. */
 struct app_forwards {
 	/*! Count of number of times this channel/bridge has been subscribed */
@@ -62,6 +68,8 @@
 	/*! Forward for the caching topic */
 	struct stasis_subscription *topic_cached_forward;
 
+	/* Type of object being forwarded */
+	enum forward_type forward_type;
 	/*! Unique id of the object being forwarded */
 	char id[];
 };
@@ -645,9 +653,39 @@
 struct ast_json *app_to_json(const struct app *app)
 {
 	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
-
-	json = ast_json_pack("{s: [], s: [], s: []}",
-		"channel_ids", "bridge_ids", "endpoint_ids");
+	struct ast_json *array;
+	struct ao2_iterator i;
+	void *obj;
+
+	json = ast_json_pack("{s: []}", "event_sources");
+	array = ast_json_object_get(json, "event_sources");
+
+	i = ao2_iterator_init(app->forwards, 0);
+	while ((obj = ao2_iterator_next(&i))) {
+		RAII_VAR(struct app_forwards *, forwards, obj, ao2_cleanup);
+		struct ast_json *uri = NULL;
+		int append_res;
+
+		switch (forwards->forward_type) {
+		case FORWARD_CHANNEL:
+			uri = ast_json_stringf("channel:%s", forwards->id);
+			break;
+		case FORWARD_BRIDGE:
+			uri = ast_json_stringf("bridge:%s", forwards->id);
+			break;
+		case FORWARD_ENDPOINT:
+			uri = ast_json_stringf("endpoint:%s", forwards->id);
+			break;
+		}
+
+		append_res = ast_json_array_append(array, uri);
+		if (append_res != 0) {
+			ast_log(LOG_ERROR, "Error building response\n");
+			ao2_iterator_destroy(&i);
+			return NULL;
+		}
+	}
+	ao2_iterator_destroy(&i);
 
 	return ast_json_ref(json);
 }

Modified: team/dlee/ASTERISK-22451-ari-subscribe/rest-api/api-docs/applications.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/rest-api/api-docs/applications.json?view=diff&rev=398805&r1=398804&r2=398805
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/rest-api/api-docs/applications.json (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/rest-api/api-docs/applications.json Wed Sep 11 08:47:52 2013
@@ -141,19 +141,9 @@
 			"id": "Application",
 			"description": "Details of a Stasis application",
 			"properties": {
-				"channel_ids": {
+				"event_sources": {
 					"type": "List[string]",
-					"description": "Id's of channels subscribed to.",
-					"required": true
-				},
-				"bridge_ids": {
-					"type": "List[string]",
-					"description": "Id's of bridges subscribed to.",
-					"required": true
-				},
-				"endpoint_ids": {
-					"type": "List[string]",
-					"description": "Tech/resource of endpoints subscribed to",
+					"description": "URI's for objects subscribed to.",
 					"required": true
 				}
 			}




More information about the asterisk-commits mailing list