2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2013, Digium, Inc.
6 * Jonathan Rose <jrose@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 Mailboxes resources
31 * \author Jonathan Rose <jrose@digium.com>
35 <depend type="module">res_ari</depend>
36 <depend type="module">res_stasis</depend>
37 <support_level>core</support_level>
42 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
44 #include "asterisk/app.h"
45 #include "asterisk/module.h"
46 #include "asterisk/stasis_app.h"
47 #include "ari/resource_mailboxes.h"
48 #if defined(AST_DEVMODE)
49 #include "ari/ari_model_validators.h"
55 * \brief Parameter parsing callback for /mailboxes.
56 * \param get_params GET parameters in the HTTP request.
57 * \param path_vars Path variables extracted from the request.
58 * \param headers HTTP headers.
59 * \param[out] response Response to the HTTP request.
61 static void ast_ari_mailboxes_list_cb(
62 struct ast_tcptls_session_instance *ser,
63 struct ast_variable *get_params, struct ast_variable *path_vars,
64 struct ast_variable *headers, struct ast_ari_response *response)
66 struct ast_ari_mailboxes_list_args args = {};
67 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
68 #if defined(AST_DEVMODE)
71 #endif /* AST_DEVMODE */
73 ast_ari_mailboxes_list(headers, &args, response);
74 #if defined(AST_DEVMODE)
75 code = response->response_code;
78 case 0: /* Implementation is still a stub, or the code wasn't set */
79 is_valid = response->message == NULL;
81 case 500: /* Internal Server Error */
82 case 501: /* Not Implemented */
86 if (200 <= code && code <= 299) {
87 is_valid = ast_ari_validate_list(response->message,
88 ast_ari_validate_mailbox_fn());
90 ast_log(LOG_ERROR, "Invalid error response %d for /mailboxes\n", code);
96 ast_log(LOG_ERROR, "Response validation failed for /mailboxes\n");
97 ast_ari_response_error(response, 500,
98 "Internal Server Error", "Response validation failed");
100 #endif /* AST_DEVMODE */
102 fin: __attribute__((unused))
106 * \brief Parameter parsing callback for /mailboxes/{mailboxName}.
107 * \param get_params GET parameters in the HTTP request.
108 * \param path_vars Path variables extracted from the request.
109 * \param headers HTTP headers.
110 * \param[out] response Response to the HTTP request.
112 static void ast_ari_mailboxes_get_cb(
113 struct ast_tcptls_session_instance *ser,
114 struct ast_variable *get_params, struct ast_variable *path_vars,
115 struct ast_variable *headers, struct ast_ari_response *response)
117 struct ast_ari_mailboxes_get_args args = {};
118 struct ast_variable *i;
119 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
120 #if defined(AST_DEVMODE)
123 #endif /* AST_DEVMODE */
125 for (i = path_vars; i; i = i->next) {
126 if (strcmp(i->name, "mailboxName") == 0) {
127 args.mailbox_name = (i->value);
131 ast_ari_mailboxes_get(headers, &args, response);
132 #if defined(AST_DEVMODE)
133 code = response->response_code;
136 case 0: /* Implementation is still a stub, or the code wasn't set */
137 is_valid = response->message == NULL;
139 case 500: /* Internal Server Error */
140 case 501: /* Not Implemented */
141 case 404: /* Mailbox not found */
145 if (200 <= code && code <= 299) {
146 is_valid = ast_ari_validate_mailbox(
149 ast_log(LOG_ERROR, "Invalid error response %d for /mailboxes/{mailboxName}\n", code);
155 ast_log(LOG_ERROR, "Response validation failed for /mailboxes/{mailboxName}\n");
156 ast_ari_response_error(response, 500,
157 "Internal Server Error", "Response validation failed");
159 #endif /* AST_DEVMODE */
161 fin: __attribute__((unused))
164 int ast_ari_mailboxes_update_parse_body(
165 struct ast_json *body,
166 struct ast_ari_mailboxes_update_args *args)
168 struct ast_json *field;
169 /* Parse query parameters out of it */
170 field = ast_json_object_get(body, "oldMessages");
172 args->old_messages = ast_json_integer_get(field);
174 field = ast_json_object_get(body, "newMessages");
176 args->new_messages = ast_json_integer_get(field);
182 * \brief Parameter parsing callback for /mailboxes/{mailboxName}.
183 * \param get_params GET parameters in the HTTP request.
184 * \param path_vars Path variables extracted from the request.
185 * \param headers HTTP headers.
186 * \param[out] response Response to the HTTP request.
188 static void ast_ari_mailboxes_update_cb(
189 struct ast_tcptls_session_instance *ser,
190 struct ast_variable *get_params, struct ast_variable *path_vars,
191 struct ast_variable *headers, struct ast_ari_response *response)
193 struct ast_ari_mailboxes_update_args args = {};
194 struct ast_variable *i;
195 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
196 #if defined(AST_DEVMODE)
199 #endif /* AST_DEVMODE */
201 for (i = get_params; i; i = i->next) {
202 if (strcmp(i->name, "oldMessages") == 0) {
203 args.old_messages = atoi(i->value);
205 if (strcmp(i->name, "newMessages") == 0) {
206 args.new_messages = atoi(i->value);
210 for (i = path_vars; i; i = i->next) {
211 if (strcmp(i->name, "mailboxName") == 0) {
212 args.mailbox_name = (i->value);
216 /* Look for a JSON request entity */
217 body = ast_http_get_json(ser, headers);
221 ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
224 ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
227 ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
231 if (ast_ari_mailboxes_update_parse_body(body, &args)) {
232 ast_ari_response_alloc_failed(response);
235 ast_ari_mailboxes_update(headers, &args, response);
236 #if defined(AST_DEVMODE)
237 code = response->response_code;
240 case 0: /* Implementation is still a stub, or the code wasn't set */
241 is_valid = response->message == NULL;
243 case 500: /* Internal Server Error */
244 case 501: /* Not Implemented */
245 case 404: /* Mailbox not found */
249 if (200 <= code && code <= 299) {
250 is_valid = ast_ari_validate_void(
253 ast_log(LOG_ERROR, "Invalid error response %d for /mailboxes/{mailboxName}\n", code);
259 ast_log(LOG_ERROR, "Response validation failed for /mailboxes/{mailboxName}\n");
260 ast_ari_response_error(response, 500,
261 "Internal Server Error", "Response validation failed");
263 #endif /* AST_DEVMODE */
265 fin: __attribute__((unused))
269 * \brief Parameter parsing callback for /mailboxes/{mailboxName}.
270 * \param get_params GET parameters in the HTTP request.
271 * \param path_vars Path variables extracted from the request.
272 * \param headers HTTP headers.
273 * \param[out] response Response to the HTTP request.
275 static void ast_ari_mailboxes_delete_cb(
276 struct ast_tcptls_session_instance *ser,
277 struct ast_variable *get_params, struct ast_variable *path_vars,
278 struct ast_variable *headers, struct ast_ari_response *response)
280 struct ast_ari_mailboxes_delete_args args = {};
281 struct ast_variable *i;
282 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
283 #if defined(AST_DEVMODE)
286 #endif /* AST_DEVMODE */
288 for (i = path_vars; i; i = i->next) {
289 if (strcmp(i->name, "mailboxName") == 0) {
290 args.mailbox_name = (i->value);
294 ast_ari_mailboxes_delete(headers, &args, response);
295 #if defined(AST_DEVMODE)
296 code = response->response_code;
299 case 0: /* Implementation is still a stub, or the code wasn't set */
300 is_valid = response->message == NULL;
302 case 500: /* Internal Server Error */
303 case 501: /* Not Implemented */
304 case 404: /* Mailbox not found */
308 if (200 <= code && code <= 299) {
309 is_valid = ast_ari_validate_void(
312 ast_log(LOG_ERROR, "Invalid error response %d for /mailboxes/{mailboxName}\n", code);
318 ast_log(LOG_ERROR, "Response validation failed for /mailboxes/{mailboxName}\n");
319 ast_ari_response_error(response, 500,
320 "Internal Server Error", "Response validation failed");
322 #endif /* AST_DEVMODE */
324 fin: __attribute__((unused))
328 /*! \brief REST handler for /api-docs/mailboxes.{format} */
329 static struct stasis_rest_handlers mailboxes_mailboxName = {
330 .path_segment = "mailboxName",
333 [AST_HTTP_GET] = ast_ari_mailboxes_get_cb,
334 [AST_HTTP_PUT] = ast_ari_mailboxes_update_cb,
335 [AST_HTTP_DELETE] = ast_ari_mailboxes_delete_cb,
340 /*! \brief REST handler for /api-docs/mailboxes.{format} */
341 static struct stasis_rest_handlers mailboxes = {
342 .path_segment = "mailboxes",
344 [AST_HTTP_GET] = ast_ari_mailboxes_list_cb,
347 .children = { &mailboxes_mailboxName, }
350 static int load_module(void)
354 res |= ast_ari_add_handler(&mailboxes);
358 static int unload_module(void)
360 ast_ari_remove_handler(&mailboxes);
365 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Mailboxes resources",
367 .unload = unload_module,
368 .nonoptreq = "res_ari,res_stasis",