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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Sep 11 15:15:33 CDT 2013


Author: dlee
Date: Wed Sep 11 15:15:31 2013
New Revision: 398840

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=398840
Log:
Channel unsubscribe

Modified:
    team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/stasis_app.h
    team/dlee/ASTERISK-22451-ari-subscribe/res/ari/resource_applications.c
    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/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/stasis_app.h?view=diff&rev=398840&r1=398839&r2=398840
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/stasis_app.h (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/stasis_app.h Wed Sep 11 15:15:31 2013
@@ -117,6 +117,10 @@
 	const char **event_sources, int event_sources_count,
 	struct ast_json **json);
 
+enum stasis_app_subscribe_res stasis_app_unsubscribe(const char *app_name,
+	const char **event_sources, int event_sources_count,
+	struct ast_json **json);
+
 /*! @} */
 
 /*! @{ */

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=398840&r1=398839&r2=398840
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/ari/resource_applications.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/ari/resource_applications.c Wed Sep 11 15:15:31 2013
@@ -113,12 +113,42 @@
 		ast_ari_response_error(response, 500, "Internal Server Error",
 			"Error processing request");
 	}
-
 }
 
 void ast_ari_application_unsubscribe(struct ast_variable *headers,
 	struct ast_application_unsubscribe_args *args,
 	struct ast_ari_response *response)
 {
-	ast_log(LOG_ERROR, "TODO: ast_ari_application_unsubscribe\n");
+	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+	enum stasis_app_subscribe_res res;
+
+	if (args->event_source_count == 0) {
+		ast_ari_response_error(response, 400, "Bad Request",
+			"Missing parameter eventSource");
+		return;
+	}
+
+	res = stasis_app_unsubscribe(args->application_name, args->event_source,
+		args->event_source_count, &json);
+
+	switch (res) {
+	case STASIS_ASR_OK:
+		ast_ari_response_ok(response, json);
+		break;
+	case STASIS_ASR_APP_NOT_FOUND:
+		ast_ari_response_error(response, 404, "Not Found",
+			"Application not found");
+		break;
+	case STASIS_ASR_EVENT_SOURCE_NOT_FOUND:
+		ast_ari_response_error(response, 422, "Unprocessable Entity",
+			"Event source was not subscribed to");
+		break;
+	case STASIS_ASR_EVENT_SOURCE_BAD_SCHEME:
+		ast_ari_response_error(response, 400, "Bad Request",
+			"Invalid event source URI scheme");
+		break;
+	case STASIS_ASR_INTERNAL_ERROR:
+		ast_ari_response_error(response, 500, "Internal Server Error",
+			"Error processing request");
+	}
 }

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=398840&r1=398839&r2=398840
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c Wed Sep 11 15:15:31 2013
@@ -878,6 +878,50 @@
 	return res;
 }
 
+enum stasis_app_subscribe_res stasis_app_unsubscribe(const char *app_name,
+	const char **event_sources, int event_sources_count,
+	struct ast_json **json)
+{
+	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
+	enum stasis_app_subscribe_res res = STASIS_ASR_OK;
+	int i;
+
+	if (app_name) {
+		app = ao2_find(apps_registry, app_name, OBJ_KEY);
+	}
+
+	if (!app) {
+		return STASIS_ASR_APP_NOT_FOUND;
+	}
+
+	/* Validate the input */
+	for (i = 0; res == STASIS_ASR_OK && i < event_sources_count; ++i) {
+		if (ast_begins_with(event_sources[i], CHANNEL_SCHEME)) {
+			const char *channel_id = event_sources[i] +
+				strlen(CHANNEL_SCHEME);
+			if (!app_is_subscribed_channel_id(app, channel_id)) {
+				res = STASIS_ASR_EVENT_SOURCE_NOT_FOUND;
+			}
+		} else {
+			res = STASIS_ASR_EVENT_SOURCE_BAD_SCHEME;
+		}
+	}
+
+	for (i = 0; res == STASIS_ASR_OK && i < event_sources_count; ++i) {
+		if (ast_begins_with(event_sources[i], CHANNEL_SCHEME)) {
+			const char *channel_id = event_sources[i] +
+				strlen(CHANNEL_SCHEME);
+			app_unsubscribe_channel_id(app, channel_id);
+		}
+	}
+
+	if (res == STASIS_ASR_OK && json) {
+		*json = app_to_json(app);
+	}
+
+	return res;
+}
+
 void stasis_app_ref(void)
 {
 	ast_module_ref(ast_module_info->self);

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=398840&r1=398839&r2=398840
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c Wed Sep 11 15:15:31 2013
@@ -730,8 +730,8 @@
 
 	forwards = ao2_find(app->forwards, id, OBJ_SEARCH_KEY | OBJ_NOLOCK);
 	if (!forwards) {
-		ast_log(LOG_ERROR,
-			"App '%s' not subscribed to %s '%s'",
+		ast_log(LOG_WARNING,
+			"App '%s' not subscribed to %s '%s'\n",
 			app->name, kind, id);
 		return -1;
 	}
@@ -753,7 +753,23 @@
 		return -1;
 	}
 
-	return unsubscribe(app, "channel", ast_channel_uniqueid(chan));
+	return app_unsubscribe_channel_id(app, ast_channel_uniqueid(chan));
+}
+
+int app_unsubscribe_channel_id(struct app *app, const char *channel_id)
+{
+	if (!app || !channel_id) {
+		return -1;
+	}
+
+	return unsubscribe(app, "channel", channel_id);
+}
+
+int app_is_subscribed_channel_id(struct app *app, const char *channel_id)
+{
+	RAII_VAR(struct app_forwards *, forwards, NULL, ao2_cleanup);
+	forwards = ao2_find(app->forwards, channel_id, OBJ_SEARCH_KEY);
+	return forwards != NULL;
 }
 
 int app_subscribe_bridge(struct app *app, struct ast_bridge *bridge)

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=398840&r1=398839&r2=398840
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.h (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.h Wed Sep 11 15:15:31 2013
@@ -134,6 +134,10 @@
  */
 int app_unsubscribe_channel(struct app *app, struct ast_channel *chan);
 
+int app_unsubscribe_channel_id(struct app *app, const char *channel_id);
+
+int app_is_subscribed_channel_id(struct app *app, const char *channel_id);
+
 /*!
  * \brief Add a bridge subscription to an existing channel subscription.
  *




More information about the asterisk-commits mailing list