Asterisk - The Open Source Telephony Project GIT-master-0deac78
resource_channels.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2012 - 2013, Digium, Inc.
5 *
6 * David M. Lee, II <dlee@digium.com>
7 *
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.
13 *
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.
17 */
18
19/*! \file
20 *
21 * \brief Implementation for ARI stubs.
22 *
23 * \author David M. Lee, II <dlee@digium.com>
24 */
25
26/*** MODULEINFO
27 <support_level>core</support_level>
28 ***/
29
30#include "asterisk.h"
31
32#include "asterisk/file.h"
33#include "asterisk/pbx.h"
34#include "asterisk/bridge.h"
35#include "asterisk/callerid.h"
36#include "asterisk/stasis_app.h"
41#include "asterisk/causes.h"
43#include "asterisk/core_local.h"
44#include "asterisk/dial.h"
46#include "asterisk/rtp_engine.h"
48#include "resource_channels.h"
49
50#include <limits.h>
51
52
53/*! \brief Return the corresponded hangup code of the given reason */
54static int convert_reason_to_hangup_code(const char* reason)
55{
56 if (!strcmp(reason, "normal")) {
57 return AST_CAUSE_NORMAL;
58 } else if (!strcmp(reason, "busy")) {
59 return AST_CAUSE_BUSY;
60 } else if (!strcmp(reason, "congestion")) {
62 } else if (!strcmp(reason, "no_answer")) {
63 return AST_CAUSE_NOANSWER;
64 } else if (!strcmp(reason, "timeout")) {
66 } else if (!strcmp(reason, "rejected")) {
68 } else if (!strcmp(reason, "unallocated")) {
70 } else if (!strcmp(reason, "normal_unspecified")) {
72 } else if (!strcmp(reason, "number_incomplete")) {
74 } else if (!strcmp(reason, "codec_mismatch")) {
76 } else if (!strcmp(reason, "interworking")) {
78 } else if (!strcmp(reason, "failure")) {
79 return AST_CAUSE_FAILURE;
80 } else if(!strcmp(reason, "answered_elsewhere")) {
82 }
83
84 return -1;
85}
86
87/*!
88 * \brief Ensure channel is in a state that allows operation to be performed.
89 *
90 * Since Asterisk 14, it has been possible for down channels, as well as unanswered
91 * outbound channels to enter Stasis. While some operations are fine to perform on
92 * such channels, operations that
93 *
94 * - Attempt to manipulate channel state
95 * - Attempt to play media
96 * - Attempt to control the channel's location in the dialplan
97 *
98 * are invalid. This function can be used to determine if the channel is in an
99 * appropriate state.
100 *
101 * \note When this function returns an error, the HTTP response is taken care of.
102 *
103 * \param control The app control
104 * \param response Response to fill in if there is an error
105 *
106 * \retval 0 Channel is in a valid state. Continue on!
107 * \retval non-zero Channel is in an invalid state. Bail!
108 */
109static int channel_state_invalid(struct stasis_app_control *control,
110 struct ast_ari_response *response)
111{
112 struct ast_channel_snapshot *snapshot;
113
114 snapshot = stasis_app_control_get_snapshot(control);
115 if (!snapshot) {
116 ast_ari_response_error(response, 404, "Not Found", "Channel not found");
117 return -1;
118 }
119
120 /* These channel states apply only to outbound channels:
121 * - Down: Channel has been created, and nothing else has been done
122 * - Reserved: For a PRI, an underlying B-channel is reserved,
123 * but the channel is not yet dialed
124 * - Ringing: The channel has been dialed.
125 *
126 * This does not affect inbound channels. Inbound channels, when they
127 * enter the dialplan, are in the "Ring" state. If they have already
128 * been answered, then they are in the "Up" state.
129 */
130 if (snapshot->state == AST_STATE_DOWN
131 || snapshot->state == AST_STATE_RESERVED
132 || snapshot->state == AST_STATE_RINGING) {
133 ast_ari_response_error(response, 412, "Precondition Failed",
134 "Channel in invalid state");
135 ao2_ref(snapshot, -1);
136
137 return -1;
138 }
139
140 ao2_ref(snapshot, -1);
141
142 return 0;
143}
144
145/*!
146 * \brief Finds the control object for a channel, filling the response with an
147 * error, if appropriate.
148 * \param[out] response Response to fill with an error if control is not found.
149 * \param channel_id ID of the channel to lookup.
150 * \return Channel control object.
151 * \retval NULL if control object does not exist.
152 */
154 struct ast_ari_response *response,
155 const char *channel_id)
156{
157 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
158
159 ast_assert(response != NULL);
160
161 control = stasis_app_control_find_by_channel_id(channel_id);
162 if (control == NULL) {
163 /* Distinguish between 404 and 409 errors */
164 RAII_VAR(struct ast_channel *, chan, NULL, ao2_cleanup);
165 chan = ast_channel_get_by_name(channel_id);
166 if (chan == NULL) {
167 ast_ari_response_error(response, 404, "Not Found",
168 "Channel not found");
169 return NULL;
170 }
171
172 ast_ari_response_error(response, 409, "Conflict",
173 "Channel not in Stasis application");
174 return NULL;
175 }
176
177 ao2_ref(control, +1);
178 return control;
179}
180
182 struct ast_variable *headers,
184 struct ast_ari_response *response)
185{
186 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
187 RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
188 int ipri;
189 const char *context;
190 const char *exten;
191
192 ast_assert(response != NULL);
193
194 control = find_control(response, args->channel_id);
195 if (control == NULL) {
196 return;
197 }
198
199 if (channel_state_invalid(control, response)) {
200 return;
201 }
202
203 snapshot = stasis_app_control_get_snapshot(control);
204 if (!snapshot) {
205 ast_ari_response_error(response, 404, "Not Found", "Channel not found");
206 return;
207 }
208
209 if (ast_strlen_zero(args->context)) {
210 context = snapshot->dialplan->context;
211 exten = S_OR(args->extension, snapshot->dialplan->exten);
212 } else {
213 context = args->context;
214 exten = S_OR(args->extension, "s");
215 }
216
217 if (!ast_strlen_zero(args->label)) {
218 /* A label was provided in the request, use that */
219
220 if (sscanf(args->label, "%30d", &ipri) != 1) {
221 ipri = ast_findlabel_extension(NULL, context, exten, args->label, NULL);
222 if (ipri == -1) {
223 ast_log(AST_LOG_ERROR, "Requested label: %s can not be found in context: %s\n", args->label, context);
224 ast_ari_response_error(response, 404, "Not Found", "Requested label can not be found");
225 return;
226 }
227 } else {
228 ast_debug(3, "Numeric value provided for label, jumping to that priority\n");
229 }
230
231 if (ipri == 0) {
232 ast_log(AST_LOG_ERROR, "Invalid priority label '%s' specified for extension %s in context: %s\n",
233 args->label, exten, context);
234 ast_ari_response_error(response, 400, "Bad Request", "Requested priority is illegal");
235 return;
236 }
237
238 } else if (args->priority) {
239 /* No label provided, use provided priority */
240 ipri = args->priority;
241 } else if (ast_strlen_zero(args->context) && ast_strlen_zero(args->extension)) {
242 /* Special case. No exten, context, or priority provided, then move on to the next priority */
243 ipri = snapshot->dialplan->priority + 1;
244 } else {
245 ipri = 1;
246 }
247
248
249 if (stasis_app_control_continue(control, context, exten, ipri)) {
251 return;
252 }
253
255}
256
259 struct ast_ari_response *response)
260{
261 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
262
263 control = find_control(response, args->channel_id);
264 if (!control) {
265 return;
266 }
267
268 if (stasis_app_control_move(control, args->app, args->app_args)) {
269 ast_ari_response_error(response, 500, "Internal Server Error",
270 "Failed to switch Stasis applications");
271 return;
272 }
273
275}
276
279 struct ast_ari_response *response)
280{
281 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
282 RAII_VAR(struct ast_channel_snapshot *, chan_snapshot, NULL, ao2_cleanup);
283 char *tech;
284 char *resource;
285 int tech_len;
286
287 control = find_control(response, args->channel_id);
288 if (!control) {
289 return;
290 }
291
292 if (channel_state_invalid(control, response)) {
293 return;
294 }
295
296 if (ast_strlen_zero(args->endpoint)) {
297 ast_ari_response_error(response, 400, "Not Found",
298 "Required parameter 'endpoint' not provided.");
299 return;
300 }
301
302 tech = ast_strdupa(args->endpoint);
303 if (!(resource = strchr(tech, '/')) || !(tech_len = resource - tech)) {
304 ast_ari_response_error(response, 422, "Unprocessable Entity",
305 "Endpoint parameter '%s' does not contain tech/resource", args->endpoint);
306 return;
307 }
308
309 *resource++ = '\0';
310 if (ast_strlen_zero(resource)) {
311 ast_ari_response_error(response, 422, "Unprocessable Entity",
312 "No resource provided in endpoint parameter '%s'", args->endpoint);
313 return;
314 }
315
316 chan_snapshot = ast_channel_snapshot_get_latest(args->channel_id);
317 if (!chan_snapshot) {
318 ast_ari_response_error(response, 500, "Internal Server Error",
319 "Unable to find channel snapshot for '%s'", args->channel_id);
320 return;
321 }
322
323 if (strncasecmp(chan_snapshot->base->type, tech, tech_len)) {
324 ast_ari_response_error(response, 422, "Unprocessable Entity",
325 "Endpoint technology '%s' does not match channel technology '%s'",
326 tech, chan_snapshot->base->type);
327 return;
328 }
329
330 if (stasis_app_control_redirect(control, resource)) {
331 ast_ari_response_error(response, 500, "Internal Server Error",
332 "Failed to redirect channel");
333 return;
334 }
335
337}
338
341 struct ast_ari_response *response)
342{
343 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
344
345 control = find_control(response, args->channel_id);
346 if (control == NULL) {
347 return;
348 }
349
350 if (channel_state_invalid(control, response)) {
351 return;
352 }
353
354 if (stasis_app_control_answer(control) != 0) {
356 response, 500, "Internal Server Error",
357 "Failed to answer channel");
358 return;
359 }
360
362}
363
366 struct ast_ari_response *response)
367{
368 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
369
370 control = find_control(response, args->channel_id);
371 if (control == NULL) {
372 return;
373 }
374
375 if (channel_state_invalid(control, response)) {
376 return;
377 }
378
380
382}
383
386 struct ast_ari_response *response)
387{
388 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
389
390 control = find_control(response, args->channel_id);
391 if (control == NULL) {
392 return;
393 }
394
395 if (channel_state_invalid(control, response)) {
396 return;
397 }
398
400
402}
403
406 struct ast_ari_response *response)
407{
408 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
409
410 control = find_control(response, args->channel_id);
411 if (control == NULL) {
412 return;
413 }
414
415 if (channel_state_invalid(control, response)) {
416 return;
417 }
418
420
422}
423
426 struct ast_ari_response *response)
427{
428 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
429 unsigned int direction = 0;
430 enum ast_frame_type frametype = AST_FRAME_VOICE;
431
432 control = find_control(response, args->channel_id);
433 if (control == NULL) {
434 return;
435 }
436
437 if (channel_state_invalid(control, response)) {
438 return;
439 }
440
441 if (ast_strlen_zero(args->direction)) {
443 response, 400, "Bad Request",
444 "Direction is required");
445 return;
446 }
447
448 if (!strcmp(args->direction, "in")) {
450 } else if (!strcmp(args->direction, "out")) {
452 } else if (!strcmp(args->direction, "both")) {
454 } else {
456 response, 400, "Bad Request",
457 "Invalid direction specified");
458 return;
459 }
460
461 stasis_app_control_mute(control, direction, frametype);
462
464}
465
468 struct ast_ari_response *response)
469{
470 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
471 unsigned int direction = 0;
472 enum ast_frame_type frametype = AST_FRAME_VOICE;
473
474 control = find_control(response, args->channel_id);
475 if (control == NULL) {
476 return;
477 }
478
479 if (channel_state_invalid(control, response)) {
480 return;
481 }
482
483 if (ast_strlen_zero(args->direction)) {
485 response, 400, "Bad Request",
486 "Direction is required");
487 return;
488 }
489
490 if (!strcmp(args->direction, "in")) {
492 } else if (!strcmp(args->direction, "out")) {
494 } else if (!strcmp(args->direction, "both")) {
496 } else {
498 response, 400, "Bad Request",
499 "Invalid direction specified");
500 return;
501 }
502
503 stasis_app_control_unmute(control, direction, frametype);
504
506}
507
510 struct ast_ari_response *response)
511{
512 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
513
514 control = find_control(response, args->channel_id);
515 if (control == NULL) {
516 return;
517 }
518
519 if (channel_state_invalid(control, response)) {
520 return;
521 }
522
523 if (ast_strlen_zero(args->dtmf)) {
525 response, 400, "Bad Request",
526 "DTMF is required");
527 return;
528 }
529
530 stasis_app_control_dtmf(control, args->dtmf, args->before, args->between, args->duration, args->after);
531
533}
534
537 struct ast_ari_response *response)
538{
539 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
540
541 control = find_control(response, args->channel_id);
542 if (control == NULL) {
543 /* Response filled in by find_control */
544 return;
545 }
546
547 if (channel_state_invalid(control, response)) {
548 return;
549 }
550
552
554}
555
558 struct ast_ari_response *response)
559{
560 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
561
562 control = find_control(response, args->channel_id);
563 if (control == NULL) {
564 /* Response filled in by find_control */
565 return;
566 }
567
568 if (channel_state_invalid(control, response)) {
569 return;
570 }
571
573
575}
576
579 struct ast_ari_response *response)
580{
581 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
582
583 control = find_control(response, args->channel_id);
584 if (control == NULL) {
585 /* Response filled in by find_control */
586 return;
587 }
588
589 if (channel_state_invalid(control, response)) {
590 return;
591 }
592
593 stasis_app_control_moh_start(control, args->moh_class);
595}
596
599 struct ast_ari_response *response)
600{
601 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
602
603 control = find_control(response, args->channel_id);
604 if (control == NULL) {
605 /* Response filled in by find_control */
606 return;
607 }
608
609 if (channel_state_invalid(control, response)) {
610 return;
611 }
612
615}
616
619 struct ast_ari_response *response)
620{
621 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
622
623 control = find_control(response, args->channel_id);
624 if (control == NULL) {
625 /* Response filled in by find_control */
626 return;
627 }
628
629 if (channel_state_invalid(control, response)) {
630 return;
631 }
632
635}
636
639 struct ast_ari_response *response)
640{
641 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
642
643 control = find_control(response, args->channel_id);
644 if (control == NULL) {
645 /* Response filled in by find_control */
646 return;
647 }
648
649 if (channel_state_invalid(control, response)) {
650 return;
651 }
652
655}
656
658 const char *args_channel_id,
659 const char **args_media,
660 size_t args_media_count,
661 const char *args_lang,
662 int args_offsetms,
663 int args_skipms,
664 const char *args_playback_id,
665 struct ast_ari_response *response)
666{
667 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
668 RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
669 RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
670 RAII_VAR(char *, playback_url, NULL, ast_free);
671 struct ast_json *json;
672 const char *language;
673
674 ast_assert(response != NULL);
675
676 control = find_control(response, args_channel_id);
677 if (control == NULL) {
678 /* Response filled in by find_control */
679 return;
680 }
681
682 if (channel_state_invalid(control, response)) {
683 return;
684 }
685
686 snapshot = stasis_app_control_get_snapshot(control);
687 if (!snapshot) {
689 response, 404, "Not Found",
690 "Channel not found");
691 return;
692 }
693
694 if (args_skipms < 0) {
696 response, 400, "Bad Request",
697 "skipms cannot be negative");
698 return;
699 }
700
701 if (args_offsetms < 0) {
703 response, 400, "Bad Request",
704 "offsetms cannot be negative");
705 return;
706 }
707
708 language = S_OR(args_lang, snapshot->base->language);
709
710 playback = stasis_app_control_play_uri(control, args_media, args_media_count, language,
711 args_channel_id, STASIS_PLAYBACK_TARGET_CHANNEL, args_skipms, args_offsetms, args_playback_id);
712 if (!playback) {
714 response, 500, "Internal Server Error",
715 "Failed to queue media for playback");
716 return;
717 }
718
719 if (ast_asprintf(&playback_url, "/playbacks/%s",
720 stasis_app_playback_get_id(playback)) == -1) {
721 playback_url = NULL;
723 response, 500, "Internal Server Error",
724 "Out of memory");
725 return;
726 }
727
728 json = stasis_app_playback_to_json(playback);
729 if (!json) {
731 response, 500, "Internal Server Error",
732 "Out of memory");
733 return;
734 }
735
736 ast_ari_response_created(response, playback_url, json);
737}
738
741 struct ast_ari_response *response)
742{
744 args->channel_id,
745 args->media,
746 args->media_count,
747 args->lang,
748 args->offsetms,
749 args->skipms,
750 args->playback_id,
751 response);
752}
753
756 struct ast_ari_response *response)
757{
759 args->channel_id,
760 args->media,
761 args->media_count,
762 args->lang,
763 args->offsetms,
764 args->skipms,
765 args->playback_id,
766 response);
767}
768
771 struct ast_ari_response *response)
772{
773 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
774 RAII_VAR(struct stasis_app_recording *, recording, NULL, ao2_cleanup);
775 RAII_VAR(char *, recording_url, NULL, ast_free);
776 struct ast_json *json;
779 RAII_VAR(char *, uri_encoded_name, NULL, ast_free);
780 size_t uri_name_maxlen;
781
782 ast_assert(response != NULL);
783
784 if (args->max_duration_seconds < 0) {
786 response, 400, "Bad Request",
787 "max_duration_seconds cannot be negative");
788 return;
789 }
790
791 if (args->max_silence_seconds < 0) {
793 response, 400, "Bad Request",
794 "max_silence_seconds cannot be negative");
795 return;
796 }
797
798 control = find_control(response, args->channel_id);
799 if (control == NULL) {
800 /* Response filled in by find_control */
801 return;
802 }
803
805 if (options == NULL) {
807 response, 500, "Internal Server Error",
808 "Out of memory");
809 }
810 ast_string_field_build(options, target, "channel:%s", args->channel_id);
811 options->max_silence_seconds = args->max_silence_seconds;
812 options->max_duration_seconds = args->max_duration_seconds;
813 options->terminate_on =
815 options->if_exists =
817 options->beep = args->beep;
818
819 if (options->terminate_on == STASIS_APP_RECORDING_TERMINATE_INVALID) {
821 response, 400, "Bad Request",
822 "terminateOn invalid");
823 return;
824 }
825
826 if (options->if_exists == AST_RECORD_IF_EXISTS_ERROR) {
828 response, 400, "Bad Request",
829 "ifExists invalid");
830 return;
831 }
832
833 if (!ast_get_format_for_file_ext(options->format)) {
835 response, 422, "Unprocessable Entity",
836 "specified format is unknown on this system");
837 return;
838 }
839
840 recording = stasis_app_control_record(control, options);
841 if (recording == NULL) {
842 switch(errno) {
843 case EINVAL:
844 /* While the arguments are invalid, we should have
845 * caught them prior to calling record.
846 */
848 response, 500, "Internal Server Error",
849 "Error parsing request");
850 break;
851 case EEXIST:
852 ast_ari_response_error(response, 409, "Conflict",
853 "Recording '%s' already exists and can not be overwritten",
854 args->name);
855 break;
856 case ENOMEM:
858 response, 500, "Internal Server Error",
859 "Out of memory");
860 break;
861 case EPERM:
863 response, 400, "Bad Request",
864 "Recording name invalid");
865 break;
866 default:
868 "Unrecognized recording error: %s\n",
869 strerror(errno));
871 response, 500, "Internal Server Error",
872 "Internal Server Error");
873 break;
874 }
875 return;
876 }
877
878 uri_name_maxlen = strlen(args->name) * 3;
879 uri_encoded_name = ast_malloc(uri_name_maxlen);
880 if (!uri_encoded_name) {
882 response, 500, "Internal Server Error",
883 "Out of memory");
884 return;
885 }
886 ast_uri_encode(args->name, uri_encoded_name, uri_name_maxlen,
888
889 if (ast_asprintf(&recording_url, "/recordings/live/%s",
890 uri_encoded_name) == -1) {
891 recording_url = NULL;
893 response, 500, "Internal Server Error",
894 "Out of memory");
895 return;
896 }
897
898 json = stasis_app_recording_to_json(recording);
899 if (!json) {
901 response, 500, "Internal Server Error",
902 "Out of memory");
903 return;
904 }
905
906 ast_ari_response_created(response, recording_url, json);
907}
908
911 struct ast_ari_response *response)
912{
913 struct ast_channel_snapshot *snapshot;
914
915 snapshot = ast_channel_snapshot_get_latest(args->channel_id);
916 if (!snapshot) {
918 response, 404, "Not Found",
919 "Channel not found");
920 return;
921 }
922
923 ast_ari_response_ok(response,
925 ao2_ref(snapshot, -1);
926}
927
930 struct ast_ari_response *response)
931{
932 RAII_VAR(struct ast_channel *, chan, NULL, ao2_cleanup);
933 int cause;
934
935 chan = ast_channel_get_by_name(args->channel_id);
936 if (chan == NULL) {
938 response, 404, "Not Found",
939 "Channel not found");
940 return;
941 }
942
943 if (!ast_strlen_zero(args->reason) && !ast_strlen_zero(args->reason_code)) {
944 ast_ari_response_error(response, 400, "Bad Request",
945 "The reason and reason_code can't both be specified");
946 return;
947 }
948
949 if (!ast_strlen_zero(args->reason_code)) {
950 /* reason_code allows any hangup code */
951 if (sscanf(args->reason_code, "%30d", &cause) != 1) {
953 response, 400, "Invalid Reason Code",
954 "Invalid reason for hangup reason code provided");
955 return;
956 }
957 } else if (!ast_strlen_zero(args->reason)) {
958 /* reason allows only listed hangup reason */
959 cause = convert_reason_to_hangup_code(args->reason);
960 if (cause == -1) {
962 response, 400, "Invalid Reason",
963 "Invalid reason for hangup reason provided");
964 return;
965 }
966 } else {
967 /* not specified. set default hangup */
968 cause = AST_CAUSE_NORMAL;
969 }
970
971 ast_channel_hangupcause_set(chan, cause);
973
975}
976
979 struct ast_ari_response *response)
980{
981 RAII_VAR(struct ao2_container *, snapshots, NULL, ao2_cleanup);
982 RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
983 struct ao2_iterator i;
984 void *obj;
986
987 snapshots = ast_channel_cache_all();
988
989 json = ast_json_array_create();
990 if (!json) {
992 return;
993 }
994
995 i = ao2_iterator_init(snapshots, 0);
996 while ((obj = ao2_iterator_next(&i))) {
997 struct ast_channel_snapshot *snapshot = obj;
998 int r;
999
1000 if (sanitize && sanitize->channel_snapshot
1001 && sanitize->channel_snapshot(snapshot)) {
1002 ao2_ref(snapshot, -1);
1003 continue;
1004 }
1005
1007 json, ast_channel_snapshot_to_json(snapshot, NULL));
1008 if (r != 0) {
1011 ao2_ref(snapshot, -1);
1012 return;
1013 }
1014 ao2_ref(snapshot, -1);
1015 }
1017
1018 ast_ari_response_ok(response, ast_json_ref(json));
1019}
1020
1021/*! \brief Structure used for origination */
1023 /*! \brief Dialplan context */
1025 /*! \brief Dialplan extension */
1027 /*! \brief Dialplan priority */
1029 /*! \brief Application data to pass to Stasis application */
1030 char appdata[0];
1031};
1032
1033/*! \brief Thread which dials and executes upon answer */
1034static void *ari_originate_dial(void *data)
1035{
1036 struct ast_dial *dial = data;
1037 struct ari_origination *origination = ast_dial_get_user_data(dial);
1038 enum ast_dial_result res;
1039
1040 res = ast_dial_run(dial, NULL, 0);
1041 if (res != AST_DIAL_RESULT_ANSWERED) {
1042 goto end;
1043 }
1044
1045 if (!ast_strlen_zero(origination->appdata)) {
1046 struct ast_app *app = pbx_findapp("Stasis");
1047
1048 if (app) {
1049 ast_verb(4, "Launching Stasis(%s) on %s\n", origination->appdata,
1051 pbx_exec(ast_dial_answered(dial), app, origination->appdata);
1052 } else {
1053 ast_log(LOG_WARNING, "No such application 'Stasis'\n");
1054 }
1055 } else {
1056 struct ast_channel *answered = ast_dial_answered(dial);
1057
1058 if (!ast_strlen_zero(origination->context)) {
1059 ast_channel_context_set(answered, origination->context);
1060 }
1061
1062 if (!ast_strlen_zero(origination->exten)) {
1063 ast_channel_exten_set(answered, origination->exten);
1064 }
1065
1066 if (origination->priority > 0) {
1067 ast_channel_priority_set(answered, origination->priority);
1068 }
1069
1070 if (ast_pbx_run(answered)) {
1071 ast_log(LOG_ERROR, "Failed to start PBX on %s\n", ast_channel_name(answered));
1072 } else {
1073 /* PBX will have taken care of hanging up, so we steal the answered channel so dial doesn't do it */
1075 }
1076 }
1077
1078end:
1079 ast_dial_destroy(dial);
1080 ast_free(origination);
1081 return NULL;
1082}
1083
1084static struct ast_channel *ari_channels_handle_originate_with_id(const char *args_endpoint,
1085 const char *args_extension,
1086 const char *args_context,
1087 long args_priority,
1088 const char *args_label,
1089 const char *args_app,
1090 const char *args_app_args,
1091 const char *args_caller_id,
1092 int args_timeout,
1093 struct ast_variable *variables,
1094 const char *args_channel_id,
1095 const char *args_other_channel_id,
1096 const char *args_originator,
1097 const char *args_formats,
1098 struct ast_ari_response *response)
1099{
1100 char *dialtech;
1101 char *dialdevice = NULL;
1102 struct ast_dial *dial;
1103 char *caller_id = NULL;
1104 char *cid_num = NULL;
1105 char *cid_name = NULL;
1106 char *stuff;
1107 struct ast_channel *other = NULL;
1108 struct ast_channel *chan = NULL;
1110 struct ast_assigned_ids assignedids = {
1111 .uniqueid = args_channel_id,
1112 .uniqueid2 = args_other_channel_id,
1113 };
1114 struct ari_origination *origination;
1115 pthread_t thread;
1116 struct ast_format_cap *format_cap = NULL;
1117
1118 if ((assignedids.uniqueid && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid))
1119 || (assignedids.uniqueid2 && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid2))) {
1120 ast_ari_response_error(response, 400, "Bad Request",
1121 "Uniqueid length exceeds maximum of %d", AST_MAX_PUBLIC_UNIQUEID);
1122 return NULL;
1123 }
1124
1125 if (ast_strlen_zero(args_endpoint)) {
1126 ast_ari_response_error(response, 400, "Bad Request",
1127 "Endpoint must be specified");
1128 return NULL;
1129 }
1130
1131 if (!ast_strlen_zero(args_originator) && !ast_strlen_zero(args_formats)) {
1132 ast_ari_response_error(response, 400, "Bad Request",
1133 "Originator and formats can't both be specified");
1134 return NULL;
1135 }
1136
1137 dialtech = ast_strdupa(args_endpoint);
1138 if ((stuff = strchr(dialtech, '/'))) {
1139 *stuff++ = '\0';
1140 dialdevice = stuff;
1141 }
1142
1143 if (ast_strlen_zero(dialtech) || ast_strlen_zero(dialdevice)) {
1144 ast_ari_response_error(response, 400, "Bad Request",
1145 "Invalid endpoint specified");
1146 return NULL;
1147 }
1148
1149 if (!ast_strlen_zero(args_app)) {
1150 RAII_VAR(struct ast_str *, appdata, ast_str_create(64), ast_free);
1151
1152 if (!appdata) {
1154 return NULL;
1155 }
1156
1157 ast_str_set(&appdata, 0, "%s", args_app);
1158 if (!ast_strlen_zero(args_app_args)) {
1159 ast_str_append(&appdata, 0, ",%s", args_app_args);
1160 }
1161
1162 origination = ast_calloc(1, sizeof(*origination) + ast_str_size(appdata) + 1);
1163 if (!origination) {
1165 return NULL;
1166 }
1167
1168 strcpy(origination->appdata, ast_str_buffer(appdata));
1169 } else if (!ast_strlen_zero(args_extension)) {
1170 origination = ast_calloc(1, sizeof(*origination) + 1);
1171 if (!origination) {
1173 return NULL;
1174 }
1175
1176 ast_copy_string(origination->context, S_OR(args_context, "default"), sizeof(origination->context));
1177 ast_copy_string(origination->exten, args_extension, sizeof(origination->exten));
1178
1179 if (!ast_strlen_zero(args_label)) {
1180 /* A label was provided in the request, use that */
1181 int ipri = 1;
1182 if (sscanf(args_label, "%30d", &ipri) != 1) {
1183 ipri = ast_findlabel_extension(chan, origination->context, origination->exten, args_label, args_caller_id);
1184
1185 if (ipri == -1) {
1186 ast_log(AST_LOG_ERROR, "Requested label: %s can not be found in context: %s\n", args_label, args_context);
1187 ast_ari_response_error(response, 404, "Not Found", "Requested label can not be found");
1188 return NULL;
1189 }
1190 } else {
1191 ast_debug(3, "Numeric value provided for label, jumping to that priority\n");
1192 }
1193
1194 if (ipri == 0) {
1195 ast_log(AST_LOG_ERROR, "Invalid priority label '%s' specified for extension %s in context: %s\n",
1196 args_label, args_extension, args_context);
1197 ast_ari_response_error(response, 400, "Bad Request", "Requested priority is illegal");
1198 return NULL;
1199 }
1200
1201 /* Our priority was provided by a label */
1202 origination->priority = ipri;
1203 } else {
1204 /* No label provided, use provided priority */
1205 origination->priority = args_priority ? args_priority : 1;
1206 }
1207
1208 origination->appdata[0] = '\0';
1209 } else {
1210 ast_ari_response_error(response, 400, "Bad Request",
1211 "Application or extension must be specified");
1212 return NULL;
1213 }
1214
1215 dial = ast_dial_create();
1216 if (!dial) {
1218 ast_free(origination);
1219 return NULL;
1220 }
1221 ast_dial_set_user_data(dial, origination);
1222
1223 if (ast_dial_append(dial, dialtech, dialdevice, &assignedids)) {
1225 ast_dial_destroy(dial);
1226 ast_free(origination);
1227 return NULL;
1228 }
1229
1230 if (args_timeout > 0) {
1231 ast_dial_set_global_timeout(dial, args_timeout * 1000);
1232 } else if (args_timeout == -1) {
1234 } else {
1235 ast_dial_set_global_timeout(dial, 30000);
1236 }
1237
1238 if (!ast_strlen_zero(args_caller_id)) {
1239 caller_id = ast_strdupa(args_caller_id);
1240 ast_callerid_parse(caller_id, &cid_name, &cid_num);
1241
1242 if (ast_is_shrinkable_phonenumber(cid_num)) {
1243 ast_shrink_phone_number(cid_num);
1244 }
1245 }
1246
1247 if (!ast_strlen_zero(args_originator)) {
1248 other = ast_channel_get_by_name(args_originator);
1249 if (!other) {
1251 response, 400, "Bad Request",
1252 "Provided originator channel was not found");
1253 ast_dial_destroy(dial);
1254 ast_free(origination);
1255 return NULL;
1256 }
1257 }
1258
1259 if (!ast_strlen_zero(args_formats)) {
1260 char *format_name;
1261 char *formats_copy = ast_strdupa(args_formats);
1262
1265 ast_dial_destroy(dial);
1266 ast_free(origination);
1267 ast_channel_cleanup(other);
1268 return NULL;
1269 }
1270
1271 while ((format_name = ast_strip(strsep(&formats_copy, ",")))) {
1272 struct ast_format *fmt = ast_format_cache_get(format_name);
1273
1274 if (!fmt || ast_format_cap_append(format_cap, fmt, 0)) {
1275 if (!fmt) {
1277 response, 400, "Bad Request",
1278 "Provided format (%s) was not found", format_name);
1279 } else {
1281 }
1282 ast_dial_destroy(dial);
1283 ast_free(origination);
1284 ast_channel_cleanup(other);
1285 ao2_ref(format_cap, -1);
1286 ao2_cleanup(fmt);
1287 return NULL;
1288 }
1289 ao2_ref(fmt, -1);
1290 }
1291 }
1292
1293 if (ast_dial_prerun(dial, other, format_cap)) {
1295 ast_ari_response_error(response, 409, "Conflict",
1296 "Channel with given unique ID already exists");
1297 } else {
1299 }
1300 ast_dial_destroy(dial);
1301 ast_free(origination);
1302 ast_channel_cleanup(other);
1303 return NULL;
1304 }
1305
1306 ast_channel_cleanup(other);
1307 ao2_cleanup(format_cap);
1308
1309 chan = ast_dial_get_channel(dial, 0);
1310 if (!chan) {
1312 ast_dial_destroy(dial);
1313 ast_free(origination);
1314 return NULL;
1315 }
1316
1317 if (!ast_strlen_zero(cid_num) || !ast_strlen_zero(cid_name)) {
1319
1320 /*
1321 * It seems strange to set the CallerID on an outgoing call leg
1322 * to whom we are calling, but this function's callers are doing
1323 * various Originate methods. This call leg goes to the local
1324 * user. Once the called party answers, the dialplan needs to
1325 * be able to access the CallerID from the CALLERID function as
1326 * if the called party had placed this call.
1327 */
1328 ast_set_callerid(chan, cid_num, cid_name, cid_num);
1329
1331 if (!ast_strlen_zero(cid_num)) {
1332 connected.id.number.valid = 1;
1333 connected.id.number.str = (char *) cid_num;
1335 }
1336 if (!ast_strlen_zero(cid_name)) {
1337 connected.id.name.valid = 1;
1338 connected.id.name.str = (char *) cid_name;
1340 }
1342 }
1343
1344 ast_channel_lock(chan);
1345 if (variables) {
1346 ast_set_variables(chan, variables);
1347 }
1349
1350 if (!ast_strlen_zero(args_app)) {
1351 struct ast_channel *local_peer;
1352
1353 stasis_app_subscribe_channel(args_app, chan);
1354
1355 /* Subscribe to the Local channel peer also. */
1356 local_peer = ast_local_get_peer(chan);
1357 if (local_peer) {
1358 stasis_app_subscribe_channel(args_app, local_peer);
1359 ast_channel_unref(local_peer);
1360 }
1361 }
1362
1364 ast_channel_unlock(chan);
1365
1366 /* Before starting the async dial bump the ref in case the dial quickly goes away and takes
1367 * the reference with it
1368 */
1369 ast_channel_ref(chan);
1370
1373 ast_dial_destroy(dial);
1374 ast_free(origination);
1375 } else {
1377 }
1378
1379 return chan;
1380}
1381
1382/*!
1383 * \internal
1384 * \brief Convert a \c ast_json list of key/value pair tuples into a \c ast_variable list
1385 * \since 13.3.0
1386 *
1387 * \param[out] response HTTP response if error
1388 * \param json_variables The JSON blob containing the variable
1389 * \param[out] variables An out reference to the variables to populate.
1390 *
1391 * \retval 0 on success.
1392 * \retval -1 on error.
1393 */
1394static int json_to_ast_variables(struct ast_ari_response *response, struct ast_json *json_variables, struct ast_variable **variables)
1395{
1397
1398 res = ast_json_to_ast_variables(json_variables, variables);
1399 switch (res) {
1401 return 0;
1403 ast_ari_response_error(response, 400, "Bad Request",
1404 "Only string values in the 'variables' object allowed");
1405 break;
1408 break;
1409 }
1410 ast_log(AST_LOG_ERROR, "Unable to convert 'variables' in JSON body to channel variables\n");
1411
1412 return -1;
1413}
1414
1417 struct ast_ari_response *response)
1418{
1419 struct ast_variable *variables = NULL;
1420 struct ast_channel *chan;
1421
1422 /* Parse any query parameters out of the body parameter */
1423 if (args->variables) {
1424 struct ast_json *json_variables;
1425
1427 json_variables = ast_json_object_get(args->variables, "variables");
1428 if (json_variables
1429 && json_to_ast_variables(response, json_variables, &variables)) {
1430 return;
1431 }
1432 }
1433
1435 args->endpoint,
1436 args->extension,
1437 args->context,
1438 args->priority,
1439 args->label,
1440 args->app,
1441 args->app_args,
1442 args->caller_id,
1443 args->timeout,
1444 variables,
1445 args->channel_id,
1446 args->other_channel_id,
1447 args->originator,
1448 args->formats,
1449 response);
1450 ast_channel_cleanup(chan);
1451 ast_variables_destroy(variables);
1452}
1453
1456 struct ast_ari_response *response)
1457{
1458 struct ast_variable *variables = NULL;
1459 struct ast_channel *chan;
1460
1461 /* Parse any query parameters out of the body parameter */
1462 if (args->variables) {
1463 struct ast_json *json_variables;
1464
1466 json_variables = ast_json_object_get(args->variables, "variables");
1467 if (json_variables
1468 && json_to_ast_variables(response, json_variables, &variables)) {
1469 return;
1470 }
1471 }
1472
1474 args->endpoint,
1475 args->extension,
1476 args->context,
1477 args->priority,
1478 args->label,
1479 args->app,
1480 args->app_args,
1481 args->caller_id,
1482 args->timeout,
1483 variables,
1484 args->channel_id,
1485 args->other_channel_id,
1486 args->originator,
1487 args->formats,
1488 response);
1489 ast_channel_cleanup(chan);
1490 ast_variables_destroy(variables);
1491}
1492
1495 struct ast_ari_response *response)
1496{
1497 RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
1498 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
1499 RAII_VAR(struct ast_str *, value, ast_str_create(32), ast_free);
1500 RAII_VAR(struct ast_channel *, channel, NULL, ast_channel_cleanup);
1501
1502 ast_assert(response != NULL);
1503
1504 if (!value) {
1506 return;
1507 }
1508
1509 if (ast_strlen_zero(args->variable)) {
1511 response, 400, "Bad Request",
1512 "Variable name is required");
1513 return;
1514 }
1515
1516 if (ast_strlen_zero(args->channel_id)) {
1518 response, 400, "Bad Request",
1519 "Channel ID is required");
1520 return;
1521 }
1522
1523 channel = ast_channel_get_by_name(args->channel_id);
1524 if (!channel) {
1526 response, 404, "Channel Not Found",
1527 "Provided channel was not found");
1528 return;
1529 }
1530
1531 /* You may be tempted to lock the channel you're about to read from. You
1532 * would be wrong. Some dialplan functions put the channel into
1533 * autoservice, which deadlocks if the channel is already locked.
1534 * ast_str_retrieve_variable() does its own locking, and the dialplan
1535 * functions need to as well. We should be fine without the lock.
1536 */
1537
1538 if (args->variable[strlen(args->variable) - 1] == ')') {
1539 if (ast_func_read2(channel, args->variable, &value, 0)) {
1541 response, 500, "Error With Function",
1542 "Unable to read provided function");
1543 return;
1544 }
1545 } else {
1546 if (!ast_str_retrieve_variable(&value, 0, channel, NULL, args->variable)) {
1548 response, 404, "Variable Not Found",
1549 "Provided variable was not found");
1550 return;
1551 }
1552 }
1553
1554 if (!(json = ast_json_pack("{s: s}", "value", S_OR(ast_str_buffer(value), "")))) {
1556 return;
1557 }
1558
1559 ast_ari_response_ok(response, ast_json_ref(json));
1560}
1561
1564 struct ast_ari_response *response)
1565{
1566 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
1567
1568 ast_assert(response != NULL);
1569
1570 if (ast_strlen_zero(args->variable)) {
1572 response, 400, "Bad Request",
1573 "Variable name is required");
1574 return;
1575 }
1576
1577 control = find_control(response, args->channel_id);
1578 if (control == NULL) {
1579 /* response filled in by find_control */
1580 return;
1581 }
1582
1583 if (stasis_app_control_set_channel_var(control, args->variable, args->value)) {
1585 response, 400, "Bad Request",
1586 "Failed to execute function");
1587 return;
1588 }
1589
1591}
1592
1594 const char *args_channel_id,
1595 const char *args_spy,
1596 const char *args_whisper,
1597 const char *args_app,
1598 const char *args_app_args,
1599 const char *args_snoop_id,
1600 struct ast_ari_response *response)
1601{
1602 enum stasis_app_snoop_direction spy, whisper;
1603 RAII_VAR(struct ast_channel *, chan, NULL, ast_channel_cleanup);
1604 RAII_VAR(struct ast_channel *, snoop, NULL, ast_channel_cleanup);
1605 RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
1606
1607 ast_assert(response != NULL);
1608
1609 if (ast_strlen_zero(args_spy) || !strcmp(args_spy, "none")) {
1611 } else if (!strcmp(args_spy, "both")) {
1613 } else if (!strcmp(args_spy, "out")) {
1615 } else if (!strcmp(args_spy, "in")) {
1617 } else {
1619 response, 400, "Bad Request",
1620 "Invalid direction specified for spy");
1621 return;
1622 }
1623
1624 if (ast_strlen_zero(args_whisper) || !strcmp(args_whisper, "none")) {
1626 } else if (!strcmp(args_whisper, "both")) {
1628 } else if (!strcmp(args_whisper, "out")) {
1630 } else if (!strcmp(args_whisper, "in")) {
1631 whisper = STASIS_SNOOP_DIRECTION_IN;
1632 } else {
1634 response, 400, "Bad Request",
1635 "Invalid direction specified for whisper");
1636 return;
1637 }
1638
1641 response, 400, "Bad Request",
1642 "Direction must be specified for at least spy or whisper");
1643 return;
1644 } else if (ast_strlen_zero(args_app)) {
1646 response, 400, "Bad Request",
1647 "Application name is required");
1648 return;
1649 }
1650
1651 chan = ast_channel_get_by_name(args_channel_id);
1652 if (chan == NULL) {
1654 response, 404, "Channel Not Found",
1655 "Provided channel was not found");
1656 return;
1657 }
1658
1659 snoop = stasis_app_control_snoop(chan, spy, whisper, args_app, args_app_args,
1660 args_snoop_id);
1661 if (snoop == NULL) {
1663 response, 500, "Internal error",
1664 "Snoop channel could not be created");
1665 return;
1666 }
1667
1670}
1671
1674 struct ast_ari_response *response)
1675{
1677 args->channel_id,
1678 args->spy,
1679 args->whisper,
1680 args->app,
1681 args->app_args,
1682 args->snoop_id,
1683 response);
1684}
1685
1688 struct ast_ari_response *response)
1689{
1691 args->channel_id,
1692 args->spy,
1693 args->whisper,
1694 args->app,
1695 args->app_args,
1696 args->snoop_id,
1697 response);
1698}
1699
1703};
1704
1705static void chan_data_destroy(struct ari_channel_thread_data *chan_data)
1706{
1707 ast_free(chan_data->stasis_stuff);
1708 ast_hangup(chan_data->chan);
1709 ast_free(chan_data);
1710}
1711
1712/*!
1713 * \brief Thread that owns stasis-created channel.
1714 *
1715 * The channel enters into a Stasis application immediately upon creation. In this
1716 * way, the channel can be manipulated by the Stasis application. Once the channel
1717 * exits the Stasis application, it is hung up.
1718 */
1719static void *ari_channel_thread(void *data)
1720{
1721 struct ari_channel_thread_data *chan_data = data;
1722 struct ast_app *stasis_app;
1723
1724 stasis_app = pbx_findapp("Stasis");
1725 if (!stasis_app) {
1726 ast_log(LOG_ERROR, "Stasis dialplan application is not registered");
1727 chan_data_destroy(chan_data);
1728 return NULL;
1729 }
1730
1731 pbx_exec(chan_data->chan, stasis_app, ast_str_buffer(chan_data->stasis_stuff));
1732
1733 chan_data_destroy(chan_data);
1734
1735 return NULL;
1736}
1737
1739 .type = "ARI Dialstring",
1740 .destroy = ast_free_ptr,
1741};
1742
1743/*!
1744 * \brief Save dialstring onto a channel datastore
1745 *
1746 * This will later be retrieved when it comes time to actually dial the channel
1747 *
1748 * \param chan The channel on which to save the dialstring
1749 * \param dialstring The dialstring to save
1750 * \retval 0 on success.
1751 * \retval -1 on error.
1752 */
1753static int save_dialstring(struct ast_channel *chan, const char *dialstring)
1754{
1755 struct ast_datastore *datastore;
1756
1758 if (!datastore) {
1759 return -1;
1760 }
1761
1762 datastore->data = ast_strdup(dialstring);
1763 if (!datastore->data) {
1764 ast_datastore_free(datastore);
1765 return -1;
1766 }
1767
1768 ast_channel_lock(chan);
1769 if (ast_channel_datastore_add(chan, datastore)) {
1770 ast_channel_unlock(chan);
1771 ast_datastore_free(datastore);
1772 return -1;
1773 }
1774 ast_channel_unlock(chan);
1775
1776 return 0;
1777}
1778
1779/*!
1780 * \brief Retrieve the dialstring from the channel datastore
1781 *
1782 * \pre chan is locked
1783 * \param chan Channel that was previously created in ARI
1784 * \retval NULL Failed to find datastore
1785 * \retval non-NULL The dialstring
1786 */
1787static char *restore_dialstring(struct ast_channel *chan)
1788{
1789 struct ast_datastore *datastore;
1790
1791 datastore = ast_channel_datastore_find(chan, &dialstring_info, NULL);
1792 if (!datastore) {
1793 return NULL;
1794 }
1795
1796 return datastore->data;
1797}
1798
1801 struct ast_ari_response *response)
1802{
1803 RAII_VAR(struct ast_variable *, variables, NULL, ast_variables_destroy);
1804 struct ast_assigned_ids assignedids;
1805 struct ari_channel_thread_data *chan_data;
1806 struct ast_channel_snapshot *snapshot;
1807 pthread_t thread;
1808 char *dialtech;
1809 char *dialdevice = NULL;
1810 char *stuff;
1811 int cause;
1812 struct ast_format_cap *request_cap;
1813 struct ast_channel *originator = NULL;
1814
1815 /* Parse any query parameters out of the body parameter */
1816 if (args->variables) {
1817 struct ast_json *json_variables;
1818
1820 json_variables = ast_json_object_get(args->variables, "variables");
1821 if (json_variables
1822 && json_to_ast_variables(response, json_variables, &variables)) {
1823 return;
1824 }
1825 }
1826
1827 assignedids.uniqueid = args->channel_id;
1828 assignedids.uniqueid2 = args->other_channel_id;
1829
1830 if (!ast_strlen_zero(args->originator) && !ast_strlen_zero(args->formats)) {
1831 ast_ari_response_error(response, 400, "Bad Request",
1832 "Originator and formats can't both be specified");
1833 return;
1834 }
1835
1836 if (ast_strlen_zero(args->endpoint)) {
1837 ast_ari_response_error(response, 400, "Bad Request",
1838 "Endpoint must be specified");
1839 return;
1840 }
1841
1842 chan_data = ast_calloc(1, sizeof(*chan_data));
1843 if (!chan_data) {
1845 return;
1846 }
1847
1848 chan_data->stasis_stuff = ast_str_create(32);
1849 if (!chan_data->stasis_stuff) {
1851 chan_data_destroy(chan_data);
1852 return;
1853 }
1854
1855 ast_str_append(&chan_data->stasis_stuff, 0, "%s", args->app);
1856 if (!ast_strlen_zero(args->app_args)) {
1857 ast_str_append(&chan_data->stasis_stuff, 0, ",%s", args->app_args);
1858 }
1859
1860 dialtech = ast_strdupa(args->endpoint);
1861 if ((stuff = strchr(dialtech, '/'))) {
1862 *stuff++ = '\0';
1863 dialdevice = stuff;
1864 }
1865
1866 if (ast_strlen_zero(dialtech) || ast_strlen_zero(dialdevice)) {
1867 ast_ari_response_error(response, 400, "Bad Request",
1868 "Invalid endpoint specified");
1869 chan_data_destroy(chan_data);
1870 return;
1871 }
1872
1873 if (!ast_strlen_zero(args->originator)) {
1874 originator = ast_channel_get_by_name(args->originator);
1875 }
1876
1877 if (originator) {
1878 request_cap = ao2_bump(ast_channel_nativeformats(originator));
1879 if (!ast_strlen_zero(args->app)) {
1880 stasis_app_subscribe_channel(args->app, originator);
1881 }
1882 } else if (!ast_strlen_zero(args->formats)) {
1883 char *format_name;
1884 char *formats_copy = ast_strdupa(args->formats);
1885
1886 if (!(request_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
1888 chan_data_destroy(chan_data);
1889 return;
1890 }
1891
1892 while ((format_name = ast_strip(strsep(&formats_copy, ",")))) {
1893 struct ast_format *fmt = ast_format_cache_get(format_name);
1894
1895 if (!fmt || ast_format_cap_append(request_cap, fmt, 0)) {
1896 if (!fmt) {
1898 response, 400, "Bad Request",
1899 "Provided format (%s) was not found", format_name);
1900 } else {
1902 }
1903 ao2_ref(request_cap, -1);
1904 ao2_cleanup(fmt);
1905 chan_data_destroy(chan_data);
1906 return;
1907 }
1908 ao2_ref(fmt, -1);
1909 }
1910 } else {
1911 if (!(request_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
1913 chan_data_destroy(chan_data);
1914 return;
1915 }
1916
1918 }
1919
1920 chan_data->chan = ast_request(dialtech, request_cap, &assignedids, originator, dialdevice, &cause);
1921 ao2_cleanup(request_cap);
1922
1923 if (!chan_data->chan) {
1925 ast_ari_response_error(response, 409, "Conflict",
1926 "Channel with given unique ID already exists");
1927 } else {
1929 }
1930 ast_channel_cleanup(originator);
1931 chan_data_destroy(chan_data);
1932 return;
1933 }
1934
1935 if (!ast_strlen_zero(args->app)) {
1936 stasis_app_subscribe_channel(args->app, chan_data->chan);
1937 }
1938
1939 if (variables) {
1940 ast_set_variables(chan_data->chan, variables);
1941 }
1942
1943 ast_channel_cleanup(originator);
1944
1945 if (save_dialstring(chan_data->chan, stuff)) {
1947 chan_data_destroy(chan_data);
1948 return;
1949 }
1950
1952
1955 chan_data_destroy(chan_data);
1956 } else {
1958 }
1959
1960 ao2_ref(snapshot, -1);
1961}
1962
1965 struct ast_ari_response *response)
1966{
1967 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
1968 RAII_VAR(struct ast_channel *, caller, NULL, ast_channel_cleanup);
1969 RAII_VAR(struct ast_channel *, callee, NULL, ast_channel_cleanup);
1970 char *dialstring;
1971
1972 control = find_control(response, args->channel_id);
1973 if (control == NULL) {
1974 /* Response filled in by find_control */
1975 return;
1976 }
1977
1978 if (!ast_strlen_zero(args->caller)) {
1979 caller = ast_channel_get_by_name(args->caller);
1980 }
1981
1982 callee = ast_channel_get_by_name(args->channel_id);
1983 if (!callee) {
1984 ast_ari_response_error(response, 404, "Not Found",
1985 "Callee not found");
1986 return;
1987 }
1988
1989 if (ast_channel_state(callee) != AST_STATE_DOWN
1990 && ast_channel_state(callee) != AST_STATE_RESERVED) {
1991 ast_ari_response_error(response, 409, "Conflict",
1992 "Channel is not in the 'Down' state");
1993 return;
1994 }
1995
1996 /* XXX This is straight up copied from main/dial.c. It's probably good
1997 * to separate this to some common method.
1998 */
1999 if (caller) {
2000 ast_channel_lock_both(caller, callee);
2001 } else {
2002 ast_channel_lock(callee);
2003 }
2004
2005 dialstring = restore_dialstring(callee);
2006 if (!dialstring) {
2007 ast_channel_unlock(callee);
2008 if (caller) {
2009 ast_channel_unlock(caller);
2010 }
2011 ast_ari_response_error(response, 409, "Conflict",
2012 "Dialing a channel not created by ARI");
2013 return;
2014 }
2015 /* Make a copy of the dialstring just in case some jerk tries to hang up the
2016 * channel before we can actually dial
2017 */
2018 dialstring = ast_strdupa(dialstring);
2019
2021 if (caller) {
2022 ast_channel_inherit_variables(caller, callee);
2023 ast_channel_datastore_inherit(caller, callee);
2025
2026 /* Copy over callerid information */
2028
2030
2032
2033 ast_channel_language_set(callee, ast_channel_language(caller));
2036 ast_channel_musicclass_set(callee, ast_channel_musicclass(caller));
2037
2040 ast_channel_unlock(caller);
2041 }
2042
2044 ast_channel_unlock(callee);
2045
2046 if (stasis_app_control_dial(control, dialstring, args->timeout)) {
2048 return;
2049 }
2050
2052}
2053
2056 struct ast_ari_response *response)
2057{
2058 RAII_VAR(struct ast_channel *, chan, NULL, ast_channel_cleanup);
2059 RAII_VAR(struct ast_rtp_instance *, rtp, NULL, ao2_cleanup);
2060 struct ast_json *j_res;
2061 const struct ast_channel_tech *tech;
2062 struct ast_rtp_glue *glue;
2063
2064 chan = ast_channel_get_by_name(args->channel_id);
2065 if (!chan) {
2066 ast_ari_response_error(response, 404, "Not Found",
2067 "Channel not found");
2068 return;
2069 }
2070
2071 ast_channel_lock(chan);
2072 tech = ast_channel_tech(chan);
2073 if (!tech) {
2074 ast_channel_unlock(chan);
2075 ast_ari_response_error(response, 404, "Not Found",
2076 "Channel's tech not found");
2077 return;
2078 }
2079
2080 glue = ast_rtp_instance_get_glue(tech->type);
2081 if (!glue) {
2082 ast_channel_unlock(chan);
2083 ast_ari_response_error(response, 403, "Forbidden",
2084 "Unsupported channel type");
2085 return;
2086 }
2087
2088 glue->get_rtp_info(chan, &rtp);
2089 if (!rtp) {
2090 ast_channel_unlock(chan);
2091 ast_ari_response_error(response, 404, "Not Found",
2092 "RTP info not found");
2093 return;
2094 }
2095
2097 if (!j_res) {
2098 ast_channel_unlock(chan);
2099 ast_ari_response_error(response, 404, "Not Found",
2100 "Statistics not found");
2101 return;
2102 }
2103
2104 ast_channel_unlock(chan);
2105 ast_ari_response_ok(response, j_res);
2106
2107 return;
2108}
2109
2111 struct ast_variable *variables,
2112 struct ast_ari_response *response)
2113{
2114 char *endpoint;
2115 struct ast_channel *chan;
2116 struct varshead *vars;
2117
2118 if (ast_asprintf(&endpoint, "UnicastRTP/%s/c(%s)",
2119 args->external_host,
2120 args->format) == -1) {
2121 return 1;
2122 }
2123
2125 endpoint,
2126 NULL,
2127 NULL,
2128 0,
2129 NULL,
2130 args->app,
2131 args->data,
2132 NULL,
2133 0,
2134 variables,
2135 args->channel_id,
2136 NULL,
2137 NULL,
2138 args->format,
2139 response);
2140
2141 ast_free(endpoint);
2142
2143 if (!chan) {
2144 return 1;
2145 }
2146
2147 ast_channel_lock(chan);
2148 vars = ast_channel_varshead(chan);
2149 if (vars && !AST_LIST_EMPTY(vars)) {
2150 ast_json_object_set(response->message, "channelvars", ast_json_channel_vars(vars));
2151 }
2152 ast_channel_unlock(chan);
2153 ast_channel_unref(chan);
2154 return 0;
2155}
2156
2158 struct ast_variable *variables,
2159 struct ast_ari_response *response)
2160{
2161 char *endpoint;
2162 struct ast_channel *chan;
2163 struct varshead *vars;
2164
2165 if (ast_strlen_zero(args->data)) {
2166 ast_ari_response_error(response, 400, "Bad Request", "data can not be empty");
2167 return 1;
2168 }
2169
2170 if (ast_asprintf(&endpoint, "AudioSocket/%s/%s",
2171 args->external_host, args->data) == -1) {
2172 return 1;
2173 }
2174
2176 endpoint,
2177 NULL,
2178 NULL,
2179 0,
2180 NULL,
2181 args->app,
2182 args->data,
2183 NULL,
2184 0,
2185 variables,
2186 args->channel_id,
2187 NULL,
2188 NULL,
2189 args->format,
2190 response);
2191
2192 ast_free(endpoint);
2193
2194 if (!chan) {
2195 return 1;
2196 }
2197
2198 ast_channel_lock(chan);
2199 vars = ast_channel_varshead(chan);
2200 if (vars && !AST_LIST_EMPTY(vars)) {
2201 ast_json_object_set(response->message, "channelvars", ast_json_channel_vars(vars));
2202 }
2203 ast_channel_unlock(chan);
2204 ast_channel_unref(chan);
2205 return 0;
2206}
2207
2209 struct ast_variable *variables,
2210 struct ast_ari_response *response)
2211{
2212 char *endpoint;
2213 struct ast_channel *chan;
2214 struct varshead *vars;
2215
2216 if (ast_asprintf(&endpoint, "WebSocket/%s/c(%s)",
2217 args->external_host,
2218 args->format) == -1) {
2219 return 1;
2220 }
2221
2223 endpoint,
2224 NULL,
2225 NULL,
2226 0,
2227 NULL,
2228 args->app,
2229 args->data,
2230 NULL,
2231 0,
2232 variables,
2233 args->channel_id,
2234 NULL,
2235 NULL,
2236 args->format,
2237 response);
2238
2239 ast_free(endpoint);
2240
2241 if (!chan) {
2242 return 1;
2243 }
2244
2245 ast_channel_lock(chan);
2246 vars = ast_channel_varshead(chan);
2247 if (vars && !AST_LIST_EMPTY(vars)) {
2248 ast_json_object_set(response->message, "channelvars", ast_json_channel_vars(vars));
2249 }
2250 ast_channel_unlock(chan);
2251 ast_channel_unref(chan);
2252 return 0;
2253}
2254
2255#include "asterisk/config.h"
2256#include "asterisk/netsock2.h"
2257
2260{
2261 RAII_VAR(struct ast_variable *, variables, NULL, ast_variables_destroy);
2262 char *external_host;
2263 char *host = NULL;
2264 char *port = NULL;
2265
2266 ast_assert(response != NULL);
2267
2268 /* Parse any query parameters out of the body parameter */
2269 if (args->variables) {
2270 struct ast_json *json_variables;
2271
2273 json_variables = ast_json_object_get(args->variables, "variables");
2274 if (json_variables
2275 && json_to_ast_variables(response, json_variables, &variables)) {
2276 return;
2277 }
2278 }
2279
2280 if (ast_strlen_zero(args->app)) {
2281 ast_ari_response_error(response, 400, "Bad Request", "app cannot be empty");
2282 return;
2283 }
2284
2285 if (ast_strlen_zero(args->transport)) {
2286 args->transport = "udp";
2287 }
2288
2289 if (ast_strlen_zero(args->encapsulation)) {
2290 args->encapsulation = "rtp";
2291 }
2292 if (ast_strings_equal(args->transport, "websocket")) {
2293 if (!ast_strings_equal(args->encapsulation, "none")) {
2294 ast_ari_response_error(response, 400, "Bad Request", "encapsulation must be 'none' for websocket transport");
2295 return;
2296 }
2297 }
2298
2299 if (ast_strings_equal(args->encapsulation, "rtp")) {
2300 if (!ast_strings_equal(args->transport, "udp")) {
2301 ast_ari_response_error(response, 400, "Bad Request", "transport must be 'udp' for rtp encapsulation");
2302 return;
2303 }
2304 }
2305
2306 if (ast_strings_equal(args->encapsulation, "audiosocket")) {
2307 if (!ast_strings_equal(args->transport, "tcp")) {
2308 ast_ari_response_error(response, 400, "Bad Request", "transport must be 'tcp' for audiosocket encapsulation");
2309 return;
2310 }
2311 }
2312
2313 if (ast_strlen_zero(args->connection_type)) {
2314 args->connection_type = "client";
2315 }
2316 if (!ast_strings_equal(args->transport, "websocket")) {
2317 if (ast_strings_equal(args->connection_type, "server")) {
2318 ast_ari_response_error(response, 400, "Bad Request", "'server' connection_type can only be used with the websocket transport");
2319 return;
2320 }
2321 }
2322
2323 if (ast_strlen_zero(args->external_host)) {
2324 if (ast_strings_equal(args->connection_type, "client")) {
2325 ast_ari_response_error(response, 400, "Bad Request", "external_host is required for all but websocket server connections");
2326 return;
2327 } else {
2328 /* server is only valid for websocket, enforced above */
2329 args->external_host = "INCOMING";
2330 }
2331 }
2332
2333 if (ast_strings_equal(args->transport, "websocket")) {
2334 if (ast_strings_equal(args->connection_type, "client")) {
2335 struct ast_websocket_client *ws_client =
2337 ao2_cleanup(ws_client);
2338 if (!ws_client) {
2339 ast_ari_response_error(response, 400, "Bad Request", "external_host must be a valid websocket_client connection id.");
2340 return;
2341 }
2342 }
2343 } else {
2344 external_host = ast_strdupa(args->external_host);
2345 if (!ast_sockaddr_split_hostport(external_host, &host, &port, PARSE_PORT_REQUIRE)) {
2346 ast_ari_response_error(response, 400, "Bad Request", "external_host must be <host>:<port> for all transports other than websocket");
2347 return;
2348 }
2349 }
2350
2351 if (ast_strlen_zero(args->format)) {
2352 ast_ari_response_error(response, 400, "Bad Request", "format cannot be empty");
2353 return;
2354 }
2355
2356 if (ast_strlen_zero(args->direction)) {
2357 args->direction = "both";
2358 }
2359
2360 if (strcasecmp(args->encapsulation, "rtp") == 0 && strcasecmp(args->transport, "udp") == 0) {
2361 if (external_media_rtp_udp(args, variables, response)) {
2363 response, 500, "Internal Server Error",
2364 "An internal error prevented this request from being handled");
2365 }
2366 } else if (strcasecmp(args->encapsulation, "audiosocket") == 0 && strcasecmp(args->transport, "tcp") == 0) {
2367 if (external_media_audiosocket_tcp(args, variables, response)) {
2369 response, 500, "Internal Server Error",
2370 "An internal error prevented this request from being handled");
2371 }
2372 } else if (strcasecmp(args->encapsulation, "none") == 0 && strcasecmp(args->transport, "websocket") == 0) {
2373 if (external_media_websocket(args, variables, response)) {
2375 response, 500, "Internal Server Error",
2376 "An internal error prevented this request from being handled");
2377 }
2378 } else {
2380 response, 501, "Not Implemented",
2381 "The encapsulation and/or transport is not supported");
2382 }
2383}
2384
2386{
2388 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
2389 RAII_VAR(struct ast_channel *, chan, NULL, ast_channel_cleanup);
2390
2391 control = find_control(response, args->channel_id);
2392 if (control == NULL) {
2393 /* Response filled in by find_control */
2394 return;
2395 }
2396
2397 chan = ast_channel_get_by_name(args->channel_id);
2398 if (!chan) {
2399 ast_ari_response_error(response, 404, "Not Found",
2400 "Callee not found");
2401 return;
2402 }
2403
2404 if (ast_strlen_zero(args->states)) {
2405 ast_ari_response_error(response, 400, "Bad Request", "states must not be empty");
2406 return;
2407 }
2408
2409 if (strcasecmp(args->states, "channel_progress") == 0) {
2411 } else if (strcasecmp(args->states, "channel_answered") == 0) {
2413 } else if (strcasecmp(args->states, "channel_unavailable") == 0) {
2415 } else if (strcasecmp(args->states, "channel_declined") == 0) {
2417 } else {
2418 ast_ari_response_error(response, 400, "Bad Request", "Invalid states value");
2419 return;
2420 }
2421
2424}
static const char app[]
Definition: app_adsiprog.c:56
pthread_t thread
Definition: app_sla.c:335
void ast_ari_response_created(struct ast_ari_response *response, const char *url, struct ast_json *message)
Fill in a Created (201) ast_ari_response.
Definition: res_ari.c:258
void ast_ari_response_error(struct ast_ari_response *response, int response_code, const char *response_text, const char *message_fmt,...)
Fill in an error ast_ari_response.
Definition: res_ari.c:212
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:229
void ast_ari_response_alloc_failed(struct ast_ari_response *response)
Fill in response with a 500 message for allocation failures.
Definition: res_ari.c:251
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:237
char * strsep(char **str, const char *delims)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1739
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:267
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
#define ast_log
Definition: astobj2.c:42
#define ao2_iterator_next(iter)
Definition: astobj2.h:1911
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
Bridging API.
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
int ast_callerid_parse(char *instr, char **name, char **location)
Destructively parse inbuf into name and location (or number)
Definition: callerid.c:1162
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()'s,...
Definition: callerid.c:1101
int ast_is_shrinkable_phonenumber(const char *exten)
Check if a string consists only of digits and + # ( ) - . (meaning it can be cleaned with ast_shrink_...
Definition: callerid.c:1157
#define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED
Definition: callerid.h:437
Internal Asterisk hangup causes.
#define AST_CAUSE_CONGESTION
Definition: causes.h:153
#define AST_CAUSE_UNALLOCATED
Definition: causes.h:98
#define AST_CAUSE_INTERWORKING
Definition: causes.h:146
#define AST_CAUSE_BEARERCAPABILITY_NOTAVAIL
Definition: causes.h:130
#define AST_CAUSE_INVALID_NUMBER_FORMAT
Definition: causes.h:116
#define AST_CAUSE_FAILURE
Definition: causes.h:150
#define AST_CAUSE_NO_USER_RESPONSE
Definition: causes.h:108
#define AST_CAUSE_NORMAL
Definition: causes.h:151
#define AST_CAUSE_CALL_REJECTED
Definition: causes.h:111
#define AST_CAUSE_ANSWERED_ELSEWHERE
Definition: causes.h:114
#define AST_CAUSE_NORMAL_UNSPECIFIED
Definition: causes.h:119
#define AST_CAUSE_NOANSWER
Definition: causes.h:152
#define AST_CAUSE_BUSY
Definition: causes.h:149
static char language[MAX_LANGUAGE]
Definition: chan_iax2.c:348
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
const char * ast_channel_name(const struct ast_channel *chan)
#define AST_MAX_PUBLIC_UNIQUEID
Definition: channel.h:147
enum ast_channel_error ast_channel_errno(void)
Get error code for latest channel operation.
Definition: channel.c:10975
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2355
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2511
struct varshead * ast_channel_varshead(struct ast_channel *chan)
@ AST_CHANNEL_REQUESTOR_BRIDGE_PEER
Definition: channel.h:1525
void ast_channel_set_connected_line(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Set the connected line information in the Asterisk channel.
Definition: channel.c:8322
const char * ast_channel_musicclass(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2972
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
unsigned short ast_channel_transfercapability(const struct ast_channel *chan)
void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars)
adds a list of channel variables to a channel
Definition: channel.c:8129
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
@ AST_CHANNEL_ERROR_ID_EXISTS
Definition: channel.h:4875
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2997
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2979
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
@ AST_FLAG_ORIGINATED
Definition: channel.h:1059
const char * ast_channel_uniqueid(const struct ast_channel *chan)
int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to)
Inherit datastores from a parent to a child.
Definition: channel.c:2338
void ast_channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
Setup new channel accountcodes from the requestor channel after ast_request().
Definition: channel.c:6402
#define AST_MUTE_DIRECTION_READ
Definition: channel.h:4790
ast_channel_adsicpe
Definition: channel.h:888
void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani)
Set caller ID number, name and ANI and generate AMI event.
Definition: channel.c:7316
void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
Inherits channel variable from parent to child channel.
Definition: channel.c:6744
struct ast_channel * ast_channel_get_by_name(const char *search)
Find a channel by name or uniqueid.
Definition: channel.c:1398
@ AST_SOFTHANGUP_EXPLICIT
Definition: channel.h:1168
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
int ast_indicate_data(struct ast_channel *chan, int condition, const void *data, size_t datalen)
Indicates condition of channel, with payload.
Definition: channel.c:4621
int ast_softhangup(struct ast_channel *chan, int cause)
Softly hangup up a channel.
Definition: channel.c:2441
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:3008
#define AST_MAX_CONTEXT
Definition: channel.h:135
const char * ast_channel_language(const struct ast_channel *chan)
void ast_channel_context_set(struct ast_channel *chan, const char *value)
void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src)
Copy the caller information to the connected line information.
Definition: channel.c:8307
#define AST_MUTE_DIRECTION_WRITE
Definition: channel.h:4791
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
void ast_party_connected_line_set_init(struct ast_party_connected_line *init, const struct ast_party_connected_line *guide)
Initialize the given connected line structure using the given guide for a set update operation.
Definition: channel.c:2013
void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value)
void ast_channel_priority_set(struct ast_channel *chan, int value)
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Definition: channel.h:3019
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
struct ast_channel * ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
Requests a channel.
Definition: channel.c:6322
#define ast_channel_unlock(chan)
Definition: channel.h:2973
#define AST_MAX_EXTENSION
Definition: channel.h:134
void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src)
Copy the source redirecting information to the destination redirecting.
Definition: channel.c:2103
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2369
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_RINGING
Definition: channelstate.h:41
@ AST_STATE_DOWN
Definition: channelstate.h:36
@ AST_STATE_RESERVED
Definition: channelstate.h:37
@ AST_MEDIA_TYPE_AUDIO
Definition: codec.h:32
Local proxy channel special access.
struct ast_channel * ast_local_get_peer(struct ast_channel *ast)
Get the other local channel in the pair.
Definition: core_local.c:288
#define ast_datastore_alloc(info, uid)
Definition: datastore.h:85
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition: datastore.c:68
Dialing API.
ast_dial_result
List of return codes for dial run API calls.
Definition: dial.h:54
@ AST_DIAL_RESULT_ANSWERED
Definition: dial.h:61
int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device, const struct ast_assigned_ids *assignedids)
Append a channel.
Definition: dial.c:280
struct ast_dial * ast_dial_create(void)
New dialing structure.
Definition: dial.c:223
struct ast_channel * ast_dial_answered(struct ast_dial *dial)
Return channel that answered.
Definition: dial.c:977
void ast_dial_set_user_data(struct ast_dial *dial, void *user_data)
Set user data on a dial structure.
Definition: dial.c:1274
int ast_dial_prerun(struct ast_dial *dial, struct ast_channel *chan, struct ast_format_cap *cap)
Request all appended channels, but do not dial.
Definition: dial.c:431
void ast_dial_set_global_timeout(struct ast_dial *dial, int timeout)
Set the maximum time (globally) allowed for trying to ring phones.
Definition: dial.c:1284
enum ast_dial_result ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, int async)
Execute dialing synchronously or asynchronously.
Definition: dial.c:935
struct ast_channel * ast_dial_answered_steal(struct ast_dial *dial)
Steal the channel that answered.
Definition: dial.c:989
void * ast_dial_get_user_data(struct ast_dial *dial)
Return the user data on a dial structure.
Definition: dial.c:1279
struct ast_channel * ast_dial_get_channel(struct ast_dial *dial, int num)
Get the dialing channel, if prerun has been executed.
Definition: dial.c:1258
int ast_dial_destroy(struct ast_dial *dial)
Destroys a dialing structure.
Definition: dial.c:1091
char connected
Definition: eagi_proxy.c:82
char * end
Definition: eagi_proxy.c:73
Generic File Format Support. Should be included by clients of the file handling routines....
struct ast_format * ast_get_format_for_file_ext(const char *file_ext)
Get the ast_format associated with the given file extension.
Definition: file.c:2040
Media Format Cache API.
#define ast_format_cache_get(name)
Retrieve a named format from the cache.
Definition: format_cache.h:278
int ast_format_cap_append_by_type(struct ast_format_cap *cap, enum ast_media_type type)
Add all codecs Asterisk knows about for a specific type to the capabilities structure.
Definition: format_cap.c:216
@ AST_FORMAT_CAP_FLAG_DEFAULT
Definition: format_cap.h:38
#define ast_format_cap_append(cap, format, framing)
Add format capability to capabilities structure.
Definition: format_cap.h:99
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition: format_cap.h:49
direction
struct ao2_container * ast_channel_cache_all(void)
struct ast_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object,...
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
@ AST_RECORD_IF_EXISTS_ERROR
Configuration File Parser.
@ PARSE_PORT_REQUIRE
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1260
ast_control_transfer
@ AST_TRANSFER_FAILED
@ AST_TRANSFER_UNAVAILABLE
@ AST_TRANSFER_SUCCESS
@ AST_TRANSFER_PROGRESS
ast_frame_type
Frame types.
@ AST_FRAME_VOICE
@ AST_CONTROL_TRANSFER
#define AST_LOG_ERROR
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_WARNING
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition: json.c:378
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:362
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:414
ast_json_to_ast_vars_code
Definition: json.h:1109
@ AST_JSON_TO_AST_VARS_CODE_INVALID_TYPE
Conversion failed because invalid value type supplied.
Definition: json.h:1116
@ AST_JSON_TO_AST_VARS_CODE_SUCCESS
Conversion successful.
Definition: json.h:1111
@ AST_JSON_TO_AST_VARS_CODE_OOM
Conversion failed because of allocation failure. (Out Of Memory)
Definition: json.h:1118
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:407
enum ast_json_to_ast_vars_code ast_json_to_ast_variables(struct ast_json *json_variables, struct ast_variable **variables)
Convert a ast_json list of key/value pair tuples into a ast_variable list.
Definition: json.c:818
struct ast_json * ast_json_channel_vars(struct varshead *channelvars)
Construct a JSON object from a ast_var_t list.
Definition: json.c:941
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
int errno
int ast_max_forwards_decrement(struct ast_channel *chan)
Decrement the max forwards count for a particular channel.
Definition: max_forwards.c:135
Network socket handling.
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
Splits a string into its host and port components.
Definition: netsock2.c:164
Core PBX routines and definitions.
int ast_findlabel_extension(struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid)
Find the priority of an extension that has the specified label.
Definition: pbx.c:4201
enum ast_pbx_result ast_pbx_run(struct ast_channel *c)
Execute the PBX in the current thread.
Definition: pbx.c:4776
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition: pbx_app.c:471
int ast_func_read2(struct ast_channel *chan, const char *function, struct ast_str **str, ssize_t maxlen)
executes a read operation on a function
const char * ast_str_retrieve_variable(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, struct varshead *headp, const char *var)
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition: ael_main.c:165
#define NULL
Definition: resample.c:96
static int save_dialstring(struct ast_channel *chan, const char *dialstring)
Save dialstring onto a channel datastore.
void ast_ari_channels_mute(struct ast_variable *headers, struct ast_ari_channels_mute_args *args, struct ast_ari_response *response)
Mute a channel.
void ast_ari_channels_snoop_channel_with_id(struct ast_variable *headers, struct ast_ari_channels_snoop_channel_with_id_args *args, struct ast_ari_response *response)
Start snooping.
void ast_ari_channels_continue_in_dialplan(struct ast_variable *headers, struct ast_ari_channels_continue_in_dialplan_args *args, struct ast_ari_response *response)
Exit application; continue execution in the dialplan.
void ast_ari_channels_start_moh(struct ast_variable *headers, struct ast_ari_channels_start_moh_args *args, struct ast_ari_response *response)
Play music on hold to a channel.
static int external_media_audiosocket_tcp(struct ast_ari_channels_external_media_args *args, struct ast_variable *variables, struct ast_ari_response *response)
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
void ast_ari_channels_stop_moh(struct ast_variable *headers, struct ast_ari_channels_stop_moh_args *args, struct ast_ari_response *response)
Stop playing music on hold to a channel.
void ast_ari_channels_move(struct ast_variable *headers, struct ast_ari_channels_move_args *args, struct ast_ari_response *response)
Move the channel from one Stasis application to another.
static char * restore_dialstring(struct ast_channel *chan)
Retrieve the dialstring from the channel datastore.
void ast_ari_channels_send_dtmf(struct ast_variable *headers, struct ast_ari_channels_send_dtmf_args *args, struct ast_ari_response *response)
Send provided DTMF to a given channel.
void ast_ari_channels_unmute(struct ast_variable *headers, struct ast_ari_channels_unmute_args *args, struct ast_ari_response *response)
Unmute a channel.
void ast_ari_channels_dial(struct ast_variable *headers, struct ast_ari_channels_dial_args *args, struct ast_ari_response *response)
Dial a created channel.
static void * ari_originate_dial(void *data)
Thread which dials and executes upon answer.
void ast_ari_channels_create(struct ast_variable *headers, struct ast_ari_channels_create_args *args, struct ast_ari_response *response)
Create channel.
static int json_to_ast_variables(struct ast_ari_response *response, struct ast_json *json_variables, struct ast_variable **variables)
void ast_ari_channels_list(struct ast_variable *headers, struct ast_ari_channels_list_args *args, struct ast_ari_response *response)
List all active channels in Asterisk.
static void ari_channels_handle_snoop_channel(const char *args_channel_id, const char *args_spy, const char *args_whisper, const char *args_app, const char *args_app_args, const char *args_snoop_id, struct ast_ari_response *response)
void ast_ari_channels_get(struct ast_variable *headers, struct ast_ari_channels_get_args *args, struct ast_ari_response *response)
Channel details.
static void * ari_channel_thread(void *data)
Thread that owns stasis-created channel.
void ast_ari_channels_snoop_channel(struct ast_variable *headers, struct ast_ari_channels_snoop_channel_args *args, struct ast_ari_response *response)
Start snooping.
struct ast_datastore_info dialstring_info
void ast_ari_channels_transfer_progress(struct ast_variable *headers, struct ast_ari_channels_transfer_progress_args *args, struct ast_ari_response *response)
Inform the channel about the progress of the attended/blind transfer.
void ast_ari_channels_ring(struct ast_variable *headers, struct ast_ari_channels_ring_args *args, struct ast_ari_response *response)
Indicate ringing to a channel.
void ast_ari_channels_play(struct ast_variable *headers, struct ast_ari_channels_play_args *args, struct ast_ari_response *response)
Start playback of media.
void ast_ari_channels_stop_silence(struct ast_variable *headers, struct ast_ari_channels_stop_silence_args *args, struct ast_ari_response *response)
Stop playing silence to a channel.
void ast_ari_channels_external_media(struct ast_variable *headers, struct ast_ari_channels_external_media_args *args, struct ast_ari_response *response)
Start an External Media session.
static void ari_channels_handle_play(const char *args_channel_id, const char **args_media, size_t args_media_count, const char *args_lang, int args_offsetms, int args_skipms, const char *args_playback_id, struct ast_ari_response *response)
void ast_ari_channels_ring_stop(struct ast_variable *headers, struct ast_ari_channels_ring_stop_args *args, struct ast_ari_response *response)
Stop ringing indication on a channel if locally generated.
void ast_ari_channels_progress(struct ast_variable *headers, struct ast_ari_channels_progress_args *args, struct ast_ari_response *response)
Indicate progress on a channel.
void ast_ari_channels_start_silence(struct ast_variable *headers, struct ast_ari_channels_start_silence_args *args, struct ast_ari_response *response)
Play silence to a channel.
static struct ast_channel * ari_channels_handle_originate_with_id(const char *args_endpoint, const char *args_extension, const char *args_context, long args_priority, const char *args_label, const char *args_app, const char *args_app_args, const char *args_caller_id, int args_timeout, struct ast_variable *variables, const char *args_channel_id, const char *args_other_channel_id, const char *args_originator, const char *args_formats, struct ast_ari_response *response)
static int convert_reason_to_hangup_code(const char *reason)
Return the corresponded hangup code of the given reason.
void ast_ari_channels_unhold(struct ast_variable *headers, struct ast_ari_channels_unhold_args *args, struct ast_ari_response *response)
Remove a channel from hold.
void ast_ari_channels_originate(struct ast_variable *headers, struct ast_ari_channels_originate_args *args, struct ast_ari_response *response)
Create a new channel (originate).
void ast_ari_channels_redirect(struct ast_variable *headers, struct ast_ari_channels_redirect_args *args, struct ast_ari_response *response)
Redirect the channel to a different location.
static int external_media_websocket(struct ast_ari_channels_external_media_args *args, struct ast_variable *variables, struct ast_ari_response *response)
void ast_ari_channels_record(struct ast_variable *headers, struct ast_ari_channels_record_args *args, struct ast_ari_response *response)
Start a recording.
static void chan_data_destroy(struct ari_channel_thread_data *chan_data)
void ast_ari_channels_set_channel_var(struct ast_variable *headers, struct ast_ari_channels_set_channel_var_args *args, struct ast_ari_response *response)
Set the value of a channel variable or function.
static int external_media_rtp_udp(struct ast_ari_channels_external_media_args *args, struct ast_variable *variables, struct ast_ari_response *response)
void ast_ari_channels_hold(struct ast_variable *headers, struct ast_ari_channels_hold_args *args, struct ast_ari_response *response)
Hold a channel.
void ast_ari_channels_answer(struct ast_variable *headers, struct ast_ari_channels_answer_args *args, struct ast_ari_response *response)
Answer a channel.
void ast_ari_channels_play_with_id(struct ast_variable *headers, struct ast_ari_channels_play_with_id_args *args, struct ast_ari_response *response)
Start playback of media and specify the playbackId.
void ast_ari_channels_rtpstatistics(struct ast_variable *headers, struct ast_ari_channels_rtpstatistics_args *args, struct ast_ari_response *response)
RTP stats on a channel.
void ast_ari_channels_get_channel_var(struct ast_variable *headers, struct ast_ari_channels_get_channel_var_args *args, struct ast_ari_response *response)
Get the value of a channel variable or function.
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
void ast_ari_channels_originate_with_id(struct ast_variable *headers, struct ast_ari_channels_originate_with_id_args *args, struct ast_ari_response *response)
Create a new channel (originate with id).
void ast_ari_channels_hangup(struct ast_variable *headers, struct ast_ari_channels_hangup_args *args, struct ast_ari_response *response)
Delete (i.e. hangup) a channel.
Generated file - declares stubs to be implemented in res/ari/resource_channels.c.
int ast_ari_channels_originate_with_id_parse_body(struct ast_json *body, struct ast_ari_channels_originate_with_id_args *args)
Body parsing function for /channels/{channelId}.
int ast_ari_channels_create_parse_body(struct ast_json *body, struct ast_ari_channels_create_args *args)
Body parsing function for /channels/create.
int ast_ari_channels_external_media_parse_body(struct ast_json *body, struct ast_ari_channels_external_media_args *args)
Body parsing function for /channels/externalMedia.
int ast_ari_channels_originate_parse_body(struct ast_json *body, struct ast_ari_channels_originate_args *args)
Body parsing function for /channels.
Pluggable RTP Architecture.
struct ast_json * ast_rtp_instance_get_stats_all_json(struct ast_rtp_instance *instance)
Retrieve statistics about an RTP instance in json format.
Definition: rtp_engine.c:4271
struct ast_rtp_glue * ast_rtp_instance_get_glue(const char *type)
Get the RTP glue that binds a channel to the RTP engine.
Definition: rtp_engine.c:2388
Stasis Application API. See Stasis Application API for detailed documentation.
struct stasis_message_sanitizer * stasis_app_get_sanitizer(void)
Get the Stasis message sanitizer for app_stasis applications.
Definition: res_stasis.c:2343
void stasis_app_control_moh_start(struct stasis_app_control *control, const char *moh_class)
Play music on hold to a channel (does not affect hold status)
Definition: control.c:821
int stasis_app_control_unmute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype)
Unmute the channel associated with this control.
Definition: control.c:700
void stasis_app_control_unhold(struct stasis_app_control *control)
Remove the channel associated with the control from hold.
Definition: control.c:802
void stasis_app_control_silence_start(struct stasis_app_control *control)
Start playing silence to a channel.
Definition: control.c:873
void stasis_app_control_silence_stop(struct stasis_app_control *control)
Stop playing silence to a channel.
Definition: control.c:896
int stasis_app_control_continue(struct stasis_app_control *control, const char *context, const char *extension, int priority)
Exit res_stasis and continue execution in the dialplan.
Definition: control.c:415
int stasis_app_control_redirect(struct stasis_app_control *control, const char *endpoint)
Redirect a channel in res_stasis to a particular endpoint.
Definition: control.c:526
void stasis_app_control_moh_stop(struct stasis_app_control *control)
Stop playing music on hold to a channel (does not affect hold status)
Definition: control.c:839
int stasis_app_control_move(struct stasis_app_control *control, const char *app_name, const char *app_args)
Exit res_stasis and move to another Stasis application.
Definition: control.c:477
int stasis_app_control_mute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype)
Mute the channel associated with this control.
Definition: control.c:672
enum stasis_app_subscribe_res stasis_app_subscribe_channel(const char *app_name, struct ast_channel *chan)
Directly subscribe an application to a channel.
Definition: res_stasis.c:2063
int stasis_app_control_dtmf(struct stasis_app_control *control, const char *dtmf, int before, int between, unsigned int duration, int after)
Send DTMF to the channel associated with this control.
Definition: control.c:591
void stasis_app_control_hold(struct stasis_app_control *control)
Place the channel associated with the control on hold.
Definition: control.c:789
struct stasis_app_control * stasis_app_control_find_by_channel_id(const char *channel_id)
Returns the handler for the channel with the given id.
Definition: res_stasis.c:349
int stasis_app_control_ring_stop(struct stasis_app_control *control)
Stop locally generated ringing on the channel associated with this control.
Definition: control.c:633
int stasis_app_control_dial(struct stasis_app_control *control, const char *dialstring, unsigned int timeout)
Dial a channel.
Definition: control.c:1711
struct ast_channel_snapshot * stasis_app_control_get_snapshot(const struct stasis_app_control *control)
Returns the most recent snapshot for the associated channel.
Definition: control.c:901
int stasis_app_control_set_channel_var(struct stasis_app_control *control, const char *variable, const char *value)
Set a variable on the channel associated with this control to value.
Definition: control.c:752
int stasis_app_control_ring(struct stasis_app_control *control)
Indicate ringing to the channel associated with this control.
Definition: control.c:618
int stasis_app_control_progress(struct stasis_app_control *control)
Indicate progress to the channel associated with this control.
Definition: control.c:648
int stasis_app_control_answer(struct stasis_app_control *control)
Answer the channel associated with this control.
Stasis Application Playback API. See StasisApplication API" for detailed documentation.
@ STASIS_PLAYBACK_TARGET_CHANNEL
struct stasis_app_playback * stasis_app_control_play_uri(struct stasis_app_control *control, const char **media, size_t media_count, const char *language, const char *target_id, enum stasis_app_playback_target_type target_type, int skipms, long offsetms, const char *id)
Play a file to the control's channel.
struct ast_json * stasis_app_playback_to_json(const struct stasis_app_playback *playback)
Convert a playback to its JSON representation.
const char * stasis_app_playback_get_id(struct stasis_app_playback *playback)
Gets the unique id of a playback object.
Stasis Application Recording API. See StasisApplication API" for detailed documentation.
struct stasis_app_recording_options * stasis_app_recording_options_create(const char *name, const char *format)
Allocate a recording options object.
struct ast_json * stasis_app_recording_to_json(const struct stasis_app_recording *recording)
Construct a JSON model of a recording.
struct stasis_app_recording * stasis_app_control_record(struct stasis_app_control *control, struct stasis_app_recording_options *options)
Record media from a channel.
enum ast_record_if_exists stasis_app_recording_if_exists_parse(const char *str)
Parse a string into the if_exists enum.
#define STASIS_APP_RECORDING_TERMINATE_INVALID
char stasis_app_recording_termination_parse(const char *str)
Parse a string into the recording termination enum.
Stasis Application Snoop API. See StasisApplication API" for detailed documentation.
struct ast_channel * stasis_app_control_snoop(struct ast_channel *chan, enum stasis_app_snoop_direction spy, enum stasis_app_snoop_direction whisper, const char *app, const char *app_args, const char *snoop_id)
Create a snoop on the provided channel.
stasis_app_snoop_direction
Directions for audio stream flow.
@ STASIS_SNOOP_DIRECTION_IN
Audio stream in from the channel.
@ STASIS_SNOOP_DIRECTION_OUT
Audio stream out to the channel.
@ STASIS_SNOOP_DIRECTION_NONE
No direction.
@ STASIS_SNOOP_DIRECTION_BOTH
Audio stream to AND from the channel.
struct ast_json * ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_channel_snapshot.
#define ast_string_field_build(x, field, fmt, args...)
Set a field to a complex (built) value.
Definition: stringfields.h:555
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
int ast_strings_equal(const char *str1, const char *str2)
Compare strings for equality checking for NULL.
Definition: strings.c:238
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:742
Generic container type.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821
struct ast_str * stasis_stuff
struct ast_channel * chan
Structure used for origination.
char appdata[0]
Application data to pass to Stasis application.
char exten[AST_MAX_EXTENSION]
Dialplan extension.
char context[AST_MAX_CONTEXT]
Dialplan context.
int priority
Dialplan priority.
ast_app: A registered application
Definition: pbx_app.c:45
struct ast_json * message
Definition: ari.h:103
Structure to pass both assignedid values to channel drivers.
Definition: channel.h:606
const char * uniqueid2
Definition: channel.h:608
const char * uniqueid
Definition: channel.h:607
Structure representing a snapshot of channel state.
enum ast_channel_state state
Structure to describe a channel "technology", ie a channel driver See for examples:
Definition: channel.h:648
const char *const type
Definition: channel.h:649
Main Channel structure associated with a channel.
struct ast_channel_snapshot * snapshot
Structure for a data store type.
Definition: datastore.h:31
const char * type
Definition: datastore.h:32
Structure for a data store object.
Definition: datastore.h:64
void * data
Definition: datastore.h:66
Main dialing structure. Contains global options, channels being dialed, and more!
Definition: dial.c:48
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
Definition of a media format.
Definition: format.c:43
Abstract JSON element (object, array, string, int, ...).
Connected Line/Party information.
Definition: channel.h:458
int transit_network_select
Transit Network Select.
Definition: channel.h:399
enum ast_rtp_glue_result(* get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance)
Callback for retrieving the RTP instance carrying audio.
Definition: rtp_engine.h:787
Support for dynamic strings.
Definition: strings.h:623
Structure for variables, used for configurations and for channel variables.
Structure containing callbacks for Stasis message sanitization.
Definition: stasis.h:200
int(* channel_snapshot)(const struct ast_channel_snapshot *snapshot)
Callback which determines whether a channel should be sanitized from a message based on the channel's...
Definition: stasis.h:221
int value
Definition: syslog.c:37
const char * args
static struct test_options options
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:978
#define ast_assert(a)
Definition: utils.h:776
char * ast_uri_encode(const char *string, char *outbuf, int buflen, struct ast_flags spec)
Turn text string to URI-encoded XX version.
Definition: utils.c:723
const struct ast_flags ast_uri_http
Definition: utils.c:719
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:625
#define ast_set_flag(p, flag)
Definition: utils.h:70
struct ast_websocket_client * ast_websocket_client_retrieve_by_id(const char *id)
Retrieve a websocket client object by ID.