diff options
Diffstat (limited to 'res/ari')
-rw-r--r-- | res/ari/resource_applications.h | 22 | ||||
-rw-r--r-- | res/ari/resource_asterisk.h | 33 | ||||
-rw-r--r-- | res/ari/resource_bridges.h | 66 | ||||
-rw-r--r-- | res/ari/resource_channels.c | 49 | ||||
-rw-r--r-- | res/ari/resource_channels.h | 134 | ||||
-rw-r--r-- | res/ari/resource_device_states.h | 11 | ||||
-rw-r--r-- | res/ari/resource_mailboxes.h | 11 | ||||
-rw-r--r-- | res/ari/resource_playbacks.h | 11 | ||||
-rw-r--r-- | res/ari/resource_sounds.h | 11 |
9 files changed, 348 insertions, 0 deletions
diff --git a/res/ari/resource_applications.h b/res/ari/resource_applications.h index a4d12c9c0..3e57ad716 100644 --- a/res/ari/resource_applications.h +++ b/res/ari/resource_applications.h @@ -75,6 +75,17 @@ struct ast_ari_applications_subscribe_args { char *event_source_parse; }; /*! + * \brief Body parsing function for /applications/{applicationName}/subscription. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_applications_subscribe_parse_body( + struct ast_json *body, + struct ast_ari_applications_subscribe_args *args); + +/*! * \brief Subscribe an application to a event source. * * Returns the state of the application after the subscriptions have changed @@ -96,6 +107,17 @@ struct ast_ari_applications_unsubscribe_args { char *event_source_parse; }; /*! + * \brief Body parsing function for /applications/{applicationName}/subscription. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_applications_unsubscribe_parse_body( + struct ast_json *body, + struct ast_ari_applications_unsubscribe_args *args); + +/*! * \brief Unsubscribe an application from an event source. * * Returns the state of the application after the subscriptions have changed diff --git a/res/ari/resource_asterisk.h b/res/ari/resource_asterisk.h index aff89c445..93e161d3f 100644 --- a/res/ari/resource_asterisk.h +++ b/res/ari/resource_asterisk.h @@ -49,6 +49,17 @@ struct ast_ari_asterisk_get_info_args { char *only_parse; }; /*! + * \brief Body parsing function for /asterisk/info. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_asterisk_get_info_parse_body( + struct ast_json *body, + struct ast_ari_asterisk_get_info_args *args); + +/*! * \brief Gets Asterisk system information. * * \param headers HTTP headers @@ -62,6 +73,17 @@ struct ast_ari_asterisk_get_global_var_args { const char *variable; }; /*! + * \brief Body parsing function for /asterisk/variable. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_asterisk_get_global_var_parse_body( + struct ast_json *body, + struct ast_ari_asterisk_get_global_var_args *args); + +/*! * \brief Get the value of a global variable. * * \param headers HTTP headers @@ -77,6 +99,17 @@ struct ast_ari_asterisk_set_global_var_args { const char *value; }; /*! + * \brief Body parsing function for /asterisk/variable. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_asterisk_set_global_var_parse_body( + struct ast_json *body, + struct ast_ari_asterisk_set_global_var_args *args); + +/*! * \brief Set the value of a global variable. * * \param headers HTTP headers diff --git a/res/ari/resource_bridges.h b/res/ari/resource_bridges.h index a7ccd3120..38ccb294b 100644 --- a/res/ari/resource_bridges.h +++ b/res/ari/resource_bridges.h @@ -58,6 +58,17 @@ struct ast_ari_bridges_create_args { const char *name; }; /*! + * \brief Body parsing function for /bridges. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_bridges_create_parse_body( + struct ast_json *body, + struct ast_ari_bridges_create_args *args); + +/*! * \brief Create a new bridge. * * This bridge persists until it has been shut down, or Asterisk has been shut down. @@ -109,6 +120,17 @@ struct ast_ari_bridges_add_channel_args { const char *role; }; /*! + * \brief Body parsing function for /bridges/{bridgeId}/addChannel. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_bridges_add_channel_parse_body( + struct ast_json *body, + struct ast_ari_bridges_add_channel_args *args); + +/*! * \brief Add a channel to a bridge. * * \param headers HTTP headers @@ -128,6 +150,17 @@ struct ast_ari_bridges_remove_channel_args { char *channel_parse; }; /*! + * \brief Body parsing function for /bridges/{bridgeId}/removeChannel. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_bridges_remove_channel_parse_body( + struct ast_json *body, + struct ast_ari_bridges_remove_channel_args *args); + +/*! * \brief Remove a channel from a bridge. * * \param headers HTTP headers @@ -143,6 +176,17 @@ struct ast_ari_bridges_start_moh_args { const char *moh_class; }; /*! + * \brief Body parsing function for /bridges/{bridgeId}/moh. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_bridges_start_moh_parse_body( + struct ast_json *body, + struct ast_ari_bridges_start_moh_args *args); + +/*! * \brief Play music on hold to a bridge or change the MOH class that is playing. * * \param headers HTTP headers @@ -179,6 +223,17 @@ struct ast_ari_bridges_play_args { int skipms; }; /*! + * \brief Body parsing function for /bridges/{bridgeId}/play. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_bridges_play_parse_body( + struct ast_json *body, + struct ast_ari_bridges_play_args *args); + +/*! * \brief Start playback of media on a bridge. * * The media URI may be any of a number of URI's. Currently sound: and recording: URI's are supported. This operation creates a playback resource that can be used to control the playback of media (pause, rewind, fast forward, etc.) @@ -208,6 +263,17 @@ struct ast_ari_bridges_record_args { const char *terminate_on; }; /*! + * \brief Body parsing function for /bridges/{bridgeId}/record. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_bridges_record_parse_body( + struct ast_json *body, + struct ast_ari_bridges_record_args *args); + +/*! * \brief Start a recording. * * This records the mixed audio from all channels participating in this bridge. diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c index e6322a37c..ab8f5b42b 100644 --- a/res/ari/resource_channels.c +++ b/res/ari/resource_channels.c @@ -687,6 +687,43 @@ void ast_ari_channels_list(struct ast_variable *headers, ast_ari_response_ok(response, ast_json_ref(json)); } +static int ari_channels_set_channel_var(struct ast_channel *chan, + const char *variable, const char *value, struct ast_ari_response *response) +{ + if (pbx_builtin_setvar_helper(chan, variable, value)) { + ast_ari_response_error( + response, 400, "Bad Request", + "Unable to set channel variable %s=%s", variable, value); + return -1; + } + + return 0; +} + +static int ari_channels_set_channel_vars(struct ast_channel *chan, + struct ast_json *variables, struct ast_ari_response *response) +{ + struct ast_json_iter *i; + + if (!variables) { + /* nothing to do */ + return 0; + } + + for (i = ast_json_object_iter(variables); i; + i = ast_json_object_iter_next(variables, i)) { + if (ari_channels_set_channel_var( + chan, ast_json_object_iter_key(i), + ast_json_string_get(ast_json_object_iter_value(i)), + response)) { + /* response filled in by called function */ + return -1; + } + } + + return 0; +} + void ast_ari_channels_originate(struct ast_variable *headers, struct ast_ari_channels_originate_args *args, struct ast_ari_response *response) @@ -704,6 +741,7 @@ void ast_ari_channels_originate(struct ast_variable *headers, char *stuff; struct ast_channel *chan; RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup); + struct ast_json *variable_list = NULL; if (!cap) { ast_ari_response_alloc_failed(response); @@ -711,6 +749,12 @@ void ast_ari_channels_originate(struct ast_variable *headers, } ast_format_cap_add(cap, ast_format_set(&tmp_fmt, AST_FORMAT_SLINEAR, 0)); + /* Parse any query parameters out of the body parameter */ + if (args->variables) { + ast_ari_channels_originate_parse_body(args->variables, args); + variable_list = ast_json_object_get(args->variables, "variables"); + } + if (ast_strlen_zero(args->endpoint)) { ast_ari_response_error(response, 400, "Bad Request", "Endpoint must be specified"); @@ -776,6 +820,11 @@ void ast_ari_channels_originate(struct ast_variable *headers, return; } + if (ari_channels_set_channel_vars(chan, variable_list, response)) { + /* response filled in by called function */ + return; + } + snapshot = ast_channel_snapshot_create(chan); ast_channel_unlock(chan); diff --git a/res/ari/resource_channels.h b/res/ari/resource_channels.h index 49ab8eb34..7f740a67c 100644 --- a/res/ari/resource_channels.h +++ b/res/ari/resource_channels.h @@ -68,8 +68,21 @@ struct ast_ari_channels_originate_args { const char *caller_id; /*! \brief Timeout (in seconds) before giving up dialing, or -1 for no timeout. */ int timeout; + /*! \brief The 'variables' key in the body object holds variable key/value pairs to set on the channel on creation. Other keys in the body object are interpreted as query parameters. Ex. { 'endpoint': 'SIP/Alice', 'variables': { 'CALLERID(name)': 'Alice' } } */ + struct ast_json *variables; }; /*! + * \brief Body parsing function for /channels. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_channels_originate_parse_body( + struct ast_json *body, + struct ast_ari_channels_originate_args *args); + +/*! * \brief Create a new channel (originate). * * The new channel is created immediately and a snapshot of it returned. If a Stasis application is provided it will be automatically subscribed to the originated channel for further events and updates. @@ -100,6 +113,17 @@ struct ast_ari_channels_hangup_args { const char *reason; }; /*! + * \brief Body parsing function for /channels/{channelId}. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_channels_hangup_parse_body( + struct ast_json *body, + struct ast_ari_channels_hangup_args *args); + +/*! * \brief Delete (i.e. hangup) a channel. * * \param headers HTTP headers @@ -119,6 +143,17 @@ struct ast_ari_channels_continue_in_dialplan_args { int priority; }; /*! + * \brief Body parsing function for /channels/{channelId}/continue. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_channels_continue_in_dialplan_parse_body( + struct ast_json *body, + struct ast_ari_channels_continue_in_dialplan_args *args); + +/*! * \brief Exit application; continue execution in the dialplan. * * \param headers HTTP headers @@ -181,6 +216,17 @@ struct ast_ari_channels_send_dtmf_args { int after; }; /*! + * \brief Body parsing function for /channels/{channelId}/dtmf. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_channels_send_dtmf_parse_body( + struct ast_json *body, + struct ast_ari_channels_send_dtmf_args *args); + +/*! * \brief Send provided DTMF to a given channel. * * \param headers HTTP headers @@ -196,6 +242,17 @@ struct ast_ari_channels_mute_args { const char *direction; }; /*! + * \brief Body parsing function for /channels/{channelId}/mute. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_channels_mute_parse_body( + struct ast_json *body, + struct ast_ari_channels_mute_args *args); + +/*! * \brief Mute a channel. * * \param headers HTTP headers @@ -211,6 +268,17 @@ struct ast_ari_channels_unmute_args { const char *direction; }; /*! + * \brief Body parsing function for /channels/{channelId}/mute. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_channels_unmute_parse_body( + struct ast_json *body, + struct ast_ari_channels_unmute_args *args); + +/*! * \brief Unmute a channel. * * \param headers HTTP headers @@ -252,6 +320,17 @@ struct ast_ari_channels_start_moh_args { const char *moh_class; }; /*! + * \brief Body parsing function for /channels/{channelId}/moh. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_channels_start_moh_parse_body( + struct ast_json *body, + struct ast_ari_channels_start_moh_args *args); + +/*! * \brief Play music on hold to a channel. * * Using media operations such as /play on a channel playing MOH in this manner will suspend MOH without resuming automatically. If continuing music on hold is desired, the stasis application must reinitiate music on hold. @@ -316,6 +395,17 @@ struct ast_ari_channels_play_args { int skipms; }; /*! + * \brief Body parsing function for /channels/{channelId}/play. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_channels_play_parse_body( + struct ast_json *body, + struct ast_ari_channels_play_args *args); + +/*! * \brief Start playback of media. * * The media URI may be any of a number of URI's. Currently sound: and recording: URI's are supported. This operation creates a playback resource that can be used to control the playback of media (pause, rewind, fast forward, etc.) @@ -345,6 +435,17 @@ struct ast_ari_channels_record_args { const char *terminate_on; }; /*! + * \brief Body parsing function for /channels/{channelId}/record. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_channels_record_parse_body( + struct ast_json *body, + struct ast_ari_channels_record_args *args); + +/*! * \brief Start a recording. * * Record audio from a channel. Note that this will not capture audio sent to the channel. The bridge itself has a record feature if that's what you want. @@ -362,6 +463,17 @@ struct ast_ari_channels_get_channel_var_args { const char *variable; }; /*! + * \brief Body parsing function for /channels/{channelId}/variable. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_channels_get_channel_var_parse_body( + struct ast_json *body, + struct ast_ari_channels_get_channel_var_args *args); + +/*! * \brief Get the value of a channel variable or function. * * \param headers HTTP headers @@ -379,6 +491,17 @@ struct ast_ari_channels_set_channel_var_args { const char *value; }; /*! + * \brief Body parsing function for /channels/{channelId}/variable. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_channels_set_channel_var_parse_body( + struct ast_json *body, + struct ast_ari_channels_set_channel_var_args *args); + +/*! * \brief Set the value of a channel variable or function. * * \param headers HTTP headers @@ -400,6 +523,17 @@ struct ast_ari_channels_snoop_channel_args { const char *app_args; }; /*! + * \brief Body parsing function for /channels/{channelId}/snoop. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_channels_snoop_channel_parse_body( + struct ast_json *body, + struct ast_ari_channels_snoop_channel_args *args); + +/*! * \brief Start snooping. * * Snoop (spy/whisper) on a specific channel. diff --git a/res/ari/resource_device_states.h b/res/ari/resource_device_states.h index a3bac999c..7e2a38b4a 100644 --- a/res/ari/resource_device_states.h +++ b/res/ari/resource_device_states.h @@ -71,6 +71,17 @@ struct ast_ari_device_states_update_args { const char *device_state; }; /*! + * \brief Body parsing function for /deviceStates/{deviceName}. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_device_states_update_parse_body( + struct ast_json *body, + struct ast_ari_device_states_update_args *args); + +/*! * \brief Change the state of a device controlled by ARI. (Note - implicitly creates the device state). * * \param headers HTTP headers diff --git a/res/ari/resource_mailboxes.h b/res/ari/resource_mailboxes.h index 33c69682d..8627321db 100644 --- a/res/ari/resource_mailboxes.h +++ b/res/ari/resource_mailboxes.h @@ -73,6 +73,17 @@ struct ast_ari_mailboxes_update_args { int new_messages; }; /*! + * \brief Body parsing function for /mailboxes/{mailboxName}. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_mailboxes_update_parse_body( + struct ast_json *body, + struct ast_ari_mailboxes_update_args *args); + +/*! * \brief Change the state of a mailbox. (Note - implicitly creates the mailbox). * * \param headers HTTP headers diff --git a/res/ari/resource_playbacks.h b/res/ari/resource_playbacks.h index 9cd9f3cbd..751be7504 100644 --- a/res/ari/resource_playbacks.h +++ b/res/ari/resource_playbacks.h @@ -73,6 +73,17 @@ struct ast_ari_playbacks_control_args { const char *operation; }; /*! + * \brief Body parsing function for /playbacks/{playbackId}/control. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_playbacks_control_parse_body( + struct ast_json *body, + struct ast_ari_playbacks_control_args *args); + +/*! * \brief Control a playback. * * \param headers HTTP headers diff --git a/res/ari/resource_sounds.h b/res/ari/resource_sounds.h index 5e8ddd43d..d9588b1c0 100644 --- a/res/ari/resource_sounds.h +++ b/res/ari/resource_sounds.h @@ -47,6 +47,17 @@ struct ast_ari_sounds_list_args { const char *format; }; /*! + * \brief Body parsing function for /sounds. + * \param body The JSON body from which to parse parameters. + * \param[out] args The args structure to parse into. + * \retval zero on success + * \retval non-zero on failure + */ +int ast_ari_sounds_list_parse_body( + struct ast_json *body, + struct ast_ari_sounds_list_args *args); + +/*! * \brief List all sounds. * * \param headers HTTP headers |