Asterisk - The Open Source Telephony Project GIT-master-0644429
control.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 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 Stasis application control support.
22 *
23 * \author David M. Lee, II <dlee@digium.com>
24 */
25
26#include "asterisk.h"
27
29#include "asterisk/stasis_app.h"
30
31#include "command.h"
32#include "control.h"
33#include "app.h"
34#include "asterisk/dial.h"
35#include "asterisk/bridge.h"
39#include "asterisk/frame.h"
40#include "asterisk/pbx.h"
42#include "asterisk/app.h"
43
44#include <signal.h>
45
47
48/*!
49 * \brief Indicates if the Stasis app internals are being shut down
50 */
51static int shutting_down;
52
55 /*! Queue of commands to dispatch on the channel */
57 /*!
58 * The associated channel.
59 * Be very careful with the threading associated w/ manipulating
60 * the channel.
61 */
63 /*!
64 * When a channel is in a bridge, the bridge that it is in.
65 */
67 /*!
68 * Bridge features which should be applied to the channel when it enters the next bridge. These only apply to the next bridge and will be emptied thereafter.
69 */
71 /*!
72 * Holding place for channel's PBX while imparted to a bridge.
73 */
74 struct ast_pbx *pbx;
75 /*!
76 * A list of rules to check before adding a channel to a bridge.
77 */
79 /*!
80 * A list of rules to check before removing a channel from a bridge.
81 */
83 /*!
84 * Silence generator, when silence is being generated.
85 */
87 /*!
88 * The app for which this control is currently controlling.
89 * This can change through the use of the /channels/{channelId}/move
90 * command.
91 */
92 struct stasis_app *app;
93 /*!
94 * The name of the next Stasis application to move to.
95 */
96 char *next_app;
97 /*!
98 * The list of arguments to pass to StasisStart when moving to another app.
99 */
101 /*!
102 * When set, /c app_stasis should exit and continue in the dialplan.
103 */
104 unsigned int is_done:1;
105};
106
107static void control_dtor(void *obj)
108{
109 struct stasis_app_control *control = obj;
110
111 ao2_cleanup(control->command_queue);
112
114 ao2_cleanup(control->app);
115
116 control_move_cleanup(control);
117
118 ast_cond_destroy(&control->wait_cond);
122
123}
124
126{
127 struct stasis_app_control *control;
128 int res;
129
130 control = ao2_alloc(sizeof(*control), control_dtor);
131 if (!control) {
132 return NULL;
133 }
134
135 AST_LIST_HEAD_INIT(&control->add_rules);
137
138 res = ast_cond_init(&control->wait_cond, NULL);
139 if (res != 0) {
140 ast_log(LOG_ERROR, "Error initializing ast_cond_t: %s\n",
141 strerror(errno));
142 ao2_ref(control, -1);
143 return NULL;
144 }
145
146 control->app = ao2_bump(app);
147
149 control->channel = channel;
150
153 if (!control->command_queue) {
154 ao2_ref(control, -1);
155 return NULL;
156 }
157
158 control->next_app = NULL;
159 AST_VECTOR_INIT(&control->next_app_args, 0);
160
161 return control;
162}
163
165 struct stasis_app_control *control,
166 struct app_control_rules *list, struct stasis_app_control_rule *obj)
167{
168 ao2_lock(control->command_queue);
169 AST_LIST_INSERT_TAIL(list, obj, next);
170 ao2_unlock(control->command_queue);
171}
172
174 struct stasis_app_control *control,
175 struct app_control_rules *list, struct stasis_app_control_rule *obj)
176{
178
179 ao2_lock(control->command_queue);
181 if (rule == obj) {
183 break;
184 }
185 }
187 ao2_unlock(control->command_queue);
188}
189
190/*!
191 * \internal
192 * \brief Checks to make sure each rule in the given list passes.
193 *
194 * \details Loops over a list of rules checking for rejections or failures.
195 * If one rule fails its resulting error code is returned.
196 *
197 * \note Command queue should be locked before calling this function.
198 *
199 * \param control The stasis application control
200 * \param list The list of rules to check
201 *
202 * \retval 0 if all rules pass
203 * \retval non-zero error code if a rule fails
204 */
206 const struct stasis_app_control *control,
207 struct app_control_rules *list)
208{
209 int res = 0;
211 AST_LIST_TRAVERSE(list, rule, next) {
212 if ((res = rule->check_rule(control))) {
213 return res;
214 }
215 }
216 return res;
217}
218
220 struct stasis_app_control *control,
222{
223 return app_control_register_rule(control, &control->add_rules, rule);
224}
225
227 struct stasis_app_control *control,
229{
230 app_control_unregister_rule(control, &control->add_rules, rule);
231}
232
234 struct stasis_app_control *control,
236{
237 return app_control_register_rule(control, &control->remove_rules, rule);
238}
239
241 struct stasis_app_control *control,
243{
244 app_control_unregister_rule(control, &control->remove_rules, rule);
245}
246
248 struct stasis_app_control *control)
249{
250 return app_control_check_rules(control, &control->add_rules);
251}
252
254 struct stasis_app_control *control)
255{
256 return app_control_check_rules(control, &control->remove_rules);
257}
258
259static int noop_cb(struct stasis_app_control *control,
260 struct ast_channel *chan, void *data)
261{
262 return 0;
263}
264
265/*! Callback type to see if the command can execute
266 note: command_queue is locked during callback */
267typedef int (*app_command_can_exec_cb)(struct stasis_app_control *control);
268
270 struct stasis_app_control *control, stasis_app_command_cb command_fn,
272 app_command_can_exec_cb can_exec_fn)
273{
274 int retval;
275 struct stasis_app_command *command;
276
277 command_fn = command_fn ? : noop_cb;
278
279 command = command_create(command_fn, data, data_destructor);
280 if (!command) {
281 return NULL;
282 }
283
284 ao2_lock(control->command_queue);
285 if (control->is_done) {
286 ao2_unlock(control->command_queue);
287 ao2_ref(command, -1);
288 return NULL;
289 }
290 if (can_exec_fn && (retval = can_exec_fn(control))) {
291 ao2_unlock(control->command_queue);
292 command_complete(command, retval);
293 return command;
294 }
295
296 ao2_link_flags(control->command_queue, command, OBJ_NOLOCK);
297 ast_cond_signal(&control->wait_cond);
298
299 if (control->channel) {
300 /* Queue a null frame so that if and when the channel is waited on,
301 return immediately to process the new command */
303 }
304
305 ao2_unlock(control->command_queue);
306
307 return command;
308}
309
311 struct stasis_app_control *control, stasis_app_command_cb command_fn,
313{
314 return exec_command_on_condition(control, command_fn, data, data_destructor, NULL);
315}
316
317static int app_control_add_role(struct stasis_app_control *control,
318 struct ast_channel *chan, void *data)
319{
320 char *role = data;
321
322 return ast_channel_add_bridge_role(chan, role);
323}
324
325int stasis_app_control_add_role(struct stasis_app_control *control, const char *role)
326{
327 char *role_dup;
328
329 role_dup = ast_strdup(role);
330 if (!role_dup) {
331 return -1;
332 }
333
335
336 return 0;
337}
338
340 struct ast_channel *chan, void *data)
341{
343
344 return 0;
345}
346
348{
350}
351
353{
354 return ao2_container_count(control->command_queue);
355}
356
358{
359 /* Called from stasis_app_exec thread; no lock needed */
360 return control->is_done;
361}
362
364{
365 /* Locking necessary to sync with other threads adding commands to the queue. */
366 ao2_lock(control->command_queue);
367 control->is_done = 1;
368 ao2_unlock(control->command_queue);
369}
370
375};
376
377static int app_control_continue(struct stasis_app_control *control,
378 struct ast_channel *chan, void *data)
379{
380 struct stasis_app_control_continue_data *continue_data = data;
381
382 ast_assert(control->channel != NULL);
383
384 /* If we're in a Stasis bridge, depart it before going back to the
385 * dialplan */
386 if (stasis_app_get_bridge(control)) {
387 ast_bridge_depart(control->channel);
388 }
389
390 /* Called from stasis_app_exec thread; no lock needed */
391 ast_explicit_goto(control->channel, continue_data->context, continue_data->extension, continue_data->priority);
392
393 control_mark_done(control);
394
395 return 0;
396}
397
398int stasis_app_control_continue(struct stasis_app_control *control, const char *context, const char *extension, int priority)
399{
400 struct stasis_app_control_continue_data *continue_data;
401
402 if (!(continue_data = ast_calloc(1, sizeof(*continue_data)))) {
403 return -1;
404 }
405 ast_copy_string(continue_data->context, S_OR(context, ""), sizeof(continue_data->context));
406 ast_copy_string(continue_data->extension, S_OR(extension, ""), sizeof(continue_data->extension));
407 if (priority > 0) {
408 continue_data->priority = priority;
409 } else {
410 continue_data->priority = -1;
411 }
412
414
415 return 0;
416}
417
419 char *app_name;
420 char *app_args;
421};
422
423static int app_control_move(struct stasis_app_control *control,
424 struct ast_channel *chan, void *data)
425{
426 struct stasis_app_control_move_data *move_data = data;
427
428 control->next_app = ast_strdup(move_data->app_name);
429 if (!control->next_app) {
430 ast_log(LOG_ERROR, "Allocation failed for next app\n");
431 return -1;
432 }
433
434 if (move_data->app_args) {
435 char *token;
436
437 while ((token = strtok_r(move_data->app_args, ",", &move_data->app_args))) {
438 int res;
439 char *arg;
440
441 if (!(arg = ast_strdup(token))) {
442 ast_log(LOG_ERROR, "Allocation failed for next app arg\n");
443 control_move_cleanup(control);
444 return -1;
445 }
446
447 res = AST_VECTOR_APPEND(&control->next_app_args, arg);
448 if (res) {
449 ast_log(LOG_ERROR, "Failed to append arg to next app args\n");
450 ast_free(arg);
451 control_move_cleanup(control);
452 return -1;
453 }
454 }
455 }
456
457 return 0;
458}
459
460int stasis_app_control_move(struct stasis_app_control *control, const char *app_name, const char *app_args)
461{
462 struct stasis_app_control_move_data *move_data;
463 size_t size;
464
465 size = sizeof(*move_data) + strlen(app_name) + 1;
466 if (app_args) {
467 /* Application arguments are optional */
468 size += strlen(app_args) + 1;
469 }
470
471 if (!(move_data = ast_calloc(1, size))) {
472 return -1;
473 }
474
475 move_data->app_name = (char *)move_data + sizeof(*move_data);
476 strcpy(move_data->app_name, app_name); /* Safe */
477
478 if (app_args) {
479 move_data->app_args = move_data->app_name + strlen(app_name) + 1;
480 strcpy(move_data->app_args, app_args); /* Safe */
481 } else {
482 move_data->app_args = NULL;
483 }
484
486
487 return 0;
488}
489
490static int app_control_redirect(struct stasis_app_control *control,
491 struct ast_channel *chan, void *data)
492{
493 char *endpoint = data;
494 int res;
495
496 ast_assert(control->channel != NULL);
497 ast_assert(endpoint != NULL);
498
499 res = ast_transfer(control->channel, endpoint);
500 if (!res) {
501 ast_log(LOG_NOTICE, "Unsupported transfer requested on channel '%s'\n",
502 ast_channel_name(control->channel));
503 return 0;
504 }
505
506 return 0;
507}
508
509int stasis_app_control_redirect(struct stasis_app_control *control, const char *endpoint)
510{
511 char *endpoint_data = ast_strdup(endpoint);
512
513 if (!endpoint_data) {
514 return -1;
515 }
516
518
519 return 0;
520}
521
525 unsigned int duration;
526 int after;
527 char dtmf[];
528};
529
530static void dtmf_in_bridge(struct ast_channel *chan, struct stasis_app_control_dtmf_data *dtmf_data)
531{
532 if (dtmf_data->before) {
533 usleep(dtmf_data->before * 1000);
534 }
535
536 ast_dtmf_stream_external(chan, dtmf_data->dtmf, dtmf_data->between, dtmf_data->duration);
537
538 if (dtmf_data->after) {
539 usleep(dtmf_data->after * 1000);
540 }
541}
542
543static void dtmf_no_bridge(struct ast_channel *chan, struct stasis_app_control_dtmf_data *dtmf_data)
544{
545 if (dtmf_data->before) {
546 ast_safe_sleep(chan, dtmf_data->before);
547 }
548
549 ast_dtmf_stream(chan, NULL, dtmf_data->dtmf, dtmf_data->between, dtmf_data->duration);
550
551 if (dtmf_data->after) {
552 ast_safe_sleep(chan, dtmf_data->after);
553 }
554}
555
556static int app_control_dtmf(struct stasis_app_control *control,
557 struct ast_channel *chan, void *data)
558{
559 struct stasis_app_control_dtmf_data *dtmf_data = data;
560
561 if (ast_channel_state(chan) != AST_STATE_UP) {
563 }
564
565 if (stasis_app_get_bridge(control)) {
566 dtmf_in_bridge(chan, dtmf_data);
567 } else {
568 dtmf_no_bridge(chan, dtmf_data);
569 }
570
571 return 0;
572}
573
574int stasis_app_control_dtmf(struct stasis_app_control *control, const char *dtmf, int before, int between, unsigned int duration, int after)
575{
576 struct stasis_app_control_dtmf_data *dtmf_data;
577
578 if (!(dtmf_data = ast_calloc(1, sizeof(*dtmf_data) + strlen(dtmf) + 1))) {
579 return -1;
580 }
581
582 dtmf_data->before = before;
583 dtmf_data->between = between;
584 dtmf_data->duration = duration;
585 dtmf_data->after = after;
586 strcpy(dtmf_data->dtmf, dtmf);
587
589
590 return 0;
591}
592
593static int app_control_ring(struct stasis_app_control *control,
594 struct ast_channel *chan, void *data)
595{
597
598 return 0;
599}
600
602{
604
605 return 0;
606}
607
608static int app_control_ring_stop(struct stasis_app_control *control,
609 struct ast_channel *chan, void *data)
610{
611 ast_indicate(control->channel, -1);
612
613 return 0;
614}
615
617{
619
620 return 0;
621}
622
625 unsigned int direction;
626};
627
628static int app_control_mute(struct stasis_app_control *control,
629 struct ast_channel *chan, void *data)
630{
631 struct stasis_app_control_mute_data *mute_data = data;
632
633 ast_channel_lock(chan);
634 ast_channel_suppress(control->channel, mute_data->direction, mute_data->frametype);
635 ast_channel_unlock(chan);
636
637 return 0;
638}
639
641{
642 struct stasis_app_control_mute_data *mute_data;
643
644 if (!(mute_data = ast_calloc(1, sizeof(*mute_data)))) {
645 return -1;
646 }
647
648 mute_data->direction = direction;
649 mute_data->frametype = frametype;
650
652
653 return 0;
654}
655
656static int app_control_unmute(struct stasis_app_control *control,
657 struct ast_channel *chan, void *data)
658{
659 struct stasis_app_control_mute_data *mute_data = data;
660
661 ast_channel_lock(chan);
662 ast_channel_unsuppress(control->channel, mute_data->direction, mute_data->frametype);
663 ast_channel_unlock(chan);
664
665 return 0;
666}
667
669{
670 struct stasis_app_control_mute_data *mute_data;
671
672 if (!(mute_data = ast_calloc(1, sizeof(*mute_data)))) {
673 return -1;
674 }
675
676 mute_data->direction = direction;
677 mute_data->frametype = frametype;
678
680
681 return 0;
682}
683
684/*!
685 * \brief structure for queuing ARI channel variable setting
686 *
687 * It may seem weird to define this custom structure given that we already have
688 * ast_var_t and ast_variable defined elsewhere. The problem with those is that
689 * they are not tolerant of NULL channel variable value pointers. In fact, in both
690 * cases, the best they could do is to have a zero-length variable value. However,
691 * when un-setting a channel variable, it is important to pass a NULL value, not
692 * a zero-length string.
693 */
694struct chanvar {
695 /*! Name of variable to set/unset */
696 char *name;
697 /*! Value of variable to set. If unsetting, this will be NULL */
698 char *value;
699};
700
701static void free_chanvar(void *data)
702{
703 struct chanvar *var = data;
704
705 ast_free(var->name);
706 ast_free(var->value);
707 ast_free(var);
708}
709
711 struct ast_channel *chan, void *data)
712{
713 struct chanvar *var = data;
714
715 pbx_builtin_setvar_helper(control->channel, var->name, var->value);
716
717 return 0;
718}
719
720int stasis_app_control_set_channel_var(struct stasis_app_control *control, const char *variable, const char *value)
721{
722 struct chanvar *var;
723
724 var = ast_calloc(1, sizeof(*var));
725 if (!var) {
726 return -1;
727 }
728
729 var->name = ast_strdup(variable);
730 if (!var->name) {
732 return -1;
733 }
734
735 /* It's kosher for value to be NULL. It means the variable is being unset */
736 if (value) {
737 var->value = ast_strdup(value);
738 if (!var->value) {
740 return -1;
741 }
742 }
743
745
746 return 0;
747}
748
749static int app_control_hold(struct stasis_app_control *control,
750 struct ast_channel *chan, void *data)
751{
753
754 return 0;
755}
756
758{
760}
761
762static int app_control_unhold(struct stasis_app_control *control,
763 struct ast_channel *chan, void *data)
764{
766
767 return 0;
768}
769
771{
773}
774
775static int app_control_moh_start(struct stasis_app_control *control,
776 struct ast_channel *chan, void *data)
777{
778 char *moh_class = data;
779
780 if (ast_channel_state(chan) != AST_STATE_UP) {
782 }
783
784 ast_moh_start(chan, moh_class, NULL);
785
786 return 0;
787}
788
789void stasis_app_control_moh_start(struct stasis_app_control *control, const char *moh_class)
790{
791 char *data = NULL;
792
793 if (!ast_strlen_zero(moh_class)) {
794 data = ast_strdup(moh_class);
795 }
796
798}
799
800static int app_control_moh_stop(struct stasis_app_control *control,
801 struct ast_channel *chan, void *data)
802{
803 ast_moh_stop(chan);
804 return 0;
805}
806
808{
810}
811
813 struct ast_channel *chan, void *data)
814{
815 if (ast_channel_state(chan) != AST_STATE_UP) {
817 }
818
819 if (control->silgen) {
820 /* We have a silence generator, but it may have been implicitly
821 * disabled by media actions (music on hold, playing media,
822 * etc.) Just stop it and restart a new one.
823 */
825 control->channel, control->silgen);
826 }
827
828 ast_debug(3, "%s: Starting silence generator\n",
831
832 if (!control->silgen) {
834 "%s: Failed to start silence generator.\n",
836 }
837
838 return 0;
839}
840
842{
844}
845
847{
848 if (control->silgen) {
849 ast_debug(3, "%s: Stopping silence generator\n",
852 control->channel, control->silgen);
853 control->silgen = NULL;
854 }
855}
856
858 struct ast_channel *chan, void *data)
859{
861 return 0;
862}
863
865{
867}
868
870 const struct stasis_app_control *control)
871{
873}
874
876 stasis_app_command_cb command_fn, void *data,
877 command_data_destructor_fn data_destructor,
878 app_command_can_exec_cb can_exec_fn)
879{
880 int ret;
881 struct stasis_app_command *command;
882
883 if (control == NULL || control->is_done) {
884 /* If exec_command_on_condition fails, it calls the data_destructor.
885 * In order to provide consistent behavior, we'll also call the data_destructor
886 * on this error path. This way, callers never have to call the
887 * data_destructor themselves.
888 */
889 if (data_destructor) {
891 }
892 return -1;
893 }
894
896 control, command_fn, data, data_destructor, can_exec_fn);
897 if (!command) {
898 return -1;
899 }
900
901 ret = command_join(command);
902 ao2_ref(command, -1);
903
904 return ret;
905}
906
909{
910 return app_send_command_on_condition(control, command_fn, data, data_destructor, NULL);
911}
912
914 stasis_app_command_cb command_fn, void *data,
916{
917 struct stasis_app_command *command;
918
919 if (control == NULL || control->is_done) {
920 /* If exec_command fails, it calls the data_destructor. In order to
921 * provide consistent behavior, we'll also call the data_destructor
922 * on this error path. This way, callers never have to call the
923 * data_destructor themselves.
924 */
925 if (data_destructor) {
927 }
928 return -1;
929 }
930
931 command = exec_command(control, command_fn, data, data_destructor);
932 if (!command) {
933 return -1;
934 }
935 ao2_ref(command, -1);
936
937 return 0;
938}
939
941{
942 struct ast_bridge *ret;
943
944 if (!control) {
945 return NULL;
946 }
947
948 ao2_lock(control);
949 ret = control->bridge;
950 ao2_unlock(control);
951
952 return ret;
953}
954
955/*!
956 * \brief Singleton dial bridge
957 *
958 * The dial bridge is a holding bridge used to hold all
959 * outbound dialed channels that are not in any "real" ARI-created
960 * bridge. The dial bridge is invisible, meaning that it does not
961 * show up in channel snapshots, AMI or ARI output, and no events
962 * get raised for it.
963 *
964 * This is used to keep dialed channels confined to the bridging system
965 * and unify the threading model used for dialing outbound channels.
966 */
967static struct ast_bridge *dial_bridge;
969
970/*!
971 * \brief Retrieve a reference to the dial bridge.
972 *
973 * If the dial bridge has not been created yet, it will
974 * be created, otherwise, a reference to the existing bridge
975 * will be returned.
976 *
977 * The caller will need to unreference the dial bridge once
978 * they are finished with it.
979 *
980 * \retval NULL Unable to find/create the dial bridge
981 * \retval non-NULL A reference to the dial bridge
982 */
983static struct ast_bridge *get_dial_bridge(void)
984{
985 struct ast_bridge *ret_bridge = NULL;
986
988
989 if (shutting_down) {
990 goto end;
991 }
992
993 if (dial_bridge) {
994 ret_bridge = ao2_bump(dial_bridge);
995 goto end;
996 }
997
998 dial_bridge = stasis_app_bridge_create_invisible("holding", "dial_bridge", NULL);
999 if (!dial_bridge) {
1000 goto end;
1001 }
1002 ret_bridge = ao2_bump(dial_bridge);
1003
1004end:
1006 return ret_bridge;
1007}
1008
1009static int bridge_channel_depart(struct stasis_app_control *control,
1010 struct ast_channel *chan, void *data);
1011
1012/*!
1013 * \brief after bridge callback for the dial bridge
1014 *
1015 * The only purpose of this callback is to ensure that the control structure's
1016 * bridge pointer is NULLed
1017 */
1018static void dial_bridge_after_cb(struct ast_channel *chan, void *data)
1019{
1020 struct stasis_app_control *control = data;
1021 struct ast_bridge_channel *bridge_channel;
1022
1024 bridge_channel = ast_channel_get_bridge_channel(chan);
1026
1027 ast_debug(3, "Channel: <%s> Reason: %d\n", ast_channel_name(control->channel), ast_channel_hangupcause(chan));
1028
1030
1031 control->bridge = NULL;
1032}
1033
1035{
1036 struct stasis_app_control *control = data;
1037
1038 ast_debug(3, "Channel: <%s> Reason: %d\n", ast_channel_name(control->channel), reason);
1039 dial_bridge_after_cb(control->channel, data);
1040}
1041
1042/*!
1043 * \brief Add a channel to the singleton dial bridge.
1044 *
1045 * \param control The Stasis control structure
1046 * \param chan The channel to add to the bridge
1047 * \retval -1 Failed
1048 * \retval 0 Success
1049 */
1050static int add_to_dial_bridge(struct stasis_app_control *control, struct ast_channel *chan)
1051{
1052 struct ast_bridge *bridge;
1053
1054 bridge = get_dial_bridge();
1055 if (!bridge) {
1056 return -1;
1057 }
1058
1059 control->bridge = bridge;
1062 control->bridge = NULL;
1063 ao2_ref(bridge, -1);
1064 return -1;
1065 }
1066
1067 ao2_ref(bridge, -1);
1068
1069 return 0;
1070}
1071
1072/*!
1073 * \brief Depart a channel from a bridge, and potentially add it back to the dial bridge
1074 *
1075 * \param control Take a guess
1076 * \param chan Take another guess
1077 */
1078static int depart_channel(struct stasis_app_control *control, struct ast_channel *chan)
1079{
1080 ast_bridge_depart(chan);
1081
1082 /* Channels which have a PBX are not ones that have been created and dialed from ARI. They
1083 * have externally come in from the dialplan, and thus should not be placed into the dial
1084 * bridge. Only channels which are created and dialed in ARI should go into the dial bridge.
1085 */
1086 if (!ast_check_hangup(chan) && ast_channel_state(chan) != AST_STATE_UP && !ast_channel_pbx(chan)) {
1087 /* Channel is still being dialed, so put it back in the dialing bridge */
1088 add_to_dial_bridge(control, chan);
1089 }
1090
1091 return 0;
1092}
1093
1095 struct ast_channel *chan, void *data)
1096{
1097 struct ast_bridge_channel *bridge_channel;
1098
1100 bridge_channel = ast_channel_internal_bridge_channel(chan);
1102
1103 if (bridge_channel != data) {
1104 ast_debug(3, "%s: Channel is no longer in departable state\n",
1106 return -1;
1107 }
1108
1109 ast_debug(3, "%s: Channel departing bridge\n",
1111
1112 depart_channel(control, chan);
1113
1114 return 0;
1115}
1116
1117static void internal_bridge_after_cb(struct ast_channel *chan, void *data,
1118 enum ast_bridge_after_cb_reason reason)
1119{
1120 struct stasis_app_control *control = data;
1121 struct ast_bridge_channel *bridge_channel;
1122
1123 ao2_lock(control);
1124 ast_debug(3, "%s, %s: %s\n",
1125 ast_channel_uniqueid(chan), control->bridge ? control->bridge->uniqueid : "unknown",
1127
1129 /* The impart actually failed so control->bridge isn't valid. */
1130 control->bridge = NULL;
1131 }
1132
1133 ast_assert(chan == control->channel);
1134
1135 /* Restore the channel's PBX */
1136 ast_channel_pbx_set(control->channel, control->pbx);
1137 control->pbx = NULL;
1138
1139 if (control->bridge) {
1140 app_unsubscribe_bridge(control->app, control->bridge);
1141
1142 /* No longer in the bridge */
1143 control->bridge = NULL;
1144
1145 /* Get the bridge channel so we don't depart from the wrong bridge */
1147 bridge_channel = ast_channel_get_bridge_channel(chan);
1149
1150 /* Depart this channel from the bridge using the command queue if possible */
1152 }
1153
1155 /* The channel has had a StasisEnd published on it, but until now had remained in
1156 * the bridging system. This means that the channel moved from a Stasis bridge to a
1157 * non-Stasis bridge and is now exiting the bridging system. Because of this, the
1158 * channel needs to exit the Stasis application and go to wherever the non-Stasis
1159 * bridge has directed it to go. If the non-Stasis bridge has not set up an after
1160 * bridge destination, then the channel should be hung up.
1161 */
1162 int hangup_flag;
1163
1166 ast_softhangup_nolock(chan, hangup_flag);
1168 }
1169 ao2_unlock(control);
1170}
1171
1172static void bridge_after_cb(struct ast_channel *chan, void *data)
1173{
1174 struct stasis_app_control *control = data;
1175
1177}
1178
1180 void *data)
1181{
1182 struct stasis_app_control *control = data;
1183
1184 internal_bridge_after_cb(control->channel, data, reason);
1185
1186 ast_debug(3, " reason: %s\n",
1188}
1189
1190/*!
1191 * \brief Dial timeout datastore
1192 *
1193 * A datastore is used because a channel may change
1194 * bridges during the course of a dial attempt. This
1195 * may be because the channel changes from the dial bridge
1196 * to a standard bridge, or it may move between standard
1197 * bridges. In order to keep the dial timeout, we need
1198 * to keep the timeout information local to the channel.
1199 * That is what this datastore is for
1200 */
1202 .type = "ARI dial timeout",
1203};
1204
1205static int hangup_channel(struct stasis_app_control *control,
1206 struct ast_channel *chan, void *data)
1207{
1209 return 0;
1210}
1211
1212/*!
1213 * \brief Dial timeout
1214 *
1215 * This is a bridge interval hook callback. The interval hook triggering
1216 * means that the dial timeout has been reached. If the channel has not
1217 * been answered by the time this callback is called, then the channel
1218 * is hung up
1219 *
1220 * \param bridge_channel Bridge channel on which interval hook has been called
1221 * \param ignore Ignored
1222 * \return -1 (i.e. remove the interval hook)
1223 */
1224static int bridge_timeout(struct ast_bridge_channel *bridge_channel, void *ignore)
1225{
1226 struct ast_datastore *datastore;
1227 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
1228
1229 control = stasis_app_control_find_by_channel(bridge_channel->chan);
1230
1231 ast_channel_lock(bridge_channel->chan);
1232 if (ast_channel_state(bridge_channel->chan) != AST_STATE_UP) {
1233 /* Don't bother removing the datastore because it will happen when the channel is hung up */
1234 ast_channel_unlock(bridge_channel->chan);
1236 return -1;
1237 }
1238
1239 datastore = ast_channel_datastore_find(bridge_channel->chan, &timeout_datastore, NULL);
1240 if (!datastore) {
1241 ast_channel_unlock(bridge_channel->chan);
1242 return -1;
1243 }
1244 ast_channel_datastore_remove(bridge_channel->chan, datastore);
1245 ast_channel_unlock(bridge_channel->chan);
1246 ast_datastore_free(datastore);
1247
1248 return -1;
1249}
1250
1251/*!
1252 * \brief Set a dial timeout interval hook on the channel.
1253 *
1254 * The absolute time that the timeout should occur is stored on
1255 * a datastore on the channel. This time is converted into a relative
1256 * number of milliseconds in the future. Then an interval hook is set
1257 * to trigger in that number of milliseconds.
1258 *
1259 * \pre chan is locked
1260 *
1261 * \param chan The channel on which to set the interval hook
1262 */
1263static void set_interval_hook(struct ast_channel *chan)
1264{
1265 struct ast_datastore *datastore;
1266 struct timeval *hangup_time;
1267 int64_t ms;
1268 struct ast_bridge_channel *bridge_channel;
1269
1271 if (!datastore) {
1272 return;
1273 }
1274
1275 hangup_time = datastore->data;
1276
1277 ms = ast_tvdiff_ms(*hangup_time, ast_tvnow());
1278 bridge_channel = ast_channel_get_bridge_channel(chan);
1279 if (!bridge_channel) {
1280 return;
1281 }
1282
1283 if (ast_bridge_interval_hook(bridge_channel->features, 0, ms > 0 ? ms : 1,
1284 bridge_timeout, NULL, NULL, 0)) {
1285 ao2_ref(bridge_channel, -1);
1286 return;
1287 }
1288
1289 ast_queue_frame(bridge_channel->chan, &ast_null_frame);
1290 ao2_ref(bridge_channel, -1);
1291}
1292
1294{
1295 int res;
1296 struct ast_bridge_features *features;
1298
1299 if (!control || !bridge) {
1300 return -1;
1301 }
1302
1303 ast_debug(3, "%s: Adding to bridge %s\n",
1305 bridge->uniqueid);
1306
1307 ast_assert(chan != NULL);
1308
1309 /* Depart whatever Stasis bridge we're currently in. */
1310 if (stasis_app_get_bridge(control)) {
1311 /* Note that it looks like there's a race condition here, since
1312 * we don't have control locked. But this happens from the
1313 * control callback thread, so there won't be any other
1314 * concurrent attempts to bridge.
1315 */
1316 ast_bridge_depart(chan);
1317 }
1318
1319
1321 bridge_after_cb_failed, control);
1322 if (res != 0) {
1323 ast_log(LOG_ERROR, "Error setting after-bridge callback\n");
1324 return -1;
1325 }
1326
1327 ao2_lock(control);
1328
1329 /* Ensure the controlling application is subscribed early enough
1330 * to receive the ChannelEnteredBridge message. This works in concert
1331 * with the subscription handled in the Stasis application execution
1332 * loop */
1333 app_subscribe_bridge(control->app, bridge);
1334
1335 /* Save off the channel's PBX */
1336 ast_assert(control->pbx == NULL);
1337 if (!control->pbx) {
1338 control->pbx = ast_channel_pbx(chan);
1340 }
1341
1342 /* Pull bridge features from the control */
1343 features = control->bridge_features;
1344 control->bridge_features = NULL;
1345 if (features && features->inhibit_colp) {
1347 }
1348
1350 /* We need to set control->bridge here since bridge_after_cb may be run
1351 * before ast_bridge_impart returns. bridge_after_cb gets a reason
1352 * code so it can tell if the bridge is actually valid or not.
1353 */
1354 control->bridge = bridge;
1355
1356 /* We can't be holding the control lock while impart is running
1357 * or we could create a deadlock with bridge_after_cb which also
1358 * tries to lock control.
1359 */
1360 ao2_unlock(control);
1361 res = ast_bridge_impart(bridge,
1362 chan,
1363 swap,
1364 features, /* features */
1365 flags);
1366 if (res != 0) {
1367 /* ast_bridge_impart failed before it could spawn the depart
1368 * thread. The callbacks aren't called in this case.
1369 * The impart could still fail even if ast_bridge_impart returned
1370 * ok but that's handled by bridge_after_cb.
1371 */
1372 ast_log(LOG_ERROR, "Error adding channel to bridge\n");
1373 ao2_lock(control);
1374 ast_channel_pbx_set(chan, control->pbx);
1375 control->pbx = NULL;
1376 control->bridge = NULL;
1377 ao2_unlock(control);
1378 } else {
1379 ast_channel_lock(chan);
1380 set_interval_hook(chan);
1381 ast_channel_unlock(chan);
1382 }
1383
1384 return res;
1385}
1386
1387int control_add_channel_to_bridge(struct stasis_app_control *control, struct ast_channel *chan, void *data)
1388{
1389 return control_swap_channel_in_bridge(control, data, chan, NULL);
1390}
1391
1393 struct stasis_app_control *control, struct ast_bridge *bridge)
1394{
1395 ast_debug(3, "%s: Sending channel add_to_bridge command\n",
1397
1399 control, control_add_channel_to_bridge, bridge, NULL,
1401}
1402
1404 struct stasis_app_control *control,
1405 struct ast_channel *chan, void *data)
1406{
1407 struct ast_bridge *bridge = data;
1408
1409 if (!control) {
1410 return -1;
1411 }
1412
1413 /* We should only depart from our own bridge */
1414 ast_debug(3, "%s: Departing bridge %s\n",
1416 bridge->uniqueid);
1417
1418 if (bridge != stasis_app_get_bridge(control)) {
1419 ast_log(LOG_WARNING, "%s: Not in bridge %s; not removing\n",
1421 bridge->uniqueid);
1422 return -1;
1423 }
1424
1425 depart_channel(control, chan);
1426 return 0;
1427}
1428
1430 struct stasis_app_control *control, struct ast_bridge *bridge)
1431{
1432 ast_debug(3, "%s: Sending channel remove_from_bridge command\n",
1437}
1438
1440 const struct stasis_app_control *control)
1441{
1442 return ast_channel_uniqueid(control->channel);
1443}
1444
1446 struct stasis_app_control *control, struct stasis_message *message)
1447{
1448 if (!control || !control->channel || !message) {
1449 return;
1450 }
1452}
1453
1456{
1457 return ast_queue_control(control->channel, frame_type);
1458}
1459
1461 struct stasis_app_control *control)
1462{
1463 struct ast_bridge_features *features;
1464
1465 features = ast_bridge_features_new();
1466 if (!features) {
1467 return 1;
1468 }
1469 control->bridge_features = features;
1470 return 0;
1471}
1472
1474 struct stasis_app_control *control, int absorb)
1475{
1476 control->bridge_features->dtmf_passthrough = !absorb;
1477}
1478
1480 struct stasis_app_control *control, int mute)
1481{
1482 control->bridge_features->mute = mute;
1483}
1484
1486 struct stasis_app_control *control, int inhibit_colp)
1487{
1489}
1490
1492{
1493 struct ao2_iterator iter;
1494 struct stasis_app_command *command;
1495
1497 while ((command = ao2_iterator_next(&iter))) {
1498 command_complete(command, -1);
1499 ao2_ref(command, -1);
1500 }
1501 ao2_iterator_destroy(&iter);
1502}
1503
1505 struct ast_channel *chan)
1506{
1507 int count = 0;
1508 struct ao2_iterator iter;
1509 struct stasis_app_command *command;
1510
1511 ast_assert(control->channel == chan);
1512
1514 while ((command = ao2_iterator_next(&iter))) {
1515 command_invoke(command, control, chan);
1516 ao2_ref(command, -1);
1517 ++count;
1518 }
1519 ao2_iterator_destroy(&iter);
1520
1521 return count;
1522}
1523
1525{
1526 if (!control) {
1527 return;
1528 }
1529
1530 ast_assert(control->command_queue != NULL);
1531
1532 ao2_lock(control->command_queue);
1533 while (ao2_container_count(control->command_queue) == 0) {
1534 int res = ast_cond_wait(&control->wait_cond,
1536 if (res < 0) {
1537 ast_log(LOG_ERROR, "Error waiting on command queue\n");
1538 break;
1539 }
1540 }
1541 ao2_unlock(control->command_queue);
1542}
1543
1545 struct ast_channel *chan)
1546{
1547 struct ao2_container *command_queue;
1548 int count = 0;
1549 struct ao2_iterator iter;
1550 struct stasis_app_command *command;
1551
1552 ast_channel_lock(chan);
1553 command_queue = command_prestart_get_container(chan);
1554 ast_channel_unlock(chan);
1555 if (!command_queue) {
1556 return 0;
1557 }
1558
1559 iter = ao2_iterator_init(command_queue, AO2_ITERATOR_UNLINK);
1560
1561 while ((command = ao2_iterator_next(&iter))) {
1562 command_invoke(command, control, chan);
1563 ao2_cleanup(command);
1564 ++count;
1565 }
1566
1567 ao2_iterator_destroy(&iter);
1568 ao2_cleanup(command_queue);
1569 return count;
1570}
1571
1573{
1574 return control->app;
1575}
1576
1578 unsigned int timeout;
1579 char dialstring[0];
1580};
1581
1583 unsigned int timeout)
1584{
1585 struct control_dial_args *args;
1586
1587 args = ast_malloc(sizeof(*args) + strlen(dialstring) + 1);
1588 if (!args) {
1589 return NULL;
1590 }
1591
1592 args->timeout = timeout;
1593 /* Safe */
1594 strcpy(args->dialstring, dialstring);
1595
1596 return args;
1597}
1598
1599static void control_dial_args_destroy(void *data)
1600{
1601 struct control_dial_args *args = data;
1602
1603 ast_free(args);
1604}
1605
1606/*!
1607 * \brief Set dial timeout on a channel to be dialed.
1608 *
1609 * \param chan The channel on which to set the dial timeout
1610 * \param timeout The timeout in seconds
1611 */
1612static int set_timeout(struct ast_channel *chan, unsigned int timeout)
1613{
1614 struct ast_datastore *datastore;
1615 struct timeval *hangup_time;
1616
1617 hangup_time = ast_malloc(sizeof(struct timeval));
1618
1620 if (!datastore) {
1621 return -1;
1622 }
1623 *hangup_time = ast_tvadd(ast_tvnow(), ast_samp2tv(timeout, 1));
1624 datastore->data = hangup_time;
1625
1626 ast_channel_lock(chan);
1627 ast_channel_datastore_add(chan, datastore);
1628
1629 if (ast_channel_is_bridged(chan)) {
1630 set_interval_hook(chan);
1631 }
1632 ast_channel_unlock(chan);
1633
1634 return 0;
1635}
1636
1637static int app_control_dial(struct stasis_app_control *control,
1638 struct ast_channel *chan, void *data)
1639{
1640 struct control_dial_args *args = data;
1641 int bridged;
1642
1643 ast_channel_lock(chan);
1644 bridged = ast_channel_is_bridged(chan);
1645 ast_channel_unlock(chan);
1646
1647 if (!bridged && add_to_dial_bridge(control, chan)) {
1648 return -1;
1649 }
1650
1651 if (args->timeout && set_timeout(chan, args->timeout)) {
1652 return -1;
1653 }
1654
1655 if (ast_call(chan, args->dialstring, 0)) {
1656 /* If call fails normally this channel would then just be normally hung up and destroyed.
1657 * In this case though the channel is being handled by the ARI control thread and dial
1658 * bridge which needs to be notified that the channel should be hung up. To do this we
1659 * queue a soft hangup which will cause each to wake up, see that the channel has been
1660 * hung up, and then destroy it.
1661 */
1662 int hangup_flag;
1664 ast_channel_lock(chan);
1665 ast_softhangup_nolock(chan, hangup_flag);
1666 ast_channel_unlock(chan);
1667 return -1;
1668 }
1669
1670 ast_channel_publish_dial(NULL, chan, args->dialstring, NULL);
1671
1672 return 0;
1673}
1674
1676 const char *dialstring, unsigned int timeout)
1677{
1678 struct control_dial_args *args;
1679
1681 if (!args) {
1682 return -1;
1683 }
1684
1687}
1688
1690{
1692 shutting_down = 1;
1693 if (dial_bridge) {
1695 dial_bridge = NULL;
1696 }
1698}
1699
1700void control_set_app(struct stasis_app_control *control, struct stasis_app *app)
1701{
1702 ao2_cleanup(control->app);
1703 control->app = ao2_bump(app);
1704}
1705
1707{
1708 return control->next_app;
1709}
1710
1712{
1713 ast_free(control->next_app);
1714 control->next_app = NULL;
1715
1717}
1718
1720{
1721 return AST_VECTOR_STEAL_ELEMENTS(&control->next_app_args);
1722}
1723
1725{
1726 return AST_VECTOR_SIZE(&control->next_app_args);
1727}
static const char app[]
Definition: app_adsiprog.c:56
#define var
Definition: ast_expr2f.c:605
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
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1739
#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
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
@ AO2_ITERATOR_UNLINK
Definition: astobj2.h:1863
#define ao2_link_flags(container, obj, flags)
Add an object to a container.
Definition: astobj2.h:1554
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
void __ao2_cleanup(void *obj)
Definition: astobj2.c:677
void * ao2_object_get_lockaddr(void *obj)
Return the mutex lock address of an object.
Definition: astobj2.c:476
#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.
@ OBJ_NOLOCK
Assume that the ao2_container is already locked.
Definition: astobj2.h:1063
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition: astobj2.h:1327
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
Bridging API.
int ast_bridge_depart(struct ast_channel *chan)
Depart a channel from a bridge.
Definition: bridge.c:1906
int ast_bridge_destroy(struct ast_bridge *bridge, int cause)
Destroy a bridge.
Definition: bridge.c:944
int ast_bridge_impart(struct ast_bridge *bridge, struct ast_channel *chan, struct ast_channel *swap, struct ast_bridge_features *features, enum ast_bridge_impart_flags flags) attribute_warn_unused_result
Impart a channel to a bridge (non-blocking)
Definition: bridge.c:1878
@ AST_BRIDGE_IMPART_CHAN_DEPARTABLE
Definition: bridge.h:588
@ AST_BRIDGE_IMPART_INHIBIT_JOIN_COLP
Definition: bridge.h:592
After Bridge Execution API.
ast_bridge_after_cb_reason
Definition: bridge_after.h:37
@ AST_BRIDGE_AFTER_CB_REASON_IMPART_FAILED
Definition: bridge_after.h:49
@ AST_BRIDGE_AFTER_CB_REASON_DEPART
Definition: bridge_after.h:45
int ast_bridge_setup_after_goto(struct ast_channel *chan)
Setup any after bridge goto location to begin execution.
Definition: bridge_after.c:435
int ast_bridge_set_after_callback(struct ast_channel *chan, ast_bridge_after_cb callback, ast_bridge_after_cb_failed failed, void *data)
Setup an after bridge callback for when the channel leaves the bridging system.
Definition: bridge_after.c:251
const char * ast_bridge_after_cb_reason_string(enum ast_bridge_after_cb_reason reason)
Get a string representation of an after bridge callback reason.
Definition: bridge_after.c:288
Basic bridge subclass API.
Channel Bridging API.
int ast_bridge_interval_hook(struct ast_bridge_features *features, enum ast_bridge_hook_timer_option flags, unsigned int interval, ast_bridge_hook_callback callback, void *hook_pvt, ast_bridge_hook_pvt_destructor destructor, enum ast_bridge_hook_remove_flags remove_flags)
Attach an interval hook to a bridge features structure.
Definition: bridge.c:3319
struct ast_bridge_features * ast_bridge_features_new(void)
Allocate a new bridge features struct.
Definition: bridge.c:3683
void ast_bridge_features_destroy(struct ast_bridge_features *features)
Destroy an allocated bridge features struct.
Definition: bridge.c:3674
int ast_channel_add_bridge_role(struct ast_channel *chan, const char *role_name)
Adds a bridge role to a channel.
Definition: bridge_roles.c:313
void ast_channel_clear_bridge_roles(struct ast_channel *chan)
Removes all bridge roles currently on a channel.
Definition: bridge_roles.c:356
static int priority
const char * ast_channel_name(const struct ast_channel *chan)
int ast_call(struct ast_channel *chan, const char *addr, int timeout)
Make a call.
Definition: channel.c:6480
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
Definition: channel.c:2404
int ast_channel_datastore_remove(struct ast_channel *chan, struct ast_datastore *datastore)
Remove a datastore from a channel.
Definition: channel.c:2413
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
#define ast_channel_lock(chan)
Definition: channel.h:2968
struct ast_silence_generator * ast_channel_start_silence_generator(struct ast_channel *chan)
Starts a silence generator on the given channel.
Definition: channel.c:8186
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
Definition: channel.c:1250
void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state)
Stops a previously-started silence generator on the given channel.
Definition: channel.c:8232
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2993
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel's frame queue.
Definition: channel.c:1158
const char * ast_channel_uniqueid(const struct ast_channel *chan)
int ast_channel_suppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype)
Suppress passing of a frame type on a channel.
Definition: channel.c:10799
struct ast_bridge_channel * ast_channel_internal_bridge_channel(const struct ast_channel *chan)
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:445
int ast_channel_hangupcause(const struct ast_channel *chan)
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
Definition: channel.c:10567
int ast_softhangup(struct ast_channel *chan, int cause)
Softly hangup up a channel.
Definition: channel.c:2490
@ AST_SOFTHANGUP_ASYNCGOTO
Definition: channel.h:1146
@ AST_SOFTHANGUP_EXPLICIT
Definition: channel.h:1168
@ AST_SOFTHANGUP_DEV
Definition: channel.h:1141
#define AST_MAX_CONTEXT
Definition: channel.h:135
struct ast_bridge_channel * ast_channel_get_bridge_channel(struct ast_channel *chan)
Get a reference to the channel's bridge pointer.
Definition: channel.c:10604
int ast_transfer(struct ast_channel *chan, char *dest)
Transfer a channel (if supported).
Definition: channel.c:6504
int ast_channel_unsuppress(struct ast_channel *chan, unsigned int direction, enum ast_frame_type frametype)
Stop suppressing of a frame type on a channel.
Definition: channel.c:10861
int ast_softhangup_nolock(struct ast_channel *chan, int cause)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2477
struct ast_pbx * ast_channel_pbx(const struct ast_channel *chan)
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Definition: channel.h:3015
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4296
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1593
#define ast_channel_unlock(chan)
Definition: channel.h:2969
#define AST_MAX_EXTENSION
Definition: channel.h:134
void ast_channel_pbx_set(struct ast_channel *chan, struct ast_pbx *value)
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:2418
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_UP
Definition: channelstate.h:42
frame_type
Definition: codec_builtin.c:44
struct ao2_container * command_prestart_get_container(struct ast_channel *chan)
Get the Stasis() prestart commands for a channel.
Definition: command.c:160
struct stasis_app_command * command_create(stasis_app_command_cb callback, void *data, command_data_destructor_fn data_destructor)
Definition: command.c:55
void command_invoke(struct stasis_app_command *command, struct stasis_app_control *control, struct ast_channel *chan)
Definition: command.c:101
void command_complete(struct stasis_app_command *command, int retval)
Definition: command.c:77
int command_join(struct stasis_app_command *command)
Definition: command.c:86
Internal API for the Stasis application commands.
void stasis_app_control_mute_in_bridge(struct stasis_app_control *control, int mute)
Set whether audio from the channel is muted instead of passing through to the bridge.
Definition: control.c:1479
static void app_control_unregister_rule(struct stasis_app_control *control, struct app_control_rules *list, struct stasis_app_control_rule *obj)
Definition: control.c:173
void stasis_app_control_register_remove_rule(struct stasis_app_control *control, struct stasis_app_control_rule *rule)
Registers a remove channel from bridge rule.
Definition: control.c:233
static void set_interval_hook(struct ast_channel *chan)
Set a dial timeout interval hook on the channel.
Definition: control.c:1263
static int app_control_ring(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:593
struct stasis_app_control * control_create(struct ast_channel *channel, struct stasis_app *app)
Create a control object.
Definition: control.c:125
static void dtmf_no_bridge(struct ast_channel *chan, struct stasis_app_control_dtmf_data *dtmf_data)
Definition: control.c:543
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:789
const char * stasis_app_control_get_channel_id(const struct stasis_app_control *control)
Returns the uniqueid of the channel associated with this control.
Definition: control.c:1439
static int app_control_continue(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:377
static int set_timeout(struct ast_channel *chan, unsigned int timeout)
Set dial timeout on a channel to be dialed.
Definition: control.c:1612
static int add_to_dial_bridge(struct stasis_app_control *control, struct ast_channel *chan)
Add a channel to the singleton dial bridge.
Definition: control.c:1050
int stasis_app_control_queue_control(struct stasis_app_control *control, enum ast_control_frame_type frame_type)
Queue a control frame without payload.
Definition: control.c:1454
static int app_control_set_channel_var(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:710
int control_prestart_dispatch_all(struct stasis_app_control *control, struct ast_channel *chan)
Dispatch all queued prestart commands.
Definition: control.c:1544
static int app_control_clear_roles(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:339
void stasis_app_control_unregister_remove_rule(struct stasis_app_control *control, struct stasis_app_control_rule *rule)
Unregisters a remove channel from bridge rule.
Definition: control.c:240
int control_swap_channel_in_bridge(struct stasis_app_control *control, struct ast_bridge *bridge, struct ast_channel *chan, struct ast_channel *swap)
Command for swapping a channel in a bridge.
Definition: control.c:1293
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:668
void stasis_app_control_unhold(struct stasis_app_control *control)
Remove the channel associated with the control from hold.
Definition: control.c:770
static struct stasis_app_command * exec_command_on_condition(struct stasis_app_control *control, stasis_app_command_cb command_fn, void *data, command_data_destructor_fn data_destructor, app_command_can_exec_cb can_exec_fn)
Definition: control.c:269
int stasis_app_control_add_channel_to_bridge(struct stasis_app_control *control, struct ast_bridge *bridge)
Add a channel to the bridge.
Definition: control.c:1392
void control_wait(struct stasis_app_control *control)
Blocks until control's command queue has a command available.
Definition: control.c:1524
char ** control_next_app_args(struct stasis_app_control *control)
Returns the list of arguments to pass to the application we are moving to.
Definition: control.c:1719
static void bridge_after_cb(struct ast_channel *chan, void *data)
Definition: control.c:1172
int stasis_app_send_command(struct stasis_app_control *control, stasis_app_command_cb command_fn, void *data, command_data_destructor_fn data_destructor)
Invokes a command on a control's channel.
Definition: control.c:907
void stasis_app_control_silence_start(struct stasis_app_control *control)
Start playing silence to a channel.
Definition: control.c:841
void stasis_app_control_silence_stop(struct stasis_app_control *control)
Stop playing silence to a channel.
Definition: control.c:864
int control_add_channel_to_bridge(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Command callback for adding a channel to a bridge.
Definition: control.c:1387
static void dial_bridge_after_cb(struct ast_channel *chan, void *data)
after bridge callback for the dial bridge
Definition: control.c:1018
void stasis_app_control_clear_roles(struct stasis_app_control *control)
Clear bridge roles currently applied to a channel controlled by a stasis app control.
Definition: control.c:347
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:398
static int app_control_ring_stop(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:608
static int app_control_hold(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:749
static enum stasis_app_control_channel_result app_control_check_rules(const struct stasis_app_control *control, struct app_control_rules *list)
Definition: control.c:205
static int app_control_unhold(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:762
int control_is_done(struct stasis_app_control *control)
Returns true if control_continue() has been called on this control.
Definition: control.c:357
static void free_chanvar(void *data)
Definition: control.c:701
void stasis_app_control_publish(struct stasis_app_control *control, struct stasis_message *message)
Publish a message to the control's channel's topic.
Definition: control.c:1445
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:509
static int app_control_remove_channel_from_bridge(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:1403
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:807
static struct control_dial_args * control_dial_args_alloc(const char *dialstring, unsigned int timeout)
Definition: control.c:1582
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:460
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:640
static struct ast_bridge * dial_bridge
Singleton dial bridge.
Definition: control.c:967
void stasis_app_control_absorb_dtmf_in_bridge(struct stasis_app_control *control, int absorb)
Set whether DTMF from the channel is absorbed instead of passing through to the bridge.
Definition: control.c:1473
struct ast_datastore_info timeout_datastore
Dial timeout datastore.
Definition: control.c:1201
static int app_control_moh_stop(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:800
static void bridge_after_cb_failed(enum ast_bridge_after_cb_reason reason, void *data)
Definition: control.c:1179
int(* app_command_can_exec_cb)(struct stasis_app_control *control)
Definition: control.c:267
static int noop_cb(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:259
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:574
static int shutting_down
Indicates if the Stasis app internals are being shut down.
Definition: control.c:51
void control_flush_queue(struct stasis_app_control *control)
Flush the control command queue.
Definition: control.c:1491
int stasis_app_control_add_role(struct stasis_app_control *control, const char *role)
Apply a bridge role to a channel controlled by a stasis app control.
Definition: control.c:325
static int app_control_add_role(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:317
void stasis_app_control_inhibit_colp_in_bridge(struct stasis_app_control *control, int inhibit_colp)
Set whether COLP frames should be generated when joining the bridge.
Definition: control.c:1485
static int app_send_command_on_condition(struct stasis_app_control *control, stasis_app_command_cb command_fn, void *data, command_data_destructor_fn data_destructor, app_command_can_exec_cb can_exec_fn)
Definition: control.c:875
int stasis_app_control_remove_channel_from_bridge(struct stasis_app_control *control, struct ast_bridge *bridge)
Remove a channel from the bridge.
Definition: control.c:1429
struct ast_bridge * stasis_app_get_bridge(struct stasis_app_control *control)
Gets the bridge currently associated with a control object.
Definition: control.c:940
int stasis_app_send_command_async(struct stasis_app_control *control, stasis_app_command_cb command_fn, void *data, command_data_destructor_fn data_destructor)
Asynchronous version of stasis_app_send_command().
Definition: control.c:913
int stasis_app_control_bridge_features_init(struct stasis_app_control *control)
Initialize bridge features into a channel control.
Definition: control.c:1460
static int app_control_move(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:423
static int hangup_channel(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:1205
static int depart_channel(struct stasis_app_control *control, struct ast_channel *chan)
Depart a channel from a bridge, and potentially add it back to the dial bridge.
Definition: control.c:1078
void stasis_app_control_hold(struct stasis_app_control *control)
Place the channel associated with the control on hold.
Definition: control.c:757
int control_dispatch_all(struct stasis_app_control *control, struct ast_channel *chan)
Dispatch all commands enqueued to this control.
Definition: control.c:1504
int control_next_app_args_size(struct stasis_app_control *control)
Returns the number of arguments to be passed to the application we are moving to.
Definition: control.c:1724
void stasis_app_control_unregister_add_rule(struct stasis_app_control *control, struct stasis_app_control_rule *rule)
UnRegister an add channel to bridge rule.
Definition: control.c:226
void control_set_app(struct stasis_app_control *control, struct stasis_app *app)
Set the application the control object belongs to.
Definition: control.c:1700
static void dtmf_in_bridge(struct ast_channel *chan, struct stasis_app_control_dtmf_data *dtmf_data)
Definition: control.c:530
static int app_control_unmute(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:656
static void app_control_register_rule(struct stasis_app_control *control, struct app_control_rules *list, struct stasis_app_control_rule *obj)
Definition: control.c:164
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:616
static int app_control_redirect(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:490
int stasis_app_control_dial(struct stasis_app_control *control, const char *dialstring, unsigned int timeout)
Dial a channel.
Definition: control.c:1675
static int bridge_timeout(struct ast_bridge_channel *bridge_channel, void *ignore)
Dial timeout.
Definition: control.c:1224
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:869
int control_command_count(struct stasis_app_control *control)
Returns the count of items in a control's command queue.
Definition: control.c:352
static int app_control_can_remove_channel_from_bridge(struct stasis_app_control *control)
Definition: control.c:253
static void control_dial_args_destroy(void *data)
Definition: control.c:1599
void stasis_app_control_register_add_rule(struct stasis_app_control *control, struct stasis_app_control_rule *rule)
Registers an add channel to bridge rule.
Definition: control.c:219
void control_silence_stop_now(struct stasis_app_control *control)
Stop playing silence to a channel right now.
Definition: control.c:846
static int app_control_silence_start(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:812
static int app_control_can_add_channel_to_bridge(struct stasis_app_control *control)
Definition: control.c:247
static struct stasis_app_command * exec_command(struct stasis_app_control *control, stasis_app_command_cb command_fn, void *data, command_data_destructor_fn data_destructor)
Definition: control.c:310
static int app_control_dial(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:1637
static int app_control_moh_start(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:775
static ast_mutex_t dial_bridge_lock
Definition: control.c:968
static int bridge_channel_depart(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:1094
static struct ast_bridge * get_dial_bridge(void)
Retrieve a reference to the dial bridge.
Definition: control.c:983
char * control_next_app(struct stasis_app_control *control)
Returns the name of the application we are moving to.
Definition: control.c:1706
static void internal_bridge_after_cb(struct ast_channel *chan, void *data, enum ast_bridge_after_cb_reason reason)
Definition: control.c:1117
static int app_control_dtmf(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:556
struct stasis_app * control_app(struct stasis_app_control *control)
Returns the pointer (non-reffed) to the app associated with this control.
Definition: control.c:1572
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:720
static int app_control_silence_stop(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:857
static int app_control_mute(struct stasis_app_control *control, struct ast_channel *chan, void *data)
Definition: control.c:628
static void dial_bridge_after_cb_failed(enum ast_bridge_after_cb_reason reason, void *data)
Definition: control.c:1034
int stasis_app_control_ring(struct stasis_app_control *control)
Indicate ringing to the channel associated with this control.
Definition: control.c:601
void control_move_cleanup(struct stasis_app_control *control)
Free any memory that was allocated for switching applications via /channels/{channelId}/move.
Definition: control.c:1711
void stasis_app_control_shutdown(void)
Let Stasis app internals shut down.
Definition: control.c:1689
static void control_dtor(void *obj)
Definition: control.c:107
void control_mark_done(struct stasis_app_control *control)
Definition: control.c:363
Internal API for the Stasis application controller.
#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.
char * end
Definition: eagi_proxy.c:73
direction
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_publish_dial(struct ast_channel *caller, struct ast_channel *peer, const char *dialstring, const char *dialstatus)
Publish in the ast_channel_topic or ast_channel_topic_all topics a stasis message for the channels in...
static ENTRY retval
Definition: hsearch.c:50
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
void ast_dtmf_stream_external(struct ast_channel *chan, const char *digits, int between, unsigned int duration)
Send a string of DTMF digits to a channel from an external thread.
Definition: main/app.c:1142
int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration)
Send a string of DTMF digits to a channel.
Definition: main/app.c:1127
Asterisk internal frame definitions.
ast_frame_type
Frame types.
ast_control_frame_type
Internal control frame subtype field values.
@ AST_CONTROL_PROGRESS
@ AST_CONTROL_UNHOLD
@ AST_CONTROL_RINGING
@ AST_CONTROL_HOLD
struct ast_frame ast_null_frame
Definition: main/frame.c:79
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define LOG_NOTICE
#define LOG_WARNING
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:570
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
#define AST_LIST_HEAD_DESTROY(head)
Destroys a list head structure.
Definition: linkedlists.h:653
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:617
#define AST_LIST_HEAD_INIT(head)
Initializes a list head structure.
Definition: linkedlists.h:626
#define AST_LIST_HEAD(name, type)
Defines a structure to be used to hold a list of specified type.
Definition: linkedlists.h:173
#define ast_cond_destroy(cond)
Definition: lock.h:202
#define ast_cond_wait(cond, mutex)
Definition: lock.h:205
#define ast_cond_init(cond, attr)
Definition: lock.h:201
#define ast_mutex_unlock(a)
Definition: lock.h:190
pthread_cond_t ast_cond_t
Definition: lock.h:178
#define ast_mutex_lock(a)
Definition: lock.h:189
#define AST_MUTEX_DEFINE_STATIC(mutex)
Definition: lock.h:520
#define ast_cond_signal(cond)
Definition: lock.h:203
int errno
Music on hold handling.
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition: channel.c:7788
void ast_moh_stop(struct ast_channel *chan)
Turn off music on hold on a given channel.
Definition: channel.c:7798
def ignore(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:48
Core PBX routines and definitions.
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
Definition: pbx.c:6945
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
int app_subscribe_bridge(struct stasis_app *app, struct ast_bridge *bridge)
Add a bridge subscription to an existing channel subscription.
int app_unsubscribe_bridge(struct stasis_app *app, struct ast_bridge *bridge)
Cancel the bridge subscription for an application.
Internal API for the Stasis application controller.
#define NULL
Definition: resample.c:96
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition: stasis.c:1512
Stasis Application API. See Stasis Application API for detailed documentation.
struct ast_bridge * stasis_app_bridge_create_invisible(const char *type, const char *name, const char *id)
Create an invisible bridge of the specified type.
Definition: res_stasis.c:859
stasis_app_control_channel_result
Result codes used when adding/removing channels to/from bridges.
Definition: stasis_app.h:776
int stasis_app_channel_is_stasis_end_published(struct ast_channel *chan)
Has this channel had a StasisEnd published on it?
Definition: res_stasis.c:1302
struct stasis_app_control * stasis_app_control_find_by_channel(const struct ast_channel *chan)
Returns the handler for the given channel.
Definition: res_stasis.c:338
void(* command_data_destructor_fn)(void *data)
Typedef for data destructor for stasis app commands.
int(* stasis_app_command_cb)(struct stasis_app_control *control, struct ast_channel *chan, void *data)
#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
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
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
Structure that contains information regarding a channel in a bridge.
struct ast_channel * swap
struct ast_bridge * bridge
Bridge this channel is participating in.
struct ast_bridge_features * features
struct ast_channel * chan
Structure that contains features information.
unsigned int dtmf_passthrough
unsigned int inhibit_colp
Structure that contains information about a bridge.
Definition: bridge.h:349
const ast_string_field uniqueid
Definition: bridge.h:401
Structure representing a snapshot of channel state.
Main Channel structure associated with a channel.
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
Definition: pbx.h:214
structure for queuing ARI channel variable setting
Definition: control.c:694
char * value
Definition: control.c:698
char * name
Definition: control.c:696
char dialstring[0]
Definition: control.c:1579
unsigned int timeout
Definition: control.c:1578
structure to hold extensions
command_data_destructor_fn data_destructor
Definition: command.c:38
char extension[AST_MAX_EXTENSION]
Definition: control.c:373
char context[AST_MAX_CONTEXT]
Definition: control.c:372
enum ast_frame_type frametype
Definition: control.c:624
Rule to check to see if an operation is allowed.
Definition: stasis_app.h:345
struct stasis_app_control_rule * next
Definition: stasis_app.h:355
struct stasis_app * app
Definition: control.c:92
struct ast_bridge_features * bridge_features
Definition: control.c:70
struct ast_channel * channel
Definition: control.c:62
struct ast_bridge * bridge
Definition: control.c:66
struct ao2_container * command_queue
Definition: control.c:56
unsigned int is_done
Definition: control.c:104
struct stasis_app_control::@489 next_app_args
struct app_control_rules remove_rules
Definition: control.c:82
struct ast_silence_generator * silgen
Definition: control.c:86
char * next_app
Definition: control.c:96
struct app_control_rules add_rules
Definition: control.c:78
ast_cond_t wait_cond
Definition: control.c:54
struct ast_pbx * pbx
Definition: control.c:74
int value
Definition: syslog.c:37
const char * args
struct timeval ast_samp2tv(unsigned int _nsamp, unsigned int _rate)
Returns a timeval corresponding to the duration of n samples at rate r. Useful to convert samples to ...
Definition: time.h:282
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2282
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159
#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:941
#define ast_assert(a)
Definition: utils.h:739
#define AST_VECTOR_RESET(vec, cleanup)
Reset vector.
Definition: vector.h:625
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_STEAL_ELEMENTS(vec)
Steal the elements from a vector and reinitialize.
Definition: vector.h:140
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256
#define AST_VECTOR(name, type)
Define a vector structure.
Definition: vector.h:44