2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2012 - 2013, Digium, Inc.
6 * Kevin Harwell <kharwell@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 Device state resources
31 * \author Kevin Harwell <kharwell@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 #include "asterisk/app.h"
44 #include "asterisk/module.h"
45 #include "asterisk/stasis_app.h"
46 #include "ari/resource_device_states.h"
47 #if defined(AST_DEVMODE)
48 #include "ari/ari_model_validators.h"
54 * \brief Parameter parsing callback for /deviceStates.
55 * \param get_params GET parameters in the HTTP request.
56 * \param path_vars Path variables extracted from the request.
57 * \param headers HTTP headers.
58 * \param[out] response Response to the HTTP request.
60 static void ast_ari_device_states_list_cb(
61 struct ast_tcptls_session_instance *ser,
62 struct ast_variable *get_params, struct ast_variable *path_vars,
63 struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
65 struct ast_ari_device_states_list_args args = {};
66 #if defined(AST_DEVMODE)
69 #endif /* AST_DEVMODE */
71 ast_ari_device_states_list(headers, &args, response);
72 #if defined(AST_DEVMODE)
73 code = response->response_code;
76 case 0: /* Implementation is still a stub, or the code wasn't set */
77 is_valid = response->message == NULL;
79 case 500: /* Internal Server Error */
80 case 501: /* Not Implemented */
84 if (200 <= code && code <= 299) {
85 is_valid = ast_ari_validate_list(response->message,
86 ast_ari_validate_device_state_fn());
88 ast_log(LOG_ERROR, "Invalid error response %d for /deviceStates\n", code);
94 ast_log(LOG_ERROR, "Response validation failed for /deviceStates\n");
95 ast_ari_response_error(response, 500,
96 "Internal Server Error", "Response validation failed");
98 #endif /* AST_DEVMODE */
100 fin: __attribute__((unused))
104 * \brief Parameter parsing callback for /deviceStates/{deviceName}.
105 * \param get_params GET parameters in the HTTP request.
106 * \param path_vars Path variables extracted from the request.
107 * \param headers HTTP headers.
108 * \param[out] response Response to the HTTP request.
110 static void ast_ari_device_states_get_cb(
111 struct ast_tcptls_session_instance *ser,
112 struct ast_variable *get_params, struct ast_variable *path_vars,
113 struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
115 struct ast_ari_device_states_get_args args = {};
116 struct ast_variable *i;
117 #if defined(AST_DEVMODE)
120 #endif /* AST_DEVMODE */
122 for (i = path_vars; i; i = i->next) {
123 if (strcmp(i->name, "deviceName") == 0) {
124 args.device_name = (i->value);
128 ast_ari_device_states_get(headers, &args, response);
129 #if defined(AST_DEVMODE)
130 code = response->response_code;
133 case 0: /* Implementation is still a stub, or the code wasn't set */
134 is_valid = response->message == NULL;
136 case 500: /* Internal Server Error */
137 case 501: /* Not Implemented */
141 if (200 <= code && code <= 299) {
142 is_valid = ast_ari_validate_device_state(
145 ast_log(LOG_ERROR, "Invalid error response %d for /deviceStates/{deviceName}\n", code);
151 ast_log(LOG_ERROR, "Response validation failed for /deviceStates/{deviceName}\n");
152 ast_ari_response_error(response, 500,
153 "Internal Server Error", "Response validation failed");
155 #endif /* AST_DEVMODE */
157 fin: __attribute__((unused))
160 int ast_ari_device_states_update_parse_body(
161 struct ast_json *body,
162 struct ast_ari_device_states_update_args *args)
164 struct ast_json *field;
165 /* Parse query parameters out of it */
166 field = ast_json_object_get(body, "deviceState");
168 args->device_state = ast_json_string_get(field);
174 * \brief Parameter parsing callback for /deviceStates/{deviceName}.
175 * \param get_params GET parameters in the HTTP request.
176 * \param path_vars Path variables extracted from the request.
177 * \param headers HTTP headers.
178 * \param[out] response Response to the HTTP request.
180 static void ast_ari_device_states_update_cb(
181 struct ast_tcptls_session_instance *ser,
182 struct ast_variable *get_params, struct ast_variable *path_vars,
183 struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
185 struct ast_ari_device_states_update_args args = {};
186 struct ast_variable *i;
187 #if defined(AST_DEVMODE)
190 #endif /* AST_DEVMODE */
192 for (i = get_params; i; i = i->next) {
193 if (strcmp(i->name, "deviceState") == 0) {
194 args.device_state = (i->value);
198 for (i = path_vars; i; i = i->next) {
199 if (strcmp(i->name, "deviceName") == 0) {
200 args.device_name = (i->value);
204 if (ast_ari_device_states_update_parse_body(body, &args)) {
205 ast_ari_response_alloc_failed(response);
208 ast_ari_device_states_update(headers, &args, response);
209 #if defined(AST_DEVMODE)
210 code = response->response_code;
213 case 0: /* Implementation is still a stub, or the code wasn't set */
214 is_valid = response->message == NULL;
216 case 500: /* Internal Server Error */
217 case 501: /* Not Implemented */
218 case 404: /* Device name is missing */
219 case 409: /* Uncontrolled device specified */
223 if (200 <= code && code <= 299) {
224 is_valid = ast_ari_validate_void(
227 ast_log(LOG_ERROR, "Invalid error response %d for /deviceStates/{deviceName}\n", code);
233 ast_log(LOG_ERROR, "Response validation failed for /deviceStates/{deviceName}\n");
234 ast_ari_response_error(response, 500,
235 "Internal Server Error", "Response validation failed");
237 #endif /* AST_DEVMODE */
239 fin: __attribute__((unused))
243 * \brief Parameter parsing callback for /deviceStates/{deviceName}.
244 * \param get_params GET parameters in the HTTP request.
245 * \param path_vars Path variables extracted from the request.
246 * \param headers HTTP headers.
247 * \param[out] response Response to the HTTP request.
249 static void ast_ari_device_states_delete_cb(
250 struct ast_tcptls_session_instance *ser,
251 struct ast_variable *get_params, struct ast_variable *path_vars,
252 struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
254 struct ast_ari_device_states_delete_args args = {};
255 struct ast_variable *i;
256 #if defined(AST_DEVMODE)
259 #endif /* AST_DEVMODE */
261 for (i = path_vars; i; i = i->next) {
262 if (strcmp(i->name, "deviceName") == 0) {
263 args.device_name = (i->value);
267 ast_ari_device_states_delete(headers, &args, response);
268 #if defined(AST_DEVMODE)
269 code = response->response_code;
272 case 0: /* Implementation is still a stub, or the code wasn't set */
273 is_valid = response->message == NULL;
275 case 500: /* Internal Server Error */
276 case 501: /* Not Implemented */
277 case 404: /* Device name is missing */
278 case 409: /* Uncontrolled device specified */
282 if (200 <= code && code <= 299) {
283 is_valid = ast_ari_validate_void(
286 ast_log(LOG_ERROR, "Invalid error response %d for /deviceStates/{deviceName}\n", code);
292 ast_log(LOG_ERROR, "Response validation failed for /deviceStates/{deviceName}\n");
293 ast_ari_response_error(response, 500,
294 "Internal Server Error", "Response validation failed");
296 #endif /* AST_DEVMODE */
298 fin: __attribute__((unused))
302 /*! \brief REST handler for /api-docs/deviceStates.json */
303 static struct stasis_rest_handlers deviceStates_deviceName = {
304 .path_segment = "deviceName",
307 [AST_HTTP_GET] = ast_ari_device_states_get_cb,
308 [AST_HTTP_PUT] = ast_ari_device_states_update_cb,
309 [AST_HTTP_DELETE] = ast_ari_device_states_delete_cb,
314 /*! \brief REST handler for /api-docs/deviceStates.json */
315 static struct stasis_rest_handlers deviceStates = {
316 .path_segment = "deviceStates",
318 [AST_HTTP_GET] = ast_ari_device_states_list_cb,
321 .children = { &deviceStates_deviceName, }
324 static int unload_module(void)
326 ast_ari_remove_handler(&deviceStates);
331 static int load_module(void)
335 res |= ast_ari_add_handler(&deviceStates);
338 return AST_MODULE_LOAD_DECLINE;
341 return AST_MODULE_LOAD_SUCCESS;
344 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Device state resources",
345 .support_level = AST_MODULE_SUPPORT_CORE,
347 .unload = unload_module,
348 .nonoptreq = "res_ari,res_stasis",