]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
ExternalMedia: Change return object from ExternalMedia to Channel
authorGeorge Joseph <gjoseph@digium.com>
Fri, 18 Oct 2019 11:36:12 +0000 (05:36 -0600)
committerGeorge Joseph <gjoseph@digium.com>
Fri, 18 Oct 2019 13:03:07 +0000 (07:03 -0600)
When we created the External Media addition to ARI we created an
ExternalMedia object to be returned from the channels/externalMedia
REST endpoint.  This object contained the channel object that was
created plus local_address and local_port attributes (which are
also in the Channel variables).  At the time, we thought that
creating an ExternalMedia object would give us more flexibility
in the future but as we created the sample speech to text
application, we discovered that it doesn't work so well with ARI
client libraries that a) don't have the ExternalMedia object
defined and/or b) can't promote the embedded channel structure
to a first-class Channel object.

This change causes the channels/externalMedia REST endpoint to
return a Channel object (like channels/create and channels/originate)
instead of the ExternalMedia object.

Change-Id: If280094debd35102cf21e0a31a5e0846fec14af9

res/ari/ari_model_validators.c
res/ari/ari_model_validators.h
res/ari/resource_channels.c
res/res_ari_channels.c
rest-api/api-docs/channels.json

index 3d63f5317fd2cddd400b0242e866dfc7bb121c52..8910bbb94a713bff9a7d3fd89a15dc9d2906c16a 100644 (file)
@@ -1385,62 +1385,6 @@ ari_validator ast_ari_validate_dialplan_cep_fn(void)
        return ast_ari_validate_dialplan_cep;
 }
 
-int ast_ari_validate_external_media(struct ast_json *json)
-{
-       int res = 1;
-       struct ast_json_iter *iter;
-       int has_channel = 0;
-
-       for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
-               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 ExternalMedia field channel failed validation\n");
-                               res = 0;
-                       }
-               } else
-               if (strcmp("local_address", ast_json_object_iter_key(iter)) == 0) {
-                       int prop_is_valid;
-                       prop_is_valid = ast_ari_validate_string(
-                               ast_json_object_iter_value(iter));
-                       if (!prop_is_valid) {
-                               ast_log(LOG_ERROR, "ARI ExternalMedia field local_address failed validation\n");
-                               res = 0;
-                       }
-               } else
-               if (strcmp("local_port", ast_json_object_iter_key(iter)) == 0) {
-                       int prop_is_valid;
-                       prop_is_valid = ast_ari_validate_int(
-                               ast_json_object_iter_value(iter));
-                       if (!prop_is_valid) {
-                               ast_log(LOG_ERROR, "ARI ExternalMedia field local_port failed validation\n");
-                               res = 0;
-                       }
-               } else
-               {
-                       ast_log(LOG_ERROR,
-                               "ARI ExternalMedia has undocumented field %s\n",
-                               ast_json_object_iter_key(iter));
-                       res = 0;
-               }
-       }
-
-       if (!has_channel) {
-               ast_log(LOG_ERROR, "ARI ExternalMedia missing required field channel\n");
-               res = 0;
-       }
-
-       return res;
-}
-
-ari_validator ast_ari_validate_external_media_fn(void)
-{
-       return ast_ari_validate_external_media;
-}
-
 int ast_ari_validate_rtpstat(struct ast_json *json)
 {
        int res = 1;
index 53a85739cbda1db176e04d8ec28d6f9d05636408..f9285b43ce40a07cce3792fee984a035375c8fec 100644 (file)
@@ -477,24 +477,6 @@ int ast_ari_validate_dialplan_cep(struct ast_json *json);
  */
 ari_validator ast_ari_validate_dialplan_cep_fn(void);
 
-/*!
- * \brief Validator for ExternalMedia.
- *
- * ExternalMedia session.
- *
- * \param json JSON object to validate.
- * \returns True (non-zero) if valid.
- * \returns False (zero) if invalid.
- */
-int ast_ari_validate_external_media(struct ast_json *json);
-
-/*!
- * \brief Function pointer to ast_ari_validate_external_media().
- *
- * See \ref ast_ari_model_validators.h for more details.
- */
-ari_validator ast_ari_validate_external_media_fn(void);
-
 /*!
  * \brief Validator for RTPstat.
  *
@@ -1540,10 +1522,6 @@ ari_validator ast_ari_validate_application_fn(void);
  * - context: string (required)
  * - exten: string (required)
  * - priority: long (required)
- * ExternalMedia
- * - channel: Channel (required)
- * - local_address: string
- * - local_port: int
  * RTPstat
  * - channel_uniqueid: string (required)
  * - local_maxjitter: double
index ec0960dc897d45cb6c88688d1cbca30e641c0764..944c94c6c7f2301c2b34fa8dd3aa02ffe768f5cd 100644 (file)
@@ -2060,7 +2060,6 @@ static void external_media_rtp_udp(struct ast_ari_channels_external_media_args *
        size_t endpoint_len;
        char *endpoint;
        struct ast_channel *chan;
-       struct ast_json *json_chan;
        struct varshead *vars;
 
        endpoint_len = strlen("UnicastRTP/") + strlen(args->external_host) + 1;
@@ -2089,43 +2088,10 @@ static void external_media_rtp_udp(struct ast_ari_channels_external_media_args *
                return;
        }
 
-       /*
-        * At this point, response->message contains a channel object so we
-        * need to save it then create a new ExternalMedia object and put the
-        * channel in it.
-        */
-       json_chan = response->message;
-       response->message = ast_json_object_create();
-       if (!response->message) {
-               ast_channel_unref(chan);
-               ast_json_unref(json_chan);
-               ast_ari_response_alloc_failed(response);
-               return;
-       }
-
-       ast_json_object_set(response->message, "channel", json_chan);
-       /*
-        * At the time the channel snapshot was taken the channel variables might
-        * not have been set so we try to grab them directly from the channel.
-        */
        ast_channel_lock(chan);
        vars = ast_channel_varshead(chan);
        if (vars && !AST_LIST_EMPTY(vars)) {
-               struct ast_var_t *variables;
-
-               /* Put them all on the channel object */
-               ast_json_object_set(json_chan, "channelvars", ast_json_channel_vars(vars));
-               /* Grab out the local address and port */
-               AST_LIST_TRAVERSE(vars, variables, entries) {
-                       if (!strcmp("UNICASTRTP_LOCAL_ADDRESS", ast_var_name(variables))) {
-                               ast_json_object_set(response->message, "local_address",
-                                       ast_json_string_create(ast_var_value(variables)));
-                       }
-                       else if (!strcmp("UNICASTRTP_LOCAL_PORT", ast_var_name(variables))) {
-                               ast_json_object_set(response->message, "local_port",
-                                       ast_json_integer_create(strtol(ast_var_value(variables), NULL, 10)));
-                       }
-               }
+               ast_json_object_set(response->message, "channelvars", ast_json_channel_vars(vars));
        }
        ast_channel_unlock(chan);
        ast_channel_unref(chan);
index fe3a96ce48bc9186e58cbfba58d8462668cca448..bb153c9df3dd4ee5ce639e7588a1e7960115b158 100644 (file)
@@ -2911,7 +2911,7 @@ static void ast_ari_channels_external_media_cb(
                break;
        default:
                if (200 <= code && code <= 299) {
-                       is_valid = ast_ari_validate_external_media(
+                       is_valid = ast_ari_validate_channel(
                                response->message);
                } else {
                        ast_log(LOG_ERROR, "Invalid error response %d for /channels/externalMedia\n", code);
index 6d964d2302a7e7e23012f09b22233967abe20967..366fec8eef240fb9c36e49f785af36dbb33ad539 100644 (file)
                                        "summary": "Start an External Media session.",
                                        "notes": "Create a channel to an External Media source/sink.",
                                        "nickname": "externalMedia",
-                                       "responseClass": "ExternalMedia",
+                                       "responseClass": "Channel",
                                        "parameters": [
                                                {
                                                        "name": "channelId",
                                        "description": "Channel variables"
                                }
                        }
-               },
-               "ExternalMedia": {
-                       "id": "ExternalMedia",
-                       "description": "ExternalMedia session.",
-                       "properties": {
-                               "channel": {
-                                       "required": true,
-                                       "type": "Channel",
-                                       "description": "The Asterisk channel representing the external media"
-                               },
-                               "local_address": {
-                                       "required": false,
-                                       "type": "string",
-                                       "description": "The local ip address used" 
-                               },
-                               "local_port": {
-                                       "required": false,
-                                       "type": "int",
-                                       "description": "The local ip port used" 
-                               }
-                       }
                }
        }
 }