summaryrefslogtreecommitdiff
path: root/res/ari/ari_model_validators.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2014-05-30 12:42:57 +0000
committerMatthew Jordan <mjordan@digium.com>2014-05-30 12:42:57 +0000
commit53968c00b34a913e0467200b95add483f79dd3b6 (patch)
tree3e04113a3c4eda1884205df78e9527b2c72cee6a /res/ari/ari_model_validators.c
parente9f09ab2bce1e1aa1b619507b45d228bbc49f12c (diff)
TALK_DETECT: A channel function that raises events when talking is detected
This patch adds a new channel function TALK_DETECT that, when set on a channel, causes events indicating the start/stop of talking on a channel to be emitted to both AMI and ARI clients. The function allows setting both the silence threshold (the length of silence after which we decide no one is talking) as well as the talking threshold (the amount of energy that counts as talking). Parameters can be updated on a channel after talk detection has been enabled, and talk detection can be removed at any time. The events raised by the function use a nomenclature similar to existing AMI/ARI events. For AMI: ChannelTalkingStart/ChannelTalkingStop For ARI: ChannelTalkingStarted/ChannelTalkingFinished Review: https://reviewboard.asterisk.org/r/3563/ #ASTERISK-23786 #close Reported by: Matt Jordan ........ Merged revisions 414934 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@414935 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/ari/ari_model_validators.c')
-rw-r--r--res/ari/ari_model_validators.c186
1 files changed, 186 insertions, 0 deletions
diff --git a/res/ari/ari_model_validators.c b/res/ari/ari_model_validators.c
index fa38155bd..d15ec494d 100644
--- a/res/ari/ari_model_validators.c
+++ b/res/ari/ari_model_validators.c
@@ -3070,6 +3070,180 @@ ari_validator ast_ari_validate_channel_state_change_fn(void)
return ast_ari_validate_channel_state_change;
}
+int ast_ari_validate_channel_talking_finished(struct ast_json *json)
+{
+ int res = 1;
+ struct ast_json_iter *iter;
+ int has_type = 0;
+ int has_application = 0;
+ int has_channel = 0;
+ int has_duration = 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 ChannelTalkingFinished 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 ChannelTalkingFinished 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 ChannelTalkingFinished field timestamp 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) {
+ ast_log(LOG_ERROR, "ARI ChannelTalkingFinished field channel failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("duration", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_duration = 1;
+ prop_is_valid = ast_ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI ChannelTalkingFinished field duration failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI ChannelTalkingFinished has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_type) {
+ ast_log(LOG_ERROR, "ARI ChannelTalkingFinished missing required field type\n");
+ res = 0;
+ }
+
+ if (!has_application) {
+ ast_log(LOG_ERROR, "ARI ChannelTalkingFinished missing required field application\n");
+ res = 0;
+ }
+
+ if (!has_channel) {
+ ast_log(LOG_ERROR, "ARI ChannelTalkingFinished missing required field channel\n");
+ res = 0;
+ }
+
+ if (!has_duration) {
+ ast_log(LOG_ERROR, "ARI ChannelTalkingFinished missing required field duration\n");
+ res = 0;
+ }
+
+ return res;
+}
+
+ari_validator ast_ari_validate_channel_talking_finished_fn(void)
+{
+ return ast_ari_validate_channel_talking_finished;
+}
+
+int ast_ari_validate_channel_talking_started(struct ast_json *json)
+{
+ int res = 1;
+ struct ast_json_iter *iter;
+ int has_type = 0;
+ int has_application = 0;
+ int has_channel = 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 ChannelTalkingStarted 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 ChannelTalkingStarted 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 ChannelTalkingStarted field timestamp 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) {
+ ast_log(LOG_ERROR, "ARI ChannelTalkingStarted field channel failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI ChannelTalkingStarted has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_type) {
+ ast_log(LOG_ERROR, "ARI ChannelTalkingStarted missing required field type\n");
+ res = 0;
+ }
+
+ if (!has_application) {
+ ast_log(LOG_ERROR, "ARI ChannelTalkingStarted missing required field application\n");
+ res = 0;
+ }
+
+ if (!has_channel) {
+ ast_log(LOG_ERROR, "ARI ChannelTalkingStarted missing required field channel\n");
+ res = 0;
+ }
+
+ return res;
+}
+
+ari_validator ast_ari_validate_channel_talking_started_fn(void)
+{
+ return ast_ari_validate_channel_talking_started;
+}
+
int ast_ari_validate_channel_userevent(struct ast_json *json)
{
int res = 1;
@@ -3647,6 +3821,12 @@ int ast_ari_validate_event(struct ast_json *json)
if (strcmp("ChannelStateChange", discriminator) == 0) {
return ast_ari_validate_channel_state_change(json);
} else
+ if (strcmp("ChannelTalkingFinished", discriminator) == 0) {
+ return ast_ari_validate_channel_talking_finished(json);
+ } else
+ if (strcmp("ChannelTalkingStarted", discriminator) == 0) {
+ return ast_ari_validate_channel_talking_started(json);
+ } else
if (strcmp("ChannelUserevent", discriminator) == 0) {
return ast_ari_validate_channel_userevent(json);
} else
@@ -3806,6 +3986,12 @@ int ast_ari_validate_message(struct ast_json *json)
if (strcmp("ChannelStateChange", discriminator) == 0) {
return ast_ari_validate_channel_state_change(json);
} else
+ if (strcmp("ChannelTalkingFinished", discriminator) == 0) {
+ return ast_ari_validate_channel_talking_finished(json);
+ } else
+ if (strcmp("ChannelTalkingStarted", discriminator) == 0) {
+ return ast_ari_validate_channel_talking_started(json);
+ } else
if (strcmp("ChannelUserevent", discriminator) == 0) {
return ast_ari_validate_channel_userevent(json);
} else