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 Channel resources
31 * \author David M. Lee, II <dlee@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_channels.h"
48 #if defined(AST_DEVMODE)
49 #include "ari/ari_model_validators.h"
55 * \brief Parameter parsing callback for /channels.
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_channels_list_cb(
62 struct ast_variable *get_params, struct ast_variable *path_vars,
63 struct ast_variable *headers, struct ast_ari_response *response)
65 struct ast_ari_channels_list_args args = {};
66 #if defined(AST_DEVMODE)
69 #endif /* AST_DEVMODE */
71 ast_ari_channels_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_channel_fn());
88 ast_log(LOG_ERROR, "Invalid error response %d for /channels\n", code);
94 ast_log(LOG_ERROR, "Response validation failed for /channels\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 /channels.
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_channels_originate_cb(
111 struct ast_variable *get_params, struct ast_variable *path_vars,
112 struct ast_variable *headers, struct ast_ari_response *response)
114 struct ast_ari_channels_originate_args args = {};
115 struct ast_variable *i;
116 #if defined(AST_DEVMODE)
119 #endif /* AST_DEVMODE */
121 for (i = get_params; i; i = i->next) {
122 if (strcmp(i->name, "endpoint") == 0) {
123 args.endpoint = (i->value);
125 if (strcmp(i->name, "extension") == 0) {
126 args.extension = (i->value);
128 if (strcmp(i->name, "context") == 0) {
129 args.context = (i->value);
131 if (strcmp(i->name, "priority") == 0) {
132 args.priority = atol(i->value);
134 if (strcmp(i->name, "app") == 0) {
135 args.app = (i->value);
137 if (strcmp(i->name, "appArgs") == 0) {
138 args.app_args = (i->value);
140 if (strcmp(i->name, "callerId") == 0) {
141 args.caller_id = (i->value);
143 if (strcmp(i->name, "timeout") == 0) {
144 args.timeout = atoi(i->value);
148 ast_ari_channels_originate(headers, &args, response);
149 #if defined(AST_DEVMODE)
150 code = response->response_code;
153 case 0: /* Implementation is still a stub, or the code wasn't set */
154 is_valid = response->message == NULL;
156 case 500: /* Internal Server Error */
157 case 501: /* Not Implemented */
158 case 400: /* Invalid parameters for originating a channel. */
162 if (200 <= code && code <= 299) {
163 is_valid = ast_ari_validate_channel(
166 ast_log(LOG_ERROR, "Invalid error response %d for /channels\n", code);
172 ast_log(LOG_ERROR, "Response validation failed for /channels\n");
173 ast_ari_response_error(response, 500,
174 "Internal Server Error", "Response validation failed");
176 #endif /* AST_DEVMODE */
178 fin: __attribute__((unused))
182 * \brief Parameter parsing callback for /channels/{channelId}.
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_channels_get_cb(
189 struct ast_variable *get_params, struct ast_variable *path_vars,
190 struct ast_variable *headers, struct ast_ari_response *response)
192 struct ast_ari_channels_get_args args = {};
193 struct ast_variable *i;
194 #if defined(AST_DEVMODE)
197 #endif /* AST_DEVMODE */
199 for (i = path_vars; i; i = i->next) {
200 if (strcmp(i->name, "channelId") == 0) {
201 args.channel_id = (i->value);
205 ast_ari_channels_get(headers, &args, response);
206 #if defined(AST_DEVMODE)
207 code = response->response_code;
210 case 0: /* Implementation is still a stub, or the code wasn't set */
211 is_valid = response->message == NULL;
213 case 500: /* Internal Server Error */
214 case 501: /* Not Implemented */
215 case 404: /* Channel not found */
219 if (200 <= code && code <= 299) {
220 is_valid = ast_ari_validate_channel(
223 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
229 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
230 ast_ari_response_error(response, 500,
231 "Internal Server Error", "Response validation failed");
233 #endif /* AST_DEVMODE */
235 fin: __attribute__((unused))
239 * \brief Parameter parsing callback for /channels/{channelId}.
240 * \param get_params GET parameters in the HTTP request.
241 * \param path_vars Path variables extracted from the request.
242 * \param headers HTTP headers.
243 * \param[out] response Response to the HTTP request.
245 static void ast_ari_channels_hangup_cb(
246 struct ast_variable *get_params, struct ast_variable *path_vars,
247 struct ast_variable *headers, struct ast_ari_response *response)
249 struct ast_ari_channels_hangup_args args = {};
250 struct ast_variable *i;
251 #if defined(AST_DEVMODE)
254 #endif /* AST_DEVMODE */
256 for (i = get_params; i; i = i->next) {
257 if (strcmp(i->name, "reason") == 0) {
258 args.reason = (i->value);
262 for (i = path_vars; i; i = i->next) {
263 if (strcmp(i->name, "channelId") == 0) {
264 args.channel_id = (i->value);
268 ast_ari_channels_hangup(headers, &args, response);
269 #if defined(AST_DEVMODE)
270 code = response->response_code;
273 case 0: /* Implementation is still a stub, or the code wasn't set */
274 is_valid = response->message == NULL;
276 case 500: /* Internal Server Error */
277 case 501: /* Not Implemented */
278 case 400: /* Invalid reason for hangup provided */
279 case 404: /* Channel not found */
283 if (200 <= code && code <= 299) {
284 is_valid = ast_ari_validate_void(
287 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
293 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
294 ast_ari_response_error(response, 500,
295 "Internal Server Error", "Response validation failed");
297 #endif /* AST_DEVMODE */
299 fin: __attribute__((unused))
303 * \brief Parameter parsing callback for /channels/{channelId}/continue.
304 * \param get_params GET parameters in the HTTP request.
305 * \param path_vars Path variables extracted from the request.
306 * \param headers HTTP headers.
307 * \param[out] response Response to the HTTP request.
309 static void ast_ari_channels_continue_in_dialplan_cb(
310 struct ast_variable *get_params, struct ast_variable *path_vars,
311 struct ast_variable *headers, struct ast_ari_response *response)
313 struct ast_ari_channels_continue_in_dialplan_args args = {};
314 struct ast_variable *i;
315 #if defined(AST_DEVMODE)
318 #endif /* AST_DEVMODE */
320 for (i = get_params; i; i = i->next) {
321 if (strcmp(i->name, "context") == 0) {
322 args.context = (i->value);
324 if (strcmp(i->name, "extension") == 0) {
325 args.extension = (i->value);
327 if (strcmp(i->name, "priority") == 0) {
328 args.priority = atoi(i->value);
332 for (i = path_vars; i; i = i->next) {
333 if (strcmp(i->name, "channelId") == 0) {
334 args.channel_id = (i->value);
338 ast_ari_channels_continue_in_dialplan(headers, &args, response);
339 #if defined(AST_DEVMODE)
340 code = response->response_code;
343 case 0: /* Implementation is still a stub, or the code wasn't set */
344 is_valid = response->message == NULL;
346 case 500: /* Internal Server Error */
347 case 501: /* Not Implemented */
348 case 404: /* Channel not found */
349 case 409: /* Channel not in a Stasis application */
353 if (200 <= code && code <= 299) {
354 is_valid = ast_ari_validate_void(
357 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/continue\n", code);
363 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/continue\n");
364 ast_ari_response_error(response, 500,
365 "Internal Server Error", "Response validation failed");
367 #endif /* AST_DEVMODE */
369 fin: __attribute__((unused))
373 * \brief Parameter parsing callback for /channels/{channelId}/answer.
374 * \param get_params GET parameters in the HTTP request.
375 * \param path_vars Path variables extracted from the request.
376 * \param headers HTTP headers.
377 * \param[out] response Response to the HTTP request.
379 static void ast_ari_channels_answer_cb(
380 struct ast_variable *get_params, struct ast_variable *path_vars,
381 struct ast_variable *headers, struct ast_ari_response *response)
383 struct ast_ari_channels_answer_args args = {};
384 struct ast_variable *i;
385 #if defined(AST_DEVMODE)
388 #endif /* AST_DEVMODE */
390 for (i = path_vars; i; i = i->next) {
391 if (strcmp(i->name, "channelId") == 0) {
392 args.channel_id = (i->value);
396 ast_ari_channels_answer(headers, &args, response);
397 #if defined(AST_DEVMODE)
398 code = response->response_code;
401 case 0: /* Implementation is still a stub, or the code wasn't set */
402 is_valid = response->message == NULL;
404 case 500: /* Internal Server Error */
405 case 501: /* Not Implemented */
406 case 404: /* Channel not found */
407 case 409: /* Channel not in a Stasis application */
411 if (200 <= code && code <= 299) {
412 is_valid = ast_ari_validate_void(
415 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/answer\n", code);
421 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/answer\n");
422 ast_ari_response_error(response, 500,
423 "Internal Server Error", "Response validation failed");
425 #endif /* AST_DEVMODE */
427 fin: __attribute__((unused))
431 * \brief Parameter parsing callback for /channels/{channelId}/ring.
432 * \param get_params GET parameters in the HTTP request.
433 * \param path_vars Path variables extracted from the request.
434 * \param headers HTTP headers.
435 * \param[out] response Response to the HTTP request.
437 static void ast_ari_channels_ring_cb(
438 struct ast_variable *get_params, struct ast_variable *path_vars,
439 struct ast_variable *headers, struct ast_ari_response *response)
441 struct ast_ari_channels_ring_args args = {};
442 struct ast_variable *i;
443 #if defined(AST_DEVMODE)
446 #endif /* AST_DEVMODE */
448 for (i = path_vars; i; i = i->next) {
449 if (strcmp(i->name, "channelId") == 0) {
450 args.channel_id = (i->value);
454 ast_ari_channels_ring(headers, &args, response);
455 #if defined(AST_DEVMODE)
456 code = response->response_code;
459 case 0: /* Implementation is still a stub, or the code wasn't set */
460 is_valid = response->message == NULL;
462 case 500: /* Internal Server Error */
463 case 501: /* Not Implemented */
464 case 404: /* Channel not found */
465 case 409: /* Channel not in a Stasis application */
469 if (200 <= code && code <= 299) {
470 is_valid = ast_ari_validate_void(
473 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/ring\n", code);
479 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/ring\n");
480 ast_ari_response_error(response, 500,
481 "Internal Server Error", "Response validation failed");
483 #endif /* AST_DEVMODE */
485 fin: __attribute__((unused))
489 * \brief Parameter parsing callback for /channels/{channelId}/ring.
490 * \param get_params GET parameters in the HTTP request.
491 * \param path_vars Path variables extracted from the request.
492 * \param headers HTTP headers.
493 * \param[out] response Response to the HTTP request.
495 static void ast_ari_channels_ring_stop_cb(
496 struct ast_variable *get_params, struct ast_variable *path_vars,
497 struct ast_variable *headers, struct ast_ari_response *response)
499 struct ast_ari_channels_ring_stop_args args = {};
500 struct ast_variable *i;
501 #if defined(AST_DEVMODE)
504 #endif /* AST_DEVMODE */
506 for (i = path_vars; i; i = i->next) {
507 if (strcmp(i->name, "channelId") == 0) {
508 args.channel_id = (i->value);
512 ast_ari_channels_ring_stop(headers, &args, response);
513 #if defined(AST_DEVMODE)
514 code = response->response_code;
517 case 0: /* Implementation is still a stub, or the code wasn't set */
518 is_valid = response->message == NULL;
520 case 500: /* Internal Server Error */
521 case 501: /* Not Implemented */
522 case 404: /* Channel not found */
523 case 409: /* Channel not in a Stasis application */
527 if (200 <= code && code <= 299) {
528 is_valid = ast_ari_validate_void(
531 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/ring\n", code);
537 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/ring\n");
538 ast_ari_response_error(response, 500,
539 "Internal Server Error", "Response validation failed");
541 #endif /* AST_DEVMODE */
543 fin: __attribute__((unused))
547 * \brief Parameter parsing callback for /channels/{channelId}/dtmf.
548 * \param get_params GET parameters in the HTTP request.
549 * \param path_vars Path variables extracted from the request.
550 * \param headers HTTP headers.
551 * \param[out] response Response to the HTTP request.
553 static void ast_ari_channels_send_dtmf_cb(
554 struct ast_variable *get_params, struct ast_variable *path_vars,
555 struct ast_variable *headers, struct ast_ari_response *response)
557 struct ast_ari_channels_send_dtmf_args args = {};
558 struct ast_variable *i;
559 #if defined(AST_DEVMODE)
562 #endif /* AST_DEVMODE */
564 for (i = get_params; i; i = i->next) {
565 if (strcmp(i->name, "dtmf") == 0) {
566 args.dtmf = (i->value);
568 if (strcmp(i->name, "before") == 0) {
569 args.before = atoi(i->value);
571 if (strcmp(i->name, "between") == 0) {
572 args.between = atoi(i->value);
574 if (strcmp(i->name, "duration") == 0) {
575 args.duration = atoi(i->value);
577 if (strcmp(i->name, "after") == 0) {
578 args.after = atoi(i->value);
582 for (i = path_vars; i; i = i->next) {
583 if (strcmp(i->name, "channelId") == 0) {
584 args.channel_id = (i->value);
588 ast_ari_channels_send_dtmf(headers, &args, response);
589 #if defined(AST_DEVMODE)
590 code = response->response_code;
593 case 0: /* Implementation is still a stub, or the code wasn't set */
594 is_valid = response->message == NULL;
596 case 500: /* Internal Server Error */
597 case 501: /* Not Implemented */
598 case 400: /* DTMF is required */
599 case 404: /* Channel not found */
600 case 409: /* Channel not in a Stasis application */
604 if (200 <= code && code <= 299) {
605 is_valid = ast_ari_validate_void(
608 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/dtmf\n", code);
614 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/dtmf\n");
615 ast_ari_response_error(response, 500,
616 "Internal Server Error", "Response validation failed");
618 #endif /* AST_DEVMODE */
620 fin: __attribute__((unused))
624 * \brief Parameter parsing callback for /channels/{channelId}/mute.
625 * \param get_params GET parameters in the HTTP request.
626 * \param path_vars Path variables extracted from the request.
627 * \param headers HTTP headers.
628 * \param[out] response Response to the HTTP request.
630 static void ast_ari_channels_mute_cb(
631 struct ast_variable *get_params, struct ast_variable *path_vars,
632 struct ast_variable *headers, struct ast_ari_response *response)
634 struct ast_ari_channels_mute_args args = {};
635 struct ast_variable *i;
636 #if defined(AST_DEVMODE)
639 #endif /* AST_DEVMODE */
641 for (i = get_params; i; i = i->next) {
642 if (strcmp(i->name, "direction") == 0) {
643 args.direction = (i->value);
647 for (i = path_vars; i; i = i->next) {
648 if (strcmp(i->name, "channelId") == 0) {
649 args.channel_id = (i->value);
653 ast_ari_channels_mute(headers, &args, response);
654 #if defined(AST_DEVMODE)
655 code = response->response_code;
658 case 0: /* Implementation is still a stub, or the code wasn't set */
659 is_valid = response->message == NULL;
661 case 500: /* Internal Server Error */
662 case 501: /* Not Implemented */
663 case 404: /* Channel not found */
664 case 409: /* Channel not in a Stasis application */
668 if (200 <= code && code <= 299) {
669 is_valid = ast_ari_validate_void(
672 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mute\n", code);
678 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mute\n");
679 ast_ari_response_error(response, 500,
680 "Internal Server Error", "Response validation failed");
682 #endif /* AST_DEVMODE */
684 fin: __attribute__((unused))
688 * \brief Parameter parsing callback for /channels/{channelId}/mute.
689 * \param get_params GET parameters in the HTTP request.
690 * \param path_vars Path variables extracted from the request.
691 * \param headers HTTP headers.
692 * \param[out] response Response to the HTTP request.
694 static void ast_ari_channels_unmute_cb(
695 struct ast_variable *get_params, struct ast_variable *path_vars,
696 struct ast_variable *headers, struct ast_ari_response *response)
698 struct ast_ari_channels_unmute_args args = {};
699 struct ast_variable *i;
700 #if defined(AST_DEVMODE)
703 #endif /* AST_DEVMODE */
705 for (i = get_params; i; i = i->next) {
706 if (strcmp(i->name, "direction") == 0) {
707 args.direction = (i->value);
711 for (i = path_vars; i; i = i->next) {
712 if (strcmp(i->name, "channelId") == 0) {
713 args.channel_id = (i->value);
717 ast_ari_channels_unmute(headers, &args, response);
718 #if defined(AST_DEVMODE)
719 code = response->response_code;
722 case 0: /* Implementation is still a stub, or the code wasn't set */
723 is_valid = response->message == NULL;
725 case 500: /* Internal Server Error */
726 case 501: /* Not Implemented */
727 case 404: /* Channel not found */
728 case 409: /* Channel not in a Stasis application */
732 if (200 <= code && code <= 299) {
733 is_valid = ast_ari_validate_void(
736 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mute\n", code);
742 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mute\n");
743 ast_ari_response_error(response, 500,
744 "Internal Server Error", "Response validation failed");
746 #endif /* AST_DEVMODE */
748 fin: __attribute__((unused))
752 * \brief Parameter parsing callback for /channels/{channelId}/hold.
753 * \param get_params GET parameters in the HTTP request.
754 * \param path_vars Path variables extracted from the request.
755 * \param headers HTTP headers.
756 * \param[out] response Response to the HTTP request.
758 static void ast_ari_channels_hold_cb(
759 struct ast_variable *get_params, struct ast_variable *path_vars,
760 struct ast_variable *headers, struct ast_ari_response *response)
762 struct ast_ari_channels_hold_args args = {};
763 struct ast_variable *i;
764 #if defined(AST_DEVMODE)
767 #endif /* AST_DEVMODE */
769 for (i = path_vars; i; i = i->next) {
770 if (strcmp(i->name, "channelId") == 0) {
771 args.channel_id = (i->value);
775 ast_ari_channels_hold(headers, &args, response);
776 #if defined(AST_DEVMODE)
777 code = response->response_code;
780 case 0: /* Implementation is still a stub, or the code wasn't set */
781 is_valid = response->message == NULL;
783 case 500: /* Internal Server Error */
784 case 501: /* Not Implemented */
785 case 404: /* Channel not found */
786 case 409: /* Channel not in a Stasis application */
790 if (200 <= code && code <= 299) {
791 is_valid = ast_ari_validate_void(
794 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/hold\n", code);
800 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/hold\n");
801 ast_ari_response_error(response, 500,
802 "Internal Server Error", "Response validation failed");
804 #endif /* AST_DEVMODE */
806 fin: __attribute__((unused))
810 * \brief Parameter parsing callback for /channels/{channelId}/hold.
811 * \param get_params GET parameters in the HTTP request.
812 * \param path_vars Path variables extracted from the request.
813 * \param headers HTTP headers.
814 * \param[out] response Response to the HTTP request.
816 static void ast_ari_channels_unhold_cb(
817 struct ast_variable *get_params, struct ast_variable *path_vars,
818 struct ast_variable *headers, struct ast_ari_response *response)
820 struct ast_ari_channels_unhold_args args = {};
821 struct ast_variable *i;
822 #if defined(AST_DEVMODE)
825 #endif /* AST_DEVMODE */
827 for (i = path_vars; i; i = i->next) {
828 if (strcmp(i->name, "channelId") == 0) {
829 args.channel_id = (i->value);
833 ast_ari_channels_unhold(headers, &args, response);
834 #if defined(AST_DEVMODE)
835 code = response->response_code;
838 case 0: /* Implementation is still a stub, or the code wasn't set */
839 is_valid = response->message == NULL;
841 case 500: /* Internal Server Error */
842 case 501: /* Not Implemented */
843 case 404: /* Channel not found */
844 case 409: /* Channel not in a Stasis application */
848 if (200 <= code && code <= 299) {
849 is_valid = ast_ari_validate_void(
852 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/hold\n", code);
858 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/hold\n");
859 ast_ari_response_error(response, 500,
860 "Internal Server Error", "Response validation failed");
862 #endif /* AST_DEVMODE */
864 fin: __attribute__((unused))
868 * \brief Parameter parsing callback for /channels/{channelId}/moh.
869 * \param get_params GET parameters in the HTTP request.
870 * \param path_vars Path variables extracted from the request.
871 * \param headers HTTP headers.
872 * \param[out] response Response to the HTTP request.
874 static void ast_ari_channels_start_moh_cb(
875 struct ast_variable *get_params, struct ast_variable *path_vars,
876 struct ast_variable *headers, struct ast_ari_response *response)
878 struct ast_ari_channels_start_moh_args args = {};
879 struct ast_variable *i;
880 #if defined(AST_DEVMODE)
883 #endif /* AST_DEVMODE */
885 for (i = get_params; i; i = i->next) {
886 if (strcmp(i->name, "mohClass") == 0) {
887 args.moh_class = (i->value);
891 for (i = path_vars; i; i = i->next) {
892 if (strcmp(i->name, "channelId") == 0) {
893 args.channel_id = (i->value);
897 ast_ari_channels_start_moh(headers, &args, response);
898 #if defined(AST_DEVMODE)
899 code = response->response_code;
902 case 0: /* Implementation is still a stub, or the code wasn't set */
903 is_valid = response->message == NULL;
905 case 500: /* Internal Server Error */
906 case 501: /* Not Implemented */
907 case 404: /* Channel not found */
908 case 409: /* Channel not in a Stasis application */
912 if (200 <= code && code <= 299) {
913 is_valid = ast_ari_validate_void(
916 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/moh\n", code);
922 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/moh\n");
923 ast_ari_response_error(response, 500,
924 "Internal Server Error", "Response validation failed");
926 #endif /* AST_DEVMODE */
928 fin: __attribute__((unused))
932 * \brief Parameter parsing callback for /channels/{channelId}/moh.
933 * \param get_params GET parameters in the HTTP request.
934 * \param path_vars Path variables extracted from the request.
935 * \param headers HTTP headers.
936 * \param[out] response Response to the HTTP request.
938 static void ast_ari_channels_stop_moh_cb(
939 struct ast_variable *get_params, struct ast_variable *path_vars,
940 struct ast_variable *headers, struct ast_ari_response *response)
942 struct ast_ari_channels_stop_moh_args args = {};
943 struct ast_variable *i;
944 #if defined(AST_DEVMODE)
947 #endif /* AST_DEVMODE */
949 for (i = path_vars; i; i = i->next) {
950 if (strcmp(i->name, "channelId") == 0) {
951 args.channel_id = (i->value);
955 ast_ari_channels_stop_moh(headers, &args, response);
956 #if defined(AST_DEVMODE)
957 code = response->response_code;
960 case 0: /* Implementation is still a stub, or the code wasn't set */
961 is_valid = response->message == NULL;
963 case 500: /* Internal Server Error */
964 case 501: /* Not Implemented */
965 case 404: /* Channel not found */
966 case 409: /* Channel not in a Stasis application */
970 if (200 <= code && code <= 299) {
971 is_valid = ast_ari_validate_void(
974 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/moh\n", code);
980 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/moh\n");
981 ast_ari_response_error(response, 500,
982 "Internal Server Error", "Response validation failed");
984 #endif /* AST_DEVMODE */
986 fin: __attribute__((unused))
990 * \brief Parameter parsing callback for /channels/{channelId}/silence.
991 * \param get_params GET parameters in the HTTP request.
992 * \param path_vars Path variables extracted from the request.
993 * \param headers HTTP headers.
994 * \param[out] response Response to the HTTP request.
996 static void ast_ari_channels_start_silence_cb(
997 struct ast_variable *get_params, struct ast_variable *path_vars,
998 struct ast_variable *headers, struct ast_ari_response *response)
1000 struct ast_ari_channels_start_silence_args args = {};
1001 struct ast_variable *i;
1002 #if defined(AST_DEVMODE)
1005 #endif /* AST_DEVMODE */
1007 for (i = path_vars; i; i = i->next) {
1008 if (strcmp(i->name, "channelId") == 0) {
1009 args.channel_id = (i->value);
1013 ast_ari_channels_start_silence(headers, &args, response);
1014 #if defined(AST_DEVMODE)
1015 code = response->response_code;
1018 case 0: /* Implementation is still a stub, or the code wasn't set */
1019 is_valid = response->message == NULL;
1021 case 500: /* Internal Server Error */
1022 case 501: /* Not Implemented */
1023 case 404: /* Channel not found */
1024 case 409: /* Channel not in a Stasis application */
1028 if (200 <= code && code <= 299) {
1029 is_valid = ast_ari_validate_void(
1032 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/silence\n", code);
1038 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/silence\n");
1039 ast_ari_response_error(response, 500,
1040 "Internal Server Error", "Response validation failed");
1042 #endif /* AST_DEVMODE */
1044 fin: __attribute__((unused))
1048 * \brief Parameter parsing callback for /channels/{channelId}/silence.
1049 * \param get_params GET parameters in the HTTP request.
1050 * \param path_vars Path variables extracted from the request.
1051 * \param headers HTTP headers.
1052 * \param[out] response Response to the HTTP request.
1054 static void ast_ari_channels_stop_silence_cb(
1055 struct ast_variable *get_params, struct ast_variable *path_vars,
1056 struct ast_variable *headers, struct ast_ari_response *response)
1058 struct ast_ari_channels_stop_silence_args args = {};
1059 struct ast_variable *i;
1060 #if defined(AST_DEVMODE)
1063 #endif /* AST_DEVMODE */
1065 for (i = path_vars; i; i = i->next) {
1066 if (strcmp(i->name, "channelId") == 0) {
1067 args.channel_id = (i->value);
1071 ast_ari_channels_stop_silence(headers, &args, response);
1072 #if defined(AST_DEVMODE)
1073 code = response->response_code;
1076 case 0: /* Implementation is still a stub, or the code wasn't set */
1077 is_valid = response->message == NULL;
1079 case 500: /* Internal Server Error */
1080 case 501: /* Not Implemented */
1081 case 404: /* Channel not found */
1082 case 409: /* Channel not in a Stasis application */
1086 if (200 <= code && code <= 299) {
1087 is_valid = ast_ari_validate_void(
1090 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/silence\n", code);
1096 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/silence\n");
1097 ast_ari_response_error(response, 500,
1098 "Internal Server Error", "Response validation failed");
1100 #endif /* AST_DEVMODE */
1102 fin: __attribute__((unused))
1106 * \brief Parameter parsing callback for /channels/{channelId}/play.
1107 * \param get_params GET parameters in the HTTP request.
1108 * \param path_vars Path variables extracted from the request.
1109 * \param headers HTTP headers.
1110 * \param[out] response Response to the HTTP request.
1112 static void ast_ari_channels_play_cb(
1113 struct ast_variable *get_params, struct ast_variable *path_vars,
1114 struct ast_variable *headers, struct ast_ari_response *response)
1116 struct ast_ari_channels_play_args args = {};
1117 struct ast_variable *i;
1118 #if defined(AST_DEVMODE)
1121 #endif /* AST_DEVMODE */
1123 for (i = get_params; i; i = i->next) {
1124 if (strcmp(i->name, "media") == 0) {
1125 args.media = (i->value);
1127 if (strcmp(i->name, "lang") == 0) {
1128 args.lang = (i->value);
1130 if (strcmp(i->name, "offsetms") == 0) {
1131 args.offsetms = atoi(i->value);
1133 if (strcmp(i->name, "skipms") == 0) {
1134 args.skipms = atoi(i->value);
1138 for (i = path_vars; i; i = i->next) {
1139 if (strcmp(i->name, "channelId") == 0) {
1140 args.channel_id = (i->value);
1144 ast_ari_channels_play(headers, &args, response);
1145 #if defined(AST_DEVMODE)
1146 code = response->response_code;
1149 case 0: /* Implementation is still a stub, or the code wasn't set */
1150 is_valid = response->message == NULL;
1152 case 500: /* Internal Server Error */
1153 case 501: /* Not Implemented */
1154 case 404: /* Channel not found */
1155 case 409: /* Channel not in a Stasis application */
1159 if (200 <= code && code <= 299) {
1160 is_valid = ast_ari_validate_playback(
1163 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/play\n", code);
1169 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/play\n");
1170 ast_ari_response_error(response, 500,
1171 "Internal Server Error", "Response validation failed");
1173 #endif /* AST_DEVMODE */
1175 fin: __attribute__((unused))
1179 * \brief Parameter parsing callback for /channels/{channelId}/record.
1180 * \param get_params GET parameters in the HTTP request.
1181 * \param path_vars Path variables extracted from the request.
1182 * \param headers HTTP headers.
1183 * \param[out] response Response to the HTTP request.
1185 static void ast_ari_channels_record_cb(
1186 struct ast_variable *get_params, struct ast_variable *path_vars,
1187 struct ast_variable *headers, struct ast_ari_response *response)
1189 struct ast_ari_channels_record_args args = {};
1190 struct ast_variable *i;
1191 #if defined(AST_DEVMODE)
1194 #endif /* AST_DEVMODE */
1196 for (i = get_params; i; i = i->next) {
1197 if (strcmp(i->name, "name") == 0) {
1198 args.name = (i->value);
1200 if (strcmp(i->name, "format") == 0) {
1201 args.format = (i->value);
1203 if (strcmp(i->name, "maxDurationSeconds") == 0) {
1204 args.max_duration_seconds = atoi(i->value);
1206 if (strcmp(i->name, "maxSilenceSeconds") == 0) {
1207 args.max_silence_seconds = atoi(i->value);
1209 if (strcmp(i->name, "ifExists") == 0) {
1210 args.if_exists = (i->value);
1212 if (strcmp(i->name, "beep") == 0) {
1213 args.beep = ast_true(i->value);
1215 if (strcmp(i->name, "terminateOn") == 0) {
1216 args.terminate_on = (i->value);
1220 for (i = path_vars; i; i = i->next) {
1221 if (strcmp(i->name, "channelId") == 0) {
1222 args.channel_id = (i->value);
1226 ast_ari_channels_record(headers, &args, response);
1227 #if defined(AST_DEVMODE)
1228 code = response->response_code;
1231 case 0: /* Implementation is still a stub, or the code wasn't set */
1232 is_valid = response->message == NULL;
1234 case 500: /* Internal Server Error */
1235 case 501: /* Not Implemented */
1236 case 400: /* Invalid parameters */
1237 case 404: /* Channel not found */
1238 case 409: /* Channel is not in a Stasis application; the channel is currently bridged with other hcannels; A recording with the same name already exists on the system and can not be overwritten because it is in progress or ifExists=fail */
1239 case 422: /* The format specified is unknown on this system */
1243 if (200 <= code && code <= 299) {
1244 is_valid = ast_ari_validate_live_recording(
1247 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/record\n", code);
1253 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/record\n");
1254 ast_ari_response_error(response, 500,
1255 "Internal Server Error", "Response validation failed");
1257 #endif /* AST_DEVMODE */
1259 fin: __attribute__((unused))
1263 * \brief Parameter parsing callback for /channels/{channelId}/variable.
1264 * \param get_params GET parameters in the HTTP request.
1265 * \param path_vars Path variables extracted from the request.
1266 * \param headers HTTP headers.
1267 * \param[out] response Response to the HTTP request.
1269 static void ast_ari_channels_get_channel_var_cb(
1270 struct ast_variable *get_params, struct ast_variable *path_vars,
1271 struct ast_variable *headers, struct ast_ari_response *response)
1273 struct ast_ari_channels_get_channel_var_args args = {};
1274 struct ast_variable *i;
1275 #if defined(AST_DEVMODE)
1278 #endif /* AST_DEVMODE */
1280 for (i = get_params; i; i = i->next) {
1281 if (strcmp(i->name, "variable") == 0) {
1282 args.variable = (i->value);
1286 for (i = path_vars; i; i = i->next) {
1287 if (strcmp(i->name, "channelId") == 0) {
1288 args.channel_id = (i->value);
1292 ast_ari_channels_get_channel_var(headers, &args, response);
1293 #if defined(AST_DEVMODE)
1294 code = response->response_code;
1297 case 0: /* Implementation is still a stub, or the code wasn't set */
1298 is_valid = response->message == NULL;
1300 case 500: /* Internal Server Error */
1301 case 501: /* Not Implemented */
1302 case 400: /* Missing variable parameter. */
1303 case 404: /* Channel not found */
1304 case 409: /* Channel not in a Stasis application */
1308 if (200 <= code && code <= 299) {
1309 is_valid = ast_ari_validate_variable(
1312 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
1318 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
1319 ast_ari_response_error(response, 500,
1320 "Internal Server Error", "Response validation failed");
1322 #endif /* AST_DEVMODE */
1324 fin: __attribute__((unused))
1328 * \brief Parameter parsing callback for /channels/{channelId}/variable.
1329 * \param get_params GET parameters in the HTTP request.
1330 * \param path_vars Path variables extracted from the request.
1331 * \param headers HTTP headers.
1332 * \param[out] response Response to the HTTP request.
1334 static void ast_ari_channels_set_channel_var_cb(
1335 struct ast_variable *get_params, struct ast_variable *path_vars,
1336 struct ast_variable *headers, struct ast_ari_response *response)
1338 struct ast_ari_channels_set_channel_var_args args = {};
1339 struct ast_variable *i;
1340 #if defined(AST_DEVMODE)
1343 #endif /* AST_DEVMODE */
1345 for (i = get_params; i; i = i->next) {
1346 if (strcmp(i->name, "variable") == 0) {
1347 args.variable = (i->value);
1349 if (strcmp(i->name, "value") == 0) {
1350 args.value = (i->value);
1354 for (i = path_vars; i; i = i->next) {
1355 if (strcmp(i->name, "channelId") == 0) {
1356 args.channel_id = (i->value);
1360 ast_ari_channels_set_channel_var(headers, &args, response);
1361 #if defined(AST_DEVMODE)
1362 code = response->response_code;
1365 case 0: /* Implementation is still a stub, or the code wasn't set */
1366 is_valid = response->message == NULL;
1368 case 500: /* Internal Server Error */
1369 case 501: /* Not Implemented */
1370 case 400: /* Missing variable parameter. */
1371 case 404: /* Channel not found */
1372 case 409: /* Channel not in a Stasis application */
1376 if (200 <= code && code <= 299) {
1377 is_valid = ast_ari_validate_void(
1380 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
1386 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
1387 ast_ari_response_error(response, 500,
1388 "Internal Server Error", "Response validation failed");
1390 #endif /* AST_DEVMODE */
1392 fin: __attribute__((unused))
1396 /*! \brief REST handler for /api-docs/channels.{format} */
1397 static struct stasis_rest_handlers channels_channelId_continue = {
1398 .path_segment = "continue",
1400 [AST_HTTP_POST] = ast_ari_channels_continue_in_dialplan_cb,
1405 /*! \brief REST handler for /api-docs/channels.{format} */
1406 static struct stasis_rest_handlers channels_channelId_answer = {
1407 .path_segment = "answer",
1409 [AST_HTTP_POST] = ast_ari_channels_answer_cb,
1414 /*! \brief REST handler for /api-docs/channels.{format} */
1415 static struct stasis_rest_handlers channels_channelId_ring = {
1416 .path_segment = "ring",
1418 [AST_HTTP_POST] = ast_ari_channels_ring_cb,
1419 [AST_HTTP_DELETE] = ast_ari_channels_ring_stop_cb,
1424 /*! \brief REST handler for /api-docs/channels.{format} */
1425 static struct stasis_rest_handlers channels_channelId_dtmf = {
1426 .path_segment = "dtmf",
1428 [AST_HTTP_POST] = ast_ari_channels_send_dtmf_cb,
1433 /*! \brief REST handler for /api-docs/channels.{format} */
1434 static struct stasis_rest_handlers channels_channelId_mute = {
1435 .path_segment = "mute",
1437 [AST_HTTP_POST] = ast_ari_channels_mute_cb,
1438 [AST_HTTP_DELETE] = ast_ari_channels_unmute_cb,
1443 /*! \brief REST handler for /api-docs/channels.{format} */
1444 static struct stasis_rest_handlers channels_channelId_hold = {
1445 .path_segment = "hold",
1447 [AST_HTTP_POST] = ast_ari_channels_hold_cb,
1448 [AST_HTTP_DELETE] = ast_ari_channels_unhold_cb,
1453 /*! \brief REST handler for /api-docs/channels.{format} */
1454 static struct stasis_rest_handlers channels_channelId_moh = {
1455 .path_segment = "moh",
1457 [AST_HTTP_POST] = ast_ari_channels_start_moh_cb,
1458 [AST_HTTP_DELETE] = ast_ari_channels_stop_moh_cb,
1463 /*! \brief REST handler for /api-docs/channels.{format} */
1464 static struct stasis_rest_handlers channels_channelId_silence = {
1465 .path_segment = "silence",
1467 [AST_HTTP_POST] = ast_ari_channels_start_silence_cb,
1468 [AST_HTTP_DELETE] = ast_ari_channels_stop_silence_cb,
1473 /*! \brief REST handler for /api-docs/channels.{format} */
1474 static struct stasis_rest_handlers channels_channelId_play = {
1475 .path_segment = "play",
1477 [AST_HTTP_POST] = ast_ari_channels_play_cb,
1482 /*! \brief REST handler for /api-docs/channels.{format} */
1483 static struct stasis_rest_handlers channels_channelId_record = {
1484 .path_segment = "record",
1486 [AST_HTTP_POST] = ast_ari_channels_record_cb,
1491 /*! \brief REST handler for /api-docs/channels.{format} */
1492 static struct stasis_rest_handlers channels_channelId_variable = {
1493 .path_segment = "variable",
1495 [AST_HTTP_GET] = ast_ari_channels_get_channel_var_cb,
1496 [AST_HTTP_POST] = ast_ari_channels_set_channel_var_cb,
1501 /*! \brief REST handler for /api-docs/channels.{format} */
1502 static struct stasis_rest_handlers channels_channelId = {
1503 .path_segment = "channelId",
1506 [AST_HTTP_GET] = ast_ari_channels_get_cb,
1507 [AST_HTTP_DELETE] = ast_ari_channels_hangup_cb,
1510 .children = { &channels_channelId_continue,&channels_channelId_answer,&channels_channelId_ring,&channels_channelId_dtmf,&channels_channelId_mute,&channels_channelId_hold,&channels_channelId_moh,&channels_channelId_silence,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable, }
1512 /*! \brief REST handler for /api-docs/channels.{format} */
1513 static struct stasis_rest_handlers channels = {
1514 .path_segment = "channels",
1516 [AST_HTTP_GET] = ast_ari_channels_list_cb,
1517 [AST_HTTP_POST] = ast_ari_channels_originate_cb,
1520 .children = { &channels_channelId, }
1523 static int load_module(void)
1527 res |= ast_ari_add_handler(&channels);
1531 static int unload_module(void)
1533 ast_ari_remove_handler(&channels);
1538 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Channel resources",
1539 .load = load_module,
1540 .unload = unload_module,
1541 .nonoptreq = "res_ari,res_stasis",