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}/continue.
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_continue_in_dialplan_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_continue_in_dialplan_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, "context") == 0) {
315 args.context = (i->value);
317 if (strcmp(i->name, "extension") == 0) {
318 args.extension = (i->value);
320 if (strcmp(i->name, "priority") == 0) {
321 args.priority = atoi(i->value);
325 for (i = path_vars; i; i = i->next) {
326 if (strcmp(i->name, "channelId") == 0) {
327 args.channel_id = (i->value);
331 ast_ari_continue_in_dialplan(headers, &args, response);
332 #if defined(AST_DEVMODE)
333 code = response->response_code;
336 case 0: /* Implementation is still a stub, or the code wasn't set */
337 is_valid = response->message == NULL;
339 case 500: /* Internal Server Error */
340 case 501: /* Not Implemented */
341 case 404: /* Channel not found */
342 case 409: /* Channel not in a Stasis application */
346 if (200 <= code && code <= 299) {
347 is_valid = ast_ari_validate_void(
350 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/continue\n", code);
356 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/continue\n");
357 ast_ari_response_error(response, 500,
358 "Internal Server Error", "Response validation failed");
360 #endif /* AST_DEVMODE */
362 fin: __attribute__((unused))
366 * \brief Parameter parsing callback for /channels/{channelId}/answer.
367 * \param get_params GET parameters in the HTTP request.
368 * \param path_vars Path variables extracted from the request.
369 * \param headers HTTP headers.
370 * \param[out] response Response to the HTTP request.
372 static void ast_ari_answer_channel_cb(
373 struct ast_variable *get_params, struct ast_variable *path_vars,
374 struct ast_variable *headers, struct ast_ari_response *response)
376 struct ast_answer_channel_args args = {};
377 struct ast_variable *i;
378 #if defined(AST_DEVMODE)
381 #endif /* AST_DEVMODE */
383 for (i = path_vars; i; i = i->next) {
384 if (strcmp(i->name, "channelId") == 0) {
385 args.channel_id = (i->value);
389 ast_ari_answer_channel(headers, &args, response);
390 #if defined(AST_DEVMODE)
391 code = response->response_code;
394 case 0: /* Implementation is still a stub, or the code wasn't set */
395 is_valid = response->message == NULL;
397 case 500: /* Internal Server Error */
398 case 501: /* Not Implemented */
399 case 404: /* Channel not found */
400 case 409: /* Channel not in a Stasis application */
404 if (200 <= code && code <= 299) {
405 is_valid = ast_ari_validate_void(
408 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/answer\n", code);
414 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/answer\n");
415 ast_ari_response_error(response, 500,
416 "Internal Server Error", "Response validation failed");
418 #endif /* AST_DEVMODE */
420 fin: __attribute__((unused))
424 * \brief Parameter parsing callback for /channels/{channelId}/mute.
425 * \param get_params GET parameters in the HTTP request.
426 * \param path_vars Path variables extracted from the request.
427 * \param headers HTTP headers.
428 * \param[out] response Response to the HTTP request.
430 static void ast_ari_mute_channel_cb(
431 struct ast_variable *get_params, struct ast_variable *path_vars,
432 struct ast_variable *headers, struct ast_ari_response *response)
434 struct ast_mute_channel_args args = {};
435 struct ast_variable *i;
436 #if defined(AST_DEVMODE)
439 #endif /* AST_DEVMODE */
441 for (i = get_params; i; i = i->next) {
442 if (strcmp(i->name, "direction") == 0) {
443 args.direction = (i->value);
447 for (i = path_vars; i; i = i->next) {
448 if (strcmp(i->name, "channelId") == 0) {
449 args.channel_id = (i->value);
453 ast_ari_mute_channel(headers, &args, response);
454 #if defined(AST_DEVMODE)
455 code = response->response_code;
458 case 0: /* Implementation is still a stub, or the code wasn't set */
459 is_valid = response->message == NULL;
461 case 500: /* Internal Server Error */
462 case 501: /* Not Implemented */
463 case 404: /* Channel not found */
464 case 409: /* Channel not in a Stasis application */
468 if (200 <= code && code <= 299) {
469 is_valid = ast_ari_validate_void(
472 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mute\n", code);
478 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mute\n");
479 ast_ari_response_error(response, 500,
480 "Internal Server Error", "Response validation failed");
482 #endif /* AST_DEVMODE */
484 fin: __attribute__((unused))
488 * \brief Parameter parsing callback for /channels/{channelId}/unmute.
489 * \param get_params GET parameters in the HTTP request.
490 * \param path_vars Path variables extracted from the request.
491 * \param headers HTTP headers.
492 * \param[out] response Response to the HTTP request.
494 static void ast_ari_unmute_channel_cb(
495 struct ast_variable *get_params, struct ast_variable *path_vars,
496 struct ast_variable *headers, struct ast_ari_response *response)
498 struct ast_unmute_channel_args args = {};
499 struct ast_variable *i;
500 #if defined(AST_DEVMODE)
503 #endif /* AST_DEVMODE */
505 for (i = get_params; i; i = i->next) {
506 if (strcmp(i->name, "direction") == 0) {
507 args.direction = (i->value);
511 for (i = path_vars; i; i = i->next) {
512 if (strcmp(i->name, "channelId") == 0) {
513 args.channel_id = (i->value);
517 ast_ari_unmute_channel(headers, &args, response);
518 #if defined(AST_DEVMODE)
519 code = response->response_code;
522 case 0: /* Implementation is still a stub, or the code wasn't set */
523 is_valid = response->message == NULL;
525 case 500: /* Internal Server Error */
526 case 501: /* Not Implemented */
527 case 404: /* Channel not found */
528 case 409: /* Channel not in a Stasis application */
532 if (200 <= code && code <= 299) {
533 is_valid = ast_ari_validate_void(
536 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/unmute\n", code);
542 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/unmute\n");
543 ast_ari_response_error(response, 500,
544 "Internal Server Error", "Response validation failed");
546 #endif /* AST_DEVMODE */
548 fin: __attribute__((unused))
552 * \brief Parameter parsing callback for /channels/{channelId}/hold.
553 * \param get_params GET parameters in the HTTP request.
554 * \param path_vars Path variables extracted from the request.
555 * \param headers HTTP headers.
556 * \param[out] response Response to the HTTP request.
558 static void ast_ari_hold_channel_cb(
559 struct ast_variable *get_params, struct ast_variable *path_vars,
560 struct ast_variable *headers, struct ast_ari_response *response)
562 struct ast_hold_channel_args args = {};
563 struct ast_variable *i;
564 #if defined(AST_DEVMODE)
567 #endif /* AST_DEVMODE */
569 for (i = path_vars; i; i = i->next) {
570 if (strcmp(i->name, "channelId") == 0) {
571 args.channel_id = (i->value);
575 ast_ari_hold_channel(headers, &args, response);
576 #if defined(AST_DEVMODE)
577 code = response->response_code;
580 case 0: /* Implementation is still a stub, or the code wasn't set */
581 is_valid = response->message == NULL;
583 case 500: /* Internal Server Error */
584 case 501: /* Not Implemented */
585 case 404: /* Channel not found */
586 case 409: /* Channel not in a Stasis application */
590 if (200 <= code && code <= 299) {
591 is_valid = ast_ari_validate_void(
594 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/hold\n", code);
600 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/hold\n");
601 ast_ari_response_error(response, 500,
602 "Internal Server Error", "Response validation failed");
604 #endif /* AST_DEVMODE */
606 fin: __attribute__((unused))
610 * \brief Parameter parsing callback for /channels/{channelId}/hold.
611 * \param get_params GET parameters in the HTTP request.
612 * \param path_vars Path variables extracted from the request.
613 * \param headers HTTP headers.
614 * \param[out] response Response to the HTTP request.
616 static void ast_ari_unhold_channel_cb(
617 struct ast_variable *get_params, struct ast_variable *path_vars,
618 struct ast_variable *headers, struct ast_ari_response *response)
620 struct ast_unhold_channel_args args = {};
621 struct ast_variable *i;
622 #if defined(AST_DEVMODE)
625 #endif /* AST_DEVMODE */
627 for (i = path_vars; i; i = i->next) {
628 if (strcmp(i->name, "channelId") == 0) {
629 args.channel_id = (i->value);
633 ast_ari_unhold_channel(headers, &args, response);
634 #if defined(AST_DEVMODE)
635 code = response->response_code;
638 case 0: /* Implementation is still a stub, or the code wasn't set */
639 is_valid = response->message == NULL;
641 case 500: /* Internal Server Error */
642 case 501: /* Not Implemented */
643 case 404: /* Channel not found */
644 case 409: /* Channel not in a Stasis application */
648 if (200 <= code && code <= 299) {
649 is_valid = ast_ari_validate_void(
652 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/hold\n", code);
658 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/hold\n");
659 ast_ari_response_error(response, 500,
660 "Internal Server Error", "Response validation failed");
662 #endif /* AST_DEVMODE */
664 fin: __attribute__((unused))
668 * \brief Parameter parsing callback for /channels/{channelId}/moh.
669 * \param get_params GET parameters in the HTTP request.
670 * \param path_vars Path variables extracted from the request.
671 * \param headers HTTP headers.
672 * \param[out] response Response to the HTTP request.
674 static void ast_ari_moh_start_channel_cb(
675 struct ast_variable *get_params, struct ast_variable *path_vars,
676 struct ast_variable *headers, struct ast_ari_response *response)
678 struct ast_moh_start_channel_args args = {};
679 struct ast_variable *i;
680 #if defined(AST_DEVMODE)
683 #endif /* AST_DEVMODE */
685 for (i = get_params; i; i = i->next) {
686 if (strcmp(i->name, "mohClass") == 0) {
687 args.moh_class = (i->value);
691 for (i = path_vars; i; i = i->next) {
692 if (strcmp(i->name, "channelId") == 0) {
693 args.channel_id = (i->value);
697 ast_ari_moh_start_channel(headers, &args, response);
698 #if defined(AST_DEVMODE)
699 code = response->response_code;
702 case 0: /* Implementation is still a stub, or the code wasn't set */
703 is_valid = response->message == NULL;
705 case 500: /* Internal Server Error */
706 case 501: /* Not Implemented */
707 case 404: /* Channel not found */
708 case 409: /* Channel not in a Stasis application */
712 if (200 <= code && code <= 299) {
713 is_valid = ast_ari_validate_void(
716 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/moh\n", code);
722 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/moh\n");
723 ast_ari_response_error(response, 500,
724 "Internal Server Error", "Response validation failed");
726 #endif /* AST_DEVMODE */
728 fin: __attribute__((unused))
732 * \brief Parameter parsing callback for /channels/{channelId}/moh.
733 * \param get_params GET parameters in the HTTP request.
734 * \param path_vars Path variables extracted from the request.
735 * \param headers HTTP headers.
736 * \param[out] response Response to the HTTP request.
738 static void ast_ari_moh_stop_channel_cb(
739 struct ast_variable *get_params, struct ast_variable *path_vars,
740 struct ast_variable *headers, struct ast_ari_response *response)
742 struct ast_moh_stop_channel_args args = {};
743 struct ast_variable *i;
744 #if defined(AST_DEVMODE)
747 #endif /* AST_DEVMODE */
749 for (i = path_vars; i; i = i->next) {
750 if (strcmp(i->name, "channelId") == 0) {
751 args.channel_id = (i->value);
755 ast_ari_moh_stop_channel(headers, &args, response);
756 #if defined(AST_DEVMODE)
757 code = response->response_code;
760 case 0: /* Implementation is still a stub, or the code wasn't set */
761 is_valid = response->message == NULL;
763 case 500: /* Internal Server Error */
764 case 501: /* Not Implemented */
765 case 404: /* Channel not found */
766 case 409: /* Channel not in a Stasis application */
770 if (200 <= code && code <= 299) {
771 is_valid = ast_ari_validate_void(
774 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/moh\n", code);
780 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/moh\n");
781 ast_ari_response_error(response, 500,
782 "Internal Server Error", "Response validation failed");
784 #endif /* AST_DEVMODE */
786 fin: __attribute__((unused))
790 * \brief Parameter parsing callback for /channels/{channelId}/play.
791 * \param get_params GET parameters in the HTTP request.
792 * \param path_vars Path variables extracted from the request.
793 * \param headers HTTP headers.
794 * \param[out] response Response to the HTTP request.
796 static void ast_ari_play_on_channel_cb(
797 struct ast_variable *get_params, struct ast_variable *path_vars,
798 struct ast_variable *headers, struct ast_ari_response *response)
800 struct ast_play_on_channel_args args = {};
801 struct ast_variable *i;
802 #if defined(AST_DEVMODE)
805 #endif /* AST_DEVMODE */
807 for (i = get_params; i; i = i->next) {
808 if (strcmp(i->name, "media") == 0) {
809 args.media = (i->value);
811 if (strcmp(i->name, "lang") == 0) {
812 args.lang = (i->value);
814 if (strcmp(i->name, "offsetms") == 0) {
815 args.offsetms = atoi(i->value);
817 if (strcmp(i->name, "skipms") == 0) {
818 args.skipms = atoi(i->value);
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_play_on_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_playback(
847 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/play\n", code);
853 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/play\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}/record.
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_record_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_record_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, "name") == 0) {
882 args.name = (i->value);
884 if (strcmp(i->name, "format") == 0) {
885 args.format = (i->value);
887 if (strcmp(i->name, "maxDurationSeconds") == 0) {
888 args.max_duration_seconds = atoi(i->value);
890 if (strcmp(i->name, "maxSilenceSeconds") == 0) {
891 args.max_silence_seconds = atoi(i->value);
893 if (strcmp(i->name, "ifExists") == 0) {
894 args.if_exists = (i->value);
896 if (strcmp(i->name, "beep") == 0) {
897 args.beep = ast_true(i->value);
899 if (strcmp(i->name, "terminateOn") == 0) {
900 args.terminate_on = (i->value);
904 for (i = path_vars; i; i = i->next) {
905 if (strcmp(i->name, "channelId") == 0) {
906 args.channel_id = (i->value);
910 ast_ari_record_channel(headers, &args, response);
911 #if defined(AST_DEVMODE)
912 code = response->response_code;
915 case 0: /* Implementation is still a stub, or the code wasn't set */
916 is_valid = response->message == NULL;
918 case 500: /* Internal Server Error */
919 case 501: /* Not Implemented */
920 case 400: /* Invalid parameters */
921 case 404: /* Channel not found */
922 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 */
923 case 422: /* The format specified is unknown on this system */
927 if (200 <= code && code <= 299) {
928 is_valid = ast_ari_validate_live_recording(
931 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/record\n", code);
937 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/record\n");
938 ast_ari_response_error(response, 500,
939 "Internal Server Error", "Response validation failed");
941 #endif /* AST_DEVMODE */
943 fin: __attribute__((unused))
947 * \brief Parameter parsing callback for /channels/{channelId}/variable.
948 * \param get_params GET parameters in the HTTP request.
949 * \param path_vars Path variables extracted from the request.
950 * \param headers HTTP headers.
951 * \param[out] response Response to the HTTP request.
953 static void ast_ari_get_channel_var_cb(
954 struct ast_variable *get_params, struct ast_variable *path_vars,
955 struct ast_variable *headers, struct ast_ari_response *response)
957 struct ast_get_channel_var_args args = {};
958 struct ast_variable *i;
959 #if defined(AST_DEVMODE)
962 #endif /* AST_DEVMODE */
964 for (i = get_params; i; i = i->next) {
965 if (strcmp(i->name, "variable") == 0) {
966 args.variable = (i->value);
970 for (i = path_vars; i; i = i->next) {
971 if (strcmp(i->name, "channelId") == 0) {
972 args.channel_id = (i->value);
976 ast_ari_get_channel_var(headers, &args, response);
977 #if defined(AST_DEVMODE)
978 code = response->response_code;
981 case 0: /* Implementation is still a stub, or the code wasn't set */
982 is_valid = response->message == NULL;
984 case 500: /* Internal Server Error */
985 case 501: /* Not Implemented */
986 case 400: /* Missing variable parameter. */
987 case 404: /* Channel not found */
988 case 409: /* Channel not in a Stasis application */
992 if (200 <= code && code <= 299) {
993 is_valid = ast_ari_validate_variable(
996 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
1002 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
1003 ast_ari_response_error(response, 500,
1004 "Internal Server Error", "Response validation failed");
1006 #endif /* AST_DEVMODE */
1008 fin: __attribute__((unused))
1012 * \brief Parameter parsing callback for /channels/{channelId}/variable.
1013 * \param get_params GET parameters in the HTTP request.
1014 * \param path_vars Path variables extracted from the request.
1015 * \param headers HTTP headers.
1016 * \param[out] response Response to the HTTP request.
1018 static void ast_ari_set_channel_var_cb(
1019 struct ast_variable *get_params, struct ast_variable *path_vars,
1020 struct ast_variable *headers, struct ast_ari_response *response)
1022 struct ast_set_channel_var_args args = {};
1023 struct ast_variable *i;
1024 #if defined(AST_DEVMODE)
1027 #endif /* AST_DEVMODE */
1029 for (i = get_params; i; i = i->next) {
1030 if (strcmp(i->name, "variable") == 0) {
1031 args.variable = (i->value);
1033 if (strcmp(i->name, "value") == 0) {
1034 args.value = (i->value);
1038 for (i = path_vars; i; i = i->next) {
1039 if (strcmp(i->name, "channelId") == 0) {
1040 args.channel_id = (i->value);
1044 ast_ari_set_channel_var(headers, &args, response);
1045 #if defined(AST_DEVMODE)
1046 code = response->response_code;
1049 case 0: /* Implementation is still a stub, or the code wasn't set */
1050 is_valid = response->message == NULL;
1052 case 500: /* Internal Server Error */
1053 case 501: /* Not Implemented */
1054 case 400: /* Missing variable parameter. */
1055 case 404: /* Channel not found */
1056 case 409: /* Channel not in a Stasis application */
1060 if (200 <= code && code <= 299) {
1061 is_valid = ast_ari_validate_void(
1064 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
1070 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
1071 ast_ari_response_error(response, 500,
1072 "Internal Server Error", "Response validation failed");
1074 #endif /* AST_DEVMODE */
1076 fin: __attribute__((unused))
1080 /*! \brief REST handler for /api-docs/channels.{format} */
1081 static struct stasis_rest_handlers channels_channelId_continue = {
1082 .path_segment = "continue",
1084 [AST_HTTP_POST] = ast_ari_continue_in_dialplan_cb,
1089 /*! \brief REST handler for /api-docs/channels.{format} */
1090 static struct stasis_rest_handlers channels_channelId_answer = {
1091 .path_segment = "answer",
1093 [AST_HTTP_POST] = ast_ari_answer_channel_cb,
1098 /*! \brief REST handler for /api-docs/channels.{format} */
1099 static struct stasis_rest_handlers channels_channelId_mute = {
1100 .path_segment = "mute",
1102 [AST_HTTP_POST] = ast_ari_mute_channel_cb,
1107 /*! \brief REST handler for /api-docs/channels.{format} */
1108 static struct stasis_rest_handlers channels_channelId_unmute = {
1109 .path_segment = "unmute",
1111 [AST_HTTP_POST] = ast_ari_unmute_channel_cb,
1116 /*! \brief REST handler for /api-docs/channels.{format} */
1117 static struct stasis_rest_handlers channels_channelId_hold = {
1118 .path_segment = "hold",
1120 [AST_HTTP_POST] = ast_ari_hold_channel_cb,
1121 [AST_HTTP_DELETE] = ast_ari_unhold_channel_cb,
1126 /*! \brief REST handler for /api-docs/channels.{format} */
1127 static struct stasis_rest_handlers channels_channelId_moh = {
1128 .path_segment = "moh",
1130 [AST_HTTP_POST] = ast_ari_moh_start_channel_cb,
1131 [AST_HTTP_DELETE] = ast_ari_moh_stop_channel_cb,
1136 /*! \brief REST handler for /api-docs/channels.{format} */
1137 static struct stasis_rest_handlers channels_channelId_play = {
1138 .path_segment = "play",
1140 [AST_HTTP_POST] = ast_ari_play_on_channel_cb,
1145 /*! \brief REST handler for /api-docs/channels.{format} */
1146 static struct stasis_rest_handlers channels_channelId_record = {
1147 .path_segment = "record",
1149 [AST_HTTP_POST] = ast_ari_record_channel_cb,
1154 /*! \brief REST handler for /api-docs/channels.{format} */
1155 static struct stasis_rest_handlers channels_channelId_variable = {
1156 .path_segment = "variable",
1158 [AST_HTTP_GET] = ast_ari_get_channel_var_cb,
1159 [AST_HTTP_POST] = ast_ari_set_channel_var_cb,
1164 /*! \brief REST handler for /api-docs/channels.{format} */
1165 static struct stasis_rest_handlers channels_channelId = {
1166 .path_segment = "channelId",
1169 [AST_HTTP_GET] = ast_ari_get_channel_cb,
1170 [AST_HTTP_DELETE] = ast_ari_delete_channel_cb,
1173 .children = { &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, }
1175 /*! \brief REST handler for /api-docs/channels.{format} */
1176 static struct stasis_rest_handlers channels = {
1177 .path_segment = "channels",
1179 [AST_HTTP_GET] = ast_ari_get_channels_cb,
1180 [AST_HTTP_POST] = ast_ari_originate_cb,
1183 .children = { &channels_channelId, }
1186 static int load_module(void)
1190 res |= ast_ari_add_handler(&channels);
1194 static int unload_module(void)
1196 ast_ari_remove_handler(&channels);
1201 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Channel resources",
1202 .load = load_module,
1203 .unload = unload_module,
1204 .nonoptreq = "res_ari,res_stasis",