summaryrefslogtreecommitdiff
path: root/res/res_ari_channels.c
diff options
context:
space:
mode:
authorScott Griepentrog <sgriepentrog@digium.com>2014-03-07 15:47:55 +0000
committerScott Griepentrog <sgriepentrog@digium.com>2014-03-07 15:47:55 +0000
commit80ef9a21b9d91ff0bafc304923bc29effa230b00 (patch)
treea67db39a4c17a4b01a87201ef37ffdc43189c119 /res/res_ari_channels.c
parentd3ac8b8a0e70049af7b5552c4dfd8adc2cc5df11 (diff)
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and much change was necessary to accomplish it. Channel uniqueids and linkedids are split into separate string and creation time components without breaking linkedid propgation. This allowed the uniqueid to be specified by the user interface - and those values are now carried through to channel creation, adding the assignedids value to every function in the chain including the channel drivers. For local channels, the second channel can be specified or left to default to a ;2 suffix of first. In ARI, bridge, playback, and snoop objects can also be created with a specified uniqueid. Along the way, the args order to allocating channels was fixed in chan_mgcp and chan_gtalk, and linkedid is no longer lost as masquerade occurs. (closes issue ASTERISK-23120) Review: https://reviewboard.asterisk.org/r/3191/ ........ Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_ari_channels.c')
-rw-r--r--res/res_ari_channels.c451
1 files changed, 447 insertions, 4 deletions
diff --git a/res/res_ari_channels.c b/res/res_ari_channels.c
index 12ef16843..ac159bfec 100644
--- a/res/res_ari_channels.c
+++ b/res/res_ari_channels.c
@@ -140,6 +140,14 @@ int ast_ari_channels_originate_parse_body(
if (field) {
args->timeout = ast_json_integer_get(field);
}
+ field = ast_json_object_get(body, "channelId");
+ if (field) {
+ args->channel_id = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "otherChannelId");
+ if (field) {
+ args->other_channel_id = ast_json_string_get(field);
+ }
return 0;
}
@@ -188,6 +196,12 @@ static void ast_ari_channels_originate_cb(
if (strcmp(i->name, "timeout") == 0) {
args.timeout = atoi(i->value);
} else
+ if (strcmp(i->name, "channelId") == 0) {
+ args.channel_id = (i->value);
+ } else
+ if (strcmp(i->name, "otherChannelId") == 0) {
+ args.other_channel_id = (i->value);
+ } else
{}
}
/* Look for a JSON request entity */
@@ -298,6 +312,156 @@ static void ast_ari_channels_get_cb(
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_originate_with_id_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_originate_with_id_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "endpoint");
+ if (field) {
+ args->endpoint = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "extension");
+ if (field) {
+ args->extension = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "context");
+ if (field) {
+ args->context = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "priority");
+ if (field) {
+ args->priority = ast_json_integer_get(field);
+ }
+ field = ast_json_object_get(body, "app");
+ if (field) {
+ args->app = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "appArgs");
+ if (field) {
+ args->app_args = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "callerId");
+ if (field) {
+ args->caller_id = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "timeout");
+ if (field) {
+ args->timeout = ast_json_integer_get(field);
+ }
+ field = ast_json_object_get(body, "otherChannelId");
+ if (field) {
+ args->other_channel_id = ast_json_string_get(field);
+ }
+ return 0;
+}
+
+/*!
+ * \brief Parameter parsing callback for /channels/{channelId}.
+ * \param get_params GET parameters in the HTTP request.
+ * \param path_vars Path variables extracted from the request.
+ * \param headers HTTP headers.
+ * \param[out] response Response to the HTTP request.
+ */
+static void ast_ari_channels_originate_with_id_cb(
+ struct ast_tcptls_session_instance *ser,
+ struct ast_variable *get_params, struct ast_variable *path_vars,
+ struct ast_variable *headers, struct ast_ari_response *response)
+{
+ struct ast_ari_channels_originate_with_id_args args = {};
+ struct ast_variable *i;
+ RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
+#if defined(AST_DEVMODE)
+ int is_valid;
+ int code;
+#endif /* AST_DEVMODE */
+
+ for (i = get_params; i; i = i->next) {
+ if (strcmp(i->name, "endpoint") == 0) {
+ args.endpoint = (i->value);
+ } else
+ if (strcmp(i->name, "extension") == 0) {
+ args.extension = (i->value);
+ } else
+ if (strcmp(i->name, "context") == 0) {
+ args.context = (i->value);
+ } else
+ if (strcmp(i->name, "priority") == 0) {
+ args.priority = atol(i->value);
+ } else
+ if (strcmp(i->name, "app") == 0) {
+ args.app = (i->value);
+ } else
+ if (strcmp(i->name, "appArgs") == 0) {
+ args.app_args = (i->value);
+ } else
+ if (strcmp(i->name, "callerId") == 0) {
+ args.caller_id = (i->value);
+ } else
+ if (strcmp(i->name, "timeout") == 0) {
+ args.timeout = atoi(i->value);
+ } else
+ if (strcmp(i->name, "otherChannelId") == 0) {
+ args.other_channel_id = (i->value);
+ } else
+ {}
+ }
+ for (i = path_vars; i; i = i->next) {
+ if (strcmp(i->name, "channelId") == 0) {
+ args.channel_id = (i->value);
+ } else
+ {}
+ }
+ /* Look for a JSON request entity */
+ body = ast_http_get_json(ser, headers);
+ if (!body) {
+ switch (errno) {
+ case EFBIG:
+ ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
+ goto fin;
+ case ENOMEM:
+ ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
+ goto fin;
+ case EIO:
+ ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
+ goto fin;
+ }
+ }
+ args.variables = ast_json_ref(body);
+ ast_ari_channels_originate_with_id(headers, &args, response);
+#if defined(AST_DEVMODE)
+ code = response->response_code;
+
+ switch (code) {
+ case 0: /* Implementation is still a stub, or the code wasn't set */
+ is_valid = response->message == NULL;
+ break;
+ case 500: /* Internal Server Error */
+ case 501: /* Not Implemented */
+ case 400: /* Invalid parameters for originating a channel. */
+ is_valid = 1;
+ break;
+ default:
+ if (200 <= code && code <= 299) {
+ is_valid = ast_ari_validate_channel(
+ response->message);
+ } else {
+ ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
+ is_valid = 0;
+ }
+ }
+
+ if (!is_valid) {
+ ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
+ ast_ari_response_error(response, 500,
+ "Internal Server Error", "Response validation failed");
+ }
+#endif /* AST_DEVMODE */
+
+fin: __attribute__((unused))
+ return;
+}
int ast_ari_channels_hangup_parse_body(
struct ast_json *body,
struct ast_ari_channels_hangup_args *args)
@@ -1431,6 +1595,10 @@ int ast_ari_channels_play_parse_body(
if (field) {
args->skipms = ast_json_integer_get(field);
}
+ field = ast_json_object_get(body, "playbackId");
+ if (field) {
+ args->playback_id = ast_json_string_get(field);
+ }
return 0;
}
@@ -1467,6 +1635,9 @@ static void ast_ari_channels_play_cb(
if (strcmp(i->name, "skipms") == 0) {
args.skipms = atoi(i->value);
} else
+ if (strcmp(i->name, "playbackId") == 0) {
+ args.playback_id = (i->value);
+ } else
{}
}
for (i = path_vars; i; i = i->next) {
@@ -1528,6 +1699,128 @@ static void ast_ari_channels_play_cb(
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_play_with_id_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_play_with_id_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "media");
+ if (field) {
+ args->media = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "lang");
+ if (field) {
+ args->lang = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "offsetms");
+ if (field) {
+ args->offsetms = ast_json_integer_get(field);
+ }
+ field = ast_json_object_get(body, "skipms");
+ if (field) {
+ args->skipms = ast_json_integer_get(field);
+ }
+ return 0;
+}
+
+/*!
+ * \brief Parameter parsing callback for /channels/{channelId}/play/{playbackId}.
+ * \param get_params GET parameters in the HTTP request.
+ * \param path_vars Path variables extracted from the request.
+ * \param headers HTTP headers.
+ * \param[out] response Response to the HTTP request.
+ */
+static void ast_ari_channels_play_with_id_cb(
+ struct ast_tcptls_session_instance *ser,
+ struct ast_variable *get_params, struct ast_variable *path_vars,
+ struct ast_variable *headers, struct ast_ari_response *response)
+{
+ struct ast_ari_channels_play_with_id_args args = {};
+ struct ast_variable *i;
+ RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
+#if defined(AST_DEVMODE)
+ int is_valid;
+ int code;
+#endif /* AST_DEVMODE */
+
+ for (i = get_params; i; i = i->next) {
+ if (strcmp(i->name, "media") == 0) {
+ args.media = (i->value);
+ } else
+ if (strcmp(i->name, "lang") == 0) {
+ args.lang = (i->value);
+ } else
+ if (strcmp(i->name, "offsetms") == 0) {
+ args.offsetms = atoi(i->value);
+ } else
+ if (strcmp(i->name, "skipms") == 0) {
+ args.skipms = atoi(i->value);
+ } else
+ {}
+ }
+ for (i = path_vars; i; i = i->next) {
+ if (strcmp(i->name, "channelId") == 0) {
+ args.channel_id = (i->value);
+ } else
+ if (strcmp(i->name, "playbackId") == 0) {
+ args.playback_id = (i->value);
+ } else
+ {}
+ }
+ /* Look for a JSON request entity */
+ body = ast_http_get_json(ser, headers);
+ if (!body) {
+ switch (errno) {
+ case EFBIG:
+ ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
+ goto fin;
+ case ENOMEM:
+ ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
+ goto fin;
+ case EIO:
+ ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
+ goto fin;
+ }
+ }
+ if (ast_ari_channels_play_with_id_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
+ }
+ ast_ari_channels_play_with_id(headers, &args, response);
+#if defined(AST_DEVMODE)
+ code = response->response_code;
+
+ switch (code) {
+ case 0: /* Implementation is still a stub, or the code wasn't set */
+ is_valid = response->message == NULL;
+ break;
+ case 500: /* Internal Server Error */
+ case 501: /* Not Implemented */
+ case 404: /* Channel not found */
+ case 409: /* Channel not in a Stasis application */
+ is_valid = 1;
+ break;
+ default:
+ if (200 <= code && code <= 299) {
+ is_valid = ast_ari_validate_playback(
+ response->message);
+ } else {
+ ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/play/{playbackId}\n", code);
+ is_valid = 0;
+ }
+ }
+
+ if (!is_valid) {
+ ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/play/{playbackId}\n");
+ ast_ari_response_error(response, 500,
+ "Internal Server Error", "Response validation failed");
+ }
+#endif /* AST_DEVMODE */
+
+fin: __attribute__((unused))
+ return;
+}
int ast_ari_channels_record_parse_body(
struct ast_json *body,
struct ast_ari_channels_record_args *args)
@@ -1897,6 +2190,10 @@ int ast_ari_channels_snoop_channel_parse_body(
if (field) {
args->app_args = ast_json_string_get(field);
}
+ field = ast_json_object_get(body, "snoopId");
+ if (field) {
+ args->snoop_id = ast_json_string_get(field);
+ }
return 0;
}
@@ -1933,6 +2230,9 @@ static void ast_ari_channels_snoop_channel_cb(
if (strcmp(i->name, "appArgs") == 0) {
args.app_args = (i->value);
} else
+ if (strcmp(i->name, "snoopId") == 0) {
+ args.snoop_id = (i->value);
+ } else
{}
}
for (i = path_vars; i; i = i->next) {
@@ -1994,6 +2294,128 @@ static void ast_ari_channels_snoop_channel_cb(
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_snoop_channel_with_id_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_snoop_channel_with_id_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "spy");
+ if (field) {
+ args->spy = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "whisper");
+ if (field) {
+ args->whisper = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "app");
+ if (field) {
+ args->app = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "appArgs");
+ if (field) {
+ args->app_args = ast_json_string_get(field);
+ }
+ return 0;
+}
+
+/*!
+ * \brief Parameter parsing callback for /channels/{channelId}/snoop/{snoopId}.
+ * \param get_params GET parameters in the HTTP request.
+ * \param path_vars Path variables extracted from the request.
+ * \param headers HTTP headers.
+ * \param[out] response Response to the HTTP request.
+ */
+static void ast_ari_channels_snoop_channel_with_id_cb(
+ struct ast_tcptls_session_instance *ser,
+ struct ast_variable *get_params, struct ast_variable *path_vars,
+ struct ast_variable *headers, struct ast_ari_response *response)
+{
+ struct ast_ari_channels_snoop_channel_with_id_args args = {};
+ struct ast_variable *i;
+ RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
+#if defined(AST_DEVMODE)
+ int is_valid;
+ int code;
+#endif /* AST_DEVMODE */
+
+ for (i = get_params; i; i = i->next) {
+ if (strcmp(i->name, "spy") == 0) {
+ args.spy = (i->value);
+ } else
+ if (strcmp(i->name, "whisper") == 0) {
+ args.whisper = (i->value);
+ } else
+ if (strcmp(i->name, "app") == 0) {
+ args.app = (i->value);
+ } else
+ if (strcmp(i->name, "appArgs") == 0) {
+ args.app_args = (i->value);
+ } else
+ {}
+ }
+ for (i = path_vars; i; i = i->next) {
+ if (strcmp(i->name, "channelId") == 0) {
+ args.channel_id = (i->value);
+ } else
+ if (strcmp(i->name, "snoopId") == 0) {
+ args.snoop_id = (i->value);
+ } else
+ {}
+ }
+ /* Look for a JSON request entity */
+ body = ast_http_get_json(ser, headers);
+ if (!body) {
+ switch (errno) {
+ case EFBIG:
+ ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
+ goto fin;
+ case ENOMEM:
+ ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
+ goto fin;
+ case EIO:
+ ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
+ goto fin;
+ }
+ }
+ if (ast_ari_channels_snoop_channel_with_id_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
+ }
+ ast_ari_channels_snoop_channel_with_id(headers, &args, response);
+#if defined(AST_DEVMODE)
+ code = response->response_code;
+
+ switch (code) {
+ case 0: /* Implementation is still a stub, or the code wasn't set */
+ is_valid = response->message == NULL;
+ break;
+ case 500: /* Internal Server Error */
+ case 501: /* Not Implemented */
+ case 400: /* Invalid parameters */
+ case 404: /* Channel not found */
+ is_valid = 1;
+ break;
+ default:
+ if (200 <= code && code <= 299) {
+ is_valid = ast_ari_validate_channel(
+ response->message);
+ } else {
+ ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/snoop/{snoopId}\n", code);
+ is_valid = 0;
+ }
+ }
+
+ if (!is_valid) {
+ ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/snoop/{snoopId}\n");
+ ast_ari_response_error(response, 500,
+ "Internal Server Error", "Response validation failed");
+ }
+#endif /* AST_DEVMODE */
+
+fin: __attribute__((unused))
+ return;
+}
/*! \brief REST handler for /api-docs/channels.{format} */
static struct stasis_rest_handlers channels_channelId_continue = {
@@ -2073,13 +2495,23 @@ static struct stasis_rest_handlers channels_channelId_silence = {
.children = { }
};
/*! \brief REST handler for /api-docs/channels.{format} */
+static struct stasis_rest_handlers channels_channelId_play_playbackId = {
+ .path_segment = "playbackId",
+ .is_wildcard = 1,
+ .callbacks = {
+ [AST_HTTP_POST] = ast_ari_channels_play_with_id_cb,
+ },
+ .num_children = 0,
+ .children = { }
+};
+/*! \brief REST handler for /api-docs/channels.{format} */
static struct stasis_rest_handlers channels_channelId_play = {
.path_segment = "play",
.callbacks = {
[AST_HTTP_POST] = ast_ari_channels_play_cb,
},
- .num_children = 0,
- .children = { }
+ .num_children = 1,
+ .children = { &channels_channelId_play_playbackId, }
};
/*! \brief REST handler for /api-docs/channels.{format} */
static struct stasis_rest_handlers channels_channelId_record = {
@@ -2101,13 +2533,23 @@ static struct stasis_rest_handlers channels_channelId_variable = {
.children = { }
};
/*! \brief REST handler for /api-docs/channels.{format} */
+static struct stasis_rest_handlers channels_channelId_snoop_snoopId = {
+ .path_segment = "snoopId",
+ .is_wildcard = 1,
+ .callbacks = {
+ [AST_HTTP_POST] = ast_ari_channels_snoop_channel_with_id_cb,
+ },
+ .num_children = 0,
+ .children = { }
+};
+/*! \brief REST handler for /api-docs/channels.{format} */
static struct stasis_rest_handlers channels_channelId_snoop = {
.path_segment = "snoop",
.callbacks = {
[AST_HTTP_POST] = ast_ari_channels_snoop_channel_cb,
},
- .num_children = 0,
- .children = { }
+ .num_children = 1,
+ .children = { &channels_channelId_snoop_snoopId, }
};
/*! \brief REST handler for /api-docs/channels.{format} */
static struct stasis_rest_handlers channels_channelId = {
@@ -2115,6 +2557,7 @@ static struct stasis_rest_handlers channels_channelId = {
.is_wildcard = 1,
.callbacks = {
[AST_HTTP_GET] = ast_ari_channels_get_cb,
+ [AST_HTTP_POST] = ast_ari_channels_originate_with_id_cb,
[AST_HTTP_DELETE] = ast_ari_channels_hangup_cb,
},
.num_children = 12,