summaryrefslogtreecommitdiff
path: root/res/ari
diff options
context:
space:
mode:
authorScott Griepentrog <sgriepentrog@digium.com>2014-05-22 16:09:51 +0000
committerScott Griepentrog <sgriepentrog@digium.com>2014-05-22 16:09:51 +0000
commitcf21644d6a4b757999be136ab1b90ba5cf6ac3bc (patch)
treea35b24bdfcf860a4085383bab882ed33bf3d3e1d /res/ari
parentd00882108fabd3798aa6566aa5697d82459e753e (diff)
ARI: Add ability to raise arbitrary User Events
User events can now be generated from ARI. Events can be signalled with arbitrary json variables, and include one or more of channel, bridge, or endpoint snapshots. An application must be specified which will receive the event message (other applications can subscribe to it). The message will also be delivered via AMI provided a channel is attached. Dialplan generated user event messages are still transmitted via the channel, and will only be received by a stasis application they are attached to or if the channel is subscribed to. This change also introduces the multi object blob mechanism used to send multiple snapshot types in a single message. The dialplan app UserEvent was also changed to use multi object blob, and a new stasis message type created to handle them. ASTERISK-22697 #close Review: https://reviewboard.asterisk.org/r/3494/ ........ Merged revisions 414405 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@414406 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/ari')
-rw-r--r--res/ari/ari_model_validators.c25
-rw-r--r--res/ari/ari_model_validators.h4
-rw-r--r--res/ari/resource_events.c56
-rw-r--r--res/ari/resource_events.h34
4 files changed, 111 insertions, 8 deletions
diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c
index 5c24b9c41..fa38155bd 100644
--- a/res/ari/ari_model_validators.c
+++ b/res/ari/ari_model_validators.c
@@ -3076,7 +3076,6 @@ int ast_ari_validate_channel_userevent(struct ast_json *json)
struct ast_json_iter *iter;
int has_type = 0;
int has_application = 0;
- int has_channel = 0;
int has_eventname = 0;
int has_userevent = 0;
@@ -3110,9 +3109,17 @@ int ast_ari_validate_channel_userevent(struct ast_json *json)
res = 0;
}
} else
+ if (strcmp("bridge", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_bridge(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI ChannelUserevent field bridge failed validation\n");
+ res = 0;
+ }
+ } else
if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
int prop_is_valid;
- has_channel = 1;
prop_is_valid = ast_ari_validate_channel(
ast_json_object_iter_value(iter));
if (!prop_is_valid) {
@@ -3120,6 +3127,15 @@ int ast_ari_validate_channel_userevent(struct ast_json *json)
res = 0;
}
} else
+ if (strcmp("endpoint", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ prop_is_valid = ast_ari_validate_endpoint(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI ChannelUserevent field endpoint failed validation\n");
+ res = 0;
+ }
+ } else
if (strcmp("eventname", ast_json_object_iter_key(iter)) == 0) {
int prop_is_valid;
has_eventname = 1;
@@ -3158,11 +3174,6 @@ int ast_ari_validate_channel_userevent(struct ast_json *json)
res = 0;
}
- if (!has_channel) {
- ast_log(LOG_ERROR, "ARI ChannelUserevent missing required field channel\n");
- res = 0;
- }
-
if (!has_eventname) {
ast_log(LOG_ERROR, "ARI ChannelUserevent missing required field eventname\n");
res = 0;
diff --git a/res/ari/ari_model_validators.h b/res/ari/ari_model_validators.h
index 7214a5875..a4512a1c7 100644
--- a/res/ari/ari_model_validators.h
+++ b/res/ari/ari_model_validators.h
@@ -1278,7 +1278,9 @@ ari_validator ast_ari_validate_application_fn(void);
* - type: string (required)
* - application: string (required)
* - timestamp: Date
- * - channel: Channel (required)
+ * - bridge: Bridge
+ * - channel: Channel
+ * - endpoint: Endpoint
* - eventname: string (required)
* - userevent: object (required)
* ChannelVarset
diff --git a/res/ari/resource_events.c b/res/ari/resource_events.c
index 098049fc6..d159741c2 100644
--- a/res/ari/resource_events.c
+++ b/res/ari/resource_events.c
@@ -217,3 +217,59 @@ void ast_ari_websocket_events_event_websocket(struct ast_ari_websocket_session *
ast_json_unref(msg);
}
}
+
+void ast_ari_events_user_event(struct ast_variable *headers,
+ struct ast_ari_events_user_event_args *args,
+ struct ast_ari_response *response)
+{
+ enum stasis_app_user_event_res res;
+ struct ast_json *json_variables = NULL;
+
+ if (args->variables) {
+ ast_ari_events_user_event_parse_body(args->variables, args);
+ json_variables = ast_json_object_get(args->variables, "variables");
+ }
+
+ if (ast_strlen_zero(args->application)) {
+ ast_ari_response_error(response, 400, "Bad Request",
+ "Missing parameter application");
+ return;
+ }
+
+ res = stasis_app_user_event(args->application,
+ args->event_name,
+ args->source, args->source_count,
+ json_variables);
+
+ switch (res) {
+ case STASIS_APP_USER_OK:
+ ast_ari_response_no_content(response);
+ break;
+
+ case STASIS_APP_USER_APP_NOT_FOUND:
+ ast_ari_response_error(response, 404, "Not Found",
+ "Application not found");
+ break;
+
+ case STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND:
+ ast_ari_response_error(response, 422, "Unprocessable Entity",
+ "Event source was not found");
+ break;
+
+ case STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME:
+ ast_ari_response_error(response, 400, "Bad Request",
+ "Invalid event source URI scheme");
+ break;
+
+ case STASIS_APP_USER_USEREVENT_INVALID:
+ ast_ari_response_error(response, 400, "Bad Request",
+ "Invalid userevnet data");
+ break;
+
+ case STASIS_APP_USER_INTERNAL_ERROR:
+ default:
+ ast_ari_response_error(response, 500, "Internal Server Error",
+ "Error processing request");
+ }
+}
+
diff --git a/res/ari/resource_events.h b/res/ari/resource_events.h
index 96ee5b3ac..08077098b 100644
--- a/res/ari/resource_events.h
+++ b/res/ari/resource_events.h
@@ -56,5 +56,39 @@ struct ast_ari_events_event_websocket_args {
* \param args Swagger parameters.
*/
void ast_ari_websocket_events_event_websocket(struct ast_ari_websocket_session *session, struct ast_variable *headers, struct ast_ari_events_event_websocket_args *args);
+/*! Argument struct for ast_ari_events_user_event() */
+struct ast_ari_events_user_event_args {
+ /*! Event name */
+ const char *event_name;
+ /*! The name of the application that will receive this event */
+ const char *application;
+ /*! Array of URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}/{resource}, deviceState:{deviceName} */
+ const char **source;
+ /*! Length of source array. */
+ size_t source_count;
+ /*! Parsing context for source. */
+ char *source_parse;
+ /*! custom key/value pairs added to the user event */
+ struct ast_json *variables;
+};
+/*!
+ * \brief Body parsing function for /events/user/{eventName}.
+ * \param body The JSON body from which to parse parameters.
+ * \param[out] args The args structure to parse into.
+ * \retval zero on success
+ * \retval non-zero on failure
+ */
+int ast_ari_events_user_event_parse_body(
+ struct ast_json *body,
+ struct ast_ari_events_user_event_args *args);
+
+/*!
+ * \brief Generate a user event.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void ast_ari_events_user_event(struct ast_variable *headers, struct ast_ari_events_user_event_args *args, struct ast_ari_response *response);
#endif /* _ASTERISK_RESOURCE_EVENTS_H */