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_get_channels_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_get_channels_args args = {};
66 #if defined(AST_DEVMODE)
69 #endif /* AST_DEVMODE */
71 ast_ari_get_channels(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_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_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_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_get_channel_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_get_channel_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_get_channel(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_delete_channel_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_delete_channel_args args = {};
250 struct ast_variable *i;
251 #if defined(AST_DEVMODE)
254 #endif /* AST_DEVMODE */
256 for (i = path_vars; i; i = i->next) {
257 if (strcmp(i->name, "channelId") == 0) {
258 args.channel_id = (i->value);
262 ast_ari_delete_channel(headers, &args, response);
263 #if defined(AST_DEVMODE)
264 code = response->response_code;
267 case 0: /* Implementation is still a stub, or the code wasn't set */
268 is_valid = response->message == NULL;
270 case 500: /* Internal Server Error */
271 case 501: /* Not Implemented */
272 case 404: /* Channel not found */
276 if (200 <= code && code <= 299) {
277 is_valid = ast_ari_validate_void(
280 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
286 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
287 ast_ari_response_error(response, 500,
288 "Internal Server Error", "Response validation failed");
290 #endif /* AST_DEVMODE */
292 fin: __attribute__((unused))
296 * \brief Parameter parsing callback for /channels/{channelId}/dial.
297 * \param get_params GET parameters in the HTTP request.
298 * \param path_vars Path variables extracted from the request.
299 * \param headers HTTP headers.
300 * \param[out] response Response to the HTTP request.
302 static void ast_ari_dial_cb(
303 struct ast_variable *get_params, struct ast_variable *path_vars,
304 struct ast_variable *headers, struct ast_ari_response *response)
306 struct ast_dial_args args = {};
307 struct ast_variable *i;
308 #if defined(AST_DEVMODE)
311 #endif /* AST_DEVMODE */
313 for (i = get_params; i; i = i->next) {
314 if (strcmp(i->name, "endpoint") == 0) {
315 args.endpoint = (i->value);
317 if (strcmp(i->name, "extension") == 0) {
318 args.extension = (i->value);
320 if (strcmp(i->name, "context") == 0) {
321 args.context = (i->value);
323 if (strcmp(i->name, "timeout") == 0) {
324 args.timeout = atoi(i->value);
328 for (i = path_vars; i; i = i->next) {
329 if (strcmp(i->name, "channelId") == 0) {
330 args.channel_id = (i->value);
334 ast_ari_dial(headers, &args, response);
335 #if defined(AST_DEVMODE)
336 code = response->response_code;
339 case 0: /* Implementation is still a stub, or the code wasn't set */
340 is_valid = response->message == NULL;
342 case 500: /* Internal Server Error */
343 case 501: /* Not Implemented */
344 case 404: /* Channel not found */
345 case 409: /* Channel not in a Stasis application */
349 if (200 <= code && code <= 299) {
350 is_valid = ast_ari_validate_dialed(
353 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/dial\n", code);
359 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/dial\n");
360 ast_ari_response_error(response, 500,
361 "Internal Server Error", "Response validation failed");
363 #endif /* AST_DEVMODE */
365 fin: __attribute__((unused))
369 * \brief Parameter parsing callback for /channels/{channelId}/continue.
370 * \param get_params GET parameters in the HTTP request.
371 * \param path_vars Path variables extracted from the request.
372 * \param headers HTTP headers.
373 * \param[out] response Response to the HTTP request.
375 static void ast_ari_continue_in_dialplan_cb(
376 struct ast_variable *get_params, struct ast_variable *path_vars,
377 struct ast_variable *headers, struct ast_ari_response *response)
379 struct ast_continue_in_dialplan_args args = {};
380 struct ast_variable *i;
381 #if defined(AST_DEVMODE)
384 #endif /* AST_DEVMODE */
386 for (i = get_params; i; i = i->next) {
387 if (strcmp(i->name, "context") == 0) {
388 args.context = (i->value);
390 if (strcmp(i->name, "extension") == 0) {
391 args.extension = (i->value);
393 if (strcmp(i->name, "priority") == 0) {
394 args.priority = atoi(i->value);
398 for (i = path_vars; i; i = i->next) {
399 if (strcmp(i->name, "channelId") == 0) {
400 args.channel_id = (i->value);
404 ast_ari_continue_in_dialplan(headers, &args, response);
405 #if defined(AST_DEVMODE)
406 code = response->response_code;
409 case 0: /* Implementation is still a stub, or the code wasn't set */
410 is_valid = response->message == NULL;
412 case 500: /* Internal Server Error */
413 case 501: /* Not Implemented */
414 case 404: /* Channel not found */
415 case 409: /* Channel not in a Stasis application */
419 if (200 <= code && code <= 299) {
420 is_valid = ast_ari_validate_void(
423 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/continue\n", code);
429 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/continue\n");
430 ast_ari_response_error(response, 500,
431 "Internal Server Error", "Response validation failed");
433 #endif /* AST_DEVMODE */
435 fin: __attribute__((unused))
439 * \brief Parameter parsing callback for /channels/{channelId}/answer.
440 * \param get_params GET parameters in the HTTP request.
441 * \param path_vars Path variables extracted from the request.
442 * \param headers HTTP headers.
443 * \param[out] response Response to the HTTP request.
445 static void ast_ari_answer_channel_cb(
446 struct ast_variable *get_params, struct ast_variable *path_vars,
447 struct ast_variable *headers, struct ast_ari_response *response)
449 struct ast_answer_channel_args args = {};
450 struct ast_variable *i;
451 #if defined(AST_DEVMODE)
454 #endif /* AST_DEVMODE */
456 for (i = path_vars; i; i = i->next) {
457 if (strcmp(i->name, "channelId") == 0) {
458 args.channel_id = (i->value);
462 ast_ari_answer_channel(headers, &args, response);
463 #if defined(AST_DEVMODE)
464 code = response->response_code;
467 case 0: /* Implementation is still a stub, or the code wasn't set */
468 is_valid = response->message == NULL;
470 case 500: /* Internal Server Error */
471 case 501: /* Not Implemented */
472 case 404: /* Channel not found */
473 case 409: /* Channel not in a Stasis application */
477 if (200 <= code && code <= 299) {
478 is_valid = ast_ari_validate_void(
481 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/answer\n", code);
487 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/answer\n");
488 ast_ari_response_error(response, 500,
489 "Internal Server Error", "Response validation failed");
491 #endif /* AST_DEVMODE */
493 fin: __attribute__((unused))
497 * \brief Parameter parsing callback for /channels/{channelId}/mute.
498 * \param get_params GET parameters in the HTTP request.
499 * \param path_vars Path variables extracted from the request.
500 * \param headers HTTP headers.
501 * \param[out] response Response to the HTTP request.
503 static void ast_ari_mute_channel_cb(
504 struct ast_variable *get_params, struct ast_variable *path_vars,
505 struct ast_variable *headers, struct ast_ari_response *response)
507 struct ast_mute_channel_args args = {};
508 struct ast_variable *i;
509 #if defined(AST_DEVMODE)
512 #endif /* AST_DEVMODE */
514 for (i = get_params; i; i = i->next) {
515 if (strcmp(i->name, "direction") == 0) {
516 args.direction = (i->value);
520 for (i = path_vars; i; i = i->next) {
521 if (strcmp(i->name, "channelId") == 0) {
522 args.channel_id = (i->value);
526 ast_ari_mute_channel(headers, &args, response);
527 #if defined(AST_DEVMODE)
528 code = response->response_code;
531 case 0: /* Implementation is still a stub, or the code wasn't set */
532 is_valid = response->message == NULL;
534 case 500: /* Internal Server Error */
535 case 501: /* Not Implemented */
536 case 404: /* Channel not found */
537 case 409: /* Channel not in a Stasis application */
541 if (200 <= code && code <= 299) {
542 is_valid = ast_ari_validate_void(
545 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mute\n", code);
551 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mute\n");
552 ast_ari_response_error(response, 500,
553 "Internal Server Error", "Response validation failed");
555 #endif /* AST_DEVMODE */
557 fin: __attribute__((unused))
561 * \brief Parameter parsing callback for /channels/{channelId}/unmute.
562 * \param get_params GET parameters in the HTTP request.
563 * \param path_vars Path variables extracted from the request.
564 * \param headers HTTP headers.
565 * \param[out] response Response to the HTTP request.
567 static void ast_ari_unmute_channel_cb(
568 struct ast_variable *get_params, struct ast_variable *path_vars,
569 struct ast_variable *headers, struct ast_ari_response *response)
571 struct ast_unmute_channel_args args = {};
572 struct ast_variable *i;
573 #if defined(AST_DEVMODE)
576 #endif /* AST_DEVMODE */
578 for (i = get_params; i; i = i->next) {
579 if (strcmp(i->name, "direction") == 0) {
580 args.direction = (i->value);
584 for (i = path_vars; i; i = i->next) {
585 if (strcmp(i->name, "channelId") == 0) {
586 args.channel_id = (i->value);
590 ast_ari_unmute_channel(headers, &args, response);
591 #if defined(AST_DEVMODE)
592 code = response->response_code;
595 case 0: /* Implementation is still a stub, or the code wasn't set */
596 is_valid = response->message == NULL;
598 case 500: /* Internal Server Error */
599 case 501: /* Not Implemented */
600 case 404: /* Channel not found */
601 case 409: /* Channel not in a Stasis application */
605 if (200 <= code && code <= 299) {
606 is_valid = ast_ari_validate_void(
609 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/unmute\n", code);
615 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/unmute\n");
616 ast_ari_response_error(response, 500,
617 "Internal Server Error", "Response validation failed");
619 #endif /* AST_DEVMODE */
621 fin: __attribute__((unused))
625 * \brief Parameter parsing callback for /channels/{channelId}/hold.
626 * \param get_params GET parameters in the HTTP request.
627 * \param path_vars Path variables extracted from the request.
628 * \param headers HTTP headers.
629 * \param[out] response Response to the HTTP request.
631 static void ast_ari_hold_channel_cb(
632 struct ast_variable *get_params, struct ast_variable *path_vars,
633 struct ast_variable *headers, struct ast_ari_response *response)
635 struct ast_hold_channel_args args = {};
636 struct ast_variable *i;
637 #if defined(AST_DEVMODE)
640 #endif /* AST_DEVMODE */
642 for (i = path_vars; i; i = i->next) {
643 if (strcmp(i->name, "channelId") == 0) {
644 args.channel_id = (i->value);
648 ast_ari_hold_channel(headers, &args, response);
649 #if defined(AST_DEVMODE)
650 code = response->response_code;
653 case 0: /* Implementation is still a stub, or the code wasn't set */
654 is_valid = response->message == NULL;
656 case 500: /* Internal Server Error */
657 case 501: /* Not Implemented */
658 case 404: /* Channel not found */
659 case 409: /* Channel not in a Stasis application */
663 if (200 <= code && code <= 299) {
664 is_valid = ast_ari_validate_void(
667 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/hold\n", code);
673 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/hold\n");
674 ast_ari_response_error(response, 500,
675 "Internal Server Error", "Response validation failed");
677 #endif /* AST_DEVMODE */
679 fin: __attribute__((unused))
683 * \brief Parameter parsing callback for /channels/{channelId}/hold.
684 * \param get_params GET parameters in the HTTP request.
685 * \param path_vars Path variables extracted from the request.
686 * \param headers HTTP headers.
687 * \param[out] response Response to the HTTP request.
689 static void ast_ari_unhold_channel_cb(
690 struct ast_variable *get_params, struct ast_variable *path_vars,
691 struct ast_variable *headers, struct ast_ari_response *response)
693 struct ast_unhold_channel_args args = {};
694 struct ast_variable *i;
695 #if defined(AST_DEVMODE)
698 #endif /* AST_DEVMODE */
700 for (i = path_vars; i; i = i->next) {
701 if (strcmp(i->name, "channelId") == 0) {
702 args.channel_id = (i->value);
706 ast_ari_unhold_channel(headers, &args, response);
707 #if defined(AST_DEVMODE)
708 code = response->response_code;
711 case 0: /* Implementation is still a stub, or the code wasn't set */
712 is_valid = response->message == NULL;
714 case 500: /* Internal Server Error */
715 case 501: /* Not Implemented */
716 case 404: /* Channel not found */
717 case 409: /* Channel not in a Stasis application */
721 if (200 <= code && code <= 299) {
722 is_valid = ast_ari_validate_void(
725 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/hold\n", code);
731 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/hold\n");
732 ast_ari_response_error(response, 500,
733 "Internal Server Error", "Response validation failed");
735 #endif /* AST_DEVMODE */
737 fin: __attribute__((unused))
741 * \brief Parameter parsing callback for /channels/{channelId}/moh.
742 * \param get_params GET parameters in the HTTP request.
743 * \param path_vars Path variables extracted from the request.
744 * \param headers HTTP headers.
745 * \param[out] response Response to the HTTP request.
747 static void ast_ari_moh_start_channel_cb(
748 struct ast_variable *get_params, struct ast_variable *path_vars,
749 struct ast_variable *headers, struct ast_ari_response *response)
751 struct ast_moh_start_channel_args args = {};
752 struct ast_variable *i;
753 #if defined(AST_DEVMODE)
756 #endif /* AST_DEVMODE */
758 for (i = get_params; i; i = i->next) {
759 if (strcmp(i->name, "mohClass") == 0) {
760 args.moh_class = (i->value);
764 for (i = path_vars; i; i = i->next) {
765 if (strcmp(i->name, "channelId") == 0) {
766 args.channel_id = (i->value);
770 ast_ari_moh_start_channel(headers, &args, response);
771 #if defined(AST_DEVMODE)
772 code = response->response_code;
775 case 0: /* Implementation is still a stub, or the code wasn't set */
776 is_valid = response->message == NULL;
778 case 500: /* Internal Server Error */
779 case 501: /* Not Implemented */
780 case 404: /* Channel not found */
781 case 409: /* Channel not in a Stasis application */
785 if (200 <= code && code <= 299) {
786 is_valid = ast_ari_validate_void(
789 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/moh\n", code);
795 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/moh\n");
796 ast_ari_response_error(response, 500,
797 "Internal Server Error", "Response validation failed");
799 #endif /* AST_DEVMODE */
801 fin: __attribute__((unused))
805 * \brief Parameter parsing callback for /channels/{channelId}/moh.
806 * \param get_params GET parameters in the HTTP request.
807 * \param path_vars Path variables extracted from the request.
808 * \param headers HTTP headers.
809 * \param[out] response Response to the HTTP request.
811 static void ast_ari_moh_stop_channel_cb(
812 struct ast_variable *get_params, struct ast_variable *path_vars,
813 struct ast_variable *headers, struct ast_ari_response *response)
815 struct ast_moh_stop_channel_args args = {};
816 struct ast_variable *i;
817 #if defined(AST_DEVMODE)
820 #endif /* AST_DEVMODE */
822 for (i = path_vars; i; i = i->next) {
823 if (strcmp(i->name, "channelId") == 0) {
824 args.channel_id = (i->value);
828 ast_ari_moh_stop_channel(headers, &args, response);
829 #if defined(AST_DEVMODE)
830 code = response->response_code;
833 case 0: /* Implementation is still a stub, or the code wasn't set */
834 is_valid = response->message == NULL;
836 case 500: /* Internal Server Error */
837 case 501: /* Not Implemented */
838 case 404: /* Channel not found */
839 case 409: /* Channel not in a Stasis application */
843 if (200 <= code && code <= 299) {
844 is_valid = ast_ari_validate_void(
847 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/moh\n", code);
853 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/moh\n");
854 ast_ari_response_error(response, 500,
855 "Internal Server Error", "Response validation failed");
857 #endif /* AST_DEVMODE */
859 fin: __attribute__((unused))
863 * \brief Parameter parsing callback for /channels/{channelId}/play.
864 * \param get_params GET parameters in the HTTP request.
865 * \param path_vars Path variables extracted from the request.
866 * \param headers HTTP headers.
867 * \param[out] response Response to the HTTP request.
869 static void ast_ari_play_on_channel_cb(
870 struct ast_variable *get_params, struct ast_variable *path_vars,
871 struct ast_variable *headers, struct ast_ari_response *response)
873 struct ast_play_on_channel_args args = {};
874 struct ast_variable *i;
875 #if defined(AST_DEVMODE)
878 #endif /* AST_DEVMODE */
880 for (i = get_params; i; i = i->next) {
881 if (strcmp(i->name, "media") == 0) {
882 args.media = (i->value);
884 if (strcmp(i->name, "lang") == 0) {
885 args.lang = (i->value);
887 if (strcmp(i->name, "offsetms") == 0) {
888 args.offsetms = atoi(i->value);
890 if (strcmp(i->name, "skipms") == 0) {
891 args.skipms = atoi(i->value);
895 for (i = path_vars; i; i = i->next) {
896 if (strcmp(i->name, "channelId") == 0) {
897 args.channel_id = (i->value);
901 ast_ari_play_on_channel(headers, &args, response);
902 #if defined(AST_DEVMODE)
903 code = response->response_code;
906 case 0: /* Implementation is still a stub, or the code wasn't set */
907 is_valid = response->message == NULL;
909 case 500: /* Internal Server Error */
910 case 501: /* Not Implemented */
911 case 404: /* Channel not found */
912 case 409: /* Channel not in a Stasis application */
916 if (200 <= code && code <= 299) {
917 is_valid = ast_ari_validate_playback(
920 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/play\n", code);
926 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/play\n");
927 ast_ari_response_error(response, 500,
928 "Internal Server Error", "Response validation failed");
930 #endif /* AST_DEVMODE */
932 fin: __attribute__((unused))
936 * \brief Parameter parsing callback for /channels/{channelId}/record.
937 * \param get_params GET parameters in the HTTP request.
938 * \param path_vars Path variables extracted from the request.
939 * \param headers HTTP headers.
940 * \param[out] response Response to the HTTP request.
942 static void ast_ari_record_channel_cb(
943 struct ast_variable *get_params, struct ast_variable *path_vars,
944 struct ast_variable *headers, struct ast_ari_response *response)
946 struct ast_record_channel_args args = {};
947 struct ast_variable *i;
948 #if defined(AST_DEVMODE)
951 #endif /* AST_DEVMODE */
953 for (i = get_params; i; i = i->next) {
954 if (strcmp(i->name, "name") == 0) {
955 args.name = (i->value);
957 if (strcmp(i->name, "format") == 0) {
958 args.format = (i->value);
960 if (strcmp(i->name, "maxDurationSeconds") == 0) {
961 args.max_duration_seconds = atoi(i->value);
963 if (strcmp(i->name, "maxSilenceSeconds") == 0) {
964 args.max_silence_seconds = atoi(i->value);
966 if (strcmp(i->name, "ifExists") == 0) {
967 args.if_exists = (i->value);
969 if (strcmp(i->name, "beep") == 0) {
970 args.beep = ast_true(i->value);
972 if (strcmp(i->name, "terminateOn") == 0) {
973 args.terminate_on = (i->value);
977 for (i = path_vars; i; i = i->next) {
978 if (strcmp(i->name, "channelId") == 0) {
979 args.channel_id = (i->value);
983 ast_ari_record_channel(headers, &args, response);
984 #if defined(AST_DEVMODE)
985 code = response->response_code;
988 case 0: /* Implementation is still a stub, or the code wasn't set */
989 is_valid = response->message == NULL;
991 case 500: /* Internal Server Error */
992 case 501: /* Not Implemented */
993 case 400: /* Invalid parameters */
994 case 404: /* Channel not found */
995 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 */
996 case 422: /* The format specified is unknown on this system */
1000 if (200 <= code && code <= 299) {
1001 is_valid = ast_ari_validate_live_recording(
1004 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/record\n", code);
1010 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/record\n");
1011 ast_ari_response_error(response, 500,
1012 "Internal Server Error", "Response validation failed");
1014 #endif /* AST_DEVMODE */
1016 fin: __attribute__((unused))
1020 * \brief Parameter parsing callback for /channels/{channelId}/variable.
1021 * \param get_params GET parameters in the HTTP request.
1022 * \param path_vars Path variables extracted from the request.
1023 * \param headers HTTP headers.
1024 * \param[out] response Response to the HTTP request.
1026 static void ast_ari_get_channel_var_cb(
1027 struct ast_variable *get_params, struct ast_variable *path_vars,
1028 struct ast_variable *headers, struct ast_ari_response *response)
1030 struct ast_get_channel_var_args args = {};
1031 struct ast_variable *i;
1032 #if defined(AST_DEVMODE)
1035 #endif /* AST_DEVMODE */
1037 for (i = get_params; i; i = i->next) {
1038 if (strcmp(i->name, "variable") == 0) {
1039 args.variable = (i->value);
1043 for (i = path_vars; i; i = i->next) {
1044 if (strcmp(i->name, "channelId") == 0) {
1045 args.channel_id = (i->value);
1049 ast_ari_get_channel_var(headers, &args, response);
1050 #if defined(AST_DEVMODE)
1051 code = response->response_code;
1054 case 0: /* Implementation is still a stub, or the code wasn't set */
1055 is_valid = response->message == NULL;
1057 case 500: /* Internal Server Error */
1058 case 501: /* Not Implemented */
1059 case 400: /* Missing variable parameter. */
1060 case 404: /* Channel not found */
1061 case 409: /* Channel not in a Stasis application */
1065 if (200 <= code && code <= 299) {
1066 is_valid = ast_ari_validate_variable(
1069 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
1075 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
1076 ast_ari_response_error(response, 500,
1077 "Internal Server Error", "Response validation failed");
1079 #endif /* AST_DEVMODE */
1081 fin: __attribute__((unused))
1085 * \brief Parameter parsing callback for /channels/{channelId}/variable.
1086 * \param get_params GET parameters in the HTTP request.
1087 * \param path_vars Path variables extracted from the request.
1088 * \param headers HTTP headers.
1089 * \param[out] response Response to the HTTP request.
1091 static void ast_ari_set_channel_var_cb(
1092 struct ast_variable *get_params, struct ast_variable *path_vars,
1093 struct ast_variable *headers, struct ast_ari_response *response)
1095 struct ast_set_channel_var_args args = {};
1096 struct ast_variable *i;
1097 #if defined(AST_DEVMODE)
1100 #endif /* AST_DEVMODE */
1102 for (i = get_params; i; i = i->next) {
1103 if (strcmp(i->name, "variable") == 0) {
1104 args.variable = (i->value);
1106 if (strcmp(i->name, "value") == 0) {
1107 args.value = (i->value);
1111 for (i = path_vars; i; i = i->next) {
1112 if (strcmp(i->name, "channelId") == 0) {
1113 args.channel_id = (i->value);
1117 ast_ari_set_channel_var(headers, &args, response);
1118 #if defined(AST_DEVMODE)
1119 code = response->response_code;
1122 case 0: /* Implementation is still a stub, or the code wasn't set */
1123 is_valid = response->message == NULL;
1125 case 500: /* Internal Server Error */
1126 case 501: /* Not Implemented */
1127 case 400: /* Missing variable parameter. */
1128 case 404: /* Channel not found */
1129 case 409: /* Channel not in a Stasis application */
1133 if (200 <= code && code <= 299) {
1134 is_valid = ast_ari_validate_void(
1137 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
1143 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
1144 ast_ari_response_error(response, 500,
1145 "Internal Server Error", "Response validation failed");
1147 #endif /* AST_DEVMODE */
1149 fin: __attribute__((unused))
1153 /*! \brief REST handler for /api-docs/channels.{format} */
1154 static struct stasis_rest_handlers channels_channelId_dial = {
1155 .path_segment = "dial",
1157 [AST_HTTP_POST] = ast_ari_dial_cb,
1162 /*! \brief REST handler for /api-docs/channels.{format} */
1163 static struct stasis_rest_handlers channels_channelId_continue = {
1164 .path_segment = "continue",
1166 [AST_HTTP_POST] = ast_ari_continue_in_dialplan_cb,
1171 /*! \brief REST handler for /api-docs/channels.{format} */
1172 static struct stasis_rest_handlers channels_channelId_answer = {
1173 .path_segment = "answer",
1175 [AST_HTTP_POST] = ast_ari_answer_channel_cb,
1180 /*! \brief REST handler for /api-docs/channels.{format} */
1181 static struct stasis_rest_handlers channels_channelId_mute = {
1182 .path_segment = "mute",
1184 [AST_HTTP_POST] = ast_ari_mute_channel_cb,
1189 /*! \brief REST handler for /api-docs/channels.{format} */
1190 static struct stasis_rest_handlers channels_channelId_unmute = {
1191 .path_segment = "unmute",
1193 [AST_HTTP_POST] = ast_ari_unmute_channel_cb,
1198 /*! \brief REST handler for /api-docs/channels.{format} */
1199 static struct stasis_rest_handlers channels_channelId_hold = {
1200 .path_segment = "hold",
1202 [AST_HTTP_POST] = ast_ari_hold_channel_cb,
1203 [AST_HTTP_DELETE] = ast_ari_unhold_channel_cb,
1208 /*! \brief REST handler for /api-docs/channels.{format} */
1209 static struct stasis_rest_handlers channels_channelId_moh = {
1210 .path_segment = "moh",
1212 [AST_HTTP_POST] = ast_ari_moh_start_channel_cb,
1213 [AST_HTTP_DELETE] = ast_ari_moh_stop_channel_cb,
1218 /*! \brief REST handler for /api-docs/channels.{format} */
1219 static struct stasis_rest_handlers channels_channelId_play = {
1220 .path_segment = "play",
1222 [AST_HTTP_POST] = ast_ari_play_on_channel_cb,
1227 /*! \brief REST handler for /api-docs/channels.{format} */
1228 static struct stasis_rest_handlers channels_channelId_record = {
1229 .path_segment = "record",
1231 [AST_HTTP_POST] = ast_ari_record_channel_cb,
1236 /*! \brief REST handler for /api-docs/channels.{format} */
1237 static struct stasis_rest_handlers channels_channelId_variable = {
1238 .path_segment = "variable",
1240 [AST_HTTP_GET] = ast_ari_get_channel_var_cb,
1241 [AST_HTTP_POST] = ast_ari_set_channel_var_cb,
1246 /*! \brief REST handler for /api-docs/channels.{format} */
1247 static struct stasis_rest_handlers channels_channelId = {
1248 .path_segment = "channelId",
1251 [AST_HTTP_GET] = ast_ari_get_channel_cb,
1252 [AST_HTTP_DELETE] = ast_ari_delete_channel_cb,
1255 .children = { &channels_channelId_dial,&channels_channelId_continue,&channels_channelId_answer,&channels_channelId_mute,&channels_channelId_unmute,&channels_channelId_hold,&channels_channelId_moh,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable, }
1257 /*! \brief REST handler for /api-docs/channels.{format} */
1258 static struct stasis_rest_handlers channels = {
1259 .path_segment = "channels",
1261 [AST_HTTP_GET] = ast_ari_get_channels_cb,
1262 [AST_HTTP_POST] = ast_ari_originate_cb,
1265 .children = { &channels_channelId, }
1268 static int load_module(void)
1272 res |= ast_ari_add_handler(&channels);
1276 static int unload_module(void)
1278 ast_ari_remove_handler(&channels);
1283 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Channel resources",
1284 .load = load_module,
1285 .unload = unload_module,
1286 .nonoptreq = "res_ari,res_stasis",