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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 17 09:19:43 CDT 2013


Author: dlee
Date: Tue Sep 17 09:19:39 2013
New Revision: 399221

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=399221
Log:
Docs and minor fixes

Modified:
    team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/endpoints.h
    team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/stasis_app.h
    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/res_stasis.c
    team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c
    team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.h

Modified: team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/endpoints.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/endpoints.h?view=diff&rev=399221&r1=399220&r2=399221
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/endpoints.h (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/endpoints.h Tue Sep 17 09:19:39 2013
@@ -83,6 +83,17 @@
  */
 struct ast_endpoint;
 
+/*!
+ * \brief Finds the endpoing with the given tech/resource id.
+ *
+ * Endpoints are refcounted, so ao2_cleanup() when you're done.
+ *
+ * \param id Tech/resource id to look for.
+ * \return Associated endpoint.
+ * \return \c NULL if not found.
+ *
+ * \since 12
+ */
 struct ast_endpoint *ast_endpoint_find_by_id(const char *id);
 
 /*!
@@ -134,6 +145,16 @@
  */
 const char *ast_endpoint_get_resource(const struct ast_endpoint *endpoint);
 
+/*!
+ * \brief Gets the tech/resource id of the given endpoint.
+ *
+ * This is unique across all endpoints, and immutable.
+ *
+ * \param endpoint The endpoint.
+ * \return Tech/resource id of the endpoint.
+ * \return \c NULL if endpoint is \c NULL.
+ * \since 12
+ */
 const char *ast_endpoint_get_id(const struct ast_endpoint *endpoint);
 
 /*!

Modified: team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/stasis_app.h?view=diff&rev=399221&r1=399220&r2=399221
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/stasis_app.h (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/stasis_app.h Tue Sep 17 09:19:39 2013
@@ -68,6 +68,12 @@
 typedef void (*stasis_app_cb)(void *data, const char *app_name,
 	struct ast_json *message);
 
+/*!
+ * \brief Gets the names of all registered Stasis applications.
+ *
+ * \return \c ast_str_container of container names.
+ * \return \c NULL on error.
+ */
 struct ao2_container *stasis_app_get_all(void);
 
 /*!
@@ -105,6 +111,7 @@
 
 struct ast_json *stasis_app_to_json(const char *app_name);
 
+/*! \brief Return code for stasis_app_[un]subscribe */
 enum stasis_app_subscribe_res {
 	STASIS_ASR_OK,
 	STASIS_ASR_APP_NOT_FOUND,
@@ -113,12 +120,28 @@
 	STASIS_ASR_INTERNAL_ERROR,
 };
 
+/*!
+ * \brief Subscribes an application to a list of event sources.
+ *
+ * \param app_name Name of the application to subscribe.
+ * \param event_source_uris URIs for the event sources to subscribe to.
+ * \param event_sources_count Array size of event_source_uris.
+ * \return \ref stasis_app_subscribe_res return code.
+ */
 enum stasis_app_subscribe_res stasis_app_subscribe(const char *app_name,
-	const char **event_sources, int event_sources_count,
+	const char **event_source_uris, int event_sources_count,
 	struct ast_json **json);
 
+/*!
+ * \brief Unsubscribes an application from a list of event sources.
+ *
+ * \param app_name Name of the application to subscribe.
+ * \param event_source_uris URIs for the event sources to subscribe to.
+ * \param event_sources_count Array size of event_source_uris.
+ * \return \ref stasis_app_subscribe_res return code.
+ */
 enum stasis_app_subscribe_res stasis_app_unsubscribe(const char *app_name,
-	const char **event_sources, int event_sources_count,
+	const char **event_source_uris, int event_sources_count,
 	struct ast_json **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=399221&r1=399220&r2=399221
==============================================================================
--- 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 Tue Sep 17 09:19:39 2013
@@ -2737,6 +2737,85 @@
 	return ast_ari_validate_channel_varset;
 }
 
+int ast_ari_validate_endpoint_state_change(struct ast_json *json)
+{
+	int res = 1;
+	struct ast_json_iter *iter;
+	int has_type = 0;
+	int has_application = 0;
+	int has_endpoint = 0;
+
+	for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+		if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+			int prop_is_valid;
+			has_type = 1;
+			prop_is_valid = ast_ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_is_valid) {
+				ast_log(LOG_ERROR, "ARI EndpointStateChange field type failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+			int prop_is_valid;
+			has_application = 1;
+			prop_is_valid = ast_ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_is_valid) {
+				ast_log(LOG_ERROR, "ARI EndpointStateChange field application failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+			int prop_is_valid;
+			prop_is_valid = ast_ari_validate_date(
+				ast_json_object_iter_value(iter));
+			if (!prop_is_valid) {
+				ast_log(LOG_ERROR, "ARI EndpointStateChange field timestamp failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("endpoint", ast_json_object_iter_key(iter)) == 0) {
+			int prop_is_valid;
+			has_endpoint = 1;
+			prop_is_valid = ast_ari_validate_endpoint(
+				ast_json_object_iter_value(iter));
+			if (!prop_is_valid) {
+				ast_log(LOG_ERROR, "ARI EndpointStateChange field endpoint failed validation\n");
+				res = 0;
+			}
+		} else
+		{
+			ast_log(LOG_ERROR,
+				"ARI EndpointStateChange has undocumented field %s\n",
+				ast_json_object_iter_key(iter));
+			res = 0;
+		}
+	}
+
+	if (!has_type) {
+		ast_log(LOG_ERROR, "ARI EndpointStateChange missing required field type\n");
+		res = 0;
+	}
+
+	if (!has_application) {
+		ast_log(LOG_ERROR, "ARI EndpointStateChange missing required field application\n");
+		res = 0;
+	}
+
+	if (!has_endpoint) {
+		ast_log(LOG_ERROR, "ARI EndpointStateChange missing required field endpoint\n");
+		res = 0;
+	}
+
+	return res;
+}
+
+ari_validator ast_ari_validate_endpoint_state_change_fn(void)
+{
+	return ast_ari_validate_endpoint_state_change;
+}
+
 int ast_ari_validate_event(struct ast_json *json)
 {
 	int res = 1;
@@ -2799,6 +2878,9 @@
 	if (strcmp("ChannelVarset", discriminator) == 0) {
 		return ast_ari_validate_channel_varset(json);
 	} else
+	if (strcmp("EndpointStateChange", discriminator) == 0) {
+		return ast_ari_validate_endpoint_state_change(json);
+	} else
 	if (strcmp("PlaybackFinished", discriminator) == 0) {
 		return ast_ari_validate_playback_finished(json);
 	} else
@@ -2934,6 +3016,9 @@
 	if (strcmp("ChannelVarset", discriminator) == 0) {
 		return ast_ari_validate_channel_varset(json);
 	} else
+	if (strcmp("EndpointStateChange", discriminator) == 0) {
+		return ast_ari_validate_endpoint_state_change(json);
+	} else
 	if (strcmp("Event", discriminator) == 0) {
 		return ast_ari_validate_event(json);
 	} else

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=399221&r1=399220&r2=399221
==============================================================================
--- 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 Tue Sep 17 09:19:39 2013
@@ -753,6 +753,24 @@
  * See \ref ast_ari_model_validators.h for more details.
  */
 ari_validator ast_ari_validate_channel_varset_fn(void);
+
+/*!
+ * \brief Validator for EndpointStateChange.
+ *
+ * Endpoint state changed.
+ *
+ * \param json JSON object to validate.
+ * \returns True (non-zero) if valid.
+ * \returns False (zero) if invalid.
+ */
+int ast_ari_validate_endpoint_state_change(struct ast_json *json);
+
+/*!
+ * \brief Function pointer to ast_ari_validate_endpoint_state_change().
+ *
+ * See \ref ast_ari_model_validators.h for more details.
+ */
+ari_validator ast_ari_validate_endpoint_state_change_fn(void);
 
 /*!
  * \brief Validator for Event.
@@ -1070,6 +1088,11 @@
  * - channel: Channel
  * - value: string (required)
  * - variable: string (required)
+ * EndpointStateChange
+ * - type: string (required)
+ * - application: string (required)
+ * - timestamp: Date
+ * - endpoint: Endpoint (required)
  * Event
  * - type: string (required)
  * - application: string (required)

Modified: team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c?view=diff&rev=399221&r1=399220&r2=399221
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c Tue Sep 17 09:19:39 2013
@@ -825,6 +825,7 @@
 #define BRIDGE_SCHEME "bridge:"
 #define ENDPOINT_SCHEME "endpoint:"
 
+/*! Struct for capturing event source information */
 struct event_source {
 	enum {
 		EVENT_SOURCE_CHANNEL,
@@ -839,7 +840,7 @@
 };
 
 enum stasis_app_subscribe_res stasis_app_subscribe(const char *app_name,
-	const char **event_source_names, int event_sources_count,
+	const char **event_source_uris, int event_sources_count,
 	struct ast_json **json)
 {
 	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
@@ -862,30 +863,30 @@
 
 	for (i = 0; res == STASIS_ASR_OK && i < event_sources_count; ++i) {
 		ast_debug(1, "%s: Checking %s\n", app_name,
-			event_source_names[i]);
-		if (ast_begins_with(event_source_names[i], CHANNEL_SCHEME)) {
+			event_source_uris[i]);
+		if (ast_begins_with(event_source_uris[i], CHANNEL_SCHEME)) {
 			event_sources[i].event_source_type =
 				EVENT_SOURCE_CHANNEL;
 			event_sources[i].channel = ast_channel_get_by_name(
-				event_source_names[i] + strlen(CHANNEL_SCHEME));
+				event_source_uris[i] + strlen(CHANNEL_SCHEME));
 			if (!event_sources[i].channel) {
 				ast_debug(1, "  Channel not found\n");
 				res = STASIS_ASR_EVENT_SOURCE_NOT_FOUND;
 			}
-		} else if (ast_begins_with(event_source_names[i], BRIDGE_SCHEME)) {
+		} else if (ast_begins_with(event_source_uris[i], BRIDGE_SCHEME)) {
 			event_sources[i].event_source_type =
 				EVENT_SOURCE_BRIDGE;
 			event_sources[i].bridge = stasis_app_bridge_find_by_id(
-				event_source_names[i] + strlen(BRIDGE_SCHEME));
+				event_source_uris[i] + strlen(BRIDGE_SCHEME));
 			if (!event_sources[i].bridge) {
 				ast_debug(1, "  Bridge not found\n");
 				res = STASIS_ASR_EVENT_SOURCE_NOT_FOUND;
 			}
-		} else if (ast_begins_with(event_source_names[i], ENDPOINT_SCHEME)) {
+		} else if (ast_begins_with(event_source_uris[i], ENDPOINT_SCHEME)) {
 			event_sources[i].event_source_type =
 				EVENT_SOURCE_ENDPOINT;
 			event_sources[i].endpoint = ast_endpoint_find_by_id(
-				event_source_names[i] + strlen(ENDPOINT_SCHEME));
+				event_source_uris[i] + strlen(ENDPOINT_SCHEME));
 			if (!event_sources[i].endpoint) {
 				ast_debug(1, "  Endpoint not found\n");
 				res = STASIS_ASR_EVENT_SOURCE_NOT_FOUND;
@@ -899,7 +900,7 @@
 	for (i = 0; res == STASIS_ASR_OK && i < event_sources_count; ++i) {
 		int sub_res = -1;
 		ast_debug(1, "%s: Subscribing to %s\n", app_name,
-			event_source_names[i]);
+			event_source_uris[i]);
 
 		switch (event_sources[i].event_source_type) {
 		case EVENT_SOURCE_CHANNEL:
@@ -919,7 +920,7 @@
 		if (sub_res != 0) {
 			ast_log(LOG_ERROR,
 				"Error subscribing app '%s' to '%s'\n",
-				app_name, event_source_names[i]);
+				app_name, event_source_uris[i]);
 			res = STASIS_ASR_INTERNAL_ERROR;
 		}
 	}
@@ -940,6 +941,8 @@
 			event_sources[i].bridge = NULL;
 			break;
 		case EVENT_SOURCE_ENDPOINT:
+			ao2_cleanup(event_sources[i].endpoint);
+			event_sources[i].endpoint = NULL;
 			break;
 		}
 	}
@@ -948,7 +951,7 @@
 }
 
 enum stasis_app_subscribe_res stasis_app_unsubscribe(const char *app_name,
-	const char **event_source_names, int event_sources_count,
+	const char **event_source_uris, int event_sources_count,
 	struct ast_json **json)
 {
 	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
@@ -965,20 +968,20 @@
 
 	/* Validate the input */
 	for (i = 0; res == STASIS_ASR_OK && i < event_sources_count; ++i) {
-		if (ast_begins_with(event_source_names[i], CHANNEL_SCHEME)) {
-			const char *channel_id = event_source_names[i] +
+		if (ast_begins_with(event_source_uris[i], CHANNEL_SCHEME)) {
+			const char *channel_id = event_source_uris[i] +
 				strlen(CHANNEL_SCHEME);
 			if (!app_is_subscribed_channel_id(app, channel_id)) {
 				res = STASIS_ASR_EVENT_SOURCE_NOT_FOUND;
 			}
-		} else if (ast_begins_with(event_source_names[i], BRIDGE_SCHEME)) {
-			const char *bridge_id = event_source_names[i] +
+		} else if (ast_begins_with(event_source_uris[i], BRIDGE_SCHEME)) {
+			const char *bridge_id = event_source_uris[i] +
 				strlen(BRIDGE_SCHEME);
 			if (!app_is_subscribed_bridge_id(app, bridge_id)) {
 				res = STASIS_ASR_EVENT_SOURCE_NOT_FOUND;
 			}
-		} else if (ast_begins_with(event_source_names[i], ENDPOINT_SCHEME)) {
-			const char *endpoint_id = event_source_names[i] +
+		} else if (ast_begins_with(event_source_uris[i], ENDPOINT_SCHEME)) {
+			const char *endpoint_id = event_source_uris[i] +
 				strlen(ENDPOINT_SCHEME);
 			if (!app_is_subscribed_endpoint_id(app, endpoint_id)) {
 				res = STASIS_ASR_EVENT_SOURCE_NOT_FOUND;
@@ -989,16 +992,16 @@
 	}
 
 	for (i = 0; res == STASIS_ASR_OK && i < event_sources_count; ++i) {
-		if (ast_begins_with(event_source_names[i], CHANNEL_SCHEME)) {
-			const char *channel_id = event_source_names[i] +
+		if (ast_begins_with(event_source_uris[i], CHANNEL_SCHEME)) {
+			const char *channel_id = event_source_uris[i] +
 				strlen(CHANNEL_SCHEME);
 			app_unsubscribe_channel_id(app, channel_id);
-		} else if (ast_begins_with(event_source_names[i], BRIDGE_SCHEME)) {
-			const char *bridge_id = event_source_names[i] +
+		} else if (ast_begins_with(event_source_uris[i], BRIDGE_SCHEME)) {
+			const char *bridge_id = event_source_uris[i] +
 				strlen(BRIDGE_SCHEME);
 			app_unsubscribe_bridge_id(app, bridge_id);
-		} else if (ast_begins_with(event_source_names[i], ENDPOINT_SCHEME)) {
-			const char *endpoint_id = event_source_names[i] +
+		} else if (ast_begins_with(event_source_uris[i], ENDPOINT_SCHEME)) {
+			const char *endpoint_id = event_source_uris[i] +
 				strlen(ENDPOINT_SCHEME);
 			app_unsubscribe_endpoint_id(app, endpoint_id);
 		}

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=399221&r1=399220&r2=399221
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c Tue Sep 17 09:19:39 2013
@@ -214,8 +214,6 @@
 	ao2_ref(forwards, +1);
 	return forwards;
 }
-
-
 
 static int forwards_sort(const void *obj_left, const void *obj_right, int flags)
 {

Modified: team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.h?view=diff&rev=399221&r1=399220&r2=399221
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.h (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.h Tue Sep 17 09:19:39 2013
@@ -130,12 +130,30 @@
  * \brief Cancel the subscription an app has for a channel.
  *
  * \param app Subscribing application.
- * \param forwards Returned object from app_subscribe_channel().
+ * \param chan Channel to unsubscribe from.
+ * \return 0 on success.
+ * \return Non-zero on error.
  */
 int app_unsubscribe_channel(struct app *app, struct ast_channel *chan);
 
+/*!
+ * \brief Cancel the subscription an app has for a channel.
+ *
+ * \param app Subscribing application.
+ * \param channel_id Id of channel to unsubscribe from.
+ * \return 0 on success.
+ * \return Non-zero on error.
+ */
 int app_unsubscribe_channel_id(struct app *app, const char *channel_id);
 
+/*!
+ * \brief Test if an app is subscribed to a channel.
+ *
+ * \param app Subscribing application.
+ * \param channel_id Id of channel to check.
+ * \return True (non-zero) if channel is subscribed to \a app.
+ * \return False (zero) if channel is not subscribed.
+ */
 int app_is_subscribed_channel_id(struct app *app, const char *channel_id);
 
 /*!
@@ -158,14 +176,54 @@
  */
 int app_unsubscribe_bridge(struct app *app, struct ast_bridge *bridge);
 
+/*!
+ * \brief Cancel the subscription an app has for a bridge.
+ *
+ * \param app Subscribing application.
+ * \param bridge_id Id of bridge to unsubscribe from.
+ * \return 0 on success.
+ * \return Non-zero on error.
+ */
 int app_unsubscribe_bridge_id(struct app *app, const char *bridge_id);
 
+/*!
+ * \brief Test if an app is subscribed to a bridge.
+ *
+ * \param app Subscribing application.
+ * \param bridge_id Id of bridge to check.
+ * \return True (non-zero) if bridge is subscribed to \a app.
+ * \return False (zero) if bridge is not subscribed.
+ */
 int app_is_subscribed_bridge_id(struct app *app, const char *bridge_id);
 
+/*!
+ * \brief Subscribes an application to a endpoint.
+ *
+ * \param app Application.
+ * \param chan Endpoint to subscribe to.
+ * \return 0 on success.
+ * \return Non-zero on error.
+ */
 int app_subscribe_endpoint(struct app *app, struct ast_endpoint *endpoint);
 
+/*!
+ * \brief Cancel the subscription an app has for a endpoint.
+ *
+ * \param app Subscribing application.
+ * \param endpoint_id Id of endpoint to unsubscribe from.
+ * \return 0 on success.
+ * \return Non-zero on error.
+ */
 int app_unsubscribe_endpoint_id(struct app *app, const char *endpoint_id);
 
+/*!
+ * \brief Test if an app is subscribed to a endpoint.
+ *
+ * \param app Subscribing application.
+ * \param endpoint_id Id of endpoint to check.
+ * \return True (non-zero) if endpoint is subscribed to \a app.
+ * \return False (zero) if endpoint is not subscribed.
+ */
 int app_is_subscribed_endpoint_id(struct app *app, const char *endpoint_id);
 
 #endif /* _ASTERISK_RES_STASIS_APP_H */




More information about the asterisk-commits mailing list