mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-02 19:16:15 +00:00
ARI: Add the ability to intercept hold and raise an event
For some applications - such as SLA - a phone pressing hold should not behave in the fashion that the Asterisk core would like it to. Instead, the hold action has some application specific behaviour associated with it - such as disconnecting the channel that initiated the hold; only playing MoH to channels in the bridge if the channels are of a particular type, etc. One way of accomplishing this is to use a framehook to intercept the hold/unhold frames, raise an event, and eat the frame. Tasty. This patch accomplishes that using a new dialplan function, HOLD_INTERCEPT. In addition, some general cleanup of raising hold/unhold Stasis messages was done, including removing some RAII_VAR usage. Review: https://reviewboard.asterisk.org/r/4549/ ASTERISK-24922 #close ........ Merged revisions 434216 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@434217 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -3197,6 +3197,85 @@ ari_validator ast_ari_validate_channel_hangup_request_fn(void)
|
||||
return ast_ari_validate_channel_hangup_request;
|
||||
}
|
||||
|
||||
int ast_ari_validate_channel_hold(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 ChannelHold 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 ChannelHold 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 ChannelHold 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 ChannelHold field channel failed validation\n");
|
||||
res = 0;
|
||||
}
|
||||
} else
|
||||
{
|
||||
ast_log(LOG_ERROR,
|
||||
"ARI ChannelHold has undocumented field %s\n",
|
||||
ast_json_object_iter_key(iter));
|
||||
res = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!has_type) {
|
||||
ast_log(LOG_ERROR, "ARI ChannelHold missing required field type\n");
|
||||
res = 0;
|
||||
}
|
||||
|
||||
if (!has_application) {
|
||||
ast_log(LOG_ERROR, "ARI ChannelHold missing required field application\n");
|
||||
res = 0;
|
||||
}
|
||||
|
||||
if (!has_channel) {
|
||||
ast_log(LOG_ERROR, "ARI ChannelHold missing required field channel\n");
|
||||
res = 0;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
ari_validator ast_ari_validate_channel_hold_fn(void)
|
||||
{
|
||||
return ast_ari_validate_channel_hold;
|
||||
}
|
||||
|
||||
int ast_ari_validate_channel_left_bridge(struct ast_json *json)
|
||||
{
|
||||
int res = 1;
|
||||
@@ -3545,6 +3624,85 @@ ari_validator ast_ari_validate_channel_talking_started_fn(void)
|
||||
return ast_ari_validate_channel_talking_started;
|
||||
}
|
||||
|
||||
int ast_ari_validate_channel_unhold(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 ChannelUnhold 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 ChannelUnhold 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 ChannelUnhold 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 ChannelUnhold field channel failed validation\n");
|
||||
res = 0;
|
||||
}
|
||||
} else
|
||||
{
|
||||
ast_log(LOG_ERROR,
|
||||
"ARI ChannelUnhold has undocumented field %s\n",
|
||||
ast_json_object_iter_key(iter));
|
||||
res = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!has_type) {
|
||||
ast_log(LOG_ERROR, "ARI ChannelUnhold missing required field type\n");
|
||||
res = 0;
|
||||
}
|
||||
|
||||
if (!has_application) {
|
||||
ast_log(LOG_ERROR, "ARI ChannelUnhold missing required field application\n");
|
||||
res = 0;
|
||||
}
|
||||
|
||||
if (!has_channel) {
|
||||
ast_log(LOG_ERROR, "ARI ChannelUnhold missing required field channel\n");
|
||||
res = 0;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
ari_validator ast_ari_validate_channel_unhold_fn(void)
|
||||
{
|
||||
return ast_ari_validate_channel_unhold;
|
||||
}
|
||||
|
||||
int ast_ari_validate_channel_userevent(struct ast_json *json)
|
||||
{
|
||||
int res = 1;
|
||||
@@ -4119,6 +4277,9 @@ int ast_ari_validate_event(struct ast_json *json)
|
||||
if (strcmp("ChannelHangupRequest", discriminator) == 0) {
|
||||
return ast_ari_validate_channel_hangup_request(json);
|
||||
} else
|
||||
if (strcmp("ChannelHold", discriminator) == 0) {
|
||||
return ast_ari_validate_channel_hold(json);
|
||||
} else
|
||||
if (strcmp("ChannelLeftBridge", discriminator) == 0) {
|
||||
return ast_ari_validate_channel_left_bridge(json);
|
||||
} else
|
||||
@@ -4131,6 +4292,9 @@ int ast_ari_validate_event(struct ast_json *json)
|
||||
if (strcmp("ChannelTalkingStarted", discriminator) == 0) {
|
||||
return ast_ari_validate_channel_talking_started(json);
|
||||
} else
|
||||
if (strcmp("ChannelUnhold", discriminator) == 0) {
|
||||
return ast_ari_validate_channel_unhold(json);
|
||||
} else
|
||||
if (strcmp("ChannelUserevent", discriminator) == 0) {
|
||||
return ast_ari_validate_channel_userevent(json);
|
||||
} else
|
||||
@@ -4290,6 +4454,9 @@ int ast_ari_validate_message(struct ast_json *json)
|
||||
if (strcmp("ChannelHangupRequest", discriminator) == 0) {
|
||||
return ast_ari_validate_channel_hangup_request(json);
|
||||
} else
|
||||
if (strcmp("ChannelHold", discriminator) == 0) {
|
||||
return ast_ari_validate_channel_hold(json);
|
||||
} else
|
||||
if (strcmp("ChannelLeftBridge", discriminator) == 0) {
|
||||
return ast_ari_validate_channel_left_bridge(json);
|
||||
} else
|
||||
@@ -4302,6 +4469,9 @@ int ast_ari_validate_message(struct ast_json *json)
|
||||
if (strcmp("ChannelTalkingStarted", discriminator) == 0) {
|
||||
return ast_ari_validate_channel_talking_started(json);
|
||||
} else
|
||||
if (strcmp("ChannelUnhold", discriminator) == 0) {
|
||||
return ast_ari_validate_channel_unhold(json);
|
||||
} else
|
||||
if (strcmp("ChannelUserevent", discriminator) == 0) {
|
||||
return ast_ari_validate_channel_userevent(json);
|
||||
} else
|
||||
|
Reference in New Issue
Block a user