diff options
author | Matthew Jordan <mjordan@digium.com> | 2013-10-04 16:01:48 +0000 |
---|---|---|
committer | Matthew Jordan <mjordan@digium.com> | 2013-10-04 16:01:48 +0000 |
commit | 8d7873b836999b09caad87abec27579f1f065b84 (patch) | |
tree | cdf683ab18142553b42102de6c5ca52fc71b22a2 /res/ari/ari_model_validators.c | |
parent | b52c972b172087d27178c0e60127d486d4e500f8 (diff) |
ARI: Add subscription support
This patch adds an /applications API to ARI, allowing explicit management of
Stasis applications.
* GET /applications - list current applications
* GET /applications/{applicationName} - get details of a specific application
* POST /applications/{applicationName}/subscription - explicitly subscribe to
a channel, bridge or endpoint
* DELETE /applications/{applicationName}/subscription - explicitly unsubscribe
from a channel, bridge or endpoint
Subscriptions work by a reference counting mechanism: if you subscript to an
event source X number of times, you must unsubscribe X number of times to stop
receiveing events for that event source.
Review: https://reviewboard.asterisk.org/r/2862
(issue ASTERISK-22451)
Reported by: Matt Jordan
........
Merged revisions 400522 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@400523 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/ari/ari_model_validators.c')
-rw-r--r-- | res/ari/ari_model_validators.c | 190 |
1 files changed, 190 insertions, 0 deletions
diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c index 0905642c8..aec2bb471 100644 --- a/res/ari/ari_model_validators.c +++ b/res/ari/ari_model_validators.c @@ -2530,6 +2530,7 @@ int ast_ari_validate_channel_userevent(struct ast_json *json) int has_application = 0; int has_channel = 0; int has_eventname = 0; + int has_userevent = 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) { @@ -2581,6 +2582,16 @@ int ast_ari_validate_channel_userevent(struct ast_json *json) res = 0; } } else + if (strcmp("userevent", ast_json_object_iter_key(iter)) == 0) { + int prop_is_valid; + has_userevent = 1; + prop_is_valid = ast_ari_validate_object( + ast_json_object_iter_value(iter)); + if (!prop_is_valid) { + ast_log(LOG_ERROR, "ARI ChannelUserevent field userevent failed validation\n"); + res = 0; + } + } else { ast_log(LOG_ERROR, "ARI ChannelUserevent has undocumented field %s\n", @@ -2609,6 +2620,11 @@ int ast_ari_validate_channel_userevent(struct ast_json *json) res = 0; } + if (!has_userevent) { + ast_log(LOG_ERROR, "ARI ChannelUserevent missing required field userevent\n"); + res = 0; + } + return res; } @@ -2721,6 +2737,85 @@ ari_validator ast_ari_validate_channel_varset_fn(void) 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; @@ -2783,6 +2878,9 @@ int ast_ari_validate_event(struct ast_json *json) 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 @@ -2918,6 +3016,9 @@ int ast_ari_validate_message(struct ast_json *json) 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 @@ -3361,3 +3462,92 @@ ari_validator ast_ari_validate_stasis_start_fn(void) { return ast_ari_validate_stasis_start; } + +int ast_ari_validate_application(struct ast_json *json) +{ + int res = 1; + struct ast_json_iter *iter; + int has_bridge_ids = 0; + int has_channel_ids = 0; + int has_endpoint_ids = 0; + int has_name = 0; + + for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) { + if (strcmp("bridge_ids", ast_json_object_iter_key(iter)) == 0) { + int prop_is_valid; + has_bridge_ids = 1; + prop_is_valid = ast_ari_validate_list( + ast_json_object_iter_value(iter), + ast_ari_validate_string); + if (!prop_is_valid) { + ast_log(LOG_ERROR, "ARI Application field bridge_ids failed validation\n"); + res = 0; + } + } else + if (strcmp("channel_ids", ast_json_object_iter_key(iter)) == 0) { + int prop_is_valid; + has_channel_ids = 1; + prop_is_valid = ast_ari_validate_list( + ast_json_object_iter_value(iter), + ast_ari_validate_string); + if (!prop_is_valid) { + ast_log(LOG_ERROR, "ARI Application field channel_ids failed validation\n"); + res = 0; + } + } else + if (strcmp("endpoint_ids", ast_json_object_iter_key(iter)) == 0) { + int prop_is_valid; + has_endpoint_ids = 1; + prop_is_valid = ast_ari_validate_list( + ast_json_object_iter_value(iter), + ast_ari_validate_string); + if (!prop_is_valid) { + ast_log(LOG_ERROR, "ARI Application field endpoint_ids failed validation\n"); + 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", + ast_json_object_iter_key(iter)); + res = 0; + } + } + + if (!has_bridge_ids) { + ast_log(LOG_ERROR, "ARI Application missing required field bridge_ids\n"); + res = 0; + } + + if (!has_channel_ids) { + ast_log(LOG_ERROR, "ARI Application missing required field channel_ids\n"); + res = 0; + } + + if (!has_endpoint_ids) { + ast_log(LOG_ERROR, "ARI Application missing required field endpoint_ids\n"); + res = 0; + } + + if (!has_name) { + ast_log(LOG_ERROR, "ARI Application missing required field name\n"); + res = 0; + } + + return res; +} + +ari_validator ast_ari_validate_application_fn(void) +{ + return ast_ari_validate_application; +} |