[asterisk-commits] dlee: branch dlee/ASTERISK-22451-ari-subscribe r398816 - in /team/dlee/ASTERI...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Sep 11 11:45:37 CDT 2013
Author: dlee
Date: Wed Sep 11 11:45:35 2013
New Revision: 398816
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=398816
Log:
Basic subscriptions work for channels
Modified:
team/dlee/ASTERISK-22451-ari-subscribe/include/asterisk/stasis_app.h
team/dlee/ASTERISK-22451-ari-subscribe/main/json.c
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/ari/resource_applications.c
team/dlee/ASTERISK-22451-ari-subscribe/res/res_ari_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/rest-api/api-docs/applications.json
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=398816&r1=398815&r2=398816
==============================================================================
--- 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 11:45:35 2013
@@ -68,6 +68,8 @@
typedef void (*stasis_app_cb)(void *data, const char *app_name,
struct ast_json *message);
+struct ao2_container *stasis_apps_get_all(void);
+
/*!
* \brief Register a new Stasis application.
*
@@ -100,6 +102,8 @@
* \return -1 for error.
*/
int stasis_app_send(const char *app_name, struct ast_json *message);
+
+struct ast_json *stasis_app_to_json(const char *app_name);
enum stasis_app_subscribe_res {
STASIS_ASR_OK,
Modified: team/dlee/ASTERISK-22451-ari-subscribe/main/json.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/main/json.c?view=diff&rev=398816&r1=398815&r2=398816
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/main/json.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/main/json.c Wed Sep 11 11:45:35 2013
@@ -689,8 +689,9 @@
if (format) {
r = (struct ast_json *)json_vpack_ex(&error, 0, format, ap);
if (!r) {
- ast_log(LOG_ERROR, "Error building JSON: %s.\n",
- error.text);
+ ast_log(LOG_ERROR,
+ "Error building JSON from '%s': %s.\n",
+ format, error.text);
}
}
return r;
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=398816&r1=398815&r2=398816
==============================================================================
--- 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 11:45:35 2013
@@ -3367,6 +3367,7 @@
int res = 1;
struct ast_json_iter *iter;
int has_event_sources = 0;
+ int has_name = 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) {
@@ -3380,6 +3381,16 @@
res = 0;
}
} else
+ if (strcmp("name", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_name = 1;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI Application field name failed validation\n");
+ res = 0;
+ }
+ } else
{
ast_log(LOG_ERROR,
"ARI Application has undocumented field %s\n",
@@ -3393,6 +3404,11 @@
res = 0;
}
+ if (!has_name) {
+ ast_log(LOG_ERROR, "ARI Application missing required field name\n");
+ res = 0;
+ }
+
return res;
}
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=398816&r1=398815&r2=398816
==============================================================================
--- 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 11:45:35 2013
@@ -1092,6 +1092,7 @@
* - channel: Channel (required)
* Application
* - event_sources: List[string] (required)
+ * - name: string (required)
*/
#endif /* _ASTERISK_ARI_MODEL_H */
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=398816&r1=398815&r2=398816
==============================================================================
--- 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 11:45:35 2013
@@ -31,17 +31,50 @@
#include "asterisk/stasis_app.h"
#include "resource_applications.h"
+static int append_json(void *obj, void *arg, int flags)
+{
+ const char *app = obj;
+ struct ast_json *array = arg;
+
+ ast_json_array_append(array, stasis_app_to_json(app));
+
+ return 0;
+}
+
void ast_ari_get_applications(struct ast_variable *headers,
struct ast_get_applications_args *args,
struct ast_ari_response *response)
{
- ast_log(LOG_ERROR, "TODO: ast_ari_get_applications\n");
+ RAII_VAR(struct ao2_container *, apps, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+
+ apps = stasis_apps_get_all();
+ json = ast_json_array_create();
+ if (!apps || !json) {
+ ast_ari_response_error(response, 500, "Internal Server Error",
+ "Allocation failed");
+ return;
+ }
+
+ ao2_callback(apps, OBJ_NODATA, append_json, json);
+ ast_ari_response_ok(response, json);
}
+
void ast_ari_get_application(struct ast_variable *headers,
struct ast_get_application_args *args,
struct ast_ari_response *response)
{
- ast_log(LOG_ERROR, "TODO: ast_ari_get_application\n");
+ RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+
+ json = stasis_app_to_json(args->application_name);
+
+ if (!json) {
+ ast_ari_response_error(response, 404, "Not Found",
+ "Application not found");
+ return;
+ }
+
+ ast_ari_response_ok(response, json);
}
void ast_ari_application_subscribe(struct ast_variable *headers,
Modified: team/dlee/ASTERISK-22451-ari-subscribe/res/res_ari_applications.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-22451-ari-subscribe/res/res_ari_applications.c?view=diff&rev=398816&r1=398815&r2=398816
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/res_ari_applications.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/res_ari_applications.c Wed Sep 11 11:45:35 2013
@@ -82,8 +82,8 @@
break;
default:
if (200 <= code && code <= 299) {
- is_valid = ast_ari_validate_application(
- response->message);
+ is_valid = ast_ari_validate_list(response->message,
+ ast_ari_validate_application_fn());
} else {
ast_log(LOG_ERROR, "Invalid error response %d for /applications\n", code);
is_valid = 0;
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=398816&r1=398815&r2=398816
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/res_stasis.c Wed Sep 11 11:45:35 2013
@@ -734,6 +734,29 @@
return 0;
}
+static int append_name(void *obj, void *arg, int flags)
+{
+ struct app *app = obj;
+ struct ao2_container *apps = arg;
+
+ ast_str_container_add(apps, app_name(app));
+ return 0;
+}
+
+struct ao2_container *stasis_apps_get_all(void)
+{
+ RAII_VAR(struct ao2_container *, apps, NULL, ao2_cleanup);
+
+ apps = ast_str_container_alloc(1);
+ if (!apps) {
+ return NULL;
+ }
+
+ ao2_callback(apps_registry, OBJ_NODATA, append_name, apps);
+
+ return ao2_bump(apps);
+}
+
int stasis_app_register(const char *app_name, stasis_app_cb handler, void *data)
{
RAII_VAR(struct app *, app, NULL, ao2_cleanup);
@@ -781,6 +804,21 @@
* and clean up, just in case
*/
cleanup();
+}
+
+struct ast_json *stasis_app_to_json(const char *app_name)
+{
+ RAII_VAR(struct app *, app, NULL, ao2_cleanup);
+
+ if (app_name) {
+ app = ao2_find(apps_registry, app_name, OBJ_KEY);
+ }
+
+ if (!app) {
+ return NULL;
+ }
+
+ return app_to_json(app);
}
#define CHANNEL_SCHEME "channel:"
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=398816&r1=398815&r2=398816
==============================================================================
--- team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c (original)
+++ team/dlee/ASTERISK-22451-ari-subscribe/res/stasis/app.c Wed Sep 11 11:45:35 2013
@@ -657,7 +657,9 @@
struct ao2_iterator i;
void *obj;
- json = ast_json_pack("{s: []}", "event_sources");
+ json = ast_json_pack("{s: s, s: []}",
+ "name", app->name,
+ "event_sources");
array = ast_json_object_get(json, "event_sources");
i = ao2_iterator_init(app->forwards, 0);
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=398816&r1=398815&r2=398816
==============================================================================
--- 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 11:45:35 2013
@@ -15,7 +15,7 @@
"httpMethod": "GET",
"summary": "List all applications.",
"nickname": "getApplications",
- "responseClass": "Application"
+ "responseClass": "List[Application]"
}
]
},
@@ -141,6 +141,11 @@
"id": "Application",
"description": "Details of a Stasis application",
"properties": {
+ "name": {
+ "type": "string",
+ "description": "Name of this application",
+ "required": true
+ },
"event_sources": {
"type": "List[string]",
"description": "URI's for objects subscribed to.",
More information about the asterisk-commits
mailing list