diff options
author | Scott Griepentrog <sgriepentrog@digium.com> | 2014-03-07 15:47:55 +0000 |
---|---|---|
committer | Scott Griepentrog <sgriepentrog@digium.com> | 2014-03-07 15:47:55 +0000 |
commit | 80ef9a21b9d91ff0bafc304923bc29effa230b00 (patch) | |
tree | a67db39a4c17a4b01a87201ef37ffdc43189c119 /res/res_ari_bridges.c | |
parent | d3ac8b8a0e70049af7b5552c4dfd8adc2cc5df11 (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_bridges.c')
-rw-r--r-- | res/res_ari_bridges.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/res/res_ari_bridges.c b/res/res_ari_bridges.c index e1c9fe672..890a2ace5 100644 --- a/res/res_ari_bridges.c +++ b/res/res_ari_bridges.c @@ -112,6 +112,10 @@ int ast_ari_bridges_create_parse_body( if (field) { args->type = ast_json_string_get(field); } + field = ast_json_object_get(body, "bridgeId"); + if (field) { + args->bridge_id = ast_json_string_get(field); + } field = ast_json_object_get(body, "name"); if (field) { args->name = ast_json_string_get(field); @@ -143,6 +147,9 @@ static void ast_ari_bridges_create_cb( if (strcmp(i->name, "type") == 0) { args.type = (i->value); } else + if (strcmp(i->name, "bridgeId") == 0) { + args.bridge_id = (i->value); + } else if (strcmp(i->name, "name") == 0) { args.name = (i->value); } else @@ -199,6 +206,109 @@ static void ast_ari_bridges_create_cb( fin: __attribute__((unused)) return; } +int ast_ari_bridges_create_or_update_with_id_parse_body( + struct ast_json *body, + struct ast_ari_bridges_create_or_update_with_id_args *args) +{ + struct ast_json *field; + /* Parse query parameters out of it */ + field = ast_json_object_get(body, "type"); + if (field) { + args->type = ast_json_string_get(field); + } + field = ast_json_object_get(body, "name"); + if (field) { + args->name = ast_json_string_get(field); + } + return 0; +} + +/*! + * \brief Parameter parsing callback for /bridges/{bridgeId}. + * \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_bridges_create_or_update_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_bridges_create_or_update_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, "type") == 0) { + args.type = (i->value); + } else + if (strcmp(i->name, "name") == 0) { + args.name = (i->value); + } else + {} + } + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "bridgeId") == 0) { + args.bridge_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_bridges_create_or_update_with_id_parse_body(body, &args)) { + ast_ari_response_alloc_failed(response); + goto fin; + } + ast_ari_bridges_create_or_update_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 */ + is_valid = 1; + break; + default: + if (200 <= code && code <= 299) { + is_valid = ast_ari_validate_bridge( + response->message); + } else { + ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}\n", code); + is_valid = 0; + } + } + + if (!is_valid) { + ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}\n"); + ast_ari_response_error(response, 500, + "Internal Server Error", "Response validation failed"); + } +#endif /* AST_DEVMODE */ + +fin: __attribute__((unused)) + return; +} /*! * \brief Parameter parsing callback for /bridges/{bridgeId}. * \param get_params GET parameters in the HTTP request. @@ -1129,6 +1239,7 @@ static struct stasis_rest_handlers bridges_bridgeId = { .path_segment = "bridgeId", .is_wildcard = 1, .callbacks = { + [AST_HTTP_POST] = ast_ari_bridges_create_or_update_with_id_cb, [AST_HTTP_GET] = ast_ari_bridges_get_cb, [AST_HTTP_DELETE] = ast_ari_bridges_destroy_cb, }, |