diff options
Diffstat (limited to 'res')
29 files changed, 4493 insertions, 7 deletions
diff --git a/res/Makefile b/res/Makefile index 53aeeaffd..fec20a2e0 100644 --- a/res/Makefile +++ b/res/Makefile @@ -67,4 +67,7 @@ endif ael/pval.o: ael/pval.c clean:: - rm -f snmp/*.o snmp/*.i ael/*.o ael/*.i ais/*.o ais/*.i + rm -f snmp/*.[oi] ael/*.[oi] ais/*.[oi] stasis_http/*.[oi] + +# Dependencies for res_stasis_http_*.so are generated, so they're in this file +include stasis_http.make diff --git a/res/res_stasis.c b/res/res_stasis.c index 3527adaa5..045362546 100644 --- a/res/res_stasis.c +++ b/res/res_stasis.c @@ -40,6 +40,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include "asterisk/stasis_channels.h" #include "asterisk/strings.h" +/*! Time to wait for a frame in the application */ +#define MAX_WAIT_MS 200 + /*! * \brief Number of buckets for the Stasis application hash table. Remember to * keep it a prime number! @@ -147,7 +150,67 @@ static void app_send(struct app *app, struct ast_json *message) app->handler(app->data, app->name, message); } +typedef void* (*stasis_app_command_cb)(struct stasis_app_control *control, + struct ast_channel *chan, + void *data); + +struct stasis_app_command { + ast_mutex_t lock; + ast_cond_t condition; + stasis_app_command_cb callback; + void *data; + void *retval; + int is_done:1; +}; + +static void command_dtor(void *obj) +{ + struct stasis_app_command *command = obj; + ast_mutex_destroy(&command->lock); + ast_cond_destroy(&command->condition); +} + +static struct stasis_app_command *command_create(stasis_app_command_cb callback, + void *data) +{ + RAII_VAR(struct stasis_app_command *, command, NULL, ao2_cleanup); + + command = ao2_alloc(sizeof(*command), command_dtor); + if (!command) { + return NULL; + } + + ast_mutex_init(&command->lock); + ast_cond_init(&command->condition, 0); + command->callback = callback; + command->data = data; + + ao2_ref(command, +1); + return command; +} + +static void command_complete(struct stasis_app_command *command, void *retval) +{ + SCOPED_MUTEX(lock, &command->lock); + + command->is_done = 1; + command->retval = retval; + ast_cond_signal(&command->condition); +} + +static void *wait_for_command(struct stasis_app_command *command) +{ + SCOPED_MUTEX(lock, &command->lock); + while (!command->is_done) { + ast_cond_wait(&command->condition, &command->lock); + } + + return command->retval; +} + struct stasis_app_control { + /*! Queue of commands to dispatch on the channel */ + struct ao2_container *command_queue; /*! * When set, /c app_stasis should exit and continue in the dialplan. */ @@ -167,11 +230,24 @@ static struct stasis_app_control *control_create(const char *uniqueid) return NULL; } + control->command_queue = ao2_container_alloc_list(0, 0, NULL, NULL); + strncpy(control->channel_id, uniqueid, size - sizeof(*control)); return control; } +static void *exec_command(struct stasis_app_control *control, + struct stasis_app_command *command) +{ + ao2_lock(control); + ao2_ref(command, +1); + ao2_link(control->command_queue, command); + ao2_unlock(control); + + return wait_for_command(command); +} + /*! AO2 hash function for \ref stasis_app_control */ static int control_hash(const void *obj, const int flags) { @@ -199,13 +275,20 @@ static int control_compare(void *lhs, void *rhs, int flags) struct stasis_app_control *stasis_app_control_find_by_channel( const struct ast_channel *chan) { - RAII_VAR(struct ao2_container *, controls, NULL, ao2_cleanup); if (chan == NULL) { return NULL; } + return stasis_app_control_find_by_channel_id( + ast_channel_uniqueid(chan)); +} + +struct stasis_app_control *stasis_app_control_find_by_channel_id( + const char *channel_id) +{ + RAII_VAR(struct ao2_container *, controls, NULL, ao2_cleanup); controls = app_controls(); - return ao2_find(controls, ast_channel_uniqueid(chan), OBJ_KEY); + return ao2_find(controls, channel_id, OBJ_KEY); } /*! @@ -233,6 +316,33 @@ void stasis_app_control_continue(struct stasis_app_control *control) control->continue_to_dialplan = 1; } +static int OK = 0; +static int FAIL = -1; + +static void *__app_control_answer(struct stasis_app_control *control, + struct ast_channel *chan, void *data) +{ + ast_debug(3, "%s: Answering", control->channel_id); + return __ast_answer(chan, 0, 1) == 0 ? &OK : &FAIL; +} + +int stasis_app_control_answer(struct stasis_app_control *control) +{ + RAII_VAR(struct stasis_app_command *, command, NULL, ao2_cleanup); + int *retval; + + ast_debug(3, "%s: Sending answer command\n", control->channel_id); + + command = command_create(__app_control_answer, NULL); + retval = exec_command(control, command); + + if (*retval != 0) { + ast_log(LOG_WARNING, "Failed to answer channel"); + } + + return *retval; +} + static struct ast_json *app_event_create( const char *event_name, const struct ast_channel_snapshot *snapshot, @@ -410,6 +520,26 @@ static void control_unlink(struct stasis_app_control *control) ao2_cleanup(control); } +static void dispatch_commands(struct stasis_app_control *control, + struct ast_channel *chan) +{ + struct ao2_iterator i; + void *obj; + + SCOPED_AO2LOCK(lock, control); + + i = ao2_iterator_init(control->command_queue, AO2_ITERATOR_UNLINK); + + while ((obj = ao2_iterator_next(&i))) { + RAII_VAR(struct stasis_app_command *, command, obj, ao2_cleanup); + void *retval = command->callback(control, chan, command->data); + command_complete(command, retval); + } + + ao2_iterator_destroy(&i); +} + + /*! /brief Stasis dialplan application callback */ int stasis_app_exec(struct ast_channel *chan, const char *app_name, int argc, char *argv[]) @@ -458,8 +588,38 @@ int stasis_app_exec(struct ast_channel *chan, const char *app_name, int argc, return res; } - while (!hungup && !control_continue_test_and_reset(control) && ast_waitfor(chan, -1) > -1) { - RAII_VAR(struct ast_frame *, f, ast_read(chan), ast_frame_dtor); + while (1) { + RAII_VAR(struct ast_frame *, f, NULL, ast_frame_dtor); + int r; + + if (hungup) { + ast_debug(3, "%s: Hangup\n", + ast_channel_uniqueid(chan)); + break; + } + + if (control_continue_test_and_reset(control)) { + ast_debug(3, "%s: Continue\n", + ast_channel_uniqueid(chan)); + break; + } + + r = ast_waitfor(chan, MAX_WAIT_MS); + + if (r < 0) { + ast_debug(3, "%s: Poll error\n", + ast_channel_uniqueid(chan)); + break; + } + + dispatch_commands(control, chan); + + if (r == 0) { + /* Timeout */ + continue; + } + + f = ast_read(chan); if (!f) { ast_debug(3, "%s: No more frames. Must be done, I guess.\n", ast_channel_uniqueid(chan)); break; @@ -468,8 +628,6 @@ int stasis_app_exec(struct ast_channel *chan, const char *app_name, int argc, switch (f->frametype) { case AST_FRAME_CONTROL: if (f->subclass.integer == AST_CONTROL_HANGUP) { - ast_debug(3, "%s: Received hangup\n", - ast_channel_uniqueid(chan)); hungup = 1; } break; diff --git a/res/res_stasis_http.c b/res/res_stasis_http.c new file mode 100644 index 000000000..aa9c8a8cd --- /dev/null +++ b/res/res_stasis_http.c @@ -0,0 +1,932 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief HTTP binding for the Stasis API + * \author David M. Lee, II <dlee@digium.com> + * + * The API itself is documented using <a + * href="https://developers.helloreverb.com/swagger/">Swagger</a>, a lightweight + * mechanism for documenting RESTful API's using JSON. This allows us to use <a + * href="https://github.com/wordnik/swagger-ui">swagger-ui</a> to provide + * executable documentation for the API, generate client bindings in different + * <a href="https://github.com/asterisk/asterisk_rest_libraries">languages</a>, + * and generate a lot of the boilerplate code for implementing the RESTful + * bindings. The API docs live in the \c rest-api/ directory. + * + * The RESTful bindings are generated from the Swagger API docs using a set of + * <a href="http://mustache.github.io/mustache.5.html">Mustache</a> templates. + * The code generator is written in Python, and uses the Python implementation + * <a href="https://github.com/defunkt/pystache">pystache</a>. Pystache has no + * dependencies, and be installed easily using \c pip. Code generation code + * lives in \c rest-api-templates/. + * + * The generated code reduces a lot of boilerplate when it comes to handling + * HTTP requests. It also helps us have greater consistency in the REST API. + * + * The structure of the generated code is: + * + * - res/stasis_http/resource_{resource}.h + * - For each operation in the resouce, a generated argument structure + * (holding the parsed arguments from the request) and function + * declarations (to implement in res/stasis_http/resource_{resource}.c) + * - res_stasis_http_{resource}.c + * - A set of \ref stasis_rest_callback functions, which glue the two + * together. They parse out path variables and request parameters to + * populate a specific \c *_args which is passed to the specific request + * handler (in res/stasis_http/resource_{resource}.c) + * - A tree of \ref stasis_rest_handlers for routing requests to its + * \ref stasis_rest_callback + * + * The basic flow of an HTTP request is: + * + * - stasis_http_callback() + * 1. Initial request validation + * 2. Routes as either a doc request (stasis_http_get_docs) or API + * request (stasis_http_invoke) + * - stasis_http_invoke() + * 1. Further request validation + * 2. Routes the request through the tree of generated + * \ref stasis_rest_handlers. + * 3. Dispatch to the generated callback + * - \c stasis_http_*_cb + * 1. Populate \c *_args struct with path and get params + * 2. Invoke the request handler + * 3. Validates and sends response + */ + +/*** MODULEINFO + <depend type="module">app_stasis</depend> + <support_level>core</support_level> + ***/ + +/*** DOCUMENTATION + <configInfo name="res_stasis_http" language="en_US"> + <synopsis>HTTP binding for the Stasis API</synopsis> + <configFile name="stasis_http.conf"> + <configObject name="global"> + <synopsis>Global configuration settings</synopsis> + <configOption name="enabled"> + <synopsis>Enable/disable the stasis-http module</synopsis> + </configOption> + <configOption name="pretty"> + <synopsis>Responses from stasis-http are formatted to be human readable</synopsis> + </configOption> + </configObject> + </configFile> + </configInfo> +***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "asterisk/module.h" +#include "asterisk/paths.h" +#include "asterisk/stasis_http.h" +#include "asterisk/config_options.h" + +#include <string.h> +#include <sys/stat.h> +#include <unistd.h> + +/*! \brief Global configuration options for stasis http. */ +struct conf_global_options { + /*! Enabled by default, disabled if false. */ + int enabled:1; + /*! Encoding format used during output (default compact). */ + enum ast_json_encoding_format format; +}; + +/*! \brief All configuration options for stasis http. */ +struct conf { + /*! The general section configuration options. */ + struct conf_global_options *global; +}; + +/*! \brief Locking container for safe configuration access. */ +static AO2_GLOBAL_OBJ_STATIC(confs); + +/*! \brief Mapping of the stasis http conf struct's globals to the + * general context in the config file. */ +static struct aco_type global_option = { + .type = ACO_GLOBAL, + .name = "global", + .item_offset = offsetof(struct conf, global), + .category = "^general$", + .category_match = ACO_WHITELIST +}; + +static struct aco_type *global_options[] = ACO_TYPES(&global_option); + +/*! \brief Disposes of the stasis http conf object */ +static void conf_destructor(void *obj) +{ + struct conf *cfg = obj; + ao2_cleanup(cfg->global); +} + +/*! \brief Creates the statis http conf object. */ +static void *conf_alloc(void) +{ + struct conf *cfg; + + if (!(cfg = ao2_alloc(sizeof(*cfg), conf_destructor))) { + return NULL; + } + + if (!(cfg->global = ao2_alloc(sizeof(*cfg->global), NULL))) { + ao2_ref(cfg, -1); + return NULL; + } + return cfg; +} + +/*! \brief The conf file that's processed for the module. */ +static struct aco_file conf_file = { + /*! The config file name. */ + .filename = "stasis_http.conf", + /*! The mapping object types to be processed. */ + .types = ACO_TYPES(&global_option), +}; + +CONFIG_INFO_STANDARD(cfg_info, confs, conf_alloc, + .files = ACO_FILES(&conf_file)); + +/*! \brief Bitfield handler since it is not possible to take address. */ +static int conf_bitfield_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) +{ + struct conf_global_options *global = obj; + + if (!strcasecmp(var->name, "enabled")) { + global->enabled = ast_true(var->value); + } else { + return -1; + } + + return 0; +} + +/*! \brief Encoding format handler converts from boolean to enum. */ +static int encoding_format_handler(const struct aco_option *opt, struct ast_variable *var, void *obj) +{ + struct conf_global_options *global = obj; + + if (!strcasecmp(var->name, "pretty")) { + global->format = ast_true(var->value) ? AST_JSON_PRETTY : AST_JSON_COMPACT; + } else { + return -1; + } + + return 0; +} + +/*! \brief Helper function to check if module is enabled. */ +static char is_enabled(void) +{ + RAII_VAR(struct conf *, cfg, ao2_global_obj_ref(confs), ao2_cleanup); + + return cfg->global->enabled; +} + +/*! Lock for \ref root_handler */ +static ast_mutex_t root_handler_lock; + +/*! Handler for root RESTful resource. */ +static struct stasis_rest_handlers *root_handler; + +/*! Pre-defined message for allocation failures. */ +static struct ast_json *alloc_failed_message; + +int stasis_http_add_handler(struct stasis_rest_handlers *handler) +{ + RAII_VAR(struct stasis_rest_handlers *, new_handler, NULL, ao2_cleanup); + size_t old_size, new_size; + + SCOPED_MUTEX(lock, &root_handler_lock); + + old_size = sizeof(*new_handler) + + root_handler->num_children * sizeof(handler); + new_size = old_size + sizeof(handler); + + new_handler = ao2_alloc(new_size, NULL); + if (!new_handler) { + return -1; + } + memcpy(new_handler, root_handler, old_size); + new_handler->children[new_handler->num_children++] = handler; + + ao2_cleanup(root_handler); + ao2_ref(new_handler, +1); + root_handler = new_handler; + return 0; +} + +int stasis_http_remove_handler(struct stasis_rest_handlers *handler) +{ + RAII_VAR(struct stasis_rest_handlers *, new_handler, NULL, ao2_cleanup); + size_t old_size, new_size, i, j; + + SCOPED_MUTEX(lock, &root_handler_lock); + old_size = sizeof(*new_handler) + + root_handler->num_children * sizeof(handler); + new_size = old_size - sizeof(handler); + + new_handler = ao2_alloc(new_size, NULL); + if (!new_handler) { + return -1; + } + memcpy(new_handler, root_handler, sizeof(*new_handler)); + + for (i = 0, j = 0; i < root_handler->num_children; ++i) { + if (root_handler->children[i] == handler) { + continue; + } + new_handler->children[j++] = root_handler->children[i]; + } + new_handler->num_children = j; + + ao2_cleanup(root_handler); + ao2_ref(new_handler, +1); + root_handler = new_handler; + return 0; +} + +static struct stasis_rest_handlers *get_root_handler(void) +{ + SCOPED_MUTEX(lock, &root_handler_lock); + ao2_ref(root_handler, +1); + return root_handler; +} + +static struct stasis_rest_handlers *root_handler_create(void) +{ + RAII_VAR(struct stasis_rest_handlers *, handler, NULL, ao2_cleanup); + + handler = ao2_alloc(sizeof(*handler), NULL); + if (!handler) { + return NULL; + } + handler->path_segment = "stasis"; + + ao2_ref(handler, +1); + return handler; +} + +void stasis_http_response_error(struct stasis_http_response *response, + int response_code, + const char *response_text, + const char *message_fmt, ...) +{ + RAII_VAR(struct ast_json *, message, NULL, ast_json_unref); + va_list ap; + + va_start(ap, message_fmt); + message = ast_json_vstringf(message_fmt, ap); + response->message = ast_json_pack("{s: o}", + "message", ast_json_ref(message)); + response->response_code = response_code; + response->response_text = response_text; +} + +void stasis_http_response_ok(struct stasis_http_response *response, + struct ast_json *message) +{ + response->message = message; + response->response_code = 200; + response->response_text = "OK"; +} + +void stasis_http_response_no_content(struct stasis_http_response *response) +{ + response->message = NULL; + response->response_code = 204; + response->response_text = "No Content"; +} + +void stasis_http_response_alloc_failed(struct stasis_http_response *response) +{ + response->message = ast_json_ref(alloc_failed_message); + response->response_code = 500; + response->response_text = "Internal Server Error"; +} + +static void add_allow_header(struct stasis_rest_handlers *handler, + struct stasis_http_response *response) +{ + enum ast_http_method m; + ast_str_append(&response->headers, 0, + "Allow: OPTIONS"); + for (m = 0; m < AST_HTTP_MAX_METHOD; ++m) { + if (handler->callbacks[m] != NULL) { + ast_str_append(&response->headers, 0, + ",%s", ast_get_http_method(m)); + } + } + ast_str_append(&response->headers, 0, "\r\n"); +} + +#define ACR_METHOD "Access-Control-Request-Method" +#define ACR_HEADERS "Access-Control-Request-Headers" +#define ACA_METHODS "Access-Control-Allow-Methods" +#define ACA_HEADERS "Access-Control-Allow-Headers" + +/*! + * \brief Handle OPTIONS request, mainly for CORS preflight requests. + * + * Some browsers will send this prior to non-simple methods (i.e. DELETE). + * See http://www.w3.org/TR/cors/ for the spec. Especially section 6.2. + */ +static void handle_options(struct stasis_rest_handlers *handler, + struct ast_variable *headers, + struct stasis_http_response *response) +{ + struct ast_variable *header; + char const *acr_method = NULL; + char const *acr_headers = NULL; + char const *origin = NULL; + + RAII_VAR(struct ast_str *, allow, NULL, ast_free); + enum ast_http_method m; + int allowed = 0; + + /* Regular OPTIONS response */ + add_allow_header(handler, response); + response->response_code = 204; + response->response_text = "No Content"; + response->message = NULL; + + /* Parse CORS headers */ + for (header = headers; header != NULL; header = header->next) { + if (strcmp(ACR_METHOD, header->name) == 0) { + acr_method = header->value; + } else if (strcmp(ACR_HEADERS, header->name) == 0) { + acr_headers = header->value; + } else if (strcmp("Origin", header->name) == 0) { + origin = header->value; + } + } + + /* CORS 6.2, #1 - "If the Origin header is not present terminate this + * set of steps. + */ + if (origin == NULL) { + return; + } + + /* CORS 6.2, #2 - "If the value of the Origin header is not a + * case-sensitive match for any of the values in list of origins do not + * set any additional headers and terminate this set of steps. + * + * "Always matching is acceptable since the list of origins can be + * unbounded. + * + * "The Origin header can only contain a single origin as the user agent + * will not follow redirects. + * + * TODO - pull list of allowed origins from config + */ + + /* CORS 6.2, #3 - "If there is no Access-Control-Request-Method header + * or if parsing failed, do not set any additional headers and terminate + * this set of steps." + */ + if (acr_method == NULL) { + return; + } + + /* CORS 6.2, #4 - "If there are no Access-Control-Request-Headers + * headers let header field-names be the empty list." + */ + if (acr_headers == NULL) { + acr_headers = ""; + } + + /* CORS 6.2, #5 - "If method is not a case-sensitive match for any of + * the values in list of methods do not set any additional headers and + * terminate this set of steps." + */ + allow = ast_str_create(20); + + if (!allow) { + stasis_http_response_alloc_failed(response); + return; + } + + /* Go ahead and build the ACA_METHODS header at the same time */ + for (m = 0; m < AST_HTTP_MAX_METHOD; ++m) { + if (handler->callbacks[m] != NULL) { + char const *m_str = ast_get_http_method(m); + if (strcmp(m_str, acr_method) == 0) { + allowed = 1; + } + ast_str_append(&allow, 0, ",%s", m_str); + } + } + + if (!allowed) { + return; + } + + /* CORS 6.2 #6 - "If any of the header field-names is not a ASCII + * case-insensitive match for any of the values in list of headers do + * not set any additional headers and terminate this set of steps. + * + * "Note: Always matching is acceptable since the list of headers can be + * unbounded." + */ + + /* CORS 6.2 #7 - "If the resource supports credentials add a single + * Access-Control-Allow-Origin header, with the value of the Origin + * header as value, and add a single Access-Control-Allow-Credentials + * header with the case-sensitive string "true" as value." + * + * Added by process_cors_request() earlier in the request. + */ + + /* CORS 6.2 #8 - "Optionally add a single Access-Control-Max-Age + * header..." + */ + + /* CORS 6.2 #9 - "Add one or more Access-Control-Allow-Methods headers + * consisting of (a subset of) the list of methods." + */ + ast_str_append(&response->headers, 0, "%s: OPTIONS,%s\r\n", + ACA_METHODS, ast_str_buffer(allow)); + + + /* CORS 6.2, #10 - "Add one or more Access-Control-Allow-Headers headers + * consisting of (a subset of) the list of headers. + * + * "Since the list of headers can be unbounded simply returning headers + * can be enough." + */ + if (!ast_strlen_zero(acr_headers)) { + ast_str_append(&response->headers, 0, "%s: %s\r\n", + ACA_HEADERS, acr_headers); + } +} + +void stasis_http_invoke(const char *uri, + enum ast_http_method method, + struct ast_variable *get_params, + struct ast_variable *headers, + struct stasis_http_response *response) +{ + RAII_VAR(char *, response_text, NULL, ast_free); + RAII_VAR(struct stasis_rest_handlers *, root, NULL, ao2_cleanup); + struct stasis_rest_handlers *handler; + struct ast_variable *path_vars = NULL; + char *path = ast_strdupa(uri); + const char *path_segment; + stasis_rest_callback callback; + + root = handler = get_root_handler(); + ast_assert(root != NULL); + + while ((path_segment = strsep(&path, "/")) && (strlen(path_segment) > 0)) { + struct stasis_rest_handlers *found_handler = NULL; + int i; + ast_debug(3, "Finding handler for %s\n", path_segment); + for (i = 0; found_handler == NULL && i < handler->num_children; ++i) { + struct stasis_rest_handlers *child = handler->children[i]; + + ast_debug(3, " Checking %s\n", child->path_segment); + if (child->is_wildcard) { + /* Record the path variable */ + struct ast_variable *path_var = ast_variable_new(child->path_segment, path_segment, __FILE__); + path_var->next = path_vars; + path_vars = path_var; + found_handler = child; + } else if (strcmp(child->path_segment, path_segment) == 0) { + found_handler = child; + } + } + + if (found_handler == NULL) { + /* resource not found */ + ast_debug(3, " Handler not found\n"); + stasis_http_response_error( + response, 404, "Not Found", + "Resource not found"); + return; + } else { + ast_debug(3, " Got it!\n"); + handler = found_handler; + } + } + + ast_assert(handler != NULL); + if (method == AST_HTTP_OPTIONS) { + handle_options(handler, headers, response); + return; + } + + if (method < 0 || method >= AST_HTTP_MAX_METHOD) { + add_allow_header(handler, response); + stasis_http_response_error( + response, 405, "Method Not Allowed", + "Invalid method"); + return; + } + + callback = handler->callbacks[method]; + if (callback == NULL) { + add_allow_header(handler, response); + stasis_http_response_error( + response, 405, "Method Not Allowed", + "Invalid method"); + return; + } + + callback(get_params, path_vars, headers, response); + if (response->message == NULL && response->response_code == 0) { + /* Really should not happen */ + ast_assert(0); + stasis_http_response_error( + response, 418, "I'm a teapot", + "Method not implemented"); + } +} + +void stasis_http_get_docs(const char *uri, struct ast_variable *headers, + struct stasis_http_response *response) +{ + RAII_VAR(struct ast_str *, absolute_path_builder, NULL, ast_free); + RAII_VAR(char *, absolute_api_dirname, NULL, free); + RAII_VAR(char *, absolute_filename, NULL, free); + struct ast_json *obj = NULL; + struct ast_variable *host = NULL; + struct ast_json_error error = {}; + struct stat file_stat; + + ast_debug(3, "%s(%s)\n", __func__, uri); + + absolute_path_builder = ast_str_create(80); + if (absolute_path_builder == NULL) { + stasis_http_response_alloc_failed(response); + return; + } + + /* absolute path to the rest-api directory */ + ast_str_append(&absolute_path_builder, 0, "%s", ast_config_AST_DATA_DIR); + ast_str_append(&absolute_path_builder, 0, "/rest-api/"); + absolute_api_dirname = realpath(ast_str_buffer(absolute_path_builder), NULL); + if (absolute_api_dirname == NULL) { + ast_log(LOG_ERROR, "Error determining real directory for rest-api\n"); + stasis_http_response_error( + response, 500, "Internal Server Error", + "Cannot find rest-api directory"); + return; + } + + /* absolute path to the requested file */ + ast_str_append(&absolute_path_builder, 0, "%s", uri); + absolute_filename = realpath(ast_str_buffer(absolute_path_builder), NULL); + if (absolute_filename == NULL) { + switch (errno) { + case ENAMETOOLONG: + case ENOENT: + case ENOTDIR: + stasis_http_response_error( + response, 404, "Not Found", + "Resource not found"); + break; + case EACCES: + stasis_http_response_error( + response, 403, "Forbidden", + "Permission denied"); + break; + default: + ast_log(LOG_ERROR, + "Error determining real path for uri '%s': %s\n", + uri, strerror(errno)); + stasis_http_response_error( + response, 500, "Internal Server Error", + "Cannot find file"); + break; + } + return; + } + + if (!ast_begins_with(absolute_filename, absolute_api_dirname)) { + /* HACKERZ! */ + ast_log(LOG_ERROR, + "Invalid attempt to access '%s' (not in %s)\n", + absolute_filename, absolute_api_dirname); + stasis_http_response_error( + response, 404, "Not Found", + "Resource not found"); + return; + } + + if (stat(absolute_filename, &file_stat) == 0) { + if (!(file_stat.st_mode & S_IFREG)) { + /* Not a file */ + stasis_http_response_error( + response, 403, "Forbidden", + "Invalid access"); + return; + } + } else { + /* Does not exist */ + stasis_http_response_error( + response, 404, "Not Found", + "Resource not found"); + return; + } + + /* Load resource object from file */ + obj = ast_json_load_new_file(absolute_filename, &error); + if (obj == NULL) { + ast_log(LOG_ERROR, "Error parsing resource file: %s:%d(%d) %s\n", + error.source, error.line, error.column, error.text); + stasis_http_response_error( + response, 500, "Internal Server Error", + "Yikes! Cannot parse resource"); + return; + } + + /* Update the basePath properly */ + if (ast_json_object_get(obj, "basePath") != NULL) { + for (host = headers; host; host = host->next) { + if (strcasecmp(host->name, "Host") == 0) { + break; + } + } + if (host != NULL) { + ast_json_object_set( + obj, "basePath", + ast_json_stringf("http://%s/stasis", host->value)); + } else { + /* Without the host, we don't have the basePath */ + ast_json_object_del(obj, "basePath"); + } + } + + stasis_http_response_ok(response, obj); +} + +static void remove_trailing_slash(const char *uri, + struct stasis_http_response *response) +{ + char *slashless = ast_strdupa(uri); + slashless[strlen(slashless) - 1] = '\0'; + + ast_str_append(&response->headers, 0, + "Location: /stasis/%s\r\n", slashless); + stasis_http_response_error(response, 302, "Found", + "Redirecting to %s", slashless); +} + +/*! + * \brief Handle CORS headers for simple requests. + * + * See http://www.w3.org/TR/cors/ for the spec. Especially section 6.1. + */ +static void process_cors_request(struct ast_variable *headers, + struct stasis_http_response *response) +{ + char const *origin = NULL; + struct ast_variable *header; + + /* Parse CORS headers */ + for (header = headers; header != NULL; header = header->next) { + if (strcmp("Origin", header->name) == 0) { + origin = header->value; + } + } + + /* CORS 6.1, #1 - "If the Origin header is not present terminate this + * set of steps." + */ + if (origin == NULL) { + return; + } + + /* CORS 6.1, #2 - "If the value of the Origin header is not a + * case-sensitive match for any of the values in list of origins, do not + * set any additional headers and terminate this set of steps. + * + * "Note: Always matching is acceptable since the list of origins can be + * unbounded." + * + * TODO - pull list of allowed origins from config + */ + + /* CORS 6.1, #3 - "If the resource supports credentials add a single + * Access-Control-Allow-Origin header, with the value of the Origin + * header as value, and add a single Access-Control-Allow-Credentials + * header with the case-sensitive string "true" as value. + * + * "Otherwise, add a single Access-Control-Allow-Origin header, with + * either the value of the Origin header or the string "*" as value." + * + * TODO - when we add authentication, this will change to + * Access-Control-Allow-Credentials. + */ + ast_str_append(&response->headers, 0, + "Access-Control-Allow-Origin: %s\r\n", origin); + + /* CORS 6.1, #4 - "If the list of exposed headers is not empty add one + * or more Access-Control-Expose-Headers headers, with as values the + * header field names given in the list of exposed headers." + * + * No exposed headers; skipping + */ +} + + +/*! + * \internal + * \brief Stasis HTTP handler. + * + * This handler takes the HTTP request and turns it into the appropriate + * RESTful request (conversion to JSON, routing, etc.) + * + * \param ser TCP session. + * \param urih URI handler. + * \param uri URI requested. + * \param method HTTP method. + * \param get_params HTTP \c GET params. + * \param headers HTTP headers. + */ +static int stasis_http_callback(struct ast_tcptls_session_instance *ser, + const struct ast_http_uri *urih, + const char *uri, + enum ast_http_method method, + struct ast_variable *get_params, + struct ast_variable *headers) +{ + RAII_VAR(struct conf *, cfg, ao2_global_obj_ref(confs), ao2_cleanup); + RAII_VAR(struct ast_str *, response_headers, ast_str_create(40), ast_free); + RAII_VAR(struct ast_str *, response_body, ast_str_create(256), ast_free); + struct stasis_http_response response = {}; + int ret = 0; + + if (!response_headers || !response_body) { + return -1; + } + + response.headers = ast_str_create(40); + + process_cors_request(headers, &response); + + if (ast_ends_with(uri, "/")) { + remove_trailing_slash(uri, &response); + } else if (ast_begins_with(uri, "api-docs/")) { + /* Serving up API docs */ + if (method != AST_HTTP_GET) { + response.message = + ast_json_pack("{s: s}", + "message", "Unsupported method"); + response.response_code = 405; + response.response_text = "Method Not Allowed"; + } else { + /* Skip the api-docs prefix */ + stasis_http_get_docs(strchr(uri, '/') + 1, headers, &response); + } + } else { + /* Other RESTful resources */ + stasis_http_invoke(uri, method, get_params, headers, &response); + } + + /* Leaving message unset is only allowed for 204 (No Content). + * If you explicitly want to have no content for a different return + * code, set message to ast_json_null(). + */ + ast_assert(response.response_code == 204 || response.message != NULL); + ast_assert(response.response_code > 0); + + ast_str_append(&response_headers, 0, "%s", ast_str_buffer(response.headers)); + + /* response.message could be NULL, in which case the empty response_body + * is correct + */ + if (response.message && !ast_json_is_null(response.message)) { + ast_str_append(&response_headers, 0, + "Content-type: application/json\r\n"); + if (ast_json_dump_str_format(response.message, &response_body, cfg->global->format) != 0) { + /* Error encoding response */ + response.response_code = 500; + response.response_text = "Internal Server Error"; + ast_str_set(&response_body, 0, "%s", ""); + ast_str_set(&response_headers, 0, "%s", ""); + ret = -1; + } + } + + ast_http_send(ser, method, response.response_code, + response.response_text, response_headers, response_body, + 0, 0); + /* ast_http_send takes ownership, so we don't have to free them */ + response_headers = NULL; + response_body = NULL; + + ast_json_unref(response.message); + return ret; +} + +static struct ast_http_uri http_uri = { + .callback = stasis_http_callback, + .description = "Asterisk RESTful API", + .uri = "stasis", + + .has_subtree = 1, + .data = NULL, + .key = __FILE__, +}; + +static int load_module(void) +{ + ast_mutex_init(&root_handler_lock); + root_handler = root_handler_create(); + if (!root_handler) { + return AST_MODULE_LOAD_FAILURE; + } + + if (aco_info_init(&cfg_info)) { + aco_info_destroy(&cfg_info); + return AST_MODULE_LOAD_DECLINE; + } + + aco_option_register_custom(&cfg_info, "enabled", ACO_EXACT, global_options, + "yes", conf_bitfield_handler, 0); + aco_option_register_custom(&cfg_info, "pretty", ACO_EXACT, global_options, + "no", encoding_format_handler, 0); + + if (aco_process_config(&cfg_info, 0)) { + aco_info_destroy(&cfg_info); + return AST_MODULE_LOAD_DECLINE; + } + + alloc_failed_message = ast_json_pack( + "{s: s}", "message", "Allocation failed"); + + if (is_enabled()) { + ast_http_uri_link(&http_uri); + } + + return AST_MODULE_LOAD_SUCCESS; +} + +static int unload_module(void) +{ + ast_json_unref(alloc_failed_message); + alloc_failed_message = NULL; + + if (is_enabled()) { + ast_http_uri_unlink(&http_uri); + } + + aco_info_destroy(&cfg_info); + ao2_global_obj_release(confs); + + ao2_cleanup(root_handler); + ast_mutex_destroy(&root_handler_lock); + + return 0; +} + +static int reload_module(void) +{ + char was_enabled = is_enabled(); + + if (aco_process_config(&cfg_info, 1)) { + return AST_MODULE_LOAD_DECLINE; + } + + if (was_enabled && !is_enabled()) { + ast_http_uri_unlink(&http_uri); + } else if (!was_enabled && is_enabled()) { + ast_http_uri_link(&http_uri); + } + + return AST_MODULE_LOAD_SUCCESS; +} + +AST_MODULE_INFO(ASTERISK_GPL_KEY, + AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, + "Stasis HTTP bindings", + .load = load_module, + .unload = unload_module, + .reload = reload_module, + .nonoptreq = "app_stasis", + .load_pri = AST_MODPRI_APP_DEPEND, + ); diff --git a/res/res_stasis_http.exports.in b/res/res_stasis_http.exports.in new file mode 100644 index 000000000..726a86424 --- /dev/null +++ b/res/res_stasis_http.exports.in @@ -0,0 +1,6 @@ +{ + global: + LINKER_SYMBOL_PREFIXstasis_http_*; + local: + *; +}; diff --git a/res/res_stasis_http_asterisk.c b/res/res_stasis_http_asterisk.c new file mode 100644 index 000000000..333c66b5c --- /dev/null +++ b/res/res_stasis_http_asterisk.c @@ -0,0 +1,103 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/res_stasis_http_resource.c.mustache + */ + +/*! \file + * + * \brief Asterisk resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/*** MODULEINFO + <depend type="module">res_stasis_http</depend> + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "asterisk/module.h" +#include "stasis_http/resource_asterisk.h" + +/*! + * \brief Parameter parsing callback for /asterisk/info. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_asterisk_info_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_asterisk_info_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "only") == 0) { + args.only = (i->value); + } else + {} + } + stasis_http_get_asterisk_info(headers, &args, response); +} + +/*! \brief REST handler for /api-docs/asterisk.{format} */ +static struct stasis_rest_handlers asterisk_info = { + .path_segment = "info", + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_asterisk_info_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/asterisk.{format} */ +static struct stasis_rest_handlers asterisk = { + .path_segment = "asterisk", + .callbacks = { + }, + .num_children = 1, + .children = { &asterisk_info, } +}; + +static int load_module(void) +{ + return stasis_http_add_handler(&asterisk); +} + +static int unload_module(void) +{ + stasis_http_remove_handler(&asterisk); + return 0; +} + +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, + "RESTful API module - Asterisk resources", + .load = load_module, + .unload = unload_module, + .nonoptreq = "res_stasis_http", + ); diff --git a/res/res_stasis_http_bridges.c b/res/res_stasis_http_bridges.c new file mode 100644 index 000000000..48d5b7277 --- /dev/null +++ b/res/res_stasis_http_bridges.c @@ -0,0 +1,291 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/res_stasis_http_resource.c.mustache + */ + +/*! \file + * + * \brief Bridge resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/*** MODULEINFO + <depend type="module">res_stasis_http</depend> + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "asterisk/module.h" +#include "stasis_http/resource_bridges.h" + +/*! + * \brief Parameter parsing callback for /bridges. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_bridges_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_bridges_args args = {}; + stasis_http_get_bridges(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /bridges. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_new_bridge_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_new_bridge_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "type") == 0) { + args.type = (i->value); + } else + {} + } + stasis_http_new_bridge(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /bridges/{bridgeId}. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_bridge_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_bridge_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "bridgeId") == 0) { + args.bridge_id = (i->value); + } else + {} + } + stasis_http_get_bridge(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /bridges/{bridgeId}. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_delete_bridge_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_delete_bridge_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "bridgeId") == 0) { + args.bridge_id = (i->value); + } else + {} + } + stasis_http_delete_bridge(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /bridges/{bridgeId}/addChannel. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_add_channel_to_bridge_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_add_channel_to_bridge_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "channel") == 0) { + args.channel = (i->value); + } else + {} + } + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "bridgeId") == 0) { + args.bridge_id = (i->value); + } else + {} + } + stasis_http_add_channel_to_bridge(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /bridges/{bridgeId}/removeChannel. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_remove_channel_from_bridge_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_remove_channel_from_bridge_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "channel") == 0) { + args.channel = (i->value); + } else + {} + } + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "bridgeId") == 0) { + args.bridge_id = (i->value); + } else + {} + } + stasis_http_remove_channel_from_bridge(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /bridges/{bridgeId}/record. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_record_bridge_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_record_bridge_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "name") == 0) { + args.name = (i->value); + } else + if (strcmp(i->name, "maxDurationSeconds") == 0) { + args.max_duration_seconds = atoi(i->value); + } else + if (strcmp(i->name, "maxSilenceSeconds") == 0) { + args.max_silence_seconds = atoi(i->value); + } else + if (strcmp(i->name, "append") == 0) { + args.append = atoi(i->value); + } else + if (strcmp(i->name, "beep") == 0) { + args.beep = atoi(i->value); + } else + if (strcmp(i->name, "terminateOn") == 0) { + args.terminate_on = (i->value); + } else + {} + } + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "bridgeId") == 0) { + args.bridge_id = (i->value); + } else + {} + } + stasis_http_record_bridge(headers, &args, response); +} + +/*! \brief REST handler for /api-docs/bridges.{format} */ +static struct stasis_rest_handlers bridges_bridgeId_addChannel = { + .path_segment = "addChannel", + .callbacks = { + [AST_HTTP_POST] = stasis_http_add_channel_to_bridge_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/bridges.{format} */ +static struct stasis_rest_handlers bridges_bridgeId_removeChannel = { + .path_segment = "removeChannel", + .callbacks = { + [AST_HTTP_POST] = stasis_http_remove_channel_from_bridge_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/bridges.{format} */ +static struct stasis_rest_handlers bridges_bridgeId_record = { + .path_segment = "record", + .callbacks = { + [AST_HTTP_POST] = stasis_http_record_bridge_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/bridges.{format} */ +static struct stasis_rest_handlers bridges_bridgeId = { + .path_segment = "bridgeId", + .is_wildcard = 1, + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_bridge_cb, + [AST_HTTP_DELETE] = stasis_http_delete_bridge_cb, + }, + .num_children = 3, + .children = { &bridges_bridgeId_addChannel,&bridges_bridgeId_removeChannel,&bridges_bridgeId_record, } +}; +/*! \brief REST handler for /api-docs/bridges.{format} */ +static struct stasis_rest_handlers bridges = { + .path_segment = "bridges", + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_bridges_cb, + [AST_HTTP_POST] = stasis_http_new_bridge_cb, + }, + .num_children = 1, + .children = { &bridges_bridgeId, } +}; + +static int load_module(void) +{ + return stasis_http_add_handler(&bridges); +} + +static int unload_module(void) +{ + stasis_http_remove_handler(&bridges); + return 0; +} + +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, + "RESTful API module - Bridge resources", + .load = load_module, + .unload = unload_module, + .nonoptreq = "res_stasis_http", + ); diff --git a/res/res_stasis_http_channels.c b/res/res_stasis_http_channels.c new file mode 100644 index 000000000..c21bc1073 --- /dev/null +++ b/res/res_stasis_http_channels.c @@ -0,0 +1,504 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/res_stasis_http_resource.c.mustache + */ + +/*! \file + * + * \brief Channel resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/*** MODULEINFO + <depend type="module">res_stasis_http</depend> + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "asterisk/module.h" +#include "stasis_http/resource_channels.h" + +/*! + * \brief Parameter parsing callback for /channels. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_channels_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_channels_args args = {}; + stasis_http_get_channels(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /channels. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_originate_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_originate_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "endpoint") == 0) { + args.endpoint = (i->value); + } else + if (strcmp(i->name, "extension") == 0) { + args.extension = (i->value); + } else + if (strcmp(i->name, "context") == 0) { + args.context = (i->value); + } else + {} + } + stasis_http_originate(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /channels/{channelId}. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_channel_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_channel_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "channelId") == 0) { + args.channel_id = (i->value); + } else + {} + } + stasis_http_get_channel(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /channels/{channelId}. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_delete_channel_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_delete_channel_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "channelId") == 0) { + args.channel_id = (i->value); + } else + {} + } + stasis_http_delete_channel(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /channels/{channelId}/dial. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_dial_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_dial_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "endpoint") == 0) { + args.endpoint = (i->value); + } else + if (strcmp(i->name, "extension") == 0) { + args.extension = (i->value); + } else + if (strcmp(i->name, "context") == 0) { + args.context = (i->value); + } else + {} + } + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "channelId") == 0) { + args.channel_id = (i->value); + } else + {} + } + stasis_http_dial(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /channels/{channelId}/continue. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_continue_in_dialplan_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_continue_in_dialplan_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "channelId") == 0) { + args.channel_id = (i->value); + } else + {} + } + stasis_http_continue_in_dialplan(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /channels/{channelId}/answer. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_answer_channel_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_answer_channel_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "channelId") == 0) { + args.channel_id = (i->value); + } else + {} + } + stasis_http_answer_channel(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /channels/{channelId}/mute. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_mute_channel_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_mute_channel_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "direction") == 0) { + args.direction = (i->value); + } else + {} + } + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "channelId") == 0) { + args.channel_id = (i->value); + } else + {} + } + stasis_http_mute_channel(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /channels/{channelId}/unmute. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_unmute_channel_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_unmute_channel_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "direction") == 0) { + args.direction = (i->value); + } else + {} + } + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "channelId") == 0) { + args.channel_id = (i->value); + } else + {} + } + stasis_http_unmute_channel(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /channels/{channelId}/hold. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_hold_channel_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_hold_channel_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "channelId") == 0) { + args.channel_id = (i->value); + } else + {} + } + stasis_http_hold_channel(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /channels/{channelId}/unhold. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_unhold_channel_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_unhold_channel_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "channelId") == 0) { + args.channel_id = (i->value); + } else + {} + } + stasis_http_unhold_channel(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /channels/{channelId}/play. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_play_on_channel_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_play_on_channel_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "media") == 0) { + args.media = (i->value); + } else + {} + } + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "channelId") == 0) { + args.channel_id = (i->value); + } else + {} + } + stasis_http_play_on_channel(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /channels/{channelId}/record. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_record_channel_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_record_channel_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "name") == 0) { + args.name = (i->value); + } else + if (strcmp(i->name, "format") == 0) { + args.format = (i->value); + } else + if (strcmp(i->name, "maxDurationSeconds") == 0) { + args.max_duration_seconds = atoi(i->value); + } else + if (strcmp(i->name, "maxSilenceSeconds") == 0) { + args.max_silence_seconds = atoi(i->value); + } else + if (strcmp(i->name, "append") == 0) { + args.append = atoi(i->value); + } else + if (strcmp(i->name, "beep") == 0) { + args.beep = atoi(i->value); + } else + if (strcmp(i->name, "terminateOn") == 0) { + args.terminate_on = (i->value); + } else + {} + } + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "channelId") == 0) { + args.channel_id = (i->value); + } else + {} + } + stasis_http_record_channel(headers, &args, response); +} + +/*! \brief REST handler for /api-docs/channels.{format} */ +static struct stasis_rest_handlers channels_channelId_dial = { + .path_segment = "dial", + .callbacks = { + [AST_HTTP_POST] = stasis_http_dial_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/channels.{format} */ +static struct stasis_rest_handlers channels_channelId_continue = { + .path_segment = "continue", + .callbacks = { + [AST_HTTP_POST] = stasis_http_continue_in_dialplan_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/channels.{format} */ +static struct stasis_rest_handlers channels_channelId_answer = { + .path_segment = "answer", + .callbacks = { + [AST_HTTP_POST] = stasis_http_answer_channel_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/channels.{format} */ +static struct stasis_rest_handlers channels_channelId_mute = { + .path_segment = "mute", + .callbacks = { + [AST_HTTP_POST] = stasis_http_mute_channel_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/channels.{format} */ +static struct stasis_rest_handlers channels_channelId_unmute = { + .path_segment = "unmute", + .callbacks = { + [AST_HTTP_POST] = stasis_http_unmute_channel_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/channels.{format} */ +static struct stasis_rest_handlers channels_channelId_hold = { + .path_segment = "hold", + .callbacks = { + [AST_HTTP_POST] = stasis_http_hold_channel_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/channels.{format} */ +static struct stasis_rest_handlers channels_channelId_unhold = { + .path_segment = "unhold", + .callbacks = { + [AST_HTTP_POST] = stasis_http_unhold_channel_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/channels.{format} */ +static struct stasis_rest_handlers channels_channelId_play = { + .path_segment = "play", + .callbacks = { + [AST_HTTP_POST] = stasis_http_play_on_channel_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/channels.{format} */ +static struct stasis_rest_handlers channels_channelId_record = { + .path_segment = "record", + .callbacks = { + [AST_HTTP_POST] = stasis_http_record_channel_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/channels.{format} */ +static struct stasis_rest_handlers channels_channelId = { + .path_segment = "channelId", + .is_wildcard = 1, + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_channel_cb, + [AST_HTTP_DELETE] = stasis_http_delete_channel_cb, + }, + .num_children = 9, + .children = { &channels_channelId_dial,&channels_channelId_continue,&channels_channelId_answer,&channels_channelId_mute,&channels_channelId_unmute,&channels_channelId_hold,&channels_channelId_unhold,&channels_channelId_play,&channels_channelId_record, } +}; +/*! \brief REST handler for /api-docs/channels.{format} */ +static struct stasis_rest_handlers channels = { + .path_segment = "channels", + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_channels_cb, + [AST_HTTP_POST] = stasis_http_originate_cb, + }, + .num_children = 1, + .children = { &channels_channelId, } +}; + +static int load_module(void) +{ + return stasis_http_add_handler(&channels); +} + +static int unload_module(void) +{ + stasis_http_remove_handler(&channels); + return 0; +} + +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, + "RESTful API module - Channel resources", + .load = load_module, + .unload = unload_module, + .nonoptreq = "res_stasis_http", + ); diff --git a/res/res_stasis_http_endpoints.c b/res/res_stasis_http_endpoints.c new file mode 100644 index 000000000..a420d4ede --- /dev/null +++ b/res/res_stasis_http_endpoints.c @@ -0,0 +1,127 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/res_stasis_http_resource.c.mustache + */ + +/*! \file + * + * \brief Endpoint resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/*** MODULEINFO + <depend type="module">res_stasis_http</depend> + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "asterisk/module.h" +#include "stasis_http/resource_endpoints.h" + +/*! + * \brief Parameter parsing callback for /endpoints. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_endpoints_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_endpoints_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "withType") == 0) { + args.with_type = (i->value); + } else + {} + } + stasis_http_get_endpoints(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /endpoints/{endpointId}. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_endpoint_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_endpoint_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "endpointId") == 0) { + args.endpoint_id = (i->value); + } else + {} + } + stasis_http_get_endpoint(headers, &args, response); +} + +/*! \brief REST handler for /api-docs/endpoints.{format} */ +static struct stasis_rest_handlers endpoints_endpointId = { + .path_segment = "endpointId", + .is_wildcard = 1, + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_endpoint_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/endpoints.{format} */ +static struct stasis_rest_handlers endpoints = { + .path_segment = "endpoints", + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_endpoints_cb, + }, + .num_children = 1, + .children = { &endpoints_endpointId, } +}; + +static int load_module(void) +{ + return stasis_http_add_handler(&endpoints); +} + +static int unload_module(void) +{ + stasis_http_remove_handler(&endpoints); + return 0; +} + +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, + "RESTful API module - Endpoint resources", + .load = load_module, + .unload = unload_module, + .nonoptreq = "res_stasis_http", + ); diff --git a/res/res_stasis_http_events.c b/res/res_stasis_http_events.c new file mode 100644 index 000000000..62ed44f96 --- /dev/null +++ b/res/res_stasis_http_events.c @@ -0,0 +1,95 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/res_stasis_http_resource.c.mustache + */ + +/*! \file + * + * \brief WebSocket resource + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/*** MODULEINFO + <depend type="module">res_stasis_http</depend> + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "asterisk/module.h" +#include "stasis_http/resource_events.h" + +/*! + * \brief Parameter parsing callback for /events. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_event_websocket_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_event_websocket_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "app") == 0) { + args.app = (i->value); + } else + {} + } + stasis_http_event_websocket(headers, &args, response); +} + +/*! \brief REST handler for /api-docs/events.{format} */ +static struct stasis_rest_handlers events = { + .path_segment = "events", + .callbacks = { + [AST_HTTP_GET] = stasis_http_event_websocket_cb, + }, + .num_children = 0, + .children = { } +}; + +static int load_module(void) +{ + return stasis_http_add_handler(&events); +} + +static int unload_module(void) +{ + stasis_http_remove_handler(&events); + return 0; +} + +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, + "RESTful API module - WebSocket resource", + .load = load_module, + .unload = unload_module, + .nonoptreq = "res_stasis_http", + ); diff --git a/res/res_stasis_http_playback.c b/res/res_stasis_http_playback.c new file mode 100644 index 000000000..77dcee41c --- /dev/null +++ b/res/res_stasis_http_playback.c @@ -0,0 +1,164 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/res_stasis_http_resource.c.mustache + */ + +/*! \file + * + * \brief Playback control resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/*** MODULEINFO + <depend type="module">res_stasis_http</depend> + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "asterisk/module.h" +#include "stasis_http/resource_playback.h" + +/*! + * \brief Parameter parsing callback for /playback/{playbackId}. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_playback_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_playback_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "playbackId") == 0) { + args.playback_id = (i->value); + } else + {} + } + stasis_http_get_playback(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /playback/{playbackId}. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_stop_playback_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_stop_playback_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "playbackId") == 0) { + args.playback_id = (i->value); + } else + {} + } + stasis_http_stop_playback(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /playback/{playbackId}/control. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_control_playback_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_control_playback_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "operation") == 0) { + args.operation = (i->value); + } else + {} + } + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "playbackId") == 0) { + args.playback_id = (i->value); + } else + {} + } + stasis_http_control_playback(headers, &args, response); +} + +/*! \brief REST handler for /api-docs/playback.{format} */ +static struct stasis_rest_handlers playback_playbackId_control = { + .path_segment = "control", + .callbacks = { + [AST_HTTP_POST] = stasis_http_control_playback_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/playback.{format} */ +static struct stasis_rest_handlers playback_playbackId = { + .path_segment = "playbackId", + .is_wildcard = 1, + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_playback_cb, + [AST_HTTP_DELETE] = stasis_http_stop_playback_cb, + }, + .num_children = 1, + .children = { &playback_playbackId_control, } +}; +/*! \brief REST handler for /api-docs/playback.{format} */ +static struct stasis_rest_handlers playback = { + .path_segment = "playback", + .callbacks = { + }, + .num_children = 1, + .children = { &playback_playbackId, } +}; + +static int load_module(void) +{ + return stasis_http_add_handler(&playback); +} + +static int unload_module(void) +{ + stasis_http_remove_handler(&playback); + return 0; +} + +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, + "RESTful API module - Playback control resources", + .load = load_module, + .unload = unload_module, + .nonoptreq = "res_stasis_http", + ); diff --git a/res/res_stasis_http_recordings.c b/res/res_stasis_http_recordings.c new file mode 100644 index 000000000..b6a3b418e --- /dev/null +++ b/res/res_stasis_http_recordings.c @@ -0,0 +1,398 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/res_stasis_http_resource.c.mustache + */ + +/*! \file + * + * \brief Recording resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/*** MODULEINFO + <depend type="module">res_stasis_http</depend> + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "asterisk/module.h" +#include "stasis_http/resource_recordings.h" + +/*! + * \brief Parameter parsing callback for /recordings. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_recordings_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_recordings_args args = {}; + stasis_http_get_recordings(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /recordings/stored. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_stored_recordings_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_stored_recordings_args args = {}; + stasis_http_get_stored_recordings(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /recordings/stored/{recordingId}. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_stored_recording_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_stored_recording_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "recordingId") == 0) { + args.recording_id = (i->value); + } else + {} + } + stasis_http_get_stored_recording(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /recordings/stored/{recordingId}. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_delete_stored_recording_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_delete_stored_recording_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "recordingId") == 0) { + args.recording_id = (i->value); + } else + {} + } + stasis_http_delete_stored_recording(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /recordings/live. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_live_recordings_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_live_recordings_args args = {}; + stasis_http_get_live_recordings(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /recordings/live/{recordingId}. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_live_recording_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_live_recording_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "recordingId") == 0) { + args.recording_id = (i->value); + } else + {} + } + stasis_http_get_live_recording(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /recordings/live/{recordingId}. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_cancel_recording_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_cancel_recording_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "recordingId") == 0) { + args.recording_id = (i->value); + } else + {} + } + stasis_http_cancel_recording(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /recordings/live/{recordingId}/stop. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_stop_recording_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_stop_recording_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "recordingId") == 0) { + args.recording_id = (i->value); + } else + {} + } + stasis_http_stop_recording(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /recordings/live/{recordingId}/pause. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_pause_recording_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_pause_recording_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "recordingId") == 0) { + args.recording_id = (i->value); + } else + {} + } + stasis_http_pause_recording(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /recordings/live/{recordingId}/unpause. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_unpause_recording_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_unpause_recording_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "recordingId") == 0) { + args.recording_id = (i->value); + } else + {} + } + stasis_http_unpause_recording(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /recordings/live/{recordingId}/mute. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_mute_recording_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_mute_recording_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "recordingId") == 0) { + args.recording_id = (i->value); + } else + {} + } + stasis_http_mute_recording(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /recordings/live/{recordingId}/unmute. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_unmute_recording_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_unmute_recording_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "recordingId") == 0) { + args.recording_id = (i->value); + } else + {} + } + stasis_http_unmute_recording(headers, &args, response); +} + +/*! \brief REST handler for /api-docs/recordings.{format} */ +static struct stasis_rest_handlers recordings_stored_recordingId = { + .path_segment = "recordingId", + .is_wildcard = 1, + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_stored_recording_cb, + [AST_HTTP_DELETE] = stasis_http_delete_stored_recording_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/recordings.{format} */ +static struct stasis_rest_handlers recordings_stored = { + .path_segment = "stored", + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_stored_recordings_cb, + }, + .num_children = 1, + .children = { &recordings_stored_recordingId, } +}; +/*! \brief REST handler for /api-docs/recordings.{format} */ +static struct stasis_rest_handlers recordings_live_recordingId_stop = { + .path_segment = "stop", + .callbacks = { + [AST_HTTP_POST] = stasis_http_stop_recording_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/recordings.{format} */ +static struct stasis_rest_handlers recordings_live_recordingId_pause = { + .path_segment = "pause", + .callbacks = { + [AST_HTTP_POST] = stasis_http_pause_recording_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/recordings.{format} */ +static struct stasis_rest_handlers recordings_live_recordingId_unpause = { + .path_segment = "unpause", + .callbacks = { + [AST_HTTP_POST] = stasis_http_unpause_recording_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/recordings.{format} */ +static struct stasis_rest_handlers recordings_live_recordingId_mute = { + .path_segment = "mute", + .callbacks = { + [AST_HTTP_POST] = stasis_http_mute_recording_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/recordings.{format} */ +static struct stasis_rest_handlers recordings_live_recordingId_unmute = { + .path_segment = "unmute", + .callbacks = { + [AST_HTTP_POST] = stasis_http_unmute_recording_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/recordings.{format} */ +static struct stasis_rest_handlers recordings_live_recordingId = { + .path_segment = "recordingId", + .is_wildcard = 1, + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_live_recording_cb, + [AST_HTTP_DELETE] = stasis_http_cancel_recording_cb, + }, + .num_children = 5, + .children = { &recordings_live_recordingId_stop,&recordings_live_recordingId_pause,&recordings_live_recordingId_unpause,&recordings_live_recordingId_mute,&recordings_live_recordingId_unmute, } +}; +/*! \brief REST handler for /api-docs/recordings.{format} */ +static struct stasis_rest_handlers recordings_live = { + .path_segment = "live", + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_live_recordings_cb, + }, + .num_children = 1, + .children = { &recordings_live_recordingId, } +}; +/*! \brief REST handler for /api-docs/recordings.{format} */ +static struct stasis_rest_handlers recordings = { + .path_segment = "recordings", + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_recordings_cb, + }, + .num_children = 2, + .children = { &recordings_stored,&recordings_live, } +}; + +static int load_module(void) +{ + return stasis_http_add_handler(&recordings); +} + +static int unload_module(void) +{ + stasis_http_remove_handler(&recordings); + return 0; +} + +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, + "RESTful API module - Recording resources", + .load = load_module, + .unload = unload_module, + .nonoptreq = "res_stasis_http", + ); diff --git a/res/res_stasis_http_sounds.c b/res/res_stasis_http_sounds.c new file mode 100644 index 000000000..39ad71e52 --- /dev/null +++ b/res/res_stasis_http_sounds.c @@ -0,0 +1,130 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/res_stasis_http_resource.c.mustache + */ + +/*! \file + * + * \brief Sound resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/*** MODULEINFO + <depend type="module">res_stasis_http</depend> + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "asterisk/module.h" +#include "stasis_http/resource_sounds.h" + +/*! + * \brief Parameter parsing callback for /sounds. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_sounds_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_sounds_args args = {}; + struct ast_variable *i; + + for (i = get_params; i; i = i->next) { + if (strcmp(i->name, "lang") == 0) { + args.lang = (i->value); + } else + if (strcmp(i->name, "format") == 0) { + args.format = (i->value); + } else + {} + } + stasis_http_get_sounds(headers, &args, response); +} +/*! + * \brief Parameter parsing callback for /sounds/{soundId}. + * \param get_params GET parameters in the HTTP request. + * \param path_vars Path variables extracted from the request. + * \param headers HTTP headers. + * \param[out] response Response to the HTTP request. + */ +static void stasis_http_get_stored_sound_cb( + struct ast_variable *get_params, struct ast_variable *path_vars, + struct ast_variable *headers, struct stasis_http_response *response) +{ + struct ast_get_stored_sound_args args = {}; + struct ast_variable *i; + + for (i = path_vars; i; i = i->next) { + if (strcmp(i->name, "soundId") == 0) { + args.sound_id = (i->value); + } else + {} + } + stasis_http_get_stored_sound(headers, &args, response); +} + +/*! \brief REST handler for /api-docs/sounds.{format} */ +static struct stasis_rest_handlers sounds_soundId = { + .path_segment = "soundId", + .is_wildcard = 1, + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_stored_sound_cb, + }, + .num_children = 0, + .children = { } +}; +/*! \brief REST handler for /api-docs/sounds.{format} */ +static struct stasis_rest_handlers sounds = { + .path_segment = "sounds", + .callbacks = { + [AST_HTTP_GET] = stasis_http_get_sounds_cb, + }, + .num_children = 1, + .children = { &sounds_soundId, } +}; + +static int load_module(void) +{ + return stasis_http_add_handler(&sounds); +} + +static int unload_module(void) +{ + stasis_http_remove_handler(&sounds); + return 0; +} + +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, + "RESTful API module - Sound resources", + .load = load_module, + .unload = unload_module, + .nonoptreq = "res_stasis_http", + ); diff --git a/res/stasis_http.make b/res/stasis_http.make new file mode 100644 index 000000000..3d80e5e88 --- /dev/null +++ b/res/stasis_http.make @@ -0,0 +1,51 @@ +# +# Asterisk -- A telephony toolkit for Linux. +# +# Generated Makefile for res_stasis_http dependencies. +# +# Copyright (C) 2013, Digium, Inc. +# +# This program is free software, distributed under the terms of +# the GNU General Public License +# + +# +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# !!!!! DO NOT EDIT !!!!! +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# This file is generated by a template. Please see the original template at +# rest-api-templates/stasis_http.make.mustache +# + +res_stasis_http_asterisk.so: stasis_http/resource_asterisk.o + +stasis_http/resource_asterisk.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_stasis_http_asterisk) + +res_stasis_http_endpoints.so: stasis_http/resource_endpoints.o + +stasis_http/resource_endpoints.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_stasis_http_endpoints) + +res_stasis_http_channels.so: stasis_http/resource_channels.o + +stasis_http/resource_channels.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_stasis_http_channels) + +res_stasis_http_bridges.so: stasis_http/resource_bridges.o + +stasis_http/resource_bridges.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_stasis_http_bridges) + +res_stasis_http_recordings.so: stasis_http/resource_recordings.o + +stasis_http/resource_recordings.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_stasis_http_recordings) + +res_stasis_http_sounds.so: stasis_http/resource_sounds.o + +stasis_http/resource_sounds.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_stasis_http_sounds) + +res_stasis_http_playback.so: stasis_http/resource_playback.o + +stasis_http/resource_playback.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_stasis_http_playback) + +res_stasis_http_events.so: stasis_http/resource_events.o + +stasis_http/resource_events.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_stasis_http_events) + diff --git a/res/stasis_http/resource_asterisk.c b/res/stasis_http/resource_asterisk.c new file mode 100644 index 000000000..b5e8b0f54 --- /dev/null +++ b/res/stasis_http/resource_asterisk.c @@ -0,0 +1,39 @@ +/* -*- C -*- + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief Implementation for stasis-http stubs. + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/*** MODULEINFO + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "resource_asterisk.h" + +void stasis_http_get_asterisk_info(struct ast_variable *headers, struct ast_get_asterisk_info_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_get_asterisk_info\n"); +} diff --git a/res/stasis_http/resource_asterisk.h b/res/stasis_http/resource_asterisk.h new file mode 100644 index 000000000..0d373ccb2 --- /dev/null +++ b/res/stasis_http/resource_asterisk.h @@ -0,0 +1,56 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief Generated file - declares stubs to be implemented in + * res/stasis_http/resource_asterisk.c + * + * Asterisk resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/stasis_http_resource.h.mustache + */ + +#ifndef _ASTERISK_RESOURCE_ASTERISK_H +#define _ASTERISK_RESOURCE_ASTERISK_H + +#include "asterisk/stasis_http.h" + +/*! \brief Argument struct for stasis_http_get_asterisk_info() */ +struct ast_get_asterisk_info_args { + /*! \brief Filter information returned */ + const char *only; +}; +/*! + * \brief Gets Asterisk system information. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_asterisk_info(struct ast_variable *headers, struct ast_get_asterisk_info_args *args, struct stasis_http_response *response); + +#endif /* _ASTERISK_RESOURCE_ASTERISK_H */ diff --git a/res/stasis_http/resource_bridges.c b/res/stasis_http/resource_bridges.c new file mode 100644 index 000000000..ca48ee725 --- /dev/null +++ b/res/stasis_http/resource_bridges.c @@ -0,0 +1,63 @@ +/* -*- C -*- + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief Implementation for stasis-http stubs. + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/*** MODULEINFO + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "resource_bridges.h" + +void stasis_http_add_channel_to_bridge(struct ast_variable *headers, struct ast_add_channel_to_bridge_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_add_channel_to_bridge\n"); +} +void stasis_http_remove_channel_from_bridge(struct ast_variable *headers, struct ast_remove_channel_from_bridge_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_remove_channel_from_bridge\n"); +} +void stasis_http_record_bridge(struct ast_variable *headers, struct ast_record_bridge_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_record_bridge\n"); +} +void stasis_http_get_bridge(struct ast_variable *headers, struct ast_get_bridge_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_get_bridge\n"); +} +void stasis_http_delete_bridge(struct ast_variable *headers, struct ast_delete_bridge_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_delete_bridge\n"); +} +void stasis_http_get_bridges(struct ast_variable *headers, struct ast_get_bridges_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_get_bridges\n"); +} +void stasis_http_new_bridge(struct ast_variable *headers, struct ast_new_bridge_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_new_bridge\n"); +} diff --git a/res/stasis_http/resource_bridges.h b/res/stasis_http/resource_bridges.h new file mode 100644 index 000000000..db6db205b --- /dev/null +++ b/res/stasis_http/resource_bridges.h @@ -0,0 +1,154 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief Generated file - declares stubs to be implemented in + * res/stasis_http/resource_bridges.c + * + * Bridge resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/stasis_http_resource.h.mustache + */ + +#ifndef _ASTERISK_RESOURCE_BRIDGES_H +#define _ASTERISK_RESOURCE_BRIDGES_H + +#include "asterisk/stasis_http.h" + +/*! \brief Argument struct for stasis_http_get_bridges() */ +struct ast_get_bridges_args { +}; +/*! + * \brief List active bridges. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_bridges(struct ast_variable *headers, struct ast_get_bridges_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_new_bridge() */ +struct ast_new_bridge_args { + /*! \brief Type of bridge to create. */ + const char *type; +}; +/*! + * \brief Create a new bridge. + * + * This bridge persists until it has been shut down, or Asterisk has been shut down. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_new_bridge(struct ast_variable *headers, struct ast_new_bridge_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_get_bridge() */ +struct ast_get_bridge_args { + /*! \brief Bridge's id */ + const char *bridge_id; +}; +/*! + * \brief Get bridge details. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_bridge(struct ast_variable *headers, struct ast_get_bridge_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_delete_bridge() */ +struct ast_delete_bridge_args { + /*! \brief Bridge's id */ + const char *bridge_id; +}; +/*! + * \brief Shut down a bridge bridge. + * + * If any channels are in this bridge, they will be removed and resume whatever they were doing beforehand. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_delete_bridge(struct ast_variable *headers, struct ast_delete_bridge_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_add_channel_to_bridge() */ +struct ast_add_channel_to_bridge_args { + /*! \brief Bridge's id */ + const char *bridge_id; + /*! \brief Channel's id */ + const char *channel; +}; +/*! + * \brief Add a channel to a bridge. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_add_channel_to_bridge(struct ast_variable *headers, struct ast_add_channel_to_bridge_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_remove_channel_from_bridge() */ +struct ast_remove_channel_from_bridge_args { + /*! \brief Bridge's id */ + const char *bridge_id; + /*! \brief Channel's id */ + const char *channel; +}; +/*! + * \brief Remove a channel from a bridge. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_remove_channel_from_bridge(struct ast_variable *headers, struct ast_remove_channel_from_bridge_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_record_bridge() */ +struct ast_record_bridge_args { + /*! \brief Bridge's id */ + const char *bridge_id; + /*! \brief Recording's filename */ + const char *name; + /*! \brief Maximum duration of the recording, in seconds. 0 for no limit. */ + int max_duration_seconds; + /*! \brief Maximum duration of silence, in seconds. 0 for no limit. */ + int max_silence_seconds; + /*! \brief If true, and recording already exists, append to recording. */ + int append; + /*! \brief Play beep when recording begins */ + int beep; + /*! \brief DTMF input to terminate recording. */ + const char *terminate_on; +}; +/*! + * \brief Start a recording. + * + * This records the mixed audio from all channels participating in this bridge. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_record_bridge(struct ast_variable *headers, struct ast_record_bridge_args *args, struct stasis_http_response *response); + +#endif /* _ASTERISK_RESOURCE_BRIDGES_H */ diff --git a/res/stasis_http/resource_channels.c b/res/stasis_http/resource_channels.c new file mode 100644 index 000000000..3cc97c511 --- /dev/null +++ b/res/stasis_http/resource_channels.c @@ -0,0 +1,251 @@ +/* -*- C -*- + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief Implementation for stasis-http stubs. + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/*** MODULEINFO + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "asterisk/stasis_app.h" +#include "asterisk/stasis_channels.h" +#include "resource_channels.h" + +/*! + * \brief Finds the control object for a channel, filling the response with an + * error, if appropriate. + * \param[out] response Response to fill with an error if control is not found. + * \param channel_id ID of the channel to lookup. + * \return Channel control object. + * \return \c NULL if control object does not exist. + */ +static struct stasis_app_control *find_control( + struct stasis_http_response *response, + const char *channel_id) +{ + RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup); + + ast_assert(response != NULL); + + control = stasis_app_control_find_by_channel_id(channel_id); + if (control == NULL) { + /* Distinguish between 404 and 409 errors */ + RAII_VAR(struct ast_channel *, chan, NULL, ao2_cleanup); + chan = ast_channel_get_by_name(channel_id); + if (chan == NULL) { + stasis_http_response_error(response, 404, "Not Found", + "Channel not found"); + return NULL; + } + + stasis_http_response_error(response, 409, "Conflict", + "Channel not in Stasis application"); + return NULL; + } + + ao2_ref(control, +1); + return control; +} + +void stasis_http_dial(struct ast_variable *headers, struct ast_dial_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_dial\n"); +} + +void stasis_http_continue_in_dialplan( + struct ast_variable *headers, + struct ast_continue_in_dialplan_args *args, + struct stasis_http_response *response) +{ + RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup); + + ast_assert(response != NULL); + + control = find_control(response, args->channel_id); + if (control == NULL) { + return; + } + + stasis_app_control_continue(control); + stasis_http_response_no_content(response); +} + +void stasis_http_answer_channel(struct ast_variable *headers, + struct ast_answer_channel_args *args, + struct stasis_http_response *response) +{ + RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup); + + control = find_control(response, args->channel_id); + if (control == NULL) { + return; + } + + if (stasis_app_control_answer(control) != 0) { + stasis_http_response_error( + response, 500, "Internal Server Error", + "Failed to answer channel"); + return; + } + + stasis_http_response_no_content(response); +} + +void stasis_http_mute_channel(struct ast_variable *headers, struct ast_mute_channel_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_mute_channel\n"); +} +void stasis_http_unmute_channel(struct ast_variable *headers, struct ast_unmute_channel_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_unmute_channel\n"); +} +void stasis_http_hold_channel(struct ast_variable *headers, struct ast_hold_channel_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_hold_channel\n"); +} +void stasis_http_unhold_channel(struct ast_variable *headers, struct ast_unhold_channel_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_unhold_channel\n"); +} +void stasis_http_play_on_channel(struct ast_variable *headers, struct ast_play_on_channel_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_play_on_channel\n"); +} +void stasis_http_record_channel(struct ast_variable *headers, struct ast_record_channel_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_record_channel\n"); +} +void stasis_http_get_channel(struct ast_variable *headers, + struct ast_get_channel_args *args, + struct stasis_http_response *response) +{ + RAII_VAR(struct stasis_caching_topic *, caching_topic, NULL, ao2_cleanup); + RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); + struct ast_channel_snapshot *snapshot; + + caching_topic = ast_channel_topic_all_cached(); + if (!caching_topic) { + stasis_http_response_error( + response, 500, "Internal Server Error", + "Message bus not initialized"); + return; + } + ao2_ref(caching_topic, +1); + + msg = stasis_cache_get(caching_topic, ast_channel_snapshot_type(), + args->channel_id); + if (!msg) { + stasis_http_response_error( + response, 404, "Not Found", + "Channel not found"); + return; + } + + snapshot = stasis_message_data(msg); + ast_assert(snapshot != NULL); + + stasis_http_response_ok(response, + ast_channel_snapshot_to_json(snapshot)); +} + +void stasis_http_delete_channel(struct ast_variable *headers, + struct ast_delete_channel_args *args, + struct stasis_http_response *response) +{ + RAII_VAR(struct ast_channel *, chan, NULL, ao2_cleanup); + + chan = ast_channel_get_by_name(args->channel_id); + if (chan == NULL) { + stasis_http_response_error( + response, 404, "Not Found", + "Channel not found"); + return; + } + + ast_softhangup(chan, AST_SOFTHANGUP_EXPLICIT); + + stasis_http_response_no_content(response); +} + +void stasis_http_get_channels(struct ast_variable *headers, + struct ast_get_channels_args *args, + struct stasis_http_response *response) +{ + RAII_VAR(struct stasis_caching_topic *, caching_topic, NULL, ao2_cleanup); + RAII_VAR(struct ao2_container *, snapshots, NULL, ao2_cleanup); + RAII_VAR(struct ast_json *, json, NULL, ast_json_unref); + struct ao2_iterator i; + void *obj; + + caching_topic = ast_channel_topic_all_cached(); + if (!caching_topic) { + stasis_http_response_error( + response, 500, "Internal Server Error", + "Message bus not initialized"); + return; + } + ao2_ref(caching_topic, +1); + + snapshots = stasis_cache_dump(caching_topic, ast_channel_snapshot_type()); + if (!snapshots) { + stasis_http_response_alloc_failed(response); + return; + } + + json = ast_json_array_create(); + if (!json) { + stasis_http_response_alloc_failed(response); + return; + } + + i = ao2_iterator_init(snapshots, 0); + while ((obj = ao2_iterator_next(&i))) { + RAII_VAR(struct stasis_message *, msg, obj, ao2_cleanup); + struct ast_channel_snapshot *snapshot = stasis_message_data(msg); + int r = ast_json_array_append( + json, ast_channel_snapshot_to_json(snapshot)); + if (r != 0) { + stasis_http_response_alloc_failed(response); + return; + } + } + ao2_iterator_destroy(&i); + + stasis_http_response_ok(response, ast_json_ref(json)); +} + +void stasis_http_originate(struct ast_variable *headers, + struct ast_originate_args *args, + struct stasis_http_response *response) +{ + if (args->endpoint) { + ast_log(LOG_DEBUG, "Dialing specific endpoint %s\n", args->endpoint); + } + + ast_log(LOG_DEBUG, "Dialing %s@%s\n", args->extension, args->context); + /* ast_pbx_outgoing_app - originates a channel, putting it into an application */ +} diff --git a/res/stasis_http/resource_channels.h b/res/stasis_http/resource_channels.h new file mode 100644 index 000000000..2c78589b7 --- /dev/null +++ b/res/stasis_http/resource_channels.h @@ -0,0 +1,244 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief Generated file - declares stubs to be implemented in + * res/stasis_http/resource_channels.c + * + * Channel resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/stasis_http_resource.h.mustache + */ + +#ifndef _ASTERISK_RESOURCE_CHANNELS_H +#define _ASTERISK_RESOURCE_CHANNELS_H + +#include "asterisk/stasis_http.h" + +/*! \brief Argument struct for stasis_http_get_channels() */ +struct ast_get_channels_args { +}; +/*! + * \brief List active channels. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_channels(struct ast_variable *headers, struct ast_get_channels_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_originate() */ +struct ast_originate_args { + /*! \brief Endpoint to call. If not specified, originate is routed via dialplan */ + const char *endpoint; + /*! \brief Extension to dial */ + const char *extension; + /*! \brief When routing via dialplan, the context use. If omitted, uses 'default' */ + const char *context; +}; +/*! + * \brief Create a new channel (originate). + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_originate(struct ast_variable *headers, struct ast_originate_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_get_channel() */ +struct ast_get_channel_args { + /*! \brief Channel's id */ + const char *channel_id; +}; +/*! + * \brief Channel details. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_channel(struct ast_variable *headers, struct ast_get_channel_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_delete_channel() */ +struct ast_delete_channel_args { + /*! \brief Channel's id */ + const char *channel_id; +}; +/*! + * \brief Delete (i.e. hangup) a channel. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_delete_channel(struct ast_variable *headers, struct ast_delete_channel_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_dial() */ +struct ast_dial_args { + /*! \brief Channel's id */ + const char *channel_id; + /*! \brief Endpoint to call. If not specified, dial is routed via dialplan */ + const char *endpoint; + /*! \brief Extension to dial */ + const char *extension; + /*! \brief When routing via dialplan, the context use. If omitted, uses 'default' */ + const char *context; +}; +/*! + * \brief Create a new channel (originate) and bridge to this channel. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_dial(struct ast_variable *headers, struct ast_dial_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_continue_in_dialplan() */ +struct ast_continue_in_dialplan_args { + /*! \brief Channel's id */ + const char *channel_id; +}; +/*! + * \brief Exit application; continue execution in the dialplan. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_continue_in_dialplan(struct ast_variable *headers, struct ast_continue_in_dialplan_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_answer_channel() */ +struct ast_answer_channel_args { + /*! \brief Channel's id */ + const char *channel_id; +}; +/*! + * \brief Answer a channel. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_answer_channel(struct ast_variable *headers, struct ast_answer_channel_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_mute_channel() */ +struct ast_mute_channel_args { + /*! \brief Channel's id */ + const char *channel_id; + /*! \brief Direction in which to mute audio */ + const char *direction; +}; +/*! + * \brief Mute a channel. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_mute_channel(struct ast_variable *headers, struct ast_mute_channel_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_unmute_channel() */ +struct ast_unmute_channel_args { + /*! \brief Channel's id */ + const char *channel_id; + /*! \brief Direction in which to unmute audio */ + const char *direction; +}; +/*! + * \brief Unmute a channel. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_unmute_channel(struct ast_variable *headers, struct ast_unmute_channel_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_hold_channel() */ +struct ast_hold_channel_args { + /*! \brief Channel's id */ + const char *channel_id; +}; +/*! + * \brief Hold a channel. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_hold_channel(struct ast_variable *headers, struct ast_hold_channel_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_unhold_channel() */ +struct ast_unhold_channel_args { + /*! \brief Channel's id */ + const char *channel_id; +}; +/*! + * \brief Remove a channel from hold. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_unhold_channel(struct ast_variable *headers, struct ast_unhold_channel_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_play_on_channel() */ +struct ast_play_on_channel_args { + /*! \brief Channel's id */ + const char *channel_id; + /*! \brief Media's URI to play. */ + const char *media; +}; +/*! + * \brief Start playback of media. + * + * The media URI may be any of a number of URI's. You may use http: and https: URI's, as well as sound: and recording: URI's. This operation creates a playback resource that can be used to control the playback of media (pause, rewind, fast forward, etc.) + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_play_on_channel(struct ast_variable *headers, struct ast_play_on_channel_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_record_channel() */ +struct ast_record_channel_args { + /*! \brief Channel's id */ + const char *channel_id; + /*! \brief Recording's filename */ + const char *name; + /*! \brief Format to encode audio in */ + const char *format; + /*! \brief Maximum duration of the recording, in seconds. 0 for no limit */ + int max_duration_seconds; + /*! \brief Maximum duration of silence, in seconds. 0 for no limit */ + int max_silence_seconds; + /*! \brief If true, and recording already exists, append to recording */ + int append; + /*! \brief Play beep when recording begins */ + int beep; + /*! \brief DTMF input to terminate recording */ + const char *terminate_on; +}; +/*! + * \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. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_record_channel(struct ast_variable *headers, struct ast_record_channel_args *args, struct stasis_http_response *response); + +#endif /* _ASTERISK_RESOURCE_CHANNELS_H */ diff --git a/res/stasis_http/resource_endpoints.c b/res/stasis_http/resource_endpoints.c new file mode 100644 index 000000000..b2611bad8 --- /dev/null +++ b/res/stasis_http/resource_endpoints.c @@ -0,0 +1,43 @@ +/* -*- C -*- + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief Implementation for stasis-http stubs. + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/*** MODULEINFO + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "resource_endpoints.h" + +void stasis_http_get_endpoint(struct ast_variable *headers, struct ast_get_endpoint_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_get_endpoint\n"); +} +void stasis_http_get_endpoints(struct ast_variable *headers, struct ast_get_endpoints_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_get_endpoints\n"); +} diff --git a/res/stasis_http/resource_endpoints.h b/res/stasis_http/resource_endpoints.h new file mode 100644 index 000000000..57f4b91ba --- /dev/null +++ b/res/stasis_http/resource_endpoints.h @@ -0,0 +1,69 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief Generated file - declares stubs to be implemented in + * res/stasis_http/resource_endpoints.c + * + * Endpoint resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/stasis_http_resource.h.mustache + */ + +#ifndef _ASTERISK_RESOURCE_ENDPOINTS_H +#define _ASTERISK_RESOURCE_ENDPOINTS_H + +#include "asterisk/stasis_http.h" + +/*! \brief Argument struct for stasis_http_get_endpoints() */ +struct ast_get_endpoints_args { + /*! \brief Filter endpoints by type (sip,iax2,dhadi,...) */ + const char *with_type; +}; +/*! + * \brief List available endoints. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_endpoints(struct ast_variable *headers, struct ast_get_endpoints_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_get_endpoint() */ +struct ast_get_endpoint_args { + /*! \brief ID of the endpoint */ + const char *endpoint_id; +}; +/*! + * \brief Details for an endpoint. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_endpoint(struct ast_variable *headers, struct ast_get_endpoint_args *args, struct stasis_http_response *response); + +#endif /* _ASTERISK_RESOURCE_ENDPOINTS_H */ diff --git a/res/stasis_http/resource_events.c b/res/stasis_http/resource_events.c new file mode 100644 index 000000000..34563fe6e --- /dev/null +++ b/res/stasis_http/resource_events.c @@ -0,0 +1,40 @@ +/* -*- C -*- + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief Implementation for stasis-http stubs. + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/*** MODULEINFO + <support_level>core</support_level> + ***/ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "resource_events.h" + +void stasis_http_event_websocket(struct ast_variable *headers, struct ast_event_websocket_args *args, struct stasis_http_response *response) +{ + /* TODO: This should promote this socket to a websocket connection */ + ast_log(LOG_ERROR, "TODO: stasis_http_event_websocket\n"); +} diff --git a/res/stasis_http/resource_events.h b/res/stasis_http/resource_events.h new file mode 100644 index 000000000..0f58476df --- /dev/null +++ b/res/stasis_http/resource_events.h @@ -0,0 +1,58 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief Generated file - declares stubs to be implemented in + * res/stasis_http/resource_events.c + * + * WebSocket resource + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/stasis_http_resource.h.mustache + */ + +#ifndef _ASTERISK_RESOURCE_EVENTS_H +#define _ASTERISK_RESOURCE_EVENTS_H + +#include "asterisk/stasis_http.h" + +/*! \brief Argument struct for stasis_http_event_websocket() */ +struct ast_event_websocket_args { + /*! \brief Comma seperated list of applications to subscribe to. */ + const char *app; + /*! \brief RFC6455 header for upgrading a connection to a websocket. */ + const char *upgrade; +}; +/*! + * \brief WebSocket connection for events. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_event_websocket(struct ast_variable *headers, struct ast_event_websocket_args *args, struct stasis_http_response *response); + +#endif /* _ASTERISK_RESOURCE_EVENTS_H */ diff --git a/res/stasis_http/resource_playback.c b/res/stasis_http/resource_playback.c new file mode 100644 index 000000000..99f2e09eb --- /dev/null +++ b/res/stasis_http/resource_playback.c @@ -0,0 +1,43 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief /api-docs/playback.{format} implementation- Playback control resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "resource_playback.h" + +void stasis_http_get_playback(struct ast_variable *headers, struct ast_get_playback_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_get_playback\n"); +} +void stasis_http_stop_playback(struct ast_variable *headers, struct ast_stop_playback_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_stop_playback\n"); +} +void stasis_http_control_playback(struct ast_variable *headers, struct ast_control_playback_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_control_playback\n"); +} diff --git a/res/stasis_http/resource_playback.h b/res/stasis_http/resource_playback.h new file mode 100644 index 000000000..36b05bc04 --- /dev/null +++ b/res/stasis_http/resource_playback.h @@ -0,0 +1,84 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief Generated file - declares stubs to be implemented in + * res/stasis_http/resource_playback.c + * + * Playback control resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/stasis_http_resource.h.mustache + */ + +#ifndef _ASTERISK_RESOURCE_PLAYBACK_H +#define _ASTERISK_RESOURCE_PLAYBACK_H + +#include "asterisk/stasis_http.h" + +/*! \brief Argument struct for stasis_http_get_playback() */ +struct ast_get_playback_args { + /*! \brief Playback's id */ + const char *playback_id; +}; +/*! + * \brief Get a playback's details. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_playback(struct ast_variable *headers, struct ast_get_playback_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_stop_playback() */ +struct ast_stop_playback_args { + /*! \brief Playback's id */ + const char *playback_id; +}; +/*! + * \brief Stop a playback. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_stop_playback(struct ast_variable *headers, struct ast_stop_playback_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_control_playback() */ +struct ast_control_playback_args { + /*! \brief Playback's id */ + const char *playback_id; + /*! \brief Operation to perform on the playback. */ + const char *operation; +}; +/*! + * \brief Get a playback's details. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_control_playback(struct ast_variable *headers, struct ast_control_playback_args *args, struct stasis_http_response *response); + +#endif /* _ASTERISK_RESOURCE_PLAYBACK_H */ diff --git a/res/stasis_http/resource_recordings.c b/res/stasis_http/resource_recordings.c new file mode 100644 index 000000000..2400a6876 --- /dev/null +++ b/res/stasis_http/resource_recordings.c @@ -0,0 +1,79 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief /api-docs/recordings.{format} implementation- Recording resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "resource_recordings.h" + +void stasis_http_get_recordings(struct ast_variable *headers, struct ast_get_recordings_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_get_recordings\n"); +} +void stasis_http_get_stored_recordings(struct ast_variable *headers, struct ast_get_stored_recordings_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_get_stored_recordings\n"); +} +void stasis_http_get_stored_recording(struct ast_variable *headers, struct ast_get_stored_recording_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_get_stored_recording\n"); +} +void stasis_http_delete_stored_recording(struct ast_variable *headers, struct ast_delete_stored_recording_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_delete_stored_recording\n"); +} +void stasis_http_get_live_recordings(struct ast_variable *headers, struct ast_get_live_recordings_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_get_live_recordings\n"); +} +void stasis_http_get_live_recording(struct ast_variable *headers, struct ast_get_live_recording_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_get_live_recording\n"); +} +void stasis_http_cancel_recording(struct ast_variable *headers, struct ast_cancel_recording_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_cancel_recording\n"); +} +void stasis_http_stop_recording(struct ast_variable *headers, struct ast_stop_recording_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_stop_recording\n"); +} +void stasis_http_pause_recording(struct ast_variable *headers, struct ast_pause_recording_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_pause_recording\n"); +} +void stasis_http_unpause_recording(struct ast_variable *headers, struct ast_unpause_recording_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_unpause_recording\n"); +} +void stasis_http_mute_recording(struct ast_variable *headers, struct ast_mute_recording_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_mute_recording\n"); +} +void stasis_http_unmute_recording(struct ast_variable *headers, struct ast_unmute_recording_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_unmute_recording\n"); +} diff --git a/res/stasis_http/resource_recordings.h b/res/stasis_http/resource_recordings.h new file mode 100644 index 000000000..ee48e43b7 --- /dev/null +++ b/res/stasis_http/resource_recordings.h @@ -0,0 +1,193 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief Generated file - declares stubs to be implemented in + * res/stasis_http/resource_recordings.c + * + * Recording resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/stasis_http_resource.h.mustache + */ + +#ifndef _ASTERISK_RESOURCE_RECORDINGS_H +#define _ASTERISK_RESOURCE_RECORDINGS_H + +#include "asterisk/stasis_http.h" + +/*! \brief Argument struct for stasis_http_get_recordings() */ +struct ast_get_recordings_args { +}; +/*! + * \brief List all recordings. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_recordings(struct ast_variable *headers, struct ast_get_recordings_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_get_stored_recordings() */ +struct ast_get_stored_recordings_args { +}; +/*! + * \brief List recordings that are complete. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_stored_recordings(struct ast_variable *headers, struct ast_get_stored_recordings_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_get_stored_recording() */ +struct ast_get_stored_recording_args { + /*! \brief Recording's id */ + const char *recording_id; +}; +/*! + * \brief Get a stored recording's details. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_stored_recording(struct ast_variable *headers, struct ast_get_stored_recording_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_delete_stored_recording() */ +struct ast_delete_stored_recording_args { + /*! \brief Recording's id */ + const char *recording_id; +}; +/*! + * \brief Delete a stored recording. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_delete_stored_recording(struct ast_variable *headers, struct ast_delete_stored_recording_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_get_live_recordings() */ +struct ast_get_live_recordings_args { +}; +/*! + * \brief List libe recordings. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_live_recordings(struct ast_variable *headers, struct ast_get_live_recordings_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_get_live_recording() */ +struct ast_get_live_recording_args { + /*! \brief Recording's id */ + const char *recording_id; +}; +/*! + * \brief List live recordings. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_live_recording(struct ast_variable *headers, struct ast_get_live_recording_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_cancel_recording() */ +struct ast_cancel_recording_args { + /*! \brief Recording's id */ + const char *recording_id; +}; +/*! + * \brief Stop a live recording and discard it. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_cancel_recording(struct ast_variable *headers, struct ast_cancel_recording_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_stop_recording() */ +struct ast_stop_recording_args { + /*! \brief Recording's id */ + const char *recording_id; +}; +/*! + * \brief Stop a live recording and store it. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_stop_recording(struct ast_variable *headers, struct ast_stop_recording_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_pause_recording() */ +struct ast_pause_recording_args { + /*! \brief Recording's id */ + const char *recording_id; +}; +/*! + * \brief Pause a live recording. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_pause_recording(struct ast_variable *headers, struct ast_pause_recording_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_unpause_recording() */ +struct ast_unpause_recording_args { + /*! \brief Recording's id */ + const char *recording_id; +}; +/*! + * \brief Unpause a live recording. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_unpause_recording(struct ast_variable *headers, struct ast_unpause_recording_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_mute_recording() */ +struct ast_mute_recording_args { + /*! \brief Recording's id */ + const char *recording_id; +}; +/*! + * \brief Mute a live recording. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_mute_recording(struct ast_variable *headers, struct ast_mute_recording_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_unmute_recording() */ +struct ast_unmute_recording_args { + /*! \brief Recording's id */ + const char *recording_id; +}; +/*! + * \brief Unmute a live recording. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_unmute_recording(struct ast_variable *headers, struct ast_unmute_recording_args *args, struct stasis_http_response *response); + +#endif /* _ASTERISK_RESOURCE_RECORDINGS_H */ diff --git a/res/stasis_http/resource_sounds.c b/res/stasis_http/resource_sounds.c new file mode 100644 index 000000000..a1808a159 --- /dev/null +++ b/res/stasis_http/resource_sounds.c @@ -0,0 +1,39 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief /api-docs/sounds.{format} implementation- Sound resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision$") + +#include "resource_sounds.h" + +void stasis_http_get_sounds(struct ast_variable *headers, struct ast_get_sounds_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_get_sounds\n"); +} +void stasis_http_get_stored_sound(struct ast_variable *headers, struct ast_get_stored_sound_args *args, struct stasis_http_response *response) +{ + ast_log(LOG_ERROR, "TODO: stasis_http_get_stored_sound\n"); +} diff --git a/res/stasis_http/resource_sounds.h b/res/stasis_http/resource_sounds.h new file mode 100644 index 000000000..f3010a920 --- /dev/null +++ b/res/stasis_http/resource_sounds.h @@ -0,0 +1,69 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2012 - 2013, Digium, Inc. + * + * David M. Lee, II <dlee@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. + */ + +/*! \file + * + * \brief Generated file - declares stubs to be implemented in + * res/stasis_http/resource_sounds.c + * + * Sound resources + * + * \author David M. Lee, II <dlee@digium.com> + */ + +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * !!!!! DO NOT EDIT !!!!! + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * This file is generated by a mustache template. Please see the original + * template in rest-api-templates/stasis_http_resource.h.mustache + */ + +#ifndef _ASTERISK_RESOURCE_SOUNDS_H +#define _ASTERISK_RESOURCE_SOUNDS_H + +#include "asterisk/stasis_http.h" + +/*! \brief Argument struct for stasis_http_get_sounds() */ +struct ast_get_sounds_args { + const char *lang; + const char *format; +}; +/*! + * \brief List all sounds. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_sounds(struct ast_variable *headers, struct ast_get_sounds_args *args, struct stasis_http_response *response); +/*! \brief Argument struct for stasis_http_get_stored_sound() */ +struct ast_get_stored_sound_args { + /*! \brief Sound's id */ + const char *sound_id; +}; +/*! + * \brief Get a sound's details. + * + * \param headers HTTP headers + * \param args Swagger parameters + * \param[out] response HTTP response + */ +void stasis_http_get_stored_sound(struct ast_variable *headers, struct ast_get_stored_sound_args *args, struct stasis_http_response *response); + +#endif /* _ASTERISK_RESOURCE_SOUNDS_H */ |