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_stasis_http_resource.c.mustache
29 * \brief Channel resources
31 * \author David M. Lee, II <dlee@digium.com>
35 <depend type="module">res_stasis_http</depend>
36 <depend type="module">res_stasis</depend>
37 <support_level>core</support_level>
42 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
44 #include "asterisk/module.h"
45 #include "asterisk/stasis_app.h"
46 #include "stasis_http/resource_channels.h"
47 #if defined(AST_DEVMODE)
48 #include "stasis_http/ari_model_validators.h"
52 * \brief Parameter parsing callback for /channels.
53 * \param get_params GET parameters in the HTTP request.
54 * \param path_vars Path variables extracted from the request.
55 * \param headers HTTP headers.
56 * \param[out] response Response to the HTTP request.
58 static void stasis_http_get_channels_cb(
59 struct ast_variable *get_params, struct ast_variable *path_vars,
60 struct ast_variable *headers, struct stasis_http_response *response)
62 #if defined(AST_DEVMODE)
65 #endif /* AST_DEVMODE */
67 struct ast_get_channels_args args = {};
68 stasis_http_get_channels(headers, &args, response);
69 #if defined(AST_DEVMODE)
70 code = response->response_code;
73 case 500: /* Internal server error */
77 if (200 <= code && code <= 299) {
78 is_valid = ari_validate_list(response->message,
79 ari_validate_channel_fn());
81 ast_log(LOG_ERROR, "Invalid error response %d for /channels\n", code);
87 ast_log(LOG_ERROR, "Response validation failed for /channels\n");
88 stasis_http_response_error(response, 500,
89 "Internal Server Error", "Response validation failed");
91 #endif /* AST_DEVMODE */
94 * \brief Parameter parsing callback for /channels.
95 * \param get_params GET parameters in the HTTP request.
96 * \param path_vars Path variables extracted from the request.
97 * \param headers HTTP headers.
98 * \param[out] response Response to the HTTP request.
100 static void stasis_http_originate_cb(
101 struct ast_variable *get_params, struct ast_variable *path_vars,
102 struct ast_variable *headers, struct stasis_http_response *response)
104 #if defined(AST_DEVMODE)
107 #endif /* AST_DEVMODE */
109 struct ast_originate_args args = {};
110 struct ast_variable *i;
112 for (i = get_params; i; i = i->next) {
113 if (strcmp(i->name, "endpoint") == 0) {
114 args.endpoint = (i->value);
116 if (strcmp(i->name, "extension") == 0) {
117 args.extension = (i->value);
119 if (strcmp(i->name, "context") == 0) {
120 args.context = (i->value);
122 if (strcmp(i->name, "priority") == 0) {
123 args.priority = atol(i->value);
125 if (strcmp(i->name, "app") == 0) {
126 args.app = (i->value);
128 if (strcmp(i->name, "appArgs") == 0) {
129 args.app_args = (i->value);
131 if (strcmp(i->name, "callerId") == 0) {
132 args.caller_id = (i->value);
134 if (strcmp(i->name, "timeout") == 0) {
135 args.timeout = atoi(i->value);
139 stasis_http_originate(headers, &args, response);
140 #if defined(AST_DEVMODE)
141 code = response->response_code;
144 case 500: /* Internal server error */
145 case 400: /* Invalid parameters for originating a channel. */
149 if (200 <= code && code <= 299) {
150 is_valid = ari_validate_void(
153 ast_log(LOG_ERROR, "Invalid error response %d for /channels\n", code);
159 ast_log(LOG_ERROR, "Response validation failed for /channels\n");
160 stasis_http_response_error(response, 500,
161 "Internal Server Error", "Response validation failed");
163 #endif /* AST_DEVMODE */
166 * \brief Parameter parsing callback for /channels/{channelId}.
167 * \param get_params GET parameters in the HTTP request.
168 * \param path_vars Path variables extracted from the request.
169 * \param headers HTTP headers.
170 * \param[out] response Response to the HTTP request.
172 static void stasis_http_get_channel_cb(
173 struct ast_variable *get_params, struct ast_variable *path_vars,
174 struct ast_variable *headers, struct stasis_http_response *response)
176 #if defined(AST_DEVMODE)
179 #endif /* AST_DEVMODE */
181 struct ast_get_channel_args args = {};
182 struct ast_variable *i;
184 for (i = path_vars; i; i = i->next) {
185 if (strcmp(i->name, "channelId") == 0) {
186 args.channel_id = (i->value);
190 stasis_http_get_channel(headers, &args, response);
191 #if defined(AST_DEVMODE)
192 code = response->response_code;
195 case 500: /* Internal server error */
196 case 404: /* Channel not found */
200 if (200 <= code && code <= 299) {
201 is_valid = ari_validate_channel(
204 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
210 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
211 stasis_http_response_error(response, 500,
212 "Internal Server Error", "Response validation failed");
214 #endif /* AST_DEVMODE */
217 * \brief Parameter parsing callback for /channels/{channelId}.
218 * \param get_params GET parameters in the HTTP request.
219 * \param path_vars Path variables extracted from the request.
220 * \param headers HTTP headers.
221 * \param[out] response Response to the HTTP request.
223 static void stasis_http_delete_channel_cb(
224 struct ast_variable *get_params, struct ast_variable *path_vars,
225 struct ast_variable *headers, struct stasis_http_response *response)
227 #if defined(AST_DEVMODE)
230 #endif /* AST_DEVMODE */
232 struct ast_delete_channel_args args = {};
233 struct ast_variable *i;
235 for (i = path_vars; i; i = i->next) {
236 if (strcmp(i->name, "channelId") == 0) {
237 args.channel_id = (i->value);
241 stasis_http_delete_channel(headers, &args, response);
242 #if defined(AST_DEVMODE)
243 code = response->response_code;
246 case 500: /* Internal server error */
247 case 404: /* Channel not found */
251 if (200 <= code && code <= 299) {
252 is_valid = ari_validate_void(
255 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
261 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
262 stasis_http_response_error(response, 500,
263 "Internal Server Error", "Response validation failed");
265 #endif /* AST_DEVMODE */
268 * \brief Parameter parsing callback for /channels/{channelId}/dial.
269 * \param get_params GET parameters in the HTTP request.
270 * \param path_vars Path variables extracted from the request.
271 * \param headers HTTP headers.
272 * \param[out] response Response to the HTTP request.
274 static void stasis_http_dial_cb(
275 struct ast_variable *get_params, struct ast_variable *path_vars,
276 struct ast_variable *headers, struct stasis_http_response *response)
278 #if defined(AST_DEVMODE)
281 #endif /* AST_DEVMODE */
283 struct ast_dial_args args = {};
284 struct ast_variable *i;
286 for (i = get_params; i; i = i->next) {
287 if (strcmp(i->name, "endpoint") == 0) {
288 args.endpoint = (i->value);
290 if (strcmp(i->name, "extension") == 0) {
291 args.extension = (i->value);
293 if (strcmp(i->name, "context") == 0) {
294 args.context = (i->value);
296 if (strcmp(i->name, "timeout") == 0) {
297 args.timeout = atoi(i->value);
301 for (i = path_vars; i; i = i->next) {
302 if (strcmp(i->name, "channelId") == 0) {
303 args.channel_id = (i->value);
307 stasis_http_dial(headers, &args, response);
308 #if defined(AST_DEVMODE)
309 code = response->response_code;
312 case 500: /* Internal server error */
313 case 404: /* Channel not found */
314 case 409: /* Channel not in a Stasis application */
318 if (200 <= code && code <= 299) {
319 is_valid = ari_validate_dialed(
322 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/dial\n", code);
328 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/dial\n");
329 stasis_http_response_error(response, 500,
330 "Internal Server Error", "Response validation failed");
332 #endif /* AST_DEVMODE */
335 * \brief Parameter parsing callback for /channels/{channelId}/continue.
336 * \param get_params GET parameters in the HTTP request.
337 * \param path_vars Path variables extracted from the request.
338 * \param headers HTTP headers.
339 * \param[out] response Response to the HTTP request.
341 static void stasis_http_continue_in_dialplan_cb(
342 struct ast_variable *get_params, struct ast_variable *path_vars,
343 struct ast_variable *headers, struct stasis_http_response *response)
345 #if defined(AST_DEVMODE)
348 #endif /* AST_DEVMODE */
350 struct ast_continue_in_dialplan_args args = {};
351 struct ast_variable *i;
353 for (i = get_params; i; i = i->next) {
354 if (strcmp(i->name, "context") == 0) {
355 args.context = (i->value);
357 if (strcmp(i->name, "extension") == 0) {
358 args.extension = (i->value);
360 if (strcmp(i->name, "priority") == 0) {
361 args.priority = atoi(i->value);
365 for (i = path_vars; i; i = i->next) {
366 if (strcmp(i->name, "channelId") == 0) {
367 args.channel_id = (i->value);
371 stasis_http_continue_in_dialplan(headers, &args, response);
372 #if defined(AST_DEVMODE)
373 code = response->response_code;
376 case 500: /* Internal server error */
377 case 404: /* Channel not found */
378 case 409: /* Channel not in a Stasis application */
382 if (200 <= code && code <= 299) {
383 is_valid = ari_validate_void(
386 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/continue\n", code);
392 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/continue\n");
393 stasis_http_response_error(response, 500,
394 "Internal Server Error", "Response validation failed");
396 #endif /* AST_DEVMODE */
399 * \brief Parameter parsing callback for /channels/{channelId}/answer.
400 * \param get_params GET parameters in the HTTP request.
401 * \param path_vars Path variables extracted from the request.
402 * \param headers HTTP headers.
403 * \param[out] response Response to the HTTP request.
405 static void stasis_http_answer_channel_cb(
406 struct ast_variable *get_params, struct ast_variable *path_vars,
407 struct ast_variable *headers, struct stasis_http_response *response)
409 #if defined(AST_DEVMODE)
412 #endif /* AST_DEVMODE */
414 struct ast_answer_channel_args args = {};
415 struct ast_variable *i;
417 for (i = path_vars; i; i = i->next) {
418 if (strcmp(i->name, "channelId") == 0) {
419 args.channel_id = (i->value);
423 stasis_http_answer_channel(headers, &args, response);
424 #if defined(AST_DEVMODE)
425 code = response->response_code;
428 case 500: /* Internal server error */
429 case 404: /* Channel not found */
430 case 409: /* Channel not in a Stasis application */
434 if (200 <= code && code <= 299) {
435 is_valid = ari_validate_void(
438 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/answer\n", code);
444 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/answer\n");
445 stasis_http_response_error(response, 500,
446 "Internal Server Error", "Response validation failed");
448 #endif /* AST_DEVMODE */
451 * \brief Parameter parsing callback for /channels/{channelId}/mute.
452 * \param get_params GET parameters in the HTTP request.
453 * \param path_vars Path variables extracted from the request.
454 * \param headers HTTP headers.
455 * \param[out] response Response to the HTTP request.
457 static void stasis_http_mute_channel_cb(
458 struct ast_variable *get_params, struct ast_variable *path_vars,
459 struct ast_variable *headers, struct stasis_http_response *response)
461 #if defined(AST_DEVMODE)
464 #endif /* AST_DEVMODE */
466 struct ast_mute_channel_args args = {};
467 struct ast_variable *i;
469 for (i = get_params; i; i = i->next) {
470 if (strcmp(i->name, "direction") == 0) {
471 args.direction = (i->value);
475 for (i = path_vars; i; i = i->next) {
476 if (strcmp(i->name, "channelId") == 0) {
477 args.channel_id = (i->value);
481 stasis_http_mute_channel(headers, &args, response);
482 #if defined(AST_DEVMODE)
483 code = response->response_code;
486 case 500: /* Internal server error */
487 case 404: /* Channel not found */
488 case 409: /* Channel not in a Stasis application */
492 if (200 <= code && code <= 299) {
493 is_valid = ari_validate_void(
496 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mute\n", code);
502 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mute\n");
503 stasis_http_response_error(response, 500,
504 "Internal Server Error", "Response validation failed");
506 #endif /* AST_DEVMODE */
509 * \brief Parameter parsing callback for /channels/{channelId}/unmute.
510 * \param get_params GET parameters in the HTTP request.
511 * \param path_vars Path variables extracted from the request.
512 * \param headers HTTP headers.
513 * \param[out] response Response to the HTTP request.
515 static void stasis_http_unmute_channel_cb(
516 struct ast_variable *get_params, struct ast_variable *path_vars,
517 struct ast_variable *headers, struct stasis_http_response *response)
519 #if defined(AST_DEVMODE)
522 #endif /* AST_DEVMODE */
524 struct ast_unmute_channel_args args = {};
525 struct ast_variable *i;
527 for (i = get_params; i; i = i->next) {
528 if (strcmp(i->name, "direction") == 0) {
529 args.direction = (i->value);
533 for (i = path_vars; i; i = i->next) {
534 if (strcmp(i->name, "channelId") == 0) {
535 args.channel_id = (i->value);
539 stasis_http_unmute_channel(headers, &args, response);
540 #if defined(AST_DEVMODE)
541 code = response->response_code;
544 case 500: /* Internal server error */
545 case 404: /* Channel not found */
546 case 409: /* Channel not in a Stasis application */
550 if (200 <= code && code <= 299) {
551 is_valid = ari_validate_void(
554 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/unmute\n", code);
560 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/unmute\n");
561 stasis_http_response_error(response, 500,
562 "Internal Server Error", "Response validation failed");
564 #endif /* AST_DEVMODE */
567 * \brief Parameter parsing callback for /channels/{channelId}/hold.
568 * \param get_params GET parameters in the HTTP request.
569 * \param path_vars Path variables extracted from the request.
570 * \param headers HTTP headers.
571 * \param[out] response Response to the HTTP request.
573 static void stasis_http_hold_channel_cb(
574 struct ast_variable *get_params, struct ast_variable *path_vars,
575 struct ast_variable *headers, struct stasis_http_response *response)
577 #if defined(AST_DEVMODE)
580 #endif /* AST_DEVMODE */
582 struct ast_hold_channel_args args = {};
583 struct ast_variable *i;
585 for (i = path_vars; i; i = i->next) {
586 if (strcmp(i->name, "channelId") == 0) {
587 args.channel_id = (i->value);
591 stasis_http_hold_channel(headers, &args, response);
592 #if defined(AST_DEVMODE)
593 code = response->response_code;
596 case 500: /* Internal server error */
597 case 404: /* Channel not found */
598 case 409: /* Channel not in a Stasis application */
602 if (200 <= code && code <= 299) {
603 is_valid = ari_validate_void(
606 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/hold\n", code);
612 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/hold\n");
613 stasis_http_response_error(response, 500,
614 "Internal Server Error", "Response validation failed");
616 #endif /* AST_DEVMODE */
619 * \brief Parameter parsing callback for /channels/{channelId}/unhold.
620 * \param get_params GET parameters in the HTTP request.
621 * \param path_vars Path variables extracted from the request.
622 * \param headers HTTP headers.
623 * \param[out] response Response to the HTTP request.
625 static void stasis_http_unhold_channel_cb(
626 struct ast_variable *get_params, struct ast_variable *path_vars,
627 struct ast_variable *headers, struct stasis_http_response *response)
629 #if defined(AST_DEVMODE)
632 #endif /* AST_DEVMODE */
634 struct ast_unhold_channel_args args = {};
635 struct ast_variable *i;
637 for (i = path_vars; i; i = i->next) {
638 if (strcmp(i->name, "channelId") == 0) {
639 args.channel_id = (i->value);
643 stasis_http_unhold_channel(headers, &args, response);
644 #if defined(AST_DEVMODE)
645 code = response->response_code;
648 case 500: /* Internal server error */
649 case 404: /* Channel not found */
650 case 409: /* Channel not in a Stasis application */
654 if (200 <= code && code <= 299) {
655 is_valid = ari_validate_void(
658 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/unhold\n", code);
664 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/unhold\n");
665 stasis_http_response_error(response, 500,
666 "Internal Server Error", "Response validation failed");
668 #endif /* AST_DEVMODE */
671 * \brief Parameter parsing callback for /channels/{channelId}/mohstart.
672 * \param get_params GET parameters in the HTTP request.
673 * \param path_vars Path variables extracted from the request.
674 * \param headers HTTP headers.
675 * \param[out] response Response to the HTTP request.
677 static void stasis_http_moh_start_channel_cb(
678 struct ast_variable *get_params, struct ast_variable *path_vars,
679 struct ast_variable *headers, struct stasis_http_response *response)
681 #if defined(AST_DEVMODE)
684 #endif /* AST_DEVMODE */
686 struct ast_moh_start_channel_args args = {};
687 struct ast_variable *i;
689 for (i = get_params; i; i = i->next) {
690 if (strcmp(i->name, "mohClass") == 0) {
691 args.moh_class = (i->value);
695 for (i = path_vars; i; i = i->next) {
696 if (strcmp(i->name, "channelId") == 0) {
697 args.channel_id = (i->value);
701 stasis_http_moh_start_channel(headers, &args, response);
702 #if defined(AST_DEVMODE)
703 code = response->response_code;
706 case 500: /* Internal server error */
707 case 404: /* Channel not found */
708 case 409: /* Channel not in a Stasis application */
712 if (200 <= code && code <= 299) {
713 is_valid = ari_validate_void(
716 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mohstart\n", code);
722 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mohstart\n");
723 stasis_http_response_error(response, 500,
724 "Internal Server Error", "Response validation failed");
726 #endif /* AST_DEVMODE */
729 * \brief Parameter parsing callback for /channels/{channelId}/mohstop.
730 * \param get_params GET parameters in the HTTP request.
731 * \param path_vars Path variables extracted from the request.
732 * \param headers HTTP headers.
733 * \param[out] response Response to the HTTP request.
735 static void stasis_http_moh_stop_channel_cb(
736 struct ast_variable *get_params, struct ast_variable *path_vars,
737 struct ast_variable *headers, struct stasis_http_response *response)
739 #if defined(AST_DEVMODE)
742 #endif /* AST_DEVMODE */
744 struct ast_moh_stop_channel_args args = {};
745 struct ast_variable *i;
747 for (i = path_vars; i; i = i->next) {
748 if (strcmp(i->name, "channelId") == 0) {
749 args.channel_id = (i->value);
753 stasis_http_moh_stop_channel(headers, &args, response);
754 #if defined(AST_DEVMODE)
755 code = response->response_code;
758 case 500: /* Internal server error */
759 case 404: /* Channel not found */
760 case 409: /* Channel not in a Stasis application */
764 if (200 <= code && code <= 299) {
765 is_valid = ari_validate_void(
768 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mohstop\n", code);
774 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mohstop\n");
775 stasis_http_response_error(response, 500,
776 "Internal Server Error", "Response validation failed");
778 #endif /* AST_DEVMODE */
781 * \brief Parameter parsing callback for /channels/{channelId}/play.
782 * \param get_params GET parameters in the HTTP request.
783 * \param path_vars Path variables extracted from the request.
784 * \param headers HTTP headers.
785 * \param[out] response Response to the HTTP request.
787 static void stasis_http_play_on_channel_cb(
788 struct ast_variable *get_params, struct ast_variable *path_vars,
789 struct ast_variable *headers, struct stasis_http_response *response)
791 #if defined(AST_DEVMODE)
794 #endif /* AST_DEVMODE */
796 struct ast_play_on_channel_args args = {};
797 struct ast_variable *i;
799 for (i = get_params; i; i = i->next) {
800 if (strcmp(i->name, "media") == 0) {
801 args.media = (i->value);
803 if (strcmp(i->name, "lang") == 0) {
804 args.lang = (i->value);
806 if (strcmp(i->name, "offsetms") == 0) {
807 args.offsetms = atoi(i->value);
809 if (strcmp(i->name, "skipms") == 0) {
810 args.skipms = atoi(i->value);
814 for (i = path_vars; i; i = i->next) {
815 if (strcmp(i->name, "channelId") == 0) {
816 args.channel_id = (i->value);
820 stasis_http_play_on_channel(headers, &args, response);
821 #if defined(AST_DEVMODE)
822 code = response->response_code;
825 case 500: /* Internal server error */
826 case 404: /* Channel not found */
827 case 409: /* Channel not in a Stasis application */
831 if (200 <= code && code <= 299) {
832 is_valid = ari_validate_playback(
835 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/play\n", code);
841 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/play\n");
842 stasis_http_response_error(response, 500,
843 "Internal Server Error", "Response validation failed");
845 #endif /* AST_DEVMODE */
848 * \brief Parameter parsing callback for /channels/{channelId}/record.
849 * \param get_params GET parameters in the HTTP request.
850 * \param path_vars Path variables extracted from the request.
851 * \param headers HTTP headers.
852 * \param[out] response Response to the HTTP request.
854 static void stasis_http_record_channel_cb(
855 struct ast_variable *get_params, struct ast_variable *path_vars,
856 struct ast_variable *headers, struct stasis_http_response *response)
858 #if defined(AST_DEVMODE)
861 #endif /* AST_DEVMODE */
863 struct ast_record_channel_args args = {};
864 struct ast_variable *i;
866 for (i = get_params; i; i = i->next) {
867 if (strcmp(i->name, "name") == 0) {
868 args.name = (i->value);
870 if (strcmp(i->name, "format") == 0) {
871 args.format = (i->value);
873 if (strcmp(i->name, "maxDurationSeconds") == 0) {
874 args.max_duration_seconds = atoi(i->value);
876 if (strcmp(i->name, "maxSilenceSeconds") == 0) {
877 args.max_silence_seconds = atoi(i->value);
879 if (strcmp(i->name, "ifExists") == 0) {
880 args.if_exists = (i->value);
882 if (strcmp(i->name, "beep") == 0) {
883 args.beep = ast_true(i->value);
885 if (strcmp(i->name, "terminateOn") == 0) {
886 args.terminate_on = (i->value);
890 for (i = path_vars; i; i = i->next) {
891 if (strcmp(i->name, "channelId") == 0) {
892 args.channel_id = (i->value);
896 stasis_http_record_channel(headers, &args, response);
897 #if defined(AST_DEVMODE)
898 code = response->response_code;
901 case 500: /* Internal server error */
902 case 400: /* Invalid parameters */
903 case 404: /* Channel not found */
904 case 409: /* Channel is not in a Stasis application; the channel is currently bridged with other channels; A recording with the same name is currently in progress. */
908 if (200 <= code && code <= 299) {
909 is_valid = ari_validate_live_recording(
912 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/record\n", code);
918 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/record\n");
919 stasis_http_response_error(response, 500,
920 "Internal Server Error", "Response validation failed");
922 #endif /* AST_DEVMODE */
925 * \brief Parameter parsing callback for /channels/{channelId}/variable.
926 * \param get_params GET parameters in the HTTP request.
927 * \param path_vars Path variables extracted from the request.
928 * \param headers HTTP headers.
929 * \param[out] response Response to the HTTP request.
931 static void stasis_http_get_channel_var_cb(
932 struct ast_variable *get_params, struct ast_variable *path_vars,
933 struct ast_variable *headers, struct stasis_http_response *response)
935 #if defined(AST_DEVMODE)
938 #endif /* AST_DEVMODE */
940 struct ast_get_channel_var_args args = {};
941 struct ast_variable *i;
943 for (i = get_params; i; i = i->next) {
944 if (strcmp(i->name, "variable") == 0) {
945 args.variable = (i->value);
949 for (i = path_vars; i; i = i->next) {
950 if (strcmp(i->name, "channelId") == 0) {
951 args.channel_id = (i->value);
955 stasis_http_get_channel_var(headers, &args, response);
956 #if defined(AST_DEVMODE)
957 code = response->response_code;
960 case 500: /* Internal server error */
961 case 404: /* Channel not found */
962 case 409: /* Channel not in a Stasis application */
966 if (200 <= code && code <= 299) {
967 is_valid = ari_validate_variable(
970 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
976 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
977 stasis_http_response_error(response, 500,
978 "Internal Server Error", "Response validation failed");
980 #endif /* AST_DEVMODE */
983 * \brief Parameter parsing callback for /channels/{channelId}/variable.
984 * \param get_params GET parameters in the HTTP request.
985 * \param path_vars Path variables extracted from the request.
986 * \param headers HTTP headers.
987 * \param[out] response Response to the HTTP request.
989 static void stasis_http_set_channel_var_cb(
990 struct ast_variable *get_params, struct ast_variable *path_vars,
991 struct ast_variable *headers, struct stasis_http_response *response)
993 #if defined(AST_DEVMODE)
996 #endif /* AST_DEVMODE */
998 struct ast_set_channel_var_args args = {};
999 struct ast_variable *i;
1001 for (i = get_params; i; i = i->next) {
1002 if (strcmp(i->name, "variable") == 0) {
1003 args.variable = (i->value);
1005 if (strcmp(i->name, "value") == 0) {
1006 args.value = (i->value);
1010 for (i = path_vars; i; i = i->next) {
1011 if (strcmp(i->name, "channelId") == 0) {
1012 args.channel_id = (i->value);
1016 stasis_http_set_channel_var(headers, &args, response);
1017 #if defined(AST_DEVMODE)
1018 code = response->response_code;
1021 case 500: /* Internal server error */
1022 case 404: /* Channel not found */
1023 case 409: /* Channel not in a Stasis application */
1027 if (200 <= code && code <= 299) {
1028 is_valid = ari_validate_void(
1031 ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
1037 ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
1038 stasis_http_response_error(response, 500,
1039 "Internal Server Error", "Response validation failed");
1041 #endif /* AST_DEVMODE */
1044 /*! \brief REST handler for /api-docs/channels.{format} */
1045 static struct stasis_rest_handlers channels_channelId_dial = {
1046 .path_segment = "dial",
1048 [AST_HTTP_POST] = stasis_http_dial_cb,
1053 /*! \brief REST handler for /api-docs/channels.{format} */
1054 static struct stasis_rest_handlers channels_channelId_continue = {
1055 .path_segment = "continue",
1057 [AST_HTTP_POST] = stasis_http_continue_in_dialplan_cb,
1062 /*! \brief REST handler for /api-docs/channels.{format} */
1063 static struct stasis_rest_handlers channels_channelId_answer = {
1064 .path_segment = "answer",
1066 [AST_HTTP_POST] = stasis_http_answer_channel_cb,
1071 /*! \brief REST handler for /api-docs/channels.{format} */
1072 static struct stasis_rest_handlers channels_channelId_mute = {
1073 .path_segment = "mute",
1075 [AST_HTTP_POST] = stasis_http_mute_channel_cb,
1080 /*! \brief REST handler for /api-docs/channels.{format} */
1081 static struct stasis_rest_handlers channels_channelId_unmute = {
1082 .path_segment = "unmute",
1084 [AST_HTTP_POST] = stasis_http_unmute_channel_cb,
1089 /*! \brief REST handler for /api-docs/channels.{format} */
1090 static struct stasis_rest_handlers channels_channelId_hold = {
1091 .path_segment = "hold",
1093 [AST_HTTP_POST] = stasis_http_hold_channel_cb,
1098 /*! \brief REST handler for /api-docs/channels.{format} */
1099 static struct stasis_rest_handlers channels_channelId_unhold = {
1100 .path_segment = "unhold",
1102 [AST_HTTP_POST] = stasis_http_unhold_channel_cb,
1107 /*! \brief REST handler for /api-docs/channels.{format} */
1108 static struct stasis_rest_handlers channels_channelId_mohstart = {
1109 .path_segment = "mohstart",
1111 [AST_HTTP_POST] = stasis_http_moh_start_channel_cb,
1116 /*! \brief REST handler for /api-docs/channels.{format} */
1117 static struct stasis_rest_handlers channels_channelId_mohstop = {
1118 .path_segment = "mohstop",
1120 [AST_HTTP_POST] = stasis_http_moh_stop_channel_cb,
1125 /*! \brief REST handler for /api-docs/channels.{format} */
1126 static struct stasis_rest_handlers channels_channelId_play = {
1127 .path_segment = "play",
1129 [AST_HTTP_POST] = stasis_http_play_on_channel_cb,
1134 /*! \brief REST handler for /api-docs/channels.{format} */
1135 static struct stasis_rest_handlers channels_channelId_record = {
1136 .path_segment = "record",
1138 [AST_HTTP_POST] = stasis_http_record_channel_cb,
1143 /*! \brief REST handler for /api-docs/channels.{format} */
1144 static struct stasis_rest_handlers channels_channelId_variable = {
1145 .path_segment = "variable",
1147 [AST_HTTP_GET] = stasis_http_get_channel_var_cb,
1148 [AST_HTTP_POST] = stasis_http_set_channel_var_cb,
1153 /*! \brief REST handler for /api-docs/channels.{format} */
1154 static struct stasis_rest_handlers channels_channelId = {
1155 .path_segment = "channelId",
1158 [AST_HTTP_GET] = stasis_http_get_channel_cb,
1159 [AST_HTTP_DELETE] = stasis_http_delete_channel_cb,
1162 .children = { &channels_channelId_dial,&channels_channelId_continue,&channels_channelId_answer,&channels_channelId_mute,&channels_channelId_unmute,&channels_channelId_hold,&channels_channelId_unhold,&channels_channelId_mohstart,&channels_channelId_mohstop,&channels_channelId_play,&channels_channelId_record,&channels_channelId_variable, }
1164 /*! \brief REST handler for /api-docs/channels.{format} */
1165 static struct stasis_rest_handlers channels = {
1166 .path_segment = "channels",
1168 [AST_HTTP_GET] = stasis_http_get_channels_cb,
1169 [AST_HTTP_POST] = stasis_http_originate_cb,
1172 .children = { &channels_channelId, }
1175 static int load_module(void)
1179 res |= stasis_http_add_handler(&channels);
1183 static int unload_module(void)
1185 stasis_http_remove_handler(&channels);
1190 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Channel resources",
1191 .load = load_module,
1192 .unload = unload_module,
1193 .nonoptreq = "res_stasis_http,res_stasis",