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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 27 14:35:39 CDT 2013


Author: dlee
Date: Fri Sep 27 14:35:36 2013
New Revision: 400005

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=400005
Log:
Addressed review feedback:
* Moved ast_endpoint_init() declaration to _private.h
* Fixed typos, comments, etc.
* Corrected endpoint_hash to match the latest hash template
* Added more error checking to ast_ari_get_applications and
  ast_ari_application_subscribe
* Improved warning messages from the underlying subscription functions.

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

Modified: team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/_private.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/_private.h?view=diff&rev=400005&r1=400004&r2=400005
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/_private.h (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/_private.h Fri Sep 27 14:35:36 2013
@@ -142,4 +142,12 @@
 
 /*! \brief initialize the sounds index */
 int ast_sounds_index_init(void);
+
+/*!
+ * \brief Endpoint support initialization.
+ * \return 0 on success.
+ * \return Non-zero on error.
+ */
+int ast_endpoint_init(void);
+
 #endif /* _ASTERISK__PRIVATE_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=400005&r1=400004&r2=400005
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/endpoints.h (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/endpoints.h Fri Sep 27 14:35:36 2013
@@ -45,13 +45,6 @@
 #include "asterisk/json.h"
 
 /*!
- * \brief Endpoint support initialization.
- * \return 0 on success.
- * \return Non-zer on error.
- */
-int ast_endpoint_init(void);
-
-/*!
  * \brief Valid states for an endpoint.
  * \since 12
  */
@@ -84,7 +77,7 @@
 struct ast_endpoint;
 
 /*!
- * \brief Finds the endpoing with the given tech/resource id.
+ * \brief Finds the endpoint with the given tech/resource id.
  *
  * Endpoints are refcounted, so ao2_cleanup() when you're done.
  *

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=400005&r1=400004&r2=400005
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/stasis_app.h (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/stasis_app.h Fri Sep 27 14:35:36 2013
@@ -85,6 +85,7 @@
  * \param app_name Name of this application.
  * \param handler Callback for application messages.
  * \param data Data blob to pass to the callback. Must be AO2 managed.
+ *
  * \return 0 for success
  * \return -1 for error.
  */
@@ -104,11 +105,20 @@
  *
  * \param app_name Name of the application to invoke.
  * \param message Message to send (borrowed reference)
+ *
  * \return 0 for success.
  * \return -1 for error.
  */
 int stasis_app_send(const char *app_name, struct ast_json *message);
 
+/*!
+ * \brief Return the JSON representation of a Stasis application.
+ *
+ * \param app_name Name of the application.
+ *
+ * \return JSON representation of app with given name.
+ * \return \c NULL on error.
+ */
 struct ast_json *stasis_app_to_json(const char *app_name);
 
 /*! \brief Return code for stasis_app_[un]subscribe */
@@ -126,6 +136,9 @@
  * \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.
+ * \param json Optional output pointer for JSON representation of the app
+ *             after adding the subscription.
+ *
  * \return \ref stasis_app_subscribe_res return code.
  */
 enum stasis_app_subscribe_res stasis_app_subscribe(const char *app_name,
@@ -138,6 +151,9 @@
  * \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.
+ * \param json Optional output pointer for JSON representation of the app
+ *             after adding the subscription.
+ *
  * \return \ref stasis_app_subscribe_res return code.
  */
 enum stasis_app_subscribe_res stasis_app_unsubscribe(const char *app_name,
@@ -154,6 +170,7 @@
 /*!
  * \brief Returns the handler for the given channel.
  * \param chan Channel to handle.
+ *
  * \return NULL channel not in Stasis application.
  * \return Pointer to \c res_stasis handler.
  */
@@ -163,6 +180,7 @@
 /*!
  * \brief Returns the handler for the channel with the given id.
  * \param channel_id Uniqueid of the channel.
+ *
  * \return NULL channel not in Stasis application, or channel does not exist.
  * \return Pointer to \c res_stasis handler.
  */
@@ -196,6 +214,7 @@
  * \brief Returns the uniqueid of the channel associated with this control
  *
  * \param control Control object.
+ *
  * \return Uniqueid of the associate channel.
  * \return \c NULL if \a control is \c NULL.
  */
@@ -285,6 +304,7 @@
  * \brief Get the value of a variable on the channel associated with this control.
  * \param control Control for \c res_stasis.
  * \param variable The name of the variable.
+ *
  * \return The value of the variable.  The returned variable must be freed.
  */
 char *stasis_app_control_get_channel_var(struct stasis_app_control *control, const char *variable);
@@ -331,6 +351,7 @@
  * The returned pointer is AO2 managed, so ao2_cleanup() when you're done.
  *
  * \param control Control for \c res_stasis.
+ *
  * \return Most recent snapshot. ao2_cleanup() when done.
  * \return \c NULL if channel isn't in cache.
  */
@@ -371,6 +392,7 @@
 /*!
  * \brief Returns the bridge with the given id.
  * \param bridge_id Uniqueid of the bridge.
+ *
  * \return NULL bridge not created by a Stasis application, or bridge does not exist.
  * \return Pointer to bridge.
  */
@@ -404,6 +426,7 @@
  *
  * \param control Control whose channel should be added to the bridge
  * \param bridge Pointer to the bridge
+ *
  * \return non-zero on failure
  * \return zero on success
  */
@@ -415,6 +438,7 @@
  *
  * \param control Control whose channel should be removed from the bridge
  * \param bridge Pointer to the bridge
+ *
  * \return non-zero on failure
  * \return zero on success
  */
@@ -426,6 +450,7 @@
  * \brief Gets the bridge currently associated with a control object.
  *
  * \param control Control object for the channel to query.
+ *
  * \return Associated \ref ast_bridge.
  * \return \c NULL if not associated with a bridge.
  */

Modified: team/dlee/ASTERISK-22451-ari-subscribe/main/endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/main/endpoints.c?view=diff&rev=400005&r1=400004&r2=400005
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/main/endpoints.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/main/endpoints.c Fri Sep 27 14:35:36 2013
@@ -38,6 +38,7 @@
 #include "asterisk/stasis_endpoints.h"
 #include "asterisk/stasis_message_router.h"
 #include "asterisk/stringfields.h"
+#include "asterisk/_private.h"
 
 /*! Buckets for endpoint->channel mappings. Keep it prime! */
 #define ENDPOINT_CHANNEL_BUCKETS 127
@@ -75,11 +76,11 @@
 	const struct ast_endpoint *endpoint;
 	const char *key;
 
-	switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
-	case OBJ_KEY:
+	switch (flags & OBJ_SEARCH_MASK) {
+	case OBJ_SEARCH_KEY:
 		key = obj;
 		return ast_str_hash(key);
-	case OBJ_POINTER:
+	case OBJ_SEARCH_OBJECT:
 		endpoint = obj;
 		return ast_str_hash(endpoint->id);
 	default:

Modified: team/dlee/ASTERISK-22451-ari-subscribe/res/ari/resource_applications.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/res/ari/resource_applications.c?view=diff&rev=400005&r1=400004&r2=400005
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/ari/resource_applications.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/ari/resource_applications.c Fri Sep 27 14:35:36 2013
@@ -47,6 +47,7 @@
 {
 	RAII_VAR(struct ao2_container *, apps, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+	size_t count;
 
 	apps = stasis_app_get_all();
 	json = ast_json_array_create();
@@ -56,7 +57,18 @@
 		return;
 	}
 
-	ao2_callback(apps, OBJ_NODATA, append_json, json);
+	ao2_lock(apps);
+	count = ao2_container_count(apps);
+	ao2_callback(apps, OBJ_NOLOCK | OBJ_NODATA, append_json, json);
+	ao2_lock(apps);
+
+	if (count != ast_json_array_size(json)) {
+		ast_ari_response_error(response, 500, "Internal Server Error",
+			"Allocation failed");
+		return;
+	}
+
+
 	ast_ari_response_ok(response, json);
 }
 
@@ -84,9 +96,15 @@
 	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
 	enum stasis_app_subscribe_res res;
 
-	if (args->event_source_count == 0) {
+	if (args->event_source_count <= 0) {
 		ast_ari_response_error(response, 400, "Bad Request",
 			"Missing parameter eventSource");
+		return;
+	}
+
+	if (ast_strlen_zero(args->application_name)) {
+		ast_ari_response_error(response, 400, "Bad Request",
+			"Missing parameter applicationName");
 		return;
 	}
 

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=400005&r1=400004&r2=400005
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c Fri Sep 27 14:35:36 2013
@@ -853,6 +853,8 @@
 	}
 
 	if (!app) {
+		ast_log(LOG_WARNING, "Could not find app '%s'\n",
+			app_name ? : "(null)");
 		return STASIS_ASR_APP_NOT_FOUND;
 	}
 
@@ -862,37 +864,38 @@
 	}
 
 	for (i = 0; res == STASIS_ASR_OK && i < event_sources_count; ++i) {
-		ast_debug(1, "%s: Checking %s\n", app_name,
-			event_source_uris[i]);
-		if (ast_begins_with(event_source_uris[i], CHANNEL_SCHEME)) {
+		const char *uri = event_source_uris[i];
+		ast_debug(3, "%s: Checking %s\n", app_name,
+			uri);
+		if (ast_begins_with(uri, CHANNEL_SCHEME)) {
 			event_sources[i].event_source_type =
 				EVENT_SOURCE_CHANNEL;
 			event_sources[i].channel = ast_channel_get_by_name(
-				event_source_uris[i] + strlen(CHANNEL_SCHEME));
+				uri + strlen(CHANNEL_SCHEME));
 			if (!event_sources[i].channel) {
-				ast_debug(1, "  Channel not found\n");
+				ast_log(LOG_WARNING, "Channel not found: %s\n", uri);
 				res = STASIS_ASR_EVENT_SOURCE_NOT_FOUND;
 			}
-		} else if (ast_begins_with(event_source_uris[i], BRIDGE_SCHEME)) {
+		} else if (ast_begins_with(uri, BRIDGE_SCHEME)) {
 			event_sources[i].event_source_type =
 				EVENT_SOURCE_BRIDGE;
 			event_sources[i].bridge = stasis_app_bridge_find_by_id(
-				event_source_uris[i] + strlen(BRIDGE_SCHEME));
+				uri + strlen(BRIDGE_SCHEME));
 			if (!event_sources[i].bridge) {
-				ast_debug(1, "  Bridge not found\n");
+				ast_log(LOG_WARNING, "Bridge not found: %s\n", uri);
 				res = STASIS_ASR_EVENT_SOURCE_NOT_FOUND;
 			}
-		} else if (ast_begins_with(event_source_uris[i], ENDPOINT_SCHEME)) {
+		} else if (ast_begins_with(uri, ENDPOINT_SCHEME)) {
 			event_sources[i].event_source_type =
 				EVENT_SOURCE_ENDPOINT;
 			event_sources[i].endpoint = ast_endpoint_find_by_id(
-				event_source_uris[i] + strlen(ENDPOINT_SCHEME));
+				uri + strlen(ENDPOINT_SCHEME));
 			if (!event_sources[i].endpoint) {
-				ast_debug(1, "  Endpoint not found\n");
+				ast_log(LOG_WARNING, "Endpoint not found: %s\n", uri);
 				res = STASIS_ASR_EVENT_SOURCE_NOT_FOUND;
 			}
 		} else {
-			ast_debug(1, "  Invalid scheme\n");
+			ast_log(LOG_WARNING, "Invalid scheme: %s\n", uri);
 			res = STASIS_ASR_EVENT_SOURCE_BAD_SCHEME;
 		}
 	}
@@ -918,7 +921,7 @@
 		}
 
 		if (sub_res != 0) {
-			ast_log(LOG_ERROR,
+			ast_log(LOG_WARNING,
 				"Error subscribing app '%s' to '%s'\n",
 				app_name, event_source_uris[i]);
 			res = STASIS_ASR_INTERNAL_ERROR;
@@ -959,6 +962,8 @@
 	int i;
 
 	if (app_name) {
+		ast_log(LOG_WARNING, "Could not find app '%s'\n",
+			app_name ? : "(null)");
 		app = ao2_find(apps_registry, app_name, OBJ_KEY);
 	}
 




More information about the asterisk-commits mailing list