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
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
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
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
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
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.
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
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
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
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.)
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.
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)
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);
}
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");
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);
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.
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
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
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
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
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
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.
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.)
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.
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
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
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.
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
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
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
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
fin: __attribute__((unused))
return;
}
+int ast_ari_applications_subscribe_parse_body(
+ struct ast_json *body,
+ struct ast_ari_applications_subscribe_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "eventSource");
+ if (field) {
+ /* If they were silly enough to both pass in a query param and a
+ * JSON body, free up the query value.
+ */
+ ast_free(args->event_source);
+ if (ast_json_typeof(field) == AST_JSON_ARRAY) {
+ /* Multiple param passed as array */
+ size_t i;
+ args->event_source_count = ast_json_array_size(field);
+ args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);
+
+ if (!args->event_source) {
+ return -1;
+ }
+
+ for (i = 0; i < args->event_source_count; ++i) {
+ args->event_source[i] = ast_json_string_get(ast_json_array_get(field, i));
+ }
+ } else {
+ /* Multiple param passed as single value */
+ args->event_source_count = 1;
+ args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);
+ if (!args->event_source) {
+ return -1;
+ }
+ args->event_source[0] = ast_json_string_get(field);
+ }
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /applications/{applicationName}/subscription.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_applications_subscribe_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "eventSource");
- if (field) {
- /* If they were silly enough to both pass in a query param and a
- * JSON body, free up the query value.
- */
- ast_free(args.event_source);
- if (ast_json_typeof(field) == AST_JSON_ARRAY) {
- /* Multiple param passed as array */
- size_t i;
- args.event_source_count = ast_json_array_size(field);
- args.event_source = ast_malloc(sizeof(*args.event_source) * args.event_source_count);
-
- if (!args.event_source) {
- ast_ari_response_alloc_failed(response);
- goto fin;
- }
-
- for (i = 0; i < args.event_source_count; ++i) {
- args.event_source[i] = ast_json_string_get(ast_json_array_get(field, i));
- }
- } else {
- /* Multiple param passed as single value */
- args.event_source_count = 1;
- args.event_source = ast_malloc(sizeof(*args.event_source) * args.event_source_count);
- if (!args.event_source) {
- ast_ari_response_alloc_failed(response);
- goto fin;
- }
- args.event_source[0] = ast_json_string_get(field);
- }
+ if (ast_ari_applications_subscribe_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_applications_subscribe(headers, &args, response);
#if defined(AST_DEVMODE)
ast_free(args.event_source);
return;
}
+int ast_ari_applications_unsubscribe_parse_body(
+ struct ast_json *body,
+ struct ast_ari_applications_unsubscribe_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "eventSource");
+ if (field) {
+ /* If they were silly enough to both pass in a query param and a
+ * JSON body, free up the query value.
+ */
+ ast_free(args->event_source);
+ if (ast_json_typeof(field) == AST_JSON_ARRAY) {
+ /* Multiple param passed as array */
+ size_t i;
+ args->event_source_count = ast_json_array_size(field);
+ args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);
+
+ if (!args->event_source) {
+ return -1;
+ }
+
+ for (i = 0; i < args->event_source_count; ++i) {
+ args->event_source[i] = ast_json_string_get(ast_json_array_get(field, i));
+ }
+ } else {
+ /* Multiple param passed as single value */
+ args->event_source_count = 1;
+ args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);
+ if (!args->event_source) {
+ return -1;
+ }
+ args->event_source[0] = ast_json_string_get(field);
+ }
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /applications/{applicationName}/subscription.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_applications_unsubscribe_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "eventSource");
- if (field) {
- /* If they were silly enough to both pass in a query param and a
- * JSON body, free up the query value.
- */
- ast_free(args.event_source);
- if (ast_json_typeof(field) == AST_JSON_ARRAY) {
- /* Multiple param passed as array */
- size_t i;
- args.event_source_count = ast_json_array_size(field);
- args.event_source = ast_malloc(sizeof(*args.event_source) * args.event_source_count);
-
- if (!args.event_source) {
- ast_ari_response_alloc_failed(response);
- goto fin;
- }
-
- for (i = 0; i < args.event_source_count; ++i) {
- args.event_source[i] = ast_json_string_get(ast_json_array_get(field, i));
- }
- } else {
- /* Multiple param passed as single value */
- args.event_source_count = 1;
- args.event_source = ast_malloc(sizeof(*args.event_source) * args.event_source_count);
- if (!args.event_source) {
- ast_ari_response_alloc_failed(response);
- goto fin;
- }
- args.event_source[0] = ast_json_string_get(field);
- }
+ if (ast_ari_applications_unsubscribe_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_applications_unsubscribe(headers, &args, response);
#if defined(AST_DEVMODE)
#define MAX_VALS 128
+int ast_ari_asterisk_get_info_parse_body(
+ struct ast_json *body,
+ struct ast_ari_asterisk_get_info_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "only");
+ if (field) {
+ /* If they were silly enough to both pass in a query param and a
+ * JSON body, free up the query value.
+ */
+ ast_free(args->only);
+ if (ast_json_typeof(field) == AST_JSON_ARRAY) {
+ /* Multiple param passed as array */
+ size_t i;
+ args->only_count = ast_json_array_size(field);
+ args->only = ast_malloc(sizeof(*args->only) * args->only_count);
+
+ if (!args->only) {
+ return -1;
+ }
+
+ for (i = 0; i < args->only_count; ++i) {
+ args->only[i] = ast_json_string_get(ast_json_array_get(field, i));
+ }
+ } else {
+ /* Multiple param passed as single value */
+ args->only_count = 1;
+ args->only = ast_malloc(sizeof(*args->only) * args->only_count);
+ if (!args->only) {
+ return -1;
+ }
+ args->only[0] = ast_json_string_get(field);
+ }
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /asterisk/info.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_asterisk_get_info_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "only");
- if (field) {
- /* If they were silly enough to both pass in a query param and a
- * JSON body, free up the query value.
- */
- ast_free(args.only);
- if (ast_json_typeof(field) == AST_JSON_ARRAY) {
- /* Multiple param passed as array */
- size_t i;
- args.only_count = ast_json_array_size(field);
- args.only = ast_malloc(sizeof(*args.only) * args.only_count);
-
- if (!args.only) {
- ast_ari_response_alloc_failed(response);
- goto fin;
- }
-
- for (i = 0; i < args.only_count; ++i) {
- args.only[i] = ast_json_string_get(ast_json_array_get(field, i));
- }
- } else {
- /* Multiple param passed as single value */
- args.only_count = 1;
- args.only = ast_malloc(sizeof(*args.only) * args.only_count);
- if (!args.only) {
- ast_ari_response_alloc_failed(response);
- goto fin;
- }
- args.only[0] = ast_json_string_get(field);
- }
+ if (ast_ari_asterisk_get_info_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_asterisk_get_info(headers, &args, response);
#if defined(AST_DEVMODE)
ast_free(args.only);
return;
}
+int ast_ari_asterisk_get_global_var_parse_body(
+ struct ast_json *body,
+ struct ast_ari_asterisk_get_global_var_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "variable");
+ if (field) {
+ args->variable = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /asterisk/variable.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_asterisk_get_global_var_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "variable");
- if (field) {
- args.variable = ast_json_string_get(field);
+ if (ast_ari_asterisk_get_global_var_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_asterisk_get_global_var(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_asterisk_set_global_var_parse_body(
+ struct ast_json *body,
+ struct ast_ari_asterisk_set_global_var_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "variable");
+ if (field) {
+ args->variable = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "value");
+ if (field) {
+ args->value = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /asterisk/variable.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_asterisk_set_global_var_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "variable");
- if (field) {
- args.variable = ast_json_string_get(field);
- }
- field = ast_json_object_get(body, "value");
- if (field) {
- args.value = ast_json_string_get(field);
+ if (ast_ari_asterisk_set_global_var_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_asterisk_set_global_var(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_bridges_create_parse_body(
+ struct ast_json *body,
+ struct ast_ari_bridges_create_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.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_bridges_create_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* 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);
+ if (ast_ari_bridges_create_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_bridges_create(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_bridges_add_channel_parse_body(
+ struct ast_json *body,
+ struct ast_ari_bridges_add_channel_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "channel");
+ if (field) {
+ /* If they were silly enough to both pass in a query param and a
+ * JSON body, free up the query value.
+ */
+ ast_free(args->channel);
+ if (ast_json_typeof(field) == AST_JSON_ARRAY) {
+ /* Multiple param passed as array */
+ size_t i;
+ args->channel_count = ast_json_array_size(field);
+ args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
+
+ if (!args->channel) {
+ return -1;
+ }
+
+ for (i = 0; i < args->channel_count; ++i) {
+ args->channel[i] = ast_json_string_get(ast_json_array_get(field, i));
+ }
+ } else {
+ /* Multiple param passed as single value */
+ args->channel_count = 1;
+ args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
+ if (!args->channel) {
+ return -1;
+ }
+ args->channel[0] = ast_json_string_get(field);
+ }
+ }
+ field = ast_json_object_get(body, "role");
+ if (field) {
+ args->role = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /bridges/{bridgeId}/addChannel.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_bridges_add_channel_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "channel");
- if (field) {
- /* If they were silly enough to both pass in a query param and a
- * JSON body, free up the query value.
- */
- ast_free(args.channel);
- if (ast_json_typeof(field) == AST_JSON_ARRAY) {
- /* Multiple param passed as array */
- size_t i;
- args.channel_count = ast_json_array_size(field);
- args.channel = ast_malloc(sizeof(*args.channel) * args.channel_count);
-
- if (!args.channel) {
- ast_ari_response_alloc_failed(response);
- goto fin;
- }
-
- for (i = 0; i < args.channel_count; ++i) {
- args.channel[i] = ast_json_string_get(ast_json_array_get(field, i));
- }
- } else {
- /* Multiple param passed as single value */
- args.channel_count = 1;
- args.channel = ast_malloc(sizeof(*args.channel) * args.channel_count);
- if (!args.channel) {
- ast_ari_response_alloc_failed(response);
- goto fin;
- }
- args.channel[0] = ast_json_string_get(field);
- }
- }
- field = ast_json_object_get(body, "role");
- if (field) {
- args.role = ast_json_string_get(field);
+ if (ast_ari_bridges_add_channel_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_bridges_add_channel(headers, &args, response);
#if defined(AST_DEVMODE)
ast_free(args.channel);
return;
}
+int ast_ari_bridges_remove_channel_parse_body(
+ struct ast_json *body,
+ struct ast_ari_bridges_remove_channel_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "channel");
+ if (field) {
+ /* If they were silly enough to both pass in a query param and a
+ * JSON body, free up the query value.
+ */
+ ast_free(args->channel);
+ if (ast_json_typeof(field) == AST_JSON_ARRAY) {
+ /* Multiple param passed as array */
+ size_t i;
+ args->channel_count = ast_json_array_size(field);
+ args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
+
+ if (!args->channel) {
+ return -1;
+ }
+
+ for (i = 0; i < args->channel_count; ++i) {
+ args->channel[i] = ast_json_string_get(ast_json_array_get(field, i));
+ }
+ } else {
+ /* Multiple param passed as single value */
+ args->channel_count = 1;
+ args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
+ if (!args->channel) {
+ return -1;
+ }
+ args->channel[0] = ast_json_string_get(field);
+ }
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /bridges/{bridgeId}/removeChannel.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_bridges_remove_channel_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "channel");
- if (field) {
- /* If they were silly enough to both pass in a query param and a
- * JSON body, free up the query value.
- */
- ast_free(args.channel);
- if (ast_json_typeof(field) == AST_JSON_ARRAY) {
- /* Multiple param passed as array */
- size_t i;
- args.channel_count = ast_json_array_size(field);
- args.channel = ast_malloc(sizeof(*args.channel) * args.channel_count);
-
- if (!args.channel) {
- ast_ari_response_alloc_failed(response);
- goto fin;
- }
-
- for (i = 0; i < args.channel_count; ++i) {
- args.channel[i] = ast_json_string_get(ast_json_array_get(field, i));
- }
- } else {
- /* Multiple param passed as single value */
- args.channel_count = 1;
- args.channel = ast_malloc(sizeof(*args.channel) * args.channel_count);
- if (!args.channel) {
- ast_ari_response_alloc_failed(response);
- goto fin;
- }
- args.channel[0] = ast_json_string_get(field);
- }
+ if (ast_ari_bridges_remove_channel_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_bridges_remove_channel(headers, &args, response);
#if defined(AST_DEVMODE)
ast_free(args.channel);
return;
}
+int ast_ari_bridges_start_moh_parse_body(
+ struct ast_json *body,
+ struct ast_ari_bridges_start_moh_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "mohClass");
+ if (field) {
+ args->moh_class = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /bridges/{bridgeId}/moh.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_bridges_start_moh_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "mohClass");
- if (field) {
- args.moh_class = ast_json_string_get(field);
+ if (ast_ari_bridges_start_moh_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_bridges_start_moh(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_bridges_play_parse_body(
+ struct ast_json *body,
+ struct ast_ari_bridges_play_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 /bridges/{bridgeId}/play.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_bridges_play_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* 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);
+ if (ast_ari_bridges_play_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_bridges_play(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_bridges_record_parse_body(
+ struct ast_json *body,
+ struct ast_ari_bridges_record_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "name");
+ if (field) {
+ args->name = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "format");
+ if (field) {
+ args->format = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "maxDurationSeconds");
+ if (field) {
+ args->max_duration_seconds = ast_json_integer_get(field);
+ }
+ field = ast_json_object_get(body, "maxSilenceSeconds");
+ if (field) {
+ args->max_silence_seconds = ast_json_integer_get(field);
+ }
+ field = ast_json_object_get(body, "ifExists");
+ if (field) {
+ args->if_exists = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "beep");
+ if (field) {
+ args->beep = ast_json_is_true(field);
+ }
+ field = ast_json_object_get(body, "terminateOn");
+ if (field) {
+ args->terminate_on = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /bridges/{bridgeId}/record.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_bridges_record_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "name");
- if (field) {
- args.name = ast_json_string_get(field);
- }
- field = ast_json_object_get(body, "format");
- if (field) {
- args.format = ast_json_string_get(field);
- }
- field = ast_json_object_get(body, "maxDurationSeconds");
- if (field) {
- args.max_duration_seconds = ast_json_integer_get(field);
- }
- field = ast_json_object_get(body, "maxSilenceSeconds");
- if (field) {
- args.max_silence_seconds = ast_json_integer_get(field);
- }
- field = ast_json_object_get(body, "ifExists");
- if (field) {
- args.if_exists = ast_json_string_get(field);
- }
- field = ast_json_object_get(body, "beep");
- if (field) {
- args.beep = ast_json_is_true(field);
- }
- field = ast_json_object_get(body, "terminateOn");
- if (field) {
- args.terminate_on = ast_json_string_get(field);
+ if (ast_ari_bridges_record_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_bridges_record(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_originate_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_originate_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);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /channels.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_channels_originate_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* 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);
- }
+ args.variables = ast_json_ref(body);
ast_ari_channels_originate(headers, &args, response);
#if defined(AST_DEVMODE)
code = response->response_code;
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_hangup_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_hangup_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "reason");
+ if (field) {
+ args->reason = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /channels/{channelId}.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_channels_hangup_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "reason");
- if (field) {
- args.reason = ast_json_string_get(field);
+ if (ast_ari_channels_hangup_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_channels_hangup(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_continue_in_dialplan_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_continue_in_dialplan_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "context");
+ if (field) {
+ args->context = 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, "priority");
+ if (field) {
+ args->priority = ast_json_integer_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /channels/{channelId}/continue.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_channels_continue_in_dialplan_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "context");
- if (field) {
- args.context = 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, "priority");
- if (field) {
- args.priority = ast_json_integer_get(field);
+ if (ast_ari_channels_continue_in_dialplan_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_channels_continue_in_dialplan(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_send_dtmf_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_send_dtmf_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "dtmf");
+ if (field) {
+ args->dtmf = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "before");
+ if (field) {
+ args->before = ast_json_integer_get(field);
+ }
+ field = ast_json_object_get(body, "between");
+ if (field) {
+ args->between = ast_json_integer_get(field);
+ }
+ field = ast_json_object_get(body, "duration");
+ if (field) {
+ args->duration = ast_json_integer_get(field);
+ }
+ field = ast_json_object_get(body, "after");
+ if (field) {
+ args->after = ast_json_integer_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /channels/{channelId}/dtmf.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_channels_send_dtmf_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "dtmf");
- if (field) {
- args.dtmf = ast_json_string_get(field);
- }
- field = ast_json_object_get(body, "before");
- if (field) {
- args.before = ast_json_integer_get(field);
- }
- field = ast_json_object_get(body, "between");
- if (field) {
- args.between = ast_json_integer_get(field);
- }
- field = ast_json_object_get(body, "duration");
- if (field) {
- args.duration = ast_json_integer_get(field);
- }
- field = ast_json_object_get(body, "after");
- if (field) {
- args.after = ast_json_integer_get(field);
+ if (ast_ari_channels_send_dtmf_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_channels_send_dtmf(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_mute_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_mute_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "direction");
+ if (field) {
+ args->direction = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /channels/{channelId}/mute.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_channels_mute_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "direction");
- if (field) {
- args.direction = ast_json_string_get(field);
+ if (ast_ari_channels_mute_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_channels_mute(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_unmute_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_unmute_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "direction");
+ if (field) {
+ args->direction = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /channels/{channelId}/mute.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_channels_unmute_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "direction");
- if (field) {
- args.direction = ast_json_string_get(field);
+ if (ast_ari_channels_unmute_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_channels_unmute(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_start_moh_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_start_moh_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "mohClass");
+ if (field) {
+ args->moh_class = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /channels/{channelId}/moh.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_channels_start_moh_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "mohClass");
- if (field) {
- args.moh_class = ast_json_string_get(field);
+ if (ast_ari_channels_start_moh_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_channels_start_moh(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_play_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_play_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.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_channels_play_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* 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);
+ if (ast_ari_channels_play_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_channels_play(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_record_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_record_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "name");
+ if (field) {
+ args->name = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "format");
+ if (field) {
+ args->format = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "maxDurationSeconds");
+ if (field) {
+ args->max_duration_seconds = ast_json_integer_get(field);
+ }
+ field = ast_json_object_get(body, "maxSilenceSeconds");
+ if (field) {
+ args->max_silence_seconds = ast_json_integer_get(field);
+ }
+ field = ast_json_object_get(body, "ifExists");
+ if (field) {
+ args->if_exists = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "beep");
+ if (field) {
+ args->beep = ast_json_is_true(field);
+ }
+ field = ast_json_object_get(body, "terminateOn");
+ if (field) {
+ args->terminate_on = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /channels/{channelId}/record.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_channels_record_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "name");
- if (field) {
- args.name = ast_json_string_get(field);
- }
- field = ast_json_object_get(body, "format");
- if (field) {
- args.format = ast_json_string_get(field);
- }
- field = ast_json_object_get(body, "maxDurationSeconds");
- if (field) {
- args.max_duration_seconds = ast_json_integer_get(field);
- }
- field = ast_json_object_get(body, "maxSilenceSeconds");
- if (field) {
- args.max_silence_seconds = ast_json_integer_get(field);
- }
- field = ast_json_object_get(body, "ifExists");
- if (field) {
- args.if_exists = ast_json_string_get(field);
- }
- field = ast_json_object_get(body, "beep");
- if (field) {
- args.beep = ast_json_is_true(field);
- }
- field = ast_json_object_get(body, "terminateOn");
- if (field) {
- args.terminate_on = ast_json_string_get(field);
+ if (ast_ari_channels_record_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_channels_record(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_get_channel_var_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_get_channel_var_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "variable");
+ if (field) {
+ args->variable = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /channels/{channelId}/variable.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_channels_get_channel_var_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "variable");
- if (field) {
- args.variable = ast_json_string_get(field);
+ if (ast_ari_channels_get_channel_var_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_channels_get_channel_var(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_set_channel_var_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_set_channel_var_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "variable");
+ if (field) {
+ args->variable = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "value");
+ if (field) {
+ args->value = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /channels/{channelId}/variable.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_channels_set_channel_var_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "variable");
- if (field) {
- args.variable = ast_json_string_get(field);
- }
- field = ast_json_object_get(body, "value");
- if (field) {
- args.value = ast_json_string_get(field);
+ if (ast_ari_channels_set_channel_var_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_channels_set_channel_var(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_channels_snoop_channel_parse_body(
+ struct ast_json *body,
+ struct ast_ari_channels_snoop_channel_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.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_channels_snoop_channel_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* 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);
+ if (ast_ari_channels_snoop_channel_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_channels_snoop_channel(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_device_states_update_parse_body(
+ struct ast_json *body,
+ struct ast_ari_device_states_update_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "deviceState");
+ if (field) {
+ args->device_state = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /deviceStates/{deviceName}.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_device_states_update_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "deviceState");
- if (field) {
- args.device_state = ast_json_string_get(field);
+ if (ast_ari_device_states_update_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_device_states_update(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_mailboxes_update_parse_body(
+ struct ast_json *body,
+ struct ast_ari_mailboxes_update_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "oldMessages");
+ if (field) {
+ args->old_messages = ast_json_integer_get(field);
+ }
+ field = ast_json_object_get(body, "newMessages");
+ if (field) {
+ args->new_messages = ast_json_integer_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /mailboxes/{mailboxName}.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_mailboxes_update_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "oldMessages");
- if (field) {
- args.old_messages = ast_json_integer_get(field);
- }
- field = ast_json_object_get(body, "newMessages");
- if (field) {
- args.new_messages = ast_json_integer_get(field);
+ if (ast_ari_mailboxes_update_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_mailboxes_update(headers, &args, response);
#if defined(AST_DEVMODE)
fin: __attribute__((unused))
return;
}
+int ast_ari_playbacks_control_parse_body(
+ struct ast_json *body,
+ struct ast_ari_playbacks_control_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "operation");
+ if (field) {
+ args->operation = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /playbacks/{playbackId}/control.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_playbacks_control_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "operation");
- if (field) {
- args.operation = ast_json_string_get(field);
+ if (ast_ari_playbacks_control_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_playbacks_control(headers, &args, response);
#if defined(AST_DEVMODE)
#define MAX_VALS 128
+int ast_ari_sounds_list_parse_body(
+ struct ast_json *body,
+ struct ast_ari_sounds_list_args *args)
+{
+ struct ast_json *field;
+ /* Parse query parameters out of it */
+ field = ast_json_object_get(body, "lang");
+ if (field) {
+ args->lang = ast_json_string_get(field);
+ }
+ field = ast_json_object_get(body, "format");
+ if (field) {
+ args->format = ast_json_string_get(field);
+ }
+ return 0;
+}
+
/*!
* \brief Parameter parsing callback for /sounds.
* \param get_params GET parameters in the HTTP request.
struct ast_ari_sounds_list_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
- struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
goto fin;
}
}
- /* Parse query parameters out of it */
- field = ast_json_object_get(body, "lang");
- if (field) {
- args.lang = ast_json_string_get(field);
- }
- field = ast_json_object_get(body, "format");
- if (field) {
- args.format = ast_json_string_get(field);
+ if (ast_ari_sounds_list_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
ast_ari_sounds_list(headers, &args, response);
#if defined(AST_DEVMODE)
{{/parameters}}
};
{{#is_req}}
+{{#parse_body}}
+/*!
+ * \brief Body parsing function for {{path}}.
+ * \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_{{c_name}}_{{c_nickname}}_parse_body(
+ struct ast_json *body,
+ struct ast_ari_{{c_name}}_{{c_nickname}}_args *args);
+
+{{/parse_body}}
/*!
* \brief {{summary}}
{{#notes}}
def process_parameter(self, parameter, context):
if parameter.param_type == 'body':
+ parameter.is_body_parameter = True;
parameter.c_data_type = 'struct ast_json *'
else:
+ parameter.is_body_parameter = False;
if not parameter.data_type in self.type_mapping:
raise SwaggerError(
"Invalid parameter type %s" % parameter.data_type, context)
--- /dev/null
+{{!
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Digium, Inc.
+ *
+ * William Kinsey Moore, III <kmoore@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+}}
+{{!
+ * Snippet for decoding parameters into an _args struct.
+}}
+{{#parse_body}}
+int ast_ari_{{c_name}}_{{c_nickname}}_parse_body(
+ struct ast_json *body,
+ struct ast_ari_{{c_name}}_{{c_nickname}}_args *args)
+{
+{{#has_query_parameters}}
+ struct ast_json *field;
+{{/has_query_parameters}}
+ /* Parse query parameters out of it */
+{{#query_parameters}}
+{{^is_body_parameter}}
+ field = ast_json_object_get(body, "{{name}}");
+ if (field) {
+{{^allow_multiple}}
+ args->{{c_name}} = {{json_convert}}(field);
+{{/allow_multiple}}
+{{#allow_multiple}}
+ /* If they were silly enough to both pass in a query param and a
+ * JSON body, free up the query value.
+ */
+ ast_free(args->{{c_name}});
+ if (ast_json_typeof(field) == AST_JSON_ARRAY) {
+ /* Multiple param passed as array */
+ size_t i;
+ args->{{c_name}}_count = ast_json_array_size(field);
+ args->{{c_name}} = ast_malloc(sizeof(*args->{{c_name}}) * args->{{c_name}}_count);
+
+ if (!args->{{c_name}}) {
+ return -1;
+ }
+
+ for (i = 0; i < args->{{c_name}}_count; ++i) {
+ args->{{c_name}}[i] = {{json_convert}}(ast_json_array_get(field, i));
+ }
+ } else {
+ /* Multiple param passed as single value */
+ args->{{c_name}}_count = 1;
+ args->{{c_name}} = ast_malloc(sizeof(*args->{{c_name}}) * args->{{c_name}}_count);
+ if (!args->{{c_name}}) {
+ return -1;
+ }
+ args->{{c_name}}[0] = {{json_convert}}(field);
+ }
+{{/allow_multiple}}
+ }
+{{/is_body_parameter}}
+{{/query_parameters}}
+ return 0;
+}
+
+{{/parse_body}}
args.{{c_name}} = ast_json_ref(body);
{{/body_parameter}}
{{^body_parameter}}
- /* Parse query parameters out of it */
-{{#query_parameters}}
- field = ast_json_object_get(body, "{{name}}");
- if (field) {
-{{^allow_multiple}}
- args.{{c_name}} = {{json_convert}}(field);
-{{/allow_multiple}}
-{{#allow_multiple}}
- /* If they were silly enough to both pass in a query param and a
- * JSON body, free up the query value.
- */
- ast_free(args.{{c_name}});
- if (ast_json_typeof(field) == AST_JSON_ARRAY) {
- /* Multiple param passed as array */
- size_t i;
- args.{{c_name}}_count = ast_json_array_size(field);
- args.{{c_name}} = ast_malloc(sizeof(*args.{{c_name}}) * args.{{c_name}}_count);
-
- if (!args.{{c_name}}) {
- ast_ari_response_alloc_failed(response);
- goto fin;
- }
-
- for (i = 0; i < args.{{c_name}}_count; ++i) {
- args.{{c_name}}[i] = {{json_convert}}(ast_json_array_get(field, i));
- }
- } else {
- /* Multiple param passed as single value */
- args.{{c_name}}_count = 1;
- args.{{c_name}} = ast_malloc(sizeof(*args.{{c_name}}) * args.{{c_name}}_count);
- if (!args.{{c_name}}) {
- ast_ari_response_alloc_failed(response);
- goto fin;
- }
- args.{{c_name}}[0] = {{json_convert}}(field);
- }
-{{/allow_multiple}}
+ if (ast_ari_{{c_name}}_{{c_nickname}}_parse_body(body, &args)) {
+ ast_ari_response_alloc_failed(response);
+ goto fin;
}
-{{/query_parameters}}
{{/body_parameter}}
{{/parse_body}}
{{/is_websocket}}
{{#apis}}
{{#operations}}
{{#is_req}}
+{{> body_parsing}}
/*!
* \brief Parameter parsing callback for {{path}}.
* \param get_params GET parameters in the HTTP request.
struct ast_variable *i;
{{/has_parameters}}
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
-{{^body_parameter}}
-{{#has_query_parameters}}
- struct ast_json *field;
-{{/has_query_parameters}}
-{{/body_parameter}}
#if defined(AST_DEVMODE)
int is_valid;
int code;
"allowMultiple": false,
"dataType": "int",
"defaultValue": 30
+ },
+ {
+ "name": "variables",
+ "description": "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' } }",
+ "paramType": "body",
+ "required": false,
+ "dataType": "containers",
+ "allowMultiple": false
}
],
"errorResponses": [