2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2012 - 2013, Digium, Inc.
6 * David M. Lee, II <dlee@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
20 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
21 * !!!!! DO NOT EDIT !!!!!
22 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
23 * This file is generated by a mustache template. Please see the original
24 * template in rest-api-templates/res_ari_resource.c.mustache
29 * \brief Playback control resources
31 * \author David M. Lee, II <dlee@digium.com>
35 <depend type="module">res_ari</depend>
36 <depend type="module">res_ari_model</depend>
37 <depend type="module">res_stasis</depend>
38 <support_level>core</support_level>
43 ASTERISK_REGISTER_FILE()
45 #include "asterisk/app.h"
46 #include "asterisk/module.h"
47 #include "asterisk/stasis_app.h"
48 #include "ari/resource_playbacks.h"
49 #if defined(AST_DEVMODE)
50 #include "ari/ari_model_validators.h"
56 * \brief Parameter parsing callback for /playbacks/{playbackId}.
57 * \param get_params GET parameters in the HTTP request.
58 * \param path_vars Path variables extracted from the request.
59 * \param headers HTTP headers.
60 * \param[out] response Response to the HTTP request.
62 static void ast_ari_playbacks_get_cb(
63 struct ast_tcptls_session_instance *ser,
64 struct ast_variable *get_params, struct ast_variable *path_vars,
65 struct ast_variable *headers, struct ast_ari_response *response)
67 struct ast_ari_playbacks_get_args args = {};
68 struct ast_variable *i;
69 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
70 #if defined(AST_DEVMODE)
73 #endif /* AST_DEVMODE */
75 for (i = path_vars; i; i = i->next) {
76 if (strcmp(i->name, "playbackId") == 0) {
77 args.playback_id = (i->value);
81 ast_ari_playbacks_get(headers, &args, response);
82 #if defined(AST_DEVMODE)
83 code = response->response_code;
86 case 0: /* Implementation is still a stub, or the code wasn't set */
87 is_valid = response->message == NULL;
89 case 500: /* Internal Server Error */
90 case 501: /* Not Implemented */
91 case 404: /* The playback cannot be found */
95 if (200 <= code && code <= 299) {
96 is_valid = ast_ari_validate_playback(
99 ast_log(LOG_ERROR, "Invalid error response %d for /playbacks/{playbackId}\n", code);
105 ast_log(LOG_ERROR, "Response validation failed for /playbacks/{playbackId}\n");
106 ast_ari_response_error(response, 500,
107 "Internal Server Error", "Response validation failed");
109 #endif /* AST_DEVMODE */
111 fin: __attribute__((unused))
115 * \brief Parameter parsing callback for /playbacks/{playbackId}.
116 * \param get_params GET parameters in the HTTP request.
117 * \param path_vars Path variables extracted from the request.
118 * \param headers HTTP headers.
119 * \param[out] response Response to the HTTP request.
121 static void ast_ari_playbacks_stop_cb(
122 struct ast_tcptls_session_instance *ser,
123 struct ast_variable *get_params, struct ast_variable *path_vars,
124 struct ast_variable *headers, struct ast_ari_response *response)
126 struct ast_ari_playbacks_stop_args args = {};
127 struct ast_variable *i;
128 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
129 #if defined(AST_DEVMODE)
132 #endif /* AST_DEVMODE */
134 for (i = path_vars; i; i = i->next) {
135 if (strcmp(i->name, "playbackId") == 0) {
136 args.playback_id = (i->value);
140 ast_ari_playbacks_stop(headers, &args, response);
141 #if defined(AST_DEVMODE)
142 code = response->response_code;
145 case 0: /* Implementation is still a stub, or the code wasn't set */
146 is_valid = response->message == NULL;
148 case 500: /* Internal Server Error */
149 case 501: /* Not Implemented */
150 case 404: /* The playback cannot be found */
154 if (200 <= code && code <= 299) {
155 is_valid = ast_ari_validate_void(
158 ast_log(LOG_ERROR, "Invalid error response %d for /playbacks/{playbackId}\n", code);
164 ast_log(LOG_ERROR, "Response validation failed for /playbacks/{playbackId}\n");
165 ast_ari_response_error(response, 500,
166 "Internal Server Error", "Response validation failed");
168 #endif /* AST_DEVMODE */
170 fin: __attribute__((unused))
173 int ast_ari_playbacks_control_parse_body(
174 struct ast_json *body,
175 struct ast_ari_playbacks_control_args *args)
177 struct ast_json *field;
178 /* Parse query parameters out of it */
179 field = ast_json_object_get(body, "operation");
181 args->operation = ast_json_string_get(field);
187 * \brief Parameter parsing callback for /playbacks/{playbackId}/control.
188 * \param get_params GET parameters in the HTTP request.
189 * \param path_vars Path variables extracted from the request.
190 * \param headers HTTP headers.
191 * \param[out] response Response to the HTTP request.
193 static void ast_ari_playbacks_control_cb(
194 struct ast_tcptls_session_instance *ser,
195 struct ast_variable *get_params, struct ast_variable *path_vars,
196 struct ast_variable *headers, struct ast_ari_response *response)
198 struct ast_ari_playbacks_control_args args = {};
199 struct ast_variable *i;
200 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
201 #if defined(AST_DEVMODE)
204 #endif /* AST_DEVMODE */
206 for (i = get_params; i; i = i->next) {
207 if (strcmp(i->name, "operation") == 0) {
208 args.operation = (i->value);
212 for (i = path_vars; i; i = i->next) {
213 if (strcmp(i->name, "playbackId") == 0) {
214 args.playback_id = (i->value);
218 /* Look for a JSON request entity */
219 body = ast_http_get_json(ser, headers);
223 ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
226 ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
229 ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
233 if (ast_ari_playbacks_control_parse_body(body, &args)) {
234 ast_ari_response_alloc_failed(response);
237 ast_ari_playbacks_control(headers, &args, response);
238 #if defined(AST_DEVMODE)
239 code = response->response_code;
242 case 0: /* Implementation is still a stub, or the code wasn't set */
243 is_valid = response->message == NULL;
245 case 500: /* Internal Server Error */
246 case 501: /* Not Implemented */
247 case 400: /* The provided operation parameter was invalid */
248 case 404: /* The playback cannot be found */
249 case 409: /* The operation cannot be performed in the playback's current state */
253 if (200 <= code && code <= 299) {
254 is_valid = ast_ari_validate_void(
257 ast_log(LOG_ERROR, "Invalid error response %d for /playbacks/{playbackId}/control\n", code);
263 ast_log(LOG_ERROR, "Response validation failed for /playbacks/{playbackId}/control\n");
264 ast_ari_response_error(response, 500,
265 "Internal Server Error", "Response validation failed");
267 #endif /* AST_DEVMODE */
269 fin: __attribute__((unused))
273 /*! \brief REST handler for /api-docs/playbacks.{format} */
274 static struct stasis_rest_handlers playbacks_playbackId_control = {
275 .path_segment = "control",
277 [AST_HTTP_POST] = ast_ari_playbacks_control_cb,
282 /*! \brief REST handler for /api-docs/playbacks.{format} */
283 static struct stasis_rest_handlers playbacks_playbackId = {
284 .path_segment = "playbackId",
287 [AST_HTTP_GET] = ast_ari_playbacks_get_cb,
288 [AST_HTTP_DELETE] = ast_ari_playbacks_stop_cb,
291 .children = { &playbacks_playbackId_control, }
293 /*! \brief REST handler for /api-docs/playbacks.{format} */
294 static struct stasis_rest_handlers playbacks = {
295 .path_segment = "playbacks",
299 .children = { &playbacks_playbackId, }
302 static int load_module(void)
306 res |= ast_ari_add_handler(&playbacks);
310 static int unload_module(void)
312 ast_ari_remove_handler(&playbacks);
317 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Playback control resources",
318 .support_level = AST_MODULE_SUPPORT_CORE,
320 .unload = unload_module,
321 .nonoptreq = "res_ari,res_stasis",