Asterisk - The Open Source Telephony Project  GIT-master-16dfe8f
bridge_channel.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2007 - 2009, Digium, Inc.
5  *
6  * Joshua Colp <jcolp@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 Bridging Channel API
22  *
23  * \author Joshua Colp <jcolp@digium.com>
24  * \author Richard Mudgett <rmudgett@digium.com>
25  * \author Matt Jordan <mjordan@digium.com>
26  *
27  */
28 
29 /*** MODULEINFO
30  <support_level>core</support_level>
31  ***/
32 
33 #include "asterisk.h"
34 
35 #include <signal.h>
36 
37 #include "asterisk/heap.h"
38 #include "asterisk/alertpipe.h"
39 #include "asterisk/astobj2.h"
40 #include "asterisk/stringfields.h"
41 #include "asterisk/app.h"
42 #include "asterisk/pbx.h"
43 #include "asterisk/channel.h"
44 #include "asterisk/timing.h"
45 #include "asterisk/bridge.h"
47 #include "asterisk/bridge_after.h"
52 #include "asterisk/musiconhold.h"
54 #include "asterisk/parking.h"
55 #include "asterisk/causes.h"
56 #include "asterisk/test.h"
57 #include "asterisk/sem.h"
58 #include "asterisk/stream.h"
59 #include "asterisk/message.h"
60 
61 /*!
62  * \brief Used to queue an action frame onto a bridge channel and write an action frame into a bridge.
63  * \since 12.0.0
64  *
65  * \param bridge_channel Which channel work with.
66  * \param action Type of bridge action frame.
67  * \param data Frame payload data to pass.
68  * \param datalen Frame payload data length to pass.
69  *
70  * \retval 0 on success.
71  * \retval -1 on error.
72  */
73 typedef int (*ast_bridge_channel_post_action_data)(struct ast_bridge_channel *bridge_channel, enum bridge_channel_action_type action, const void *data, size_t datalen);
74 
75 /*!
76  * \brief Counter used for assigning synchronous bridge action IDs
77  */
78 static int sync_ids;
79 
80 /*!
81  * \brief Frame payload for synchronous bridge actions.
82  *
83  * The payload serves as a wrapper around the actual payload of the
84  * frame, with the addition of an id used to find the associated
85  * bridge_sync object.
86  */
87 struct sync_payload {
88  /*! Unique ID for this synchronous action */
89  unsigned int id;
90  /*! Actual frame data to process */
91  unsigned char data[0];
92 };
93 
94 /*!
95  * \brief Synchronous bridge action object.
96  *
97  * Synchronous bridge actions require the ability for one thread to wait
98  * and for another thread to indicate that the action has completed. This
99  * structure facilitates that goal by providing synchronization structures.
100  */
101 struct bridge_sync {
102  /*! Unique ID of this synchronization object. Corresponds with ID in synchronous frame payload */
103  unsigned int id;
104  /*! Semaphore used for synchronization */
105  struct ast_sem sem;
106  /*! Pointer to next entry in the list */
108 };
109 
110 /*!
111  * \brief List holding active synchronous action objects.
112  */
114 
115 /*!
116  * \brief initialize a synchronous bridge object.
117  *
118  * This both initializes the structure and adds it to the list of
119  * synchronization structures.
120  *
121  * \param sync_struct The synchronization object to initialize.
122  * \param id ID to assign to the synchronization object.
123  */
124 static void bridge_sync_init(struct bridge_sync *sync_struct, unsigned int id)
125 {
126  memset(sync_struct, 0, sizeof(*sync_struct));
127  sync_struct->id = id;
128  ast_sem_init(&sync_struct->sem, 0, 0);
129 
131  AST_RWLIST_INSERT_TAIL(&sync_structs, sync_struct, list);
133 }
134 
135 /*!
136  * \brief Clean up a syncrhonization bridge object.
137  *
138  * This frees fields within the synchronization object and removes
139  * it from the list of active synchronization objects.
140  *
141  * Since synchronization objects are stack-allocated, it is vital
142  * that this is called before the synchronization object goes
143  * out of scope.
144  *
145  * \param sync_struct Synchronization object to clean up.
146  */
147 static void bridge_sync_cleanup(struct bridge_sync *sync_struct)
148 {
149  struct bridge_sync *iter;
150 
153  if (iter->id == sync_struct->id) {
155  break;
156  }
157  }
160 
161  ast_sem_destroy(&sync_struct->sem);
162 }
163 
164 /*!
165  * \brief Failsafe for synchronous bridge action waiting.
166  *
167  * When waiting for a synchronous bridge action to complete,
168  * if there is a frame resource leak somewhere, it is possible
169  * that we will never get notified that the synchronous action
170  * completed.
171  *
172  * If a significant amount of time passes, then we will abandon
173  * waiting for the synchrnous bridge action to complete.
174  *
175  * This constant represents the number of milliseconds we will
176  * wait for the bridge action to complete.
177  */
178 #define PLAYBACK_TIMEOUT (600 * 1000)
179 
180 /*!
181  * \brief Wait for a synchronous bridge action to complete.
182  *
183  * \param sync_struct Synchronization object corresponding to the bridge action.
184  */
185 static void bridge_sync_wait(struct bridge_sync *sync_struct)
186 {
187  struct timeval timeout_val = ast_tvadd(ast_tvnow(), ast_samp2tv(PLAYBACK_TIMEOUT, 1000));
188  struct timespec timeout_spec = {
189  .tv_sec = timeout_val.tv_sec,
190  .tv_nsec = timeout_val.tv_usec * 1000,
191  };
192 
193  ast_sem_timedwait(&sync_struct->sem, &timeout_spec);
194 }
195 
196 /*!
197  * \brief Signal that waiting for a synchronous bridge action is no longer necessary.
198  *
199  * This may occur for several reasons
200  * \li The synchronous bridge action has completed.
201  * \li The bridge channel has been removed from the bridge.
202  * \li The synchronous bridge action could not be queued.
203  *
204  * \param sync_struct Synchronization object corresponding to the bridge action.
205  */
206 static void bridge_sync_signal(struct bridge_sync *sync_struct)
207 {
208  ast_sem_post(&sync_struct->sem);
209 }
210 
212 {
213  struct ast_channel *chan;
214 
215  ao2_lock(bridge_channel);
216  chan = ao2_bump(bridge_channel->chan);
217  ao2_unlock(bridge_channel);
218 
219  return chan;
220 }
221 
223 {
224  struct ast_bridge *bridge;
225 
226  for (;;) {
227  /* Safely get the bridge pointer */
228  ast_bridge_channel_lock(bridge_channel);
229  bridge = bridge_channel->bridge;
230  ao2_ref(bridge, +1);
231  ast_bridge_channel_unlock(bridge_channel);
232 
233  /* Lock the bridge and see if it is still the bridge we need to lock. */
234  ast_bridge_lock(bridge);
235  if (bridge == bridge_channel->bridge) {
236  ao2_ref(bridge, -1);
237  return;
238  }
239  ast_bridge_unlock(bridge);
240  ao2_ref(bridge, -1);
241  }
242 }
243 
244 int ast_bridge_channel_notify_talking(struct ast_bridge_channel *bridge_channel, int started_talking)
245 {
246  struct ast_frame action = {
248  .subclass.integer = started_talking
250  };
251 
252  return ast_bridge_channel_queue_frame(bridge_channel, &action);
253 }
254 
255 /*!
256  * \internal
257  * \brief Poke the bridge_channel thread
258  */
259 static void bridge_channel_poke(struct ast_bridge_channel *bridge_channel)
260 {
261  if (!pthread_equal(pthread_self(), bridge_channel->thread)) {
262  /* Wake up the bridge channel thread. */
263  ast_queue_frame(bridge_channel->chan, &ast_null_frame);
264  }
265 }
266 
267 /*!
268  * \internal
269  * \brief Set actual cause on channel.
270  * \since 12.0.0
271  *
272  * \param chan Channel to set cause.
273  * \param cause Cause to set on channel.
274  * If cause <= 0 then use cause on channel if cause still <= 0 use AST_CAUSE_NORMAL_CLEARING.
275  *
276  * \return Actual cause set on channel.
277  */
278 static int channel_set_cause(struct ast_channel *chan, int cause)
279 {
280  ast_channel_lock(chan);
281  if (cause <= 0) {
282  cause = ast_channel_hangupcause(chan);
283  if (cause <= 0) {
285  }
286  }
287  ast_channel_hangupcause_set(chan, cause);
288  ast_channel_unlock(chan);
289  return cause;
290 }
291 
292 void ast_bridge_channel_leave_bridge_nolock(struct ast_bridge_channel *bridge_channel, enum bridge_channel_state new_state, int cause)
293 {
294  if (bridge_channel->state != BRIDGE_CHANNEL_STATE_WAIT) {
295  return;
296  }
297 
298  ast_debug(1, "Setting %p(%s) state from:%u to:%u\n",
299  bridge_channel, ast_channel_name(bridge_channel->chan), bridge_channel->state,
300  new_state);
301 
302  channel_set_cause(bridge_channel->chan, cause);
303 
304  ast_channel_lock(bridge_channel->chan);
305  ast_bridge_vars_set(bridge_channel->chan, NULL, NULL);
306  ast_channel_unlock(bridge_channel->chan);
307 
308  /* Change the state on the bridge channel */
309  bridge_channel->state = new_state;
310 
311  bridge_channel_poke(bridge_channel);
312 }
313 
314 void ast_bridge_channel_leave_bridge(struct ast_bridge_channel *bridge_channel, enum bridge_channel_state new_state, int cause)
315 {
316  ast_bridge_channel_lock(bridge_channel);
317  ast_bridge_channel_leave_bridge_nolock(bridge_channel, new_state, cause);
318  ast_bridge_channel_unlock(bridge_channel);
319 }
320 
322 {
323  struct ast_bridge *bridge = bridge_channel->bridge;
324  struct ast_bridge_channel *other = NULL;
325 
326  if (bridge_channel->in_bridge && bridge->num_channels == 2) {
327  AST_LIST_TRAVERSE(&bridge->channels, other, entry) {
328  if (other != bridge_channel) {
329  break;
330  }
331  }
332  }
333 
334  return other;
335 }
336 
338 {
339  ast_assert(bridge_channel->read_format != NULL);
340  ast_assert(bridge_channel->write_format != NULL);
341 
342  ast_channel_lock(bridge_channel->chan);
343 
344  /* Restore original formats of the channel as they came in */
345  if (ast_format_cmp(ast_channel_readformat(bridge_channel->chan), bridge_channel->read_format) == AST_FORMAT_CMP_NOT_EQUAL) {
346  ast_debug(1, "Bridge is returning %p(%s) to read format %s\n",
347  bridge_channel, ast_channel_name(bridge_channel->chan),
348  ast_format_get_name(bridge_channel->read_format));
349  if (ast_set_read_format(bridge_channel->chan, bridge_channel->read_format)) {
350  ast_debug(1, "Bridge failed to return %p(%s) to read format %s\n",
351  bridge_channel, ast_channel_name(bridge_channel->chan),
352  ast_format_get_name(bridge_channel->read_format));
353  }
354  }
355  if (ast_format_cmp(ast_channel_writeformat(bridge_channel->chan), bridge_channel->write_format) == AST_FORMAT_CMP_NOT_EQUAL) {
356  ast_debug(1, "Bridge is returning %p(%s) to write format %s\n",
357  bridge_channel, ast_channel_name(bridge_channel->chan),
358  ast_format_get_name(bridge_channel->write_format));
359  if (ast_set_write_format(bridge_channel->chan, bridge_channel->write_format)) {
360  ast_debug(1, "Bridge failed to return %p(%s) to write format %s\n",
361  bridge_channel, ast_channel_name(bridge_channel->chan),
362  ast_format_get_name(bridge_channel->write_format));
363  }
364  }
365 
366  ast_channel_unlock(bridge_channel->chan);
367 }
368 
370 {
371  struct ast_bridge *bridge;
372 
373  ast_bridge_channel_lock_bridge(bridge_channel);
374  bridge = bridge_channel->bridge;
375  ao2_ref(bridge, +1);
376  bridge_merge_inhibit_nolock(bridge, request);
377  ast_bridge_unlock(bridge);
378  return bridge;
379 }
380 
382 {
383  struct ast_bridge_channel *other;
384  struct ast_bridge *bridge = bridge_channel->bridge;
385  struct ast_channel *oldest_linkedid_chan = bridge_channel->chan;
386 
387  AST_LIST_TRAVERSE(&bridge->channels, other, entry) {
388  if (other == swap) {
389  continue;
390  }
391  oldest_linkedid_chan = ast_channel_internal_oldest_linkedid(
392  oldest_linkedid_chan, other->chan);
393  }
394 
395  ast_channel_lock(bridge_channel->chan);
396  ast_channel_internal_copy_linkedid(bridge_channel->chan, oldest_linkedid_chan);
397  ast_channel_unlock(bridge_channel->chan);
398  AST_LIST_TRAVERSE(&bridge->channels, other, entry) {
399  if (other == swap) {
400  continue;
401  }
402  ast_channel_lock(other->chan);
403  ast_channel_internal_copy_linkedid(other->chan, oldest_linkedid_chan);
404  ast_channel_unlock(other->chan);
405  }
406 }
407 
408 /*!
409  * \internal
410  * \brief Set dest's empty peeraccount with the src's non-empty accountcode.
411  * \since 12.5.0
412  *
413  * \param dest Channel to update peeraccount.
414  * \param src Channel to get accountcode from.
415  *
416  * \note Both channels are already locked.
417  *
418  * \return Nothing
419  */
420 static void channel_fill_empty_peeraccount(struct ast_channel *dest, struct ast_channel *src)
421 {
424  ast_debug(1, "Setting channel %s peeraccount with channel %s accountcode '%s'.\n",
425  ast_channel_name(dest),
427  ast_channel_peeraccount_set(dest, ast_channel_accountcode(src));
428  }
429 }
430 
431 /*!
432  * \internal
433  * \brief Set dest's empty accountcode with the src's non-empty peeraccount.
434  * \since 12.5.0
435  *
436  * \param dest Channel to update accountcode.
437  * \param src Channel to get peeraccount from.
438  *
439  * \note Both channels are already locked.
440  *
441  * \return Nothing
442  */
443 static void channel_fill_empty_accountcode(struct ast_channel *dest, struct ast_channel *src)
444 {
447  ast_debug(1, "Setting channel %s accountcode with channel %s peeraccount '%s'.\n",
448  ast_channel_name(dest),
450  ast_channel_accountcode_set(dest, ast_channel_peeraccount(src));
451  }
452 }
453 
454 /*!
455  * \internal
456  * \brief Set empty peeraccount and accountcode in a channel from the other channel.
457  * \since 12.5.0
458  *
459  * \param c0 First bridge channel to update.
460  * \param c1 Second bridge channel to update.
461  *
462  * \note Both channels are already locked.
463  *
464  * \return Nothing
465  */
466 static void channel_set_empty_accountcodes(struct ast_channel *c0, struct ast_channel *c1)
467 {
468  /* Set empty peeraccount from the other channel's accountcode. */
471 
472  /* Set empty accountcode from the other channel's peeraccount. */
475 }
476 
477 /*!
478  * \internal
479  * \brief Update dest's peeraccount with the src's different accountcode.
480  * \since 12.5.0
481  *
482  * \param dest Channel to update peeraccount.
483  * \param src Channel to get accountcode from.
484  *
485  * \note Both channels are already locked.
486  *
487  * \return Nothing
488  */
489 static void channel_update_peeraccount(struct ast_channel *dest, struct ast_channel *src)
490 {
491  if (strcmp(ast_channel_accountcode(src), ast_channel_peeraccount(dest))) {
492  ast_debug(1, "Changing channel %s peeraccount '%s' to match channel %s accountcode '%s'.\n",
495  ast_channel_peeraccount_set(dest, ast_channel_accountcode(src));
496  }
497 }
498 
499 /*!
500  * \internal
501  * \brief Update peeraccounts to match the other channel's accountcode.
502  * \since 12.5.0
503  *
504  * \param c0 First channel to update.
505  * \param c1 Second channel to update.
506  *
507  * \note Both channels are already locked.
508  *
509  * \return Nothing
510  */
511 static void channel_update_peeraccounts(struct ast_channel *c0, struct ast_channel *c1)
512 {
515 }
516 
517 /*!
518  * \internal
519  * \brief Update channel accountcodes because a channel is joining a bridge.
520  * \since 12.5.0
521  *
522  * \param joining Channel joining the bridge.
523  * \param swap Channel being replaced by the joining channel. May be NULL.
524  *
525  * \note The bridge must be locked prior to calling this function.
526  *
527  * \return Nothing
528  */
530 {
531  struct ast_bridge *bridge = joining->bridge;
532  struct ast_bridge_channel *other;
533  unsigned int swap_in_bridge = 0;
534  unsigned int will_be_two_party;
535 
536  /*
537  * Only update the peeraccount to match if the joining channel
538  * will make it a two party bridge.
539  */
540  if (bridge->num_channels <= 2 && swap) {
541  AST_LIST_TRAVERSE(&bridge->channels, other, entry) {
542  if (other == swap) {
543  swap_in_bridge = 1;
544  break;
545  }
546  }
547  }
548  will_be_two_party = (1 == bridge->num_channels - swap_in_bridge);
549 
550  AST_LIST_TRAVERSE(&bridge->channels, other, entry) {
551  if (other == swap) {
552  continue;
553  }
554  ast_assert(joining != other);
555  ast_channel_lock_both(joining->chan, other->chan);
556  channel_set_empty_accountcodes(joining->chan, other->chan);
557  if (will_be_two_party) {
558  channel_update_peeraccounts(joining->chan, other->chan);
559  }
560  ast_channel_unlock(joining->chan);
561  ast_channel_unlock(other->chan);
562  }
563 }
564 
565 /*!
566  * \internal
567  * \brief Update channel peeraccount codes because a channel has left a bridge.
568  * \since 12.5.0
569  *
570  * \param leaving Channel leaving the bridge. (Has already been removed actually)
571  *
572  * \note The bridge must be locked prior to calling this function.
573  *
574  * \return Nothing
575  */
577 {
578  struct ast_bridge *bridge = leaving->bridge;
579  struct ast_bridge_channel *first;
580  struct ast_bridge_channel *second;
581 
582  if (bridge->num_channels != 2 || bridge->dissolved) {
583  return;
584  }
585 
586  first = AST_LIST_FIRST(&bridge->channels);
587  second = AST_LIST_LAST(&bridge->channels);
588  ast_assert(first && first != second);
589  ast_channel_lock_both(first->chan, second->chan);
590  channel_set_empty_accountcodes(first->chan, second->chan);
591  channel_update_peeraccounts(first->chan, second->chan);
592  ast_channel_unlock(second->chan);
593  ast_channel_unlock(first->chan);
594 }
595 
597 {
598  if (joining) {
600  } else {
602  }
603 }
604 
605 void ast_bridge_channel_kick(struct ast_bridge_channel *bridge_channel, int cause)
606 {
607  struct ast_bridge_features *features = bridge_channel->features;
608  struct ast_bridge_hook *hook;
609  struct ao2_iterator iter;
610 
611  ast_bridge_channel_lock(bridge_channel);
612  if (bridge_channel->state == BRIDGE_CHANNEL_STATE_WAIT) {
613  channel_set_cause(bridge_channel->chan, cause);
614  cause = 0;
615  }
616  ast_bridge_channel_unlock(bridge_channel);
617 
618  /* Run any hangup hooks. */
619  iter = ao2_iterator_init(features->other_hooks, 0);
620  for (; (hook = ao2_iterator_next(&iter)); ao2_ref(hook, -1)) {
621  int remove_me;
622 
623  if (hook->type != AST_BRIDGE_HOOK_TYPE_HANGUP) {
624  continue;
625  }
626  remove_me = hook->callback(bridge_channel, hook->hook_pvt);
627  if (remove_me) {
628  ast_debug(1, "Hangup hook %p is being removed from %p(%s)\n",
629  hook, bridge_channel, ast_channel_name(bridge_channel->chan));
630  ao2_unlink(features->other_hooks, hook);
631  }
632  }
633  ao2_iterator_destroy(&iter);
634 
635  /* Default hangup action. */
637 }
638 
639 /*!
640  * \internal
641  * \brief Write an \ref ast_frame into the bridge
642  * \since 12.0.0
643  *
644  * \param bridge_channel Which channel is queueing the frame.
645  * \param frame The frame to write into the bridge
646  *
647  * \retval 0 on success.
648  * \retval -1 on error.
649  */
650 static int bridge_channel_write_frame(struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
651 {
652  const struct ast_control_t38_parameters *t38_parameters;
653  int unmapped_stream_num;
654  int deferred;
655 
657 
658  ast_bridge_channel_lock_bridge(bridge_channel);
659 
660  /* Map the frame to the bridge. */
661  if (ast_channel_is_multistream(bridge_channel->chan)) {
662  unmapped_stream_num = frame->stream_num;
663  switch (frame->frametype) {
664  case AST_FRAME_VOICE:
665  case AST_FRAME_VIDEO:
666  case AST_FRAME_TEXT:
667  case AST_FRAME_IMAGE:
668  case AST_FRAME_RTCP:
669  /* These frames need to be mapped to an appropriate write stream */
670  if (frame->stream_num < 0) {
671  /* Map to default stream */
672  frame->stream_num = -1;
673  break;
674  }
675  ast_bridge_channel_lock(bridge_channel);
676  if (frame->stream_num < (int)AST_VECTOR_SIZE(&bridge_channel->stream_map.to_bridge)) {
677  frame->stream_num = AST_VECTOR_GET(
678  &bridge_channel->stream_map.to_bridge, frame->stream_num);
679  if (0 <= frame->stream_num) {
680  ast_bridge_channel_unlock(bridge_channel);
681  break;
682  }
683  }
684  ast_bridge_channel_unlock(bridge_channel);
685  ast_bridge_unlock(bridge_channel->bridge);
686  /*
687  * Ignore frame because we don't know how to map the frame
688  * or the bridge is not expecting any media from that
689  * stream.
690  */
691  return 0;
693  case AST_FRAME_DTMF_END:
694  /*
695  * XXX It makes sense that DTMF could be on any audio stream.
696  * For now we will only put it on the default audio stream.
697  */
698  default:
699  frame->stream_num = -1;
700  break;
701  }
702  } else {
703  unmapped_stream_num = -1;
704  frame->stream_num = -1;
705  }
706 
707  deferred = bridge_channel->bridge->technology->write(bridge_channel->bridge, bridge_channel, frame);
708  if (deferred) {
709  struct ast_frame *dup;
710 
711  dup = ast_frdup(frame);
712  if (dup) {
713  /*
714  * We have to unmap the deferred frame so it comes back
715  * in like a new frame.
716  */
717  dup->stream_num = unmapped_stream_num;
718  ast_bridge_channel_lock(bridge_channel);
719  AST_LIST_INSERT_HEAD(&bridge_channel->deferred_queue, dup, frame_list);
720  ast_bridge_channel_unlock(bridge_channel);
721  }
722  }
723 
724  /* Remember any owed events to the bridge. */
725  switch (frame->frametype) {
727  bridge_channel->owed.dtmf_tv = ast_tvnow();
728  bridge_channel->owed.dtmf_digit = frame->subclass.integer;
729  break;
730  case AST_FRAME_DTMF_END:
731  bridge_channel->owed.dtmf_digit = '\0';
732  break;
733  case AST_FRAME_CONTROL:
734  /*
735  * We explicitly will not remember HOLD/UNHOLD frames because
736  * things like attended transfers will handle them.
737  */
738  switch (frame->subclass.integer) {
740  t38_parameters = frame->data.ptr;
741  switch (t38_parameters->request_response) {
743  case AST_T38_NEGOTIATED:
744  bridge_channel->owed.t38_terminate = 1;
745  break;
747  case AST_T38_TERMINATED:
748  case AST_T38_REFUSED:
749  bridge_channel->owed.t38_terminate = 0;
750  break;
751  default:
752  break;
753  }
754  break;
755  default:
756  break;
757  }
758  break;
759  default:
760  break;
761  }
762  ast_bridge_unlock(bridge_channel->bridge);
763 
764  /*
765  * Claim successful write to bridge. If deferred frame
766  * support is added, claim successfully deferred.
767  */
768  return 0;
769 }
770 
771 /*!
772  * \internal
773  * \brief Cancel owed events by the channel to the bridge.
774  * \since 13.8.0
775  *
776  * \param bridge_channel Channel that owes events to the bridge.
777  *
778  * \note On entry, the bridge_channel->bridge is already locked.
779  *
780  * \return Nothing
781  */
782 static void bridge_channel_cancel_owed_events(struct ast_bridge_channel *bridge_channel)
783 {
784  bridge_channel->owed.dtmf_digit = '\0';
785  bridge_channel->owed.t38_terminate = 0;
786 }
787 
788 void bridge_channel_settle_owed_events(struct ast_bridge *orig_bridge, struct ast_bridge_channel *bridge_channel)
789 {
790  if (bridge_channel->owed.dtmf_digit) {
791  struct ast_frame frame = {
793  .subclass.integer = bridge_channel->owed.dtmf_digit,
794  .src = "Bridge channel owed DTMF",
795  };
796 
797  frame.len = ast_tvdiff_ms(ast_tvnow(), bridge_channel->owed.dtmf_tv);
798  if (frame.len < option_dtmfminduration) {
799  frame.len = option_dtmfminduration;
800  }
801  ast_log(LOG_DTMF, "DTMF end '%c' simulated to bridge %s because %s left. Duration %ld ms.\n",
802  bridge_channel->owed.dtmf_digit, orig_bridge->uniqueid,
803  ast_channel_name(bridge_channel->chan), frame.len);
804  bridge_channel->owed.dtmf_digit = '\0';
805  orig_bridge->technology->write(orig_bridge, NULL, &frame);
806  }
807  if (bridge_channel->owed.t38_terminate) {
808  struct ast_control_t38_parameters t38_parameters = {
810  };
811  struct ast_frame frame = {
813  .subclass.integer = AST_CONTROL_T38_PARAMETERS,
814  .data.ptr = &t38_parameters,
815  .datalen = sizeof(t38_parameters),
816  .src = "Bridge channel owed T.38 terminate",
817  };
818 
819  ast_debug(1, "T.38 terminate simulated to bridge %s because %s left.\n",
820  orig_bridge->uniqueid, ast_channel_name(bridge_channel->chan));
821  bridge_channel->owed.t38_terminate = 0;
822  orig_bridge->technology->write(orig_bridge, NULL, &frame);
823  }
824 }
825 
827 {
828  struct ast_frame *frame;
829 
830  ast_bridge_channel_lock(bridge_channel);
831  ast_channel_lock(bridge_channel->chan);
832  while ((frame = AST_LIST_REMOVE_HEAD(&bridge_channel->deferred_queue, frame_list))) {
833  ast_queue_frame_head(bridge_channel->chan, frame);
834  ast_frfree(frame);
835  }
836  ast_channel_unlock(bridge_channel->chan);
837  ast_bridge_channel_unlock(bridge_channel);
838 }
839 
840 /*!
841  * \internal
842  * \brief Suspend a channel from a bridge.
843  *
844  * \param bridge_channel Channel to suspend.
845  *
846  * \note This function assumes bridge_channel->bridge is locked.
847  *
848  * \return Nothing
849  */
851 {
852  bridge_channel->suspended = 1;
853  if (bridge_channel->in_bridge) {
854  --bridge_channel->bridge->num_active;
855  }
856 
857  /* Get technology bridge threads off of the channel. */
858  if (bridge_channel->bridge->technology->suspend) {
859  bridge_channel->bridge->technology->suspend(bridge_channel->bridge, bridge_channel);
860  }
861 }
862 
863 /*!
864  * \internal
865  * \brief Suspend a channel from a bridge.
866  *
867  * \param bridge_channel Channel to suspend.
868  *
869  * \return Nothing
870  */
871 static void bridge_channel_suspend(struct ast_bridge_channel *bridge_channel)
872 {
873  ast_bridge_channel_lock_bridge(bridge_channel);
875  ast_bridge_unlock(bridge_channel->bridge);
876 }
877 
878 /*!
879  * \internal
880  * \brief Unsuspend a channel from a bridge.
881  *
882  * \param bridge_channel Channel to unsuspend.
883  *
884  * \note This function assumes bridge_channel->bridge is locked.
885  *
886  * \return Nothing
887  */
889 {
890  bridge_channel->suspended = 0;
891  if (bridge_channel->in_bridge) {
892  ++bridge_channel->bridge->num_active;
893  }
894 
895  /* Wake technology bridge threads to take care of channel again. */
896  if (bridge_channel->bridge->technology->unsuspend) {
897  bridge_channel->bridge->technology->unsuspend(bridge_channel->bridge, bridge_channel);
898  }
899 
900  /* Wake suspended channel. */
901  ast_bridge_channel_lock(bridge_channel);
902  ast_cond_signal(&bridge_channel->cond);
903  ast_bridge_channel_unlock(bridge_channel);
904 }
905 
906 /*!
907  * \internal
908  * \brief Unsuspend a channel from a bridge.
909  *
910  * \param bridge_channel Channel to unsuspend.
911  *
912  * \return Nothing
913  */
914 static void bridge_channel_unsuspend(struct ast_bridge_channel *bridge_channel)
915 {
916  ast_bridge_channel_lock_bridge(bridge_channel);
918  ast_bridge_unlock(bridge_channel->bridge);
919 }
920 
921 /*!
922  * \internal
923  * \brief Queue an action frame onto the bridge channel with data.
924  * \since 12.0.0
925  *
926  * \param bridge_channel Which channel to queue the frame onto.
927  * \param action Type of bridge action frame.
928  * \param data Frame payload data to pass.
929  * \param datalen Frame payload data length to pass.
930  *
931  * \retval 0 on success.
932  * \retval -1 on error.
933  */
934 static int bridge_channel_queue_action_data(struct ast_bridge_channel *bridge_channel,
935  enum bridge_channel_action_type action, const void *data, size_t datalen)
936 {
937  struct ast_frame frame = {
939  .subclass.integer = action,
940  .datalen = datalen,
941  .data.ptr = (void *) data,
942  };
943 
944  return ast_bridge_channel_queue_frame(bridge_channel, &frame);
945 }
946 
947 /*!
948  * \internal
949  * \brief Queue an action frame onto the bridge channel with data synchronously.
950  * \since 12.2.0
951  *
952  * The function will not return until the queued frame is freed.
953  *
954  * \param bridge_channel Which channel to queue the frame onto.
955  * \param action Type of bridge action frame.
956  * \param data Frame payload data to pass.
957  * \param datalen Frame payload data length to pass.
958  *
959  * \retval 0 on success.
960  * \retval -1 on error.
961  */
963  enum bridge_channel_action_type action, const void *data, size_t datalen)
964 {
965  struct sync_payload *sync_payload;
966  int sync_payload_len = sizeof(*sync_payload) + datalen;
967  struct bridge_sync sync_struct;
968  struct ast_frame frame = {
970  .subclass.integer = action,
971  };
972 
973  /* Make sure we don't end up trying to wait on ourself to deliver the frame */
974  ast_assert(!pthread_equal(pthread_self(), bridge_channel->thread));
975 
976  sync_payload = ast_alloca(sync_payload_len);
977  sync_payload->id = ast_atomic_fetchadd_int(&sync_ids, +1);
978  memcpy(sync_payload->data, data, datalen);
979 
980  frame.datalen = sync_payload_len;
981  frame.data.ptr = sync_payload;
982 
983  bridge_sync_init(&sync_struct, sync_payload->id);
984  if (ast_bridge_channel_queue_frame(bridge_channel, &frame)) {
985  bridge_sync_cleanup(&sync_struct);
986  return -1;
987  }
988 
989  bridge_sync_wait(&sync_struct);
990  bridge_sync_cleanup(&sync_struct);
991  return 0;
992 }
993 /*!
994  * \internal
995  * \brief Write an action frame onto the bridge channel with data.
996  * \since 12.0.0
997  *
998  * \param bridge_channel Which channel to queue the frame onto.
999  * \param action Type of bridge action frame.
1000  * \param data Frame payload data to pass.
1001  * \param datalen Frame payload data length to pass.
1002  *
1003  * \retval 0 on success.
1004  * \retval -1 on error.
1005  */
1006 static int bridge_channel_write_action_data(struct ast_bridge_channel *bridge_channel,
1007  enum bridge_channel_action_type action, const void *data, size_t datalen)
1008 {
1009  struct ast_frame frame = {
1011  .subclass.integer = action,
1012  .datalen = datalen,
1013  .data.ptr = (void *) data,
1014  };
1015 
1016  return bridge_channel_write_frame(bridge_channel, &frame);
1017 }
1018 
1019 static void bridge_frame_free(struct ast_frame *frame)
1020 {
1021  if (frame->frametype == AST_FRAME_BRIDGE_ACTION_SYNC) {
1022  struct sync_payload *sync_payload = frame->data.ptr;
1023  struct bridge_sync *sync;
1024 
1027  if (sync->id == sync_payload->id) {
1028  break;
1029  }
1030  }
1031  if (sync) {
1032  bridge_sync_signal(sync);
1033  }
1035  }
1036 
1037  ast_frfree(frame);
1038 }
1039 
1040 int ast_bridge_channel_queue_frame(struct ast_bridge_channel *bridge_channel, struct ast_frame *fr)
1041 {
1042  struct ast_frame *dup;
1043 
1044  if (bridge_channel->suspended
1045  /* Also defer DTMF frames. */
1047  && fr->frametype != AST_FRAME_DTMF_END
1048  && !ast_is_deferrable_frame(fr)) {
1049  /* Drop non-deferable frames when suspended. */
1050  return 0;
1051  }
1052  if (fr->frametype == AST_FRAME_NULL) {
1053  /* "Accept" the frame and discard it. */
1054  return 0;
1055  }
1056 
1057  if ((fr->frametype == AST_FRAME_VOICE || fr->frametype == AST_FRAME_VIDEO ||
1059  fr->frametype == AST_FRAME_RTCP) && fr->stream_num > -1) {
1060  int num = -1;
1061 
1062  ast_bridge_channel_lock(bridge_channel);
1063  if (fr->stream_num < (int)AST_VECTOR_SIZE(&bridge_channel->stream_map.to_channel)) {
1064  num = AST_VECTOR_GET(&bridge_channel->stream_map.to_channel, fr->stream_num);
1065  }
1066  ast_bridge_channel_unlock(bridge_channel);
1067 
1068  if (num == -1) {
1069  /* We don't have a mapped stream so just discard this frame. */
1070  return 0;
1071  }
1072  }
1073 
1074  dup = ast_frdup(fr);
1075  if (!dup) {
1076  return -1;
1077  }
1078 
1079  ast_bridge_channel_lock(bridge_channel);
1080  if (bridge_channel->state != BRIDGE_CHANNEL_STATE_WAIT) {
1081  /* Drop frames on channels leaving the bridge. */
1082  ast_bridge_channel_unlock(bridge_channel);
1083  bridge_frame_free(dup);
1084  return 0;
1085  }
1086 
1087  if ((fr->frametype == AST_FRAME_TEXT || fr->frametype == AST_FRAME_TEXT_DATA) &&
1088  !bridge_channel->features->text_messaging) {
1089  /* This channel is not accepting text messages. */
1090  ast_bridge_channel_unlock(bridge_channel);
1091  bridge_frame_free(dup);
1092  return 0;
1093  }
1094 
1095  if (DEBUG_ATLEAST(1)) {
1096  if (fr->frametype == AST_FRAME_TEXT) {
1097  ast_log(LOG_DEBUG, "Queuing TEXT frame to '%s': %*.s\n", ast_channel_name(bridge_channel->chan),
1098  fr->datalen, (char *)fr->data.ptr);
1099  } else if (fr->frametype == AST_FRAME_TEXT_DATA) {
1100  struct ast_msg_data *msg = fr->data.ptr;
1101  ast_log(LOG_DEBUG, "Queueing TEXT_DATA frame from '%s' to '%s:%s': %s\n",
1104  ast_channel_name(bridge_channel->chan),
1106  }
1107  }
1108 
1109  AST_LIST_INSERT_TAIL(&bridge_channel->wr_queue, dup, frame_list);
1110  if (ast_alertpipe_write(bridge_channel->alert_pipe)) {
1111  ast_log(LOG_ERROR, "We couldn't write alert pipe for %p(%s)... something is VERY wrong\n",
1112  bridge_channel, ast_channel_name(bridge_channel->chan));
1113  }
1114  ast_bridge_channel_unlock(bridge_channel);
1115  return 0;
1116 }
1117 
1118 int ast_bridge_queue_everyone_else(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
1119 {
1120  struct ast_bridge_channel *cur;
1121  int not_written = -1;
1122 
1123  if (frame->frametype == AST_FRAME_NULL) {
1124  /* "Accept" the frame and discard it. */
1125  return 0;
1126  }
1127 
1128  AST_LIST_TRAVERSE(&bridge->channels, cur, entry) {
1129  if (cur == bridge_channel) {
1130  continue;
1131  }
1132  if (!ast_bridge_channel_queue_frame(cur, frame)) {
1133  not_written = 0;
1134  }
1135  }
1136  return not_written;
1137 }
1138 
1139 int ast_bridge_channel_queue_control_data(struct ast_bridge_channel *bridge_channel, enum ast_control_frame_type control, const void *data, size_t datalen)
1140 {
1141  struct ast_frame frame = {
1143  .subclass.integer = control,
1144  .datalen = datalen,
1145  .data.ptr = (void *) data,
1146  };
1147 
1148  return ast_bridge_channel_queue_frame(bridge_channel, &frame);
1149 }
1150 
1151 int ast_bridge_channel_write_control_data(struct ast_bridge_channel *bridge_channel, enum ast_control_frame_type control, const void *data, size_t datalen)
1152 {
1153  struct ast_frame frame = {
1155  .subclass.integer = control,
1156  .datalen = datalen,
1157  .data.ptr = (void *) data,
1158  };
1159 
1160  return bridge_channel_write_frame(bridge_channel, &frame);
1161 }
1162 
1163 int ast_bridge_channel_write_hold(struct ast_bridge_channel *bridge_channel, const char *moh_class)
1164 {
1165  struct ast_json *blob;
1166  int res;
1167  size_t datalen;
1168 
1169  if (!ast_strlen_zero(moh_class)) {
1170  datalen = strlen(moh_class) + 1;
1171 
1172  blob = ast_json_pack("{s: s}",
1173  "musicclass", moh_class);
1174  } else {
1175  moh_class = NULL;
1176  datalen = 0;
1177  blob = NULL;
1178  }
1179 
1181 
1183  moh_class, datalen);
1184 
1185  ast_json_unref(blob);
1186  return res;
1187 }
1188 
1190 {
1191  struct ast_channel *chan = ast_bridge_channel_get_chan(bridge_channel);
1192 
1193  if (!chan) {
1194  return -1;
1195  }
1196 
1198  ao2_ref(chan, -1);
1199 
1201 }
1202 
1203 /*!
1204  * \internal
1205  * \brief Helper function to kick off a PBX app on a bridge_channel
1206  */
1207 static int run_app_helper(struct ast_channel *chan, const char *app_name, const char *app_args)
1208 {
1209  int res = 0;
1210 
1211  if (!strcasecmp("Gosub", app_name)) {
1212  ast_app_exec_sub(NULL, chan, app_args, 0);
1213  } else if (!strcasecmp("Macro", app_name)) {
1214  ast_app_exec_macro(NULL, chan, app_args);
1215  } else {
1216  struct ast_app *app;
1217 
1218  app = pbx_findapp(app_name);
1219  if (!app) {
1220  ast_log(LOG_WARNING, "Could not find application (%s)\n", app_name);
1221  } else {
1222  struct ast_str *substituted_args = ast_str_create(16);
1223 
1224  if (substituted_args) {
1225  ast_str_substitute_variables(&substituted_args, 0, chan, app_args);
1226  res = pbx_exec(chan, app, ast_str_buffer(substituted_args));
1227  ast_free(substituted_args);
1228  } else {
1229  ast_log(LOG_WARNING, "Could not substitute application argument variables for %s\n", app_name);
1230  res = pbx_exec(chan, app, app_args);
1231  }
1232  }
1233  }
1234  return res;
1235 }
1236 
1237 void ast_bridge_channel_run_app(struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class)
1238 {
1239  if (moh_class) {
1240  ast_bridge_channel_write_hold(bridge_channel, moh_class);
1241  }
1242  if (run_app_helper(bridge_channel->chan, app_name, S_OR(app_args, ""))) {
1243  /* Break the bridge if the app returns non-zero. */
1245  }
1246  if (moh_class) {
1247  ast_bridge_channel_write_unhold(bridge_channel);
1248  }
1249 }
1250 
1252  /*! Offset into app_name[] where the MOH class name starts. (zero if no MOH) */
1254  /*! Offset into app_name[] where the application argument string starts. (zero if no arguments) */
1256  /*! Application name to run. */
1257  char app_name[0];
1258 };
1259 
1260 /*!
1261  * \internal
1262  * \brief Handle the run application bridge action.
1263  * \since 12.0.0
1264  *
1265  * \param bridge_channel Which channel to run the application on.
1266  * \param data Action frame data to run the application.
1267  *
1268  * \return Nothing
1269  */
1270 static void bridge_channel_run_app(struct ast_bridge_channel *bridge_channel, struct bridge_run_app *data)
1271 {
1272  ast_bridge_channel_run_app(bridge_channel, data->app_name,
1273  data->app_args_offset ? &data->app_name[data->app_args_offset] : NULL,
1274  data->moh_offset ? &data->app_name[data->moh_offset] : NULL);
1275 }
1276 
1277 /*!
1278  * \internal
1279  * \brief Marshal an application to be executed on a bridge_channel
1280  */
1282  struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class)
1283 {
1284  struct bridge_run_app *app_data;
1285  size_t len_name = strlen(app_name) + 1;
1286  size_t len_args = ast_strlen_zero(app_args) ? 0 : strlen(app_args) + 1;
1287  size_t len_moh = !moh_class ? 0 : strlen(moh_class) + 1;
1288  size_t len_data = sizeof(*app_data) + len_name + len_args + len_moh;
1289 
1290  /* Fill in application run frame data. */
1291  app_data = alloca(len_data);
1292  app_data->app_args_offset = len_args ? len_name : 0;
1293  app_data->moh_offset = len_moh ? len_name + len_args : 0;
1294  strcpy(app_data->app_name, app_name);/* Safe */
1295  if (len_args) {
1296  strcpy(&app_data->app_name[app_data->app_args_offset], app_args);/* Safe */
1297  }
1298  if (moh_class) {
1299  strcpy(&app_data->app_name[app_data->moh_offset], moh_class);/* Safe */
1300  }
1301 
1302  return post_it(bridge_channel, BRIDGE_CHANNEL_ACTION_RUN_APP, app_data, len_data);
1303 }
1304 
1305 int ast_bridge_channel_write_app(struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class)
1306 {
1308  bridge_channel, app_name, app_args, moh_class);
1309 }
1310 
1311 int ast_bridge_channel_queue_app(struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class)
1312 {
1314  bridge_channel, app_name, app_args, moh_class);
1315 }
1316 
1317 void ast_bridge_channel_playfile(struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
1318 {
1319  if (moh_class) {
1320  ast_bridge_channel_write_hold(bridge_channel, moh_class);
1321  }
1322  if (custom_play) {
1323  custom_play(bridge_channel, playfile);
1324  } else {
1325  ast_stream_and_wait(bridge_channel->chan, playfile, AST_DIGIT_NONE);
1326  }
1327  if (moh_class) {
1328  ast_bridge_channel_write_unhold(bridge_channel);
1329  }
1330 
1331  /*
1332  * It may be necessary to resume music on hold after we finish
1333  * playing the announcment.
1334  */
1335  if (ast_test_flag(ast_channel_flags(bridge_channel->chan), AST_FLAG_MOH)) {
1336  const char *latest_musicclass;
1337 
1338  ast_channel_lock(bridge_channel->chan);
1339  latest_musicclass = ast_strdupa(ast_channel_latest_musicclass(bridge_channel->chan));
1340  ast_channel_unlock(bridge_channel->chan);
1341  ast_moh_start(bridge_channel->chan, latest_musicclass, NULL);
1342  }
1343 }
1344 
1346  /*! Call this function to play the playfile. (NULL if normal sound file to play) */
1348  /*! Offset into playfile[] where the MOH class name starts. (zero if no MOH)*/
1350  /*! Filename to play. */
1351  char playfile[0];
1352 };
1353 
1354 /*!
1355  * \internal
1356  * \brief Handle the playfile bridge action.
1357  * \since 12.0.0
1358  *
1359  * \param bridge_channel Which channel to play a file on.
1360  * \param payload Action frame payload to play a file.
1361  *
1362  * \return Nothing
1363  */
1364 static void bridge_channel_playfile(struct ast_bridge_channel *bridge_channel, struct bridge_playfile *payload)
1365 {
1366  ast_bridge_channel_playfile(bridge_channel, payload->custom_play, payload->playfile,
1367  payload->moh_offset ? &payload->playfile[payload->moh_offset] : NULL);
1368 }
1369 
1370 /*!
1371  * \internal
1372  * \brief Marshal a file to be played on a bridge_channel
1373  */
1375  struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
1376 {
1377  struct bridge_playfile *payload;
1378  size_t len_name = strlen(playfile) + 1;
1379  size_t len_moh = !moh_class ? 0 : strlen(moh_class) + 1;
1380  size_t len_payload = sizeof(*payload) + len_name + len_moh;
1381 
1382  /* Fill in play file frame data. */
1383  payload = ast_alloca(len_payload);
1384  payload->custom_play = custom_play;
1385  payload->moh_offset = len_moh ? len_name : 0;
1386  strcpy(payload->playfile, playfile);/* Safe */
1387  if (moh_class) {
1388  strcpy(&payload->playfile[payload->moh_offset], moh_class);/* Safe */
1389  }
1390 
1391  return post_it(bridge_channel, BRIDGE_CHANNEL_ACTION_PLAY_FILE, payload, len_payload);
1392 }
1393 
1394 int ast_bridge_channel_write_playfile(struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
1395 {
1397  bridge_channel, custom_play, playfile, moh_class);
1398 }
1399 
1400 int ast_bridge_channel_queue_playfile(struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
1401 {
1403  bridge_channel, custom_play, playfile, moh_class);
1404 }
1405 
1407  ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
1408 {
1410  bridge_channel, custom_play, playfile, moh_class);
1411 }
1412 
1414  /*! Call this function on the bridge channel thread. */
1416  /*! Size of the payload if it exists. A number otherwise. */
1418  /*! Option flags determining how callback is called. */
1419  unsigned int flags;
1420  /*! Nonzero if the payload exists. */
1422  /*! Payload to give to callback. */
1423  char payload[0];
1424 };
1425 
1426 /*!
1427  * \internal
1428  * \brief Handle the do custom callback bridge action.
1429  * \since 12.0.0
1430  *
1431  * \param bridge_channel Which channel to call the callback on.
1432  * \param data Action frame data to call the callback.
1433  *
1434  * \return Nothing
1435  */
1436 static void bridge_channel_do_callback(struct ast_bridge_channel *bridge_channel, struct bridge_custom_callback *data)
1437 {
1439  bridge_channel_suspend(bridge_channel);
1440  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
1441  }
1442  data->callback(bridge_channel, data->payload_exists ? data->payload : NULL, data->payload_size);
1444  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
1445  bridge_channel_unsuspend(bridge_channel);
1446  }
1447 }
1448 
1449 /*!
1450  * \internal
1451  * \brief Marshal a custom callback function to be called on a bridge_channel
1452  */
1454  struct ast_bridge_channel *bridge_channel,
1456  ast_bridge_custom_callback_fn callback, const void *payload, size_t payload_size)
1457 {
1458  struct bridge_custom_callback *cb_data;
1459  size_t len_data = sizeof(*cb_data) + (payload ? payload_size : 0);
1460 
1461  /* Sanity check. */
1462  if (!callback) {
1463  ast_assert(0);
1464  return -1;
1465  }
1466 
1467  /* Fill in custom callback frame data. */
1468  cb_data = alloca(len_data);
1469  cb_data->callback = callback;
1470  cb_data->payload_size = payload_size;
1471  cb_data->flags = flags;
1472  cb_data->payload_exists = payload && payload_size;
1473  if (cb_data->payload_exists) {
1474  memcpy(cb_data->payload, payload, payload_size);/* Safe */
1475  }
1476 
1477  return post_it(bridge_channel, BRIDGE_CHANNEL_ACTION_CALLBACK, cb_data, len_data);
1478 }
1479 
1483 {
1485  bridge_channel, flags, callback, payload, payload_size);
1486 }
1487 
1491 {
1493  bridge_channel, flags, callback, payload, payload_size);
1494 }
1495 
1496 struct bridge_park {
1499  /* buffer used for holding those strings */
1500  char parkee_uuid[0];
1501 };
1502 
1503 /*!
1504  * \internal
1505  * \brief Park a bridge_cahnnel
1506  */
1507 static void bridge_channel_park(struct ast_bridge_channel *bridge_channel, struct bridge_park *payload)
1508 {
1510  ast_log(AST_LOG_WARNING, "Unable to park %s: No parking provider loaded!\n",
1511  ast_channel_name(bridge_channel->chan));
1512  return;
1513  }
1514 
1515  if (ast_parking_park_bridge_channel(bridge_channel, payload->parkee_uuid,
1516  &payload->parkee_uuid[payload->parker_uuid_offset],
1517  payload->app_data_offset ? &payload->parkee_uuid[payload->app_data_offset] : NULL)) {
1518  ast_log(AST_LOG_WARNING, "Error occurred while parking %s\n",
1519  ast_channel_name(bridge_channel->chan));
1520  }
1521 }
1522 
1523 /*!
1524  * \internal
1525  * \brief Marshal a park action onto a bridge_channel
1526  */
1528  struct ast_bridge_channel *bridge_channel,
1529  const char *parkee_uuid,
1530  const char *parker_uuid,
1531  const char *app_data)
1532 {
1533  struct bridge_park *payload;
1534  size_t len_parkee_uuid = strlen(parkee_uuid) + 1;
1535  size_t len_parker_uuid = strlen(parker_uuid) + 1;
1536  size_t len_app_data = !app_data ? 0 : strlen(app_data) + 1;
1537  size_t len_payload = sizeof(*payload) + len_parker_uuid + len_parkee_uuid + len_app_data;
1538 
1539  payload = alloca(len_payload);
1540  payload->app_data_offset = len_app_data ? len_parkee_uuid + len_parker_uuid : 0;
1541  payload->parker_uuid_offset = len_parkee_uuid;
1542  strcpy(payload->parkee_uuid, parkee_uuid);
1543  strcpy(&payload->parkee_uuid[payload->parker_uuid_offset], parker_uuid);
1544  if (app_data) {
1545  strcpy(&payload->parkee_uuid[payload->app_data_offset], app_data);
1546  }
1547 
1548  return post_it(bridge_channel, BRIDGE_CHANNEL_ACTION_PARK, payload, len_payload);
1549 }
1550 
1551 int ast_bridge_channel_write_park(struct ast_bridge_channel *bridge_channel, const char *parkee_uuid, const char *parker_uuid, const char *app_data)
1552 {
1554  bridge_channel, parkee_uuid, parker_uuid, app_data);
1555 }
1556 
1557 /*!
1558  * \internal
1559  * \brief Handle bridge channel interval expiration.
1560  * \since 12.0.0
1561  *
1562  * \param bridge_channel Channel to run expired intervals on.
1563  *
1564  * \return Nothing
1565  */
1566 static void bridge_channel_handle_interval(struct ast_bridge_channel *bridge_channel)
1567 {
1568  struct ast_heap *interval_hooks;
1569  struct ast_bridge_hook_timer *hook;
1570  struct timeval start;
1571  int chan_suspended = 0;
1572 
1573  interval_hooks = bridge_channel->features->interval_hooks;
1574  ast_heap_wrlock(interval_hooks);
1575  start = ast_tvnow();
1576  while ((hook = ast_heap_peek(interval_hooks, 1))) {
1577  int interval;
1578  unsigned int execution_time;
1579 
1580  if (ast_tvdiff_ms(hook->timer.trip_time, start) > 0) {
1581  ast_debug(1, "Hook %p on %p(%s) wants to happen in the future, stopping our traversal\n",
1582  hook, bridge_channel, ast_channel_name(bridge_channel->chan));
1583  break;
1584  }
1585  ao2_ref(hook, +1);
1586  ast_heap_unlock(interval_hooks);
1587 
1588  if (!chan_suspended
1590  chan_suspended = 1;
1591  bridge_channel_suspend(bridge_channel);
1592  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
1593  }
1594 
1595  ast_debug(1, "Executing hook %p on %p(%s)\n",
1596  hook, bridge_channel, ast_channel_name(bridge_channel->chan));
1597  interval = hook->generic.callback(bridge_channel, hook->generic.hook_pvt);
1598 
1599  ast_heap_wrlock(interval_hooks);
1600  if (ast_heap_peek(interval_hooks, hook->timer.heap_index) != hook
1601  || !ast_heap_remove(interval_hooks, hook)) {
1602  /* Interval hook is already removed from the bridge_channel. */
1603  ao2_ref(hook, -1);
1604  continue;
1605  }
1606  ao2_ref(hook, -1);
1607 
1608  if (interval < 0) {
1609  ast_debug(1, "Removed interval hook %p from %p(%s)\n",
1610  hook, bridge_channel, ast_channel_name(bridge_channel->chan));
1611  ao2_ref(hook, -1);
1612  continue;
1613  }
1614  if (interval) {
1615  /* Set new interval for the hook. */
1616  hook->timer.interval = interval;
1617  }
1618 
1619  ast_debug(1, "Updating interval hook %p with interval %u on %p(%s)\n",
1620  hook, hook->timer.interval, bridge_channel,
1621  ast_channel_name(bridge_channel->chan));
1622 
1623  /* resetting start */
1624  start = ast_tvnow();
1625 
1626  /*
1627  * Resetup the interval hook for the next interval. We may need
1628  * to skip over any missed intervals because the hook was
1629  * delayed or took too long.
1630  */
1631  execution_time = ast_tvdiff_ms(start, hook->timer.trip_time);
1632  while (hook->timer.interval < execution_time) {
1633  execution_time -= hook->timer.interval;
1634  }
1635  hook->timer.trip_time = ast_tvadd(start, ast_samp2tv(hook->timer.interval - execution_time, 1000));
1636  hook->timer.seqno = ast_atomic_fetchadd_int((int *) &bridge_channel->features->interval_sequence, +1);
1637 
1638  if (ast_heap_push(interval_hooks, hook)) {
1639  /* Could not push the hook back onto the heap. */
1640  ao2_ref(hook, -1);
1641  }
1642  }
1643  ast_heap_unlock(interval_hooks);
1644 
1645  if (chan_suspended) {
1646  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
1647  bridge_channel_unsuspend(bridge_channel);
1648  }
1649 }
1650 
1651 /*!
1652  * \internal
1653  * \brief Write a DTMF stream out to a channel
1654  */
1655 static int bridge_channel_write_dtmf_stream(struct ast_bridge_channel *bridge_channel, const char *dtmf)
1656 {
1657  return bridge_channel_write_action_data(bridge_channel,
1658  BRIDGE_CHANNEL_ACTION_DTMF_STREAM, dtmf, strlen(dtmf) + 1);
1659 }
1660 
1661 /*!
1662  * \internal
1663  * \brief Indicate to the testsuite a feature was successfully detected.
1664  *
1665  * Currently, this function only will relay built-in features to the testsuite,
1666  * but it could be modified to detect applicationmap items should the need arise.
1667  *
1668  * \param chan The channel that activated the feature
1669  * \param dtmf The DTMF sequence entered to activate the feature
1670  */
1671 static void testsuite_notify_feature_success(struct ast_channel *chan, const char *dtmf)
1672 {
1673 #ifdef TEST_FRAMEWORK
1674  char *feature = "unknown";
1675  struct ast_featuremap_config *featuremap;
1676  struct ast_features_xfer_config *xfer;
1677 
1678  ast_channel_lock(chan);
1679  featuremap = ast_get_chan_featuremap_config(chan);
1680  xfer = ast_get_chan_features_xfer_config(chan);
1681  ast_channel_unlock(chan);
1682 
1683  if (featuremap) {
1684  if (!strcmp(dtmf, featuremap->blindxfer)) {
1685  feature = "blindxfer";
1686  } else if (!strcmp(dtmf, featuremap->atxfer)) {
1687  feature = "atxfer";
1688  } else if (!strcmp(dtmf, featuremap->disconnect)) {
1689  feature = "disconnect";
1690  } else if (!strcmp(dtmf, featuremap->automon)) {
1691  feature = "automon";
1692  } else if (!strcmp(dtmf, featuremap->automixmon)) {
1693  feature = "automixmon";
1694  } else if (!strcmp(dtmf, featuremap->parkcall)) {
1695  feature = "parkcall";
1696  }
1697  }
1698  if (xfer) {
1699  if (!strcmp(dtmf, xfer->atxferthreeway)) {
1700  feature = "atxferthreeway";
1701  }
1702  }
1703 
1704  ao2_cleanup(featuremap);
1705  ao2_cleanup(xfer);
1706 
1707  ast_test_suite_event_notify("FEATURE_DETECTION",
1708  "Result: success\r\n"
1709  "Feature: %s", feature);
1710 #endif /* TEST_FRAMEWORK */
1711 }
1712 
1714  struct ast_bridge_channel *bridge_channel, int digit, size_t dtmf_len)
1715 {
1716  if (dtmf_len < ARRAY_LEN(bridge_channel->dtmf_hook_state.collected) - 1) {
1717  /* Add the new digit to the DTMF string so we can do our matching */
1718  bridge_channel->dtmf_hook_state.collected[dtmf_len++] = digit;
1719  bridge_channel->dtmf_hook_state.collected[dtmf_len] = '\0';
1720 
1721  ast_debug(1, "DTMF feature string on %p(%s) is now '%s'\n",
1722  bridge_channel, ast_channel_name(bridge_channel->chan),
1723  bridge_channel->dtmf_hook_state.collected);
1724  }
1725 
1726  return dtmf_len;
1727 }
1728 
1729 static unsigned int bridge_channel_feature_digit_timeout(struct ast_bridge_channel *bridge_channel)
1730 {
1731  unsigned int digit_timeout;
1732  struct ast_features_general_config *gen_cfg;
1733 
1734  /* Determine interdigit timeout */
1735  ast_channel_lock(bridge_channel->chan);
1736  gen_cfg = ast_get_chan_features_general_config(bridge_channel->chan);
1737  ast_channel_unlock(bridge_channel->chan);
1738 
1739  if (!gen_cfg) {
1740  ast_log(LOG_ERROR, "Unable to retrieve features configuration.\n");
1741  return 3000; /* Pick a reasonable failsafe timeout in ms */
1742  }
1743 
1744  digit_timeout = gen_cfg->featuredigittimeout;
1745  ao2_ref(gen_cfg, -1);
1746 
1747  return digit_timeout;
1748 }
1749 
1751 {
1752  if (digit) {
1754  bridge_channel, digit, strlen(bridge_channel->dtmf_hook_state.collected));
1755  }
1756 }
1757 
1759 {
1760  struct ast_bridge_features *features = bridge_channel->features;
1761  struct ast_bridge_hook_dtmf *hook = NULL;
1762  size_t dtmf_len;
1763 
1764  struct sanity_check_of_dtmf_size {
1765  char check[1 / (ARRAY_LEN(bridge_channel->dtmf_hook_state.collected) == ARRAY_LEN(hook->dtmf.code))];
1766  };
1767 
1768  dtmf_len = strlen(bridge_channel->dtmf_hook_state.collected);
1769  if (!dtmf_len && !digit) {
1770  /* Nothing to do */
1771  return;
1772  }
1773 
1774  if (digit) {
1775  dtmf_len = bridge_channel_feature_digit_add(bridge_channel, digit, dtmf_len);
1776  }
1777 
1778  while (digit) {
1779  /* See if a DTMF feature hook matches or can match */
1780  hook = ao2_find(features->dtmf_hooks, bridge_channel->dtmf_hook_state.collected,
1782  if (!hook) {
1783  ast_debug(1, "No DTMF feature hooks on %p(%s) match '%s'\n",
1784  bridge_channel, ast_channel_name(bridge_channel->chan),
1785  bridge_channel->dtmf_hook_state.collected);
1786  break;
1787  } else if (dtmf_len != strlen(hook->dtmf.code)) {
1788  unsigned int digit_timeout;
1789  /* Need more digits to match */
1790  ao2_ref(hook, -1);
1791  digit_timeout = bridge_channel_feature_digit_timeout(bridge_channel);
1792  bridge_channel->dtmf_hook_state.interdigit_timeout =
1793  ast_tvadd(ast_tvnow(), ast_samp2tv(digit_timeout, 1000));
1794  return;
1795  } else {
1796  int remove_me;
1797  int already_suspended;
1798 
1799  ast_debug(1, "DTMF feature hook %p matched DTMF string '%s' on %p(%s)\n",
1800  hook, bridge_channel->dtmf_hook_state.collected, bridge_channel,
1801  ast_channel_name(bridge_channel->chan));
1802 
1803  /*
1804  * Clear the collected digits before executing the hook
1805  * in case the hook starts another sequence.
1806  */
1807  bridge_channel->dtmf_hook_state.collected[0] = '\0';
1808 
1809  ast_bridge_channel_lock_bridge(bridge_channel);
1810  already_suspended = bridge_channel->suspended;
1811  if (!already_suspended) {
1813  }
1814  ast_bridge_unlock(bridge_channel->bridge);
1815  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
1816 
1817  /* Execute the matched hook on this channel. */
1818  remove_me = hook->generic.callback(bridge_channel, hook->generic.hook_pvt);
1819  if (remove_me) {
1820  ast_debug(1, "DTMF hook %p is being removed from %p(%s)\n",
1821  hook, bridge_channel, ast_channel_name(bridge_channel->chan));
1822  ao2_unlink(features->dtmf_hooks, hook);
1823  }
1824  testsuite_notify_feature_success(bridge_channel->chan, hook->dtmf.code);
1825  ao2_ref(hook, -1);
1826 
1827  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
1828  if (!already_suspended) {
1829  bridge_channel_unsuspend(bridge_channel);
1830  }
1831 
1832  /*
1833  * If we are handing the channel off to an external hook for
1834  * ownership, we are not guaranteed what kind of state it will
1835  * come back in. If the channel hungup, we need to detect that
1836  * here if the hook did not already change the state.
1837  */
1838  if (bridge_channel->chan && ast_check_hangup_locked(bridge_channel->chan)) {
1839  ast_bridge_channel_kick(bridge_channel, 0);
1840  bridge_channel->dtmf_hook_state.collected[0] = '\0';
1841  return;
1842  }
1843 
1844  /* if there is dtmf that has been collected then loop back through,
1845  but set digit to -1 so it doesn't try to do an add since the dtmf
1846  is already in the buffer */
1847  dtmf_len = strlen(bridge_channel->dtmf_hook_state.collected);
1848  if (!dtmf_len) {
1849  return;
1850  }
1851  }
1852  }
1853 
1854  if (!digit) {
1855  ast_debug(1, "DTMF feature string collection on %p(%s) timed out\n",
1856  bridge_channel, ast_channel_name(bridge_channel->chan));
1857  }
1858 
1859  /* Timeout or DTMF digit didn't allow a match with any hooks. */
1860  if (features->dtmf_passthrough) {
1861  /* Stream the collected DTMF to the other channels. */
1862  bridge_channel_write_dtmf_stream(bridge_channel,
1863  bridge_channel->dtmf_hook_state.collected);
1864  }
1865  bridge_channel->dtmf_hook_state.collected[0] = '\0';
1866 
1867  ast_test_suite_event_notify("FEATURE_DETECTION", "Result: fail");
1868 }
1869 
1870 /*!
1871  * \internal
1872  * \brief Handle bridge channel DTMF feature timeout expiration.
1873  * \since 12.8.0
1874  *
1875  * \param bridge_channel Channel to check expired interdigit timer on.
1876  *
1877  * \return Nothing
1878  */
1880 {
1881  if (!bridge_channel->dtmf_hook_state.collected[0]
1882  || 0 < ast_tvdiff_ms(bridge_channel->dtmf_hook_state.interdigit_timeout,
1883  ast_tvnow())) {
1884  /* Not within a sequence or not timed out. */
1885  return;
1886  }
1887 
1888  ast_bridge_channel_feature_digit(bridge_channel, 0);
1889 }
1890 
1891 /*!
1892  * \internal
1893  * \brief Indicate that a bridge_channel is talking
1894  */
1895 static void bridge_channel_talking(struct ast_bridge_channel *bridge_channel, int talking)
1896 {
1897  struct ast_bridge_features *features = bridge_channel->features;
1898  struct ast_bridge_hook *hook;
1899  struct ao2_iterator iter;
1900 
1901  /* Run any talk detection hooks. */
1902  iter = ao2_iterator_init(features->other_hooks, 0);
1903  for (; (hook = ao2_iterator_next(&iter)); ao2_ref(hook, -1)) {
1904  int remove_me;
1906 
1907  if (hook->type != AST_BRIDGE_HOOK_TYPE_TALK) {
1908  continue;
1909  }
1911  remove_me = talk_cb(bridge_channel, hook->hook_pvt, talking);
1912  if (remove_me) {
1913  ast_debug(1, "Talk detection hook %p is being removed from %p(%s)\n",
1914  hook, bridge_channel, ast_channel_name(bridge_channel->chan));
1915  ao2_unlink(features->other_hooks, hook);
1916  }
1917  }
1918  ao2_iterator_destroy(&iter);
1919 }
1920 
1921 /*! \brief Internal function that plays back DTMF on a bridge channel */
1922 static void bridge_channel_dtmf_stream(struct ast_bridge_channel *bridge_channel, const char *dtmf)
1923 {
1924  ast_debug(1, "Playing DTMF stream '%s' out to %p(%s)\n",
1925  dtmf, bridge_channel, ast_channel_name(bridge_channel->chan));
1926  ast_dtmf_stream(bridge_channel->chan, NULL, dtmf, 0, 0);
1927 }
1928 
1929 /*! \brief Data specifying where a blind transfer is going to */
1933 };
1934 
1935 /*!
1936  * \internal
1937  * \brief Execute after bridge actions on a channel when it leaves a bridge
1938  */
1939 static void after_bridge_move_channel(struct ast_channel *chan_bridged, void *data)
1940 {
1941  RAII_VAR(struct ast_channel *, chan_target, data, ao2_cleanup);
1942  struct ast_party_connected_line connected_target;
1943  unsigned char connected_line_data[1024];
1944  int payload_size;
1945 
1946  ast_party_connected_line_init(&connected_target);
1947 
1948  ast_channel_lock(chan_target);
1949  ast_party_connected_line_copy(&connected_target, ast_channel_connected(chan_target));
1950  ast_channel_unlock(chan_target);
1951  ast_party_id_reset(&connected_target.priv);
1952 
1953  if (ast_channel_move(chan_target, chan_bridged)) {
1954  ast_softhangup(chan_target, AST_SOFTHANGUP_DEV);
1955  ast_party_connected_line_free(&connected_target);
1956  return;
1957  }
1958 
1959  /* The ast_channel_move function will end up updating the connected line information
1960  * on chan_target to the value we have here, but will not inform it. To ensure that
1961  * AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO is executed we wipe it away here. If
1962  * we don't do this then the change will be considered redundant, since the connected
1963  * line information is already there (despite the channel not being told).
1964  */
1965  ast_channel_lock(chan_target);
1968  ast_channel_unlock(chan_target);
1969 
1970  if ((payload_size = ast_connected_line_build_data(connected_line_data,
1971  sizeof(connected_line_data), &connected_target, NULL)) != -1) {
1972  struct ast_control_read_action_payload *frame_payload;
1973  int frame_size;
1974 
1975  frame_size = payload_size + sizeof(*frame_payload);
1976  frame_payload = ast_alloca(frame_size);
1977  frame_payload->action = AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO;
1978  frame_payload->payload_size = payload_size;
1979  memcpy(frame_payload->payload, connected_line_data, payload_size);
1980  ast_queue_control_data(chan_target, AST_CONTROL_READ_ACTION, frame_payload, frame_size);
1981  }
1982 
1983  /* A connected line update is queued so that if chan_target is remotely involved with
1984  * anything (such as dialing a channel) the other channel(s) will be informed of the
1985  * new channel they are involved with.
1986  */
1987  ast_channel_lock(chan_target);
1988  ast_connected_line_copy_from_caller(&connected_target, ast_channel_caller(chan_target));
1989  ast_channel_queue_connected_line_update(chan_target, &connected_target, NULL);
1990  ast_channel_unlock(chan_target);
1991 
1992  ast_party_connected_line_free(&connected_target);
1993 }
1994 
1995 /*!
1996  * \internal
1997  * \brief Execute logic to cleanup when after bridge fails
1998  */
2000 {
2001  RAII_VAR(struct ast_channel *, chan_target, data, ao2_cleanup);
2002 
2003  ast_log(LOG_WARNING, "Unable to complete transfer: %s\n",
2005  ast_softhangup(chan_target, AST_SOFTHANGUP_DEV);
2006 }
2007 
2008 /*!
2009  * \internal
2010  * \brief Perform a blind transfer on a channel in a bridge
2011  */
2012 static void bridge_channel_blind_transfer(struct ast_bridge_channel *bridge_channel,
2013  struct blind_transfer_data *blind_data)
2014 {
2015  ast_async_goto(bridge_channel->chan, blind_data->context, blind_data->exten, 1);
2017 }
2018 
2019 /*!
2020  * \internal
2021  * \brief Perform an attended transfer on a channel in a bridge
2022  */
2023 static void bridge_channel_attended_transfer(struct ast_bridge_channel *bridge_channel,
2024  const char *target_chan_name)
2025 {
2026  RAII_VAR(struct ast_channel *, chan_target, NULL, ao2_cleanup);
2027  RAII_VAR(struct ast_channel *, chan_bridged, NULL, ao2_cleanup);
2028 
2029  chan_target = ast_channel_get_by_name(target_chan_name);
2030  if (!chan_target) {
2031  /* Dang, it disappeared somehow */
2033  return;
2034  }
2035 
2036  ast_bridge_channel_lock(bridge_channel);
2037  chan_bridged = bridge_channel->chan;
2038  ast_assert(chan_bridged != NULL);
2039  ao2_ref(chan_bridged, +1);
2040  ast_bridge_channel_unlock(bridge_channel);
2041 
2044  ast_softhangup(chan_target, AST_SOFTHANGUP_DEV);
2045 
2046  /* Release the ref we tried to pass to ast_bridge_set_after_callback(). */
2047  ast_channel_unref(chan_target);
2048  }
2050 }
2051 
2052 /*!
2053  * \internal
2054  * \brief Handle bridge channel bridge action frame.
2055  * \since 12.0.0
2056  *
2057  * \param bridge_channel Channel to execute the action on.
2058  * \param action What to do.
2059  * \param data data from the action.
2060  *
2061  * \return Nothing
2062  */
2063 static void bridge_channel_handle_action(struct ast_bridge_channel *bridge_channel,
2065 {
2066  switch (action) {
2068  bridge_channel_suspend(bridge_channel);
2069  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
2070  bridge_channel_dtmf_stream(bridge_channel, data);
2071  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
2072  bridge_channel_unsuspend(bridge_channel);
2073  break;
2076  bridge_channel_talking(bridge_channel,
2078  break;
2080  bridge_channel_suspend(bridge_channel);
2081  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
2082  bridge_channel_playfile(bridge_channel, data);
2083  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
2084  bridge_channel_unsuspend(bridge_channel);
2085  break;
2087  bridge_channel_suspend(bridge_channel);
2088  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
2089  bridge_channel_run_app(bridge_channel, data);
2090  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
2091  bridge_channel_unsuspend(bridge_channel);
2092  break;
2094  bridge_channel_do_callback(bridge_channel, data);
2095  break;
2097  bridge_channel_suspend(bridge_channel);
2098  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
2099  bridge_channel_park(bridge_channel, data);
2100  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
2101  bridge_channel_unsuspend(bridge_channel);
2102  break;
2104  bridge_channel_blind_transfer(bridge_channel, data);
2105  break;
2107  bridge_channel_attended_transfer(bridge_channel, data);
2108  break;
2109  default:
2110  break;
2111  }
2112 
2113  /* While invoking an action it is possible for the channel to be hung up. So
2114  * that the bridge respects this we check here and if hung up kick it out.
2115  */
2116  if (bridge_channel->chan && ast_check_hangup_locked(bridge_channel->chan)) {
2117  ast_bridge_channel_kick(bridge_channel, 0);
2118  }
2119 }
2120 
2121 /*!
2122  * \internal
2123  * \brief Check if a bridge should dissolve and do it.
2124  * \since 12.0.0
2125  *
2126  * \param bridge_channel Channel causing the check.
2127  *
2128  * \note On entry, bridge_channel->bridge is already locked.
2129  *
2130  * \return Nothing
2131  */
2132 static void bridge_channel_dissolve_check(struct ast_bridge_channel *bridge_channel)
2133 {
2134  struct ast_bridge *bridge = bridge_channel->bridge;
2135 
2136  if (bridge->dissolved) {
2137  return;
2138  }
2139 
2140  if (!bridge->num_channels
2142  /* Last channel leaving the bridge turns off the lights. */
2143  bridge_dissolve(bridge, ast_channel_hangupcause(bridge_channel->chan));
2144  return;
2145  }
2146 
2147  switch (bridge_channel->state) {
2149  /* Do we need to dissolve the bridge because this channel hung up? */
2151  || (bridge_channel->features->usable
2152  && ast_test_flag(&bridge_channel->features->feature_flags,
2154  bridge_dissolve(bridge, ast_channel_hangupcause(bridge_channel->chan));
2155  return;
2156  }
2157  break;
2158  default:
2159  break;
2160  }
2161 
2162  if (bridge->num_lonely && bridge->num_lonely == bridge->num_channels) {
2163  /*
2164  * This will start a chain reaction where each channel leaving
2165  * enters this function and causes the next to leave as long as
2166  * there aren't non-lonely channels in the bridge.
2167  */
2170  ast_channel_hangupcause(bridge_channel->chan));
2171  }
2172 }
2173 
2175 {
2176  struct ast_bridge *bridge = bridge_channel->bridge;
2177 
2178  if (!bridge_channel->in_bridge) {
2179  return;
2180  }
2181  bridge_channel->in_bridge = 0;
2182 
2183  ast_debug(1, "Bridge %s: pulling %p(%s)\n",
2184  bridge->uniqueid, bridge_channel, ast_channel_name(bridge_channel->chan));
2185 
2186  ast_verb(3, "Channel %s left '%s' %s-bridge <%s>\n",
2187  ast_channel_name(bridge_channel->chan),
2188  bridge->technology->name,
2189  bridge->v_table->name,
2190  bridge->uniqueid);
2191 
2192  if (!bridge_channel->just_joined) {
2193  /* Tell the bridge technology we are leaving so they tear us down */
2194  ast_debug(1, "Bridge %s: %p(%s) is leaving %s technology\n",
2195  bridge->uniqueid, bridge_channel, ast_channel_name(bridge_channel->chan),
2196  bridge->technology->name);
2197  if (bridge->technology->leave) {
2198  bridge->technology->leave(bridge, bridge_channel);
2199  }
2200  }
2201 
2202  /* Remove channel from the bridge */
2203  if (!bridge_channel->suspended) {
2204  --bridge->num_active;
2205  }
2207  --bridge->num_lonely;
2208  }
2209  --bridge->num_channels;
2210  AST_LIST_REMOVE(&bridge->channels, bridge_channel, entry);
2211 
2212  bridge_channel_dissolve_check(bridge_channel);
2213  bridge->v_table->pull(bridge, bridge_channel);
2214 
2215  ast_bridge_channel_clear_roles(bridge_channel);
2216 
2217  /* If we are not going to be hung up after leaving a bridge, and we were an
2218  * outgoing channel, clear the outgoing flag.
2219  */
2220  if (ast_test_flag(ast_channel_flags(bridge_channel->chan), AST_FLAG_OUTGOING)
2221  && (ast_channel_is_leaving_bridge(bridge_channel->chan)
2222  || bridge_channel->state == BRIDGE_CHANNEL_STATE_WAIT)) {
2223  ast_debug(2, "Channel %s will survive this bridge; clearing outgoing (dialed) flag\n", ast_channel_name(bridge_channel->chan));
2224  ast_channel_clear_flag(bridge_channel->chan, AST_FLAG_OUTGOING);
2225  }
2226 
2227  bridge->reconfigured = 1;
2228  ast_bridge_publish_leave(bridge, bridge_channel->chan);
2229 }
2230 
2231 int bridge_channel_internal_push_full(struct ast_bridge_channel *bridge_channel, int optimized)
2232 {
2233  struct ast_bridge *bridge = bridge_channel->bridge;
2234  struct ast_bridge_channel *swap;
2235 
2236  ast_assert(!bridge_channel->in_bridge);
2237 
2238  swap = bridge_find_channel(bridge, bridge_channel->swap);
2239  bridge_channel->swap = NULL;
2240 
2241  if (swap) {
2242  ast_debug(1, "Bridge %s: pushing %p(%s) by swapping with %p(%s)\n",
2243  bridge->uniqueid, bridge_channel, ast_channel_name(bridge_channel->chan),
2244  swap, ast_channel_name(swap->chan));
2245  } else {
2246  ast_debug(1, "Bridge %s: pushing %p(%s)\n",
2247  bridge->uniqueid, bridge_channel, ast_channel_name(bridge_channel->chan));
2248  }
2249 
2250  /* Add channel to the bridge */
2251  if (bridge->dissolved
2252  || bridge_channel->state != BRIDGE_CHANNEL_STATE_WAIT
2253  || (swap && swap->state != BRIDGE_CHANNEL_STATE_WAIT)
2254  || bridge->v_table->push(bridge, bridge_channel, swap)) {
2255  ast_debug(1, "Bridge %s: pushing %p(%s) into bridge failed\n",
2256  bridge->uniqueid, bridge_channel, ast_channel_name(bridge_channel->chan));
2257  return -1;
2258  }
2259 
2260  ast_bridge_channel_establish_roles(bridge_channel);
2261 
2262  if (swap) {
2264 
2265  /* This flag is cleared so the act of this channel leaving does not cause it to dissolve if need be */
2267 
2268  if (optimized) {
2270  }
2273 
2275  }
2276 
2277  bridge_channel->in_bridge = 1;
2278  bridge_channel->just_joined = 1;
2279  AST_LIST_INSERT_TAIL(&bridge->channels, bridge_channel, entry);
2280  ++bridge->num_channels;
2282  ++bridge->num_lonely;
2283  }
2284  if (!bridge_channel->suspended) {
2285  ++bridge->num_active;
2286  }
2287 
2288  ast_verb(3, "Channel %s %s%s%s '%s' %s-bridge <%s>\n",
2289  ast_channel_name(bridge_channel->chan),
2290  swap ? "swapped with " : "joined",
2291  swap ? ast_channel_name(swap->chan) : "",
2292  swap ? " into" : "",
2293  bridge->technology->name,
2294  bridge->v_table->name,
2295  bridge->uniqueid);
2296 
2297  ast_bridge_publish_enter(bridge, bridge_channel->chan, swap ? swap->chan : NULL);
2298 
2299  /* Clear any BLINDTRANSFER,ATTENDEDTRANSFER and FORWARDERNAME since the transfer has completed. */
2300  pbx_builtin_setvar_helper(bridge_channel->chan, "BLINDTRANSFER", NULL);
2301  pbx_builtin_setvar_helper(bridge_channel->chan, "ATTENDEDTRANSFER", NULL);
2302  pbx_builtin_setvar_helper(bridge_channel->chan, "FORWARDERNAME", NULL);
2303 
2304  /* Wake up the bridge channel thread to reevaluate any interval timers. */
2305  ast_queue_frame(bridge_channel->chan, &ast_null_frame);
2306 
2307  bridge->reconfigured = 1;
2308  return 0;
2309 }
2310 
2312 {
2313  return bridge_channel_internal_push_full(bridge_channel, 0);
2314 }
2315 
2316 /*!
2317  * \internal
2318  * \brief Handle bridge channel control frame action.
2319  * \since 12.0.0
2320  *
2321  * \param bridge_channel Channel to execute the control frame action on.
2322  * \param fr Control frame to handle.
2323  *
2324  * \return Nothing
2325  */
2326 static void bridge_channel_handle_control(struct ast_bridge_channel *bridge_channel, struct ast_frame *fr)
2327 {
2328  struct ast_channel *chan;
2329  struct ast_option_header *aoh;
2330  int is_caller;
2331 
2332  chan = bridge_channel->chan;
2333  switch (fr->subclass.integer) {
2335  is_caller = !ast_test_flag(ast_channel_flags(chan), AST_FLAG_OUTGOING);
2336  if (ast_channel_redirecting_sub(NULL, chan, fr, 1) &&
2337  ast_channel_redirecting_macro(NULL, chan, fr, is_caller, 1)) {
2338  ast_indicate_data(chan, fr->subclass.integer, fr->data.ptr, fr->datalen);
2339  }
2340  break;
2342  is_caller = !ast_test_flag(ast_channel_flags(chan), AST_FLAG_OUTGOING);
2343  if (ast_channel_connected_line_sub(NULL, chan, fr, 1) &&
2344  ast_channel_connected_line_macro(NULL, chan, fr, is_caller, 1)) {
2345  ast_indicate_data(chan, fr->subclass.integer, fr->data.ptr, fr->datalen);
2346  }
2347  break;
2348  case AST_CONTROL_OPTION:
2349  /*
2350  * Forward option Requests, but only ones we know are safe These
2351  * are ONLY sent by chan_iax2 and I'm not convinced that they
2352  * are useful. I haven't deleted them entirely because I just am
2353  * not sure of the ramifications of removing them.
2354  */
2355  aoh = fr->data.ptr;
2356  if (aoh && aoh->flag == AST_OPTION_FLAG_REQUEST) {
2357  switch (ntohs(aoh->option)) {
2359  case AST_OPTION_TDD:
2360  case AST_OPTION_RELAXDTMF:
2361  case AST_OPTION_AUDIO_MODE:
2363  case AST_OPTION_FAX_DETECT:
2364  ast_channel_setoption(chan, ntohs(aoh->option), aoh->data,
2365  fr->datalen - sizeof(*aoh), 0);
2366  break;
2367  default:
2368  break;
2369  }
2370  }
2371  break;
2372  case AST_CONTROL_ANSWER:
2373  if (ast_channel_state(chan) != AST_STATE_UP) {
2374  ast_answer(chan);
2375  ast_bridge_channel_lock_bridge(bridge_channel);
2376  bridge_channel->bridge->reconfigured = 1;
2377  bridge_reconfigured(bridge_channel->bridge, 0);
2378  ast_bridge_unlock(bridge_channel->bridge);
2379  } else {
2380  ast_indicate(chan, -1);
2381  }
2382  break;
2384  /* Should never happen. */
2385  ast_assert(0);
2386  break;
2388  ast_indicate_data(chan, fr->subclass.integer, fr->data.ptr, fr->datalen);
2389  break;
2390  default:
2391  ast_indicate_data(chan, fr->subclass.integer, fr->data.ptr, fr->datalen);
2392  break;
2393  }
2394 }
2395 
2396 /*!
2397  * \internal
2398  * \brief Ensure text data is zero terminated before sending
2399  *
2400  * \param chan Channel to send text to
2401  * \param f The frame containing the text data to send
2402  *
2403  * \return Nothing
2404  */
2405 static void sendtext_safe(struct ast_channel *chan, const struct ast_frame *f)
2406 {
2407  if (f->datalen) {
2408  char *text = f->data.ptr;
2409 
2410  if (text[f->datalen - 1]) {
2411  /* Not zero terminated, we need to allocate */
2412  text = ast_strndup(text, f->datalen);
2413  if (!text) {
2414  return;
2415  }
2416  }
2417 
2418  ast_sendtext(chan, text);
2419 
2420  if (text != f->data.ptr) {
2421  /* Only free if we allocated */
2422  ast_free(text);
2423  }
2424  } else {
2425  /* Special case if the frame length is zero (although I
2426  * am not sure this is possible?) */
2427  ast_sendtext(chan, "");
2428  }
2429 }
2430 
2431 /*!
2432  * \internal
2433  * \brief Handle bridge channel write frame to channel.
2434  * \since 12.0.0
2435  *
2436  * \param bridge_channel Channel to write outgoing frame.
2437  *
2438  * \return Nothing
2439  */
2440 static void bridge_channel_handle_write(struct ast_bridge_channel *bridge_channel)
2441 {
2442  struct ast_frame *fr;
2443  struct sync_payload *sync_payload;
2444  int num;
2445  struct ast_msg_data *msg;
2446 
2447  ast_bridge_channel_lock(bridge_channel);
2448 
2449  /* It's not good to have unbalanced frames and alert_pipe alerts. */
2450  ast_assert(!AST_LIST_EMPTY(&bridge_channel->wr_queue));
2451  if (AST_LIST_EMPTY(&bridge_channel->wr_queue)) {
2452  /* No frame, flush the alert pipe of excess alerts. */
2453  ast_log(LOG_WARNING, "Weird. No frame from bridge for %s to process?\n",
2454  ast_channel_name(bridge_channel->chan));
2455  ast_alertpipe_read(bridge_channel->alert_pipe);
2456  ast_bridge_channel_unlock(bridge_channel);
2457  return;
2458  }
2459 
2460  AST_LIST_TRAVERSE_SAFE_BEGIN(&bridge_channel->wr_queue, fr, frame_list) {
2461  if (bridge_channel->dtmf_hook_state.collected[0]) {
2462  switch (fr->frametype) {
2465  /* Defer processing these frames while DTMF is collected. */
2466  continue;
2467  default:
2468  break;
2469  }
2470  }
2471  ast_alertpipe_read(bridge_channel->alert_pipe);
2473  break;
2474  }
2476 
2477  ast_bridge_channel_unlock(bridge_channel);
2478 
2479  if (!fr) {
2480  /*
2481  * Wait some to reduce CPU usage from a tight loop
2482  * without any wait because we only have deferred
2483  * frames in the wr_queue.
2484  */
2485  usleep(1);
2486  return;
2487  }
2488 
2489  switch (fr->frametype) {
2491  bridge_channel_handle_action(bridge_channel, fr->subclass.integer, fr->data.ptr);
2492  break;
2494  sync_payload = fr->data.ptr;
2495  bridge_channel_handle_action(bridge_channel, fr->subclass.integer, sync_payload->data);
2496  break;
2497  case AST_FRAME_CONTROL:
2498  bridge_channel_handle_control(bridge_channel, fr);
2499  break;
2500  case AST_FRAME_NULL:
2501  break;
2502  case AST_FRAME_TEXT:
2503  ast_debug(1, "Sending TEXT frame to '%s': %*.s\n",
2504  ast_channel_name(bridge_channel->chan), fr->datalen, (char *)fr->data.ptr);
2505  sendtext_safe(bridge_channel->chan, fr);
2506  break;
2507  case AST_FRAME_TEXT_DATA:
2508  msg = (struct ast_msg_data *)fr->data.ptr;
2509  ast_debug(1, "Sending TEXT_DATA frame from '%s' to '%s:%s': %s\n",
2512  ast_channel_name(bridge_channel->chan),
2514  ast_sendtext_data(bridge_channel->chan, msg);
2515  break;
2516  default:
2517  /* Assume that there is no mapped stream for this */
2518  num = -1;
2519 
2520  if (fr->stream_num > -1) {
2521  ast_bridge_channel_lock(bridge_channel);
2522  if (fr->stream_num < (int)AST_VECTOR_SIZE(&bridge_channel->stream_map.to_channel)) {
2523  num = AST_VECTOR_GET(&bridge_channel->stream_map.to_channel, fr->stream_num);
2524  }
2525  ast_bridge_channel_unlock(bridge_channel);
2526 
2527  /* If there is no mapped stream after checking the mapping then there is nowhere
2528  * to write this frame to, so drop it.
2529  */
2530  if (num == -1) {
2531  break;
2532  }
2533  }
2534 
2535  /* Write the frame to the channel. */
2536  bridge_channel->activity = BRIDGE_CHANNEL_THREAD_SIMPLE;
2537  ast_write_stream(bridge_channel->chan, num, fr);
2538  break;
2539  }
2540  bridge_frame_free(fr);
2541 }
2542 
2543 /*! \brief Internal function to handle DTMF from a channel */
2544 static struct ast_frame *bridge_handle_dtmf(struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
2545 {
2546  struct ast_bridge_features *features = bridge_channel->features;
2547  struct ast_bridge_hook_dtmf *hook = NULL;
2548  char dtmf[2];
2549 
2550  /*
2551  * See if we are already matching a DTMF feature hook sequence or
2552  * if this DTMF matches the beginning of any DTMF feature hooks.
2553  */
2554  dtmf[0] = frame->subclass.integer;
2555  dtmf[1] = '\0';
2556  if (bridge_channel->dtmf_hook_state.collected[0]
2557  || (hook = ao2_find(features->dtmf_hooks, dtmf, OBJ_SEARCH_PARTIAL_KEY))) {
2558  enum ast_frame_type frametype = frame->frametype;
2559 
2560  bridge_frame_free(frame);
2561  frame = NULL;
2562 
2563  ao2_cleanup(hook);
2564 
2565  switch (frametype) {
2566  case AST_FRAME_DTMF_BEGIN:
2567  /* Just eat the frame. */
2568  break;
2569  case AST_FRAME_DTMF_END:
2570  ast_bridge_channel_feature_digit(bridge_channel, dtmf[0]);
2571  break;
2572  default:
2573  /* Unexpected frame type. */
2574  ast_assert(0);
2575  break;
2576  }
2577 #ifdef TEST_FRAMEWORK
2578  } else if (frame->frametype == AST_FRAME_DTMF_END) {
2579  /* Only transmit this event on DTMF end or else every DTMF
2580  * press will result in the event being broadcast twice
2581  */
2582  ast_test_suite_event_notify("FEATURE_DETECTION", "Result: fail");
2583 #endif
2584  }
2585 
2586  return frame;
2587 }
2588 
2589 static const char *controls[] = {
2590  [AST_CONTROL_RINGING] = "RINGING",
2591  [AST_CONTROL_PROCEEDING] = "PROCEEDING",
2592  [AST_CONTROL_PROGRESS] = "PROGRESS",
2593  [AST_CONTROL_BUSY] = "BUSY",
2594  [AST_CONTROL_CONGESTION] = "CONGESTION",
2595  [AST_CONTROL_ANSWER] = "ANSWER",
2596 };
2597 
2598 /*!
2599  * \internal
2600  * \brief Feed notification that a frame is waiting on a channel into the bridging core
2601  *
2602  * \param bridge_channel Bridge channel the notification was received on
2603  */
2604 static void bridge_handle_trip(struct ast_bridge_channel *bridge_channel)
2605 {
2606  struct ast_frame *frame;
2607  int blocked;
2608 
2609  if (!ast_strlen_zero(ast_channel_call_forward(bridge_channel->chan))) {
2610  /* TODO If early bridging is ever used by anything other than ARI,
2611  * it's important that we actually attempt to handle the call forward
2612  * attempt, as well as expand features on a bridge channel to allow/disallow
2613  * call forwarding. For now, all we do is raise an event, showing that
2614  * a call forward is being attempted.
2615  */
2616  ast_channel_publish_dial_forward(NULL, bridge_channel->chan, NULL, NULL, "CANCEL",
2617  ast_channel_call_forward(bridge_channel->chan));
2618  }
2619 
2620  if (bridge_channel->features->mute) {
2621  frame = ast_read_stream_noaudio(bridge_channel->chan);
2622  } else {
2623  frame = ast_read_stream(bridge_channel->chan);
2624  }
2625 
2626  if (!frame) {
2627  ast_bridge_channel_kick(bridge_channel, 0);
2628  return;
2629  }
2630 
2631  if (!ast_channel_is_multistream(bridge_channel->chan)) {
2632  /* This may not be initialized by non-multistream channel drivers */
2633  frame->stream_num = -1;
2634  }
2635 
2636  switch (frame->frametype) {
2637  case AST_FRAME_CONTROL:
2638  switch (frame->subclass.integer) {
2640  case AST_CONTROL_BUSY:
2641  ast_channel_publish_dial(NULL, bridge_channel->chan, NULL, controls[frame->subclass.integer]);
2642  break;
2643  case AST_CONTROL_HANGUP:
2644  ast_bridge_channel_kick(bridge_channel, 0);
2645  bridge_frame_free(frame);
2646  return;
2647  case AST_CONTROL_RINGING:
2648  case AST_CONTROL_PROGRESS:
2650  case AST_CONTROL_ANSWER:
2651  ast_channel_publish_dial(NULL, bridge_channel->chan, NULL, controls[frame->subclass.integer]);
2652  break;
2654  ast_bridge_channel_lock_bridge(bridge_channel);
2655  blocked = bridge_channel->bridge->technology->stream_topology_request_change
2656  && bridge_channel->bridge->technology->stream_topology_request_change(
2657  bridge_channel->bridge, bridge_channel);
2658  ast_bridge_unlock(bridge_channel->bridge);
2659  if (blocked) {
2660  /*
2661  * Topology change was intercepted by the bridge technology
2662  * so drop frame.
2663  */
2664  bridge_frame_free(frame);
2665  return;
2666  }
2667  break;
2669  /*
2670  * If a stream topology has changed then the bridge_channel's
2671  * media mapping needs to be updated.
2672  */
2673  ast_bridge_channel_lock_bridge(bridge_channel);
2674  if (bridge_channel->bridge->technology->stream_topology_changed) {
2675  bridge_channel->bridge->technology->stream_topology_changed(
2676  bridge_channel->bridge, bridge_channel);
2677  } else {
2678  ast_bridge_channel_stream_map(bridge_channel);
2679  }
2680  ast_bridge_unlock(bridge_channel->bridge);
2681  break;
2682  default:
2683  break;
2684  }
2685  break;
2686  case AST_FRAME_DTMF_BEGIN:
2687  case AST_FRAME_DTMF_END:
2688  frame = bridge_handle_dtmf(bridge_channel, frame);
2689  if (!frame) {
2690  return;
2691  }
2692  if (!bridge_channel->features->dtmf_passthrough) {
2693  bridge_frame_free(frame);
2694  return;
2695  }
2696  break;
2697  default:
2698  break;
2699  }
2700 
2701  /* Simply write the frame out to the bridge technology. */
2702  bridge_channel_write_frame(bridge_channel, frame);
2703  bridge_frame_free(frame);
2704 }
2705 
2706 /*!
2707  * \internal
2708  * \brief Determine how long till the next timer interval.
2709  * \since 12.0.0
2710  *
2711  * \param bridge_channel Channel to determine how long can wait.
2712  *
2713  * \retval ms Number of milliseconds to wait.
2714  * \retval -1 to wait forever.
2715  */
2716 static int bridge_channel_next_interval(struct ast_bridge_channel *bridge_channel)
2717 {
2718  struct ast_heap *interval_hooks = bridge_channel->features->interval_hooks;
2719  struct ast_bridge_hook_timer *hook;
2720  int ms;
2721 
2722  ast_heap_wrlock(interval_hooks);
2723  hook = ast_heap_peek(interval_hooks, 1);
2724  if (hook) {
2725  ms = ast_tvdiff_ms(hook->timer.trip_time, ast_tvnow());
2726  if (ms < 0) {
2727  /* Expire immediately. An interval hook is ready to run. */
2728  ms = 0;
2729  }
2730  } else {
2731  /* No hook so wait forever. */
2732  ms = -1;
2733  }
2734  ast_heap_unlock(interval_hooks);
2735 
2736  return ms;
2737 }
2738 
2739 /*!
2740  * \internal
2741  * \brief Determine how long till the DTMF interdigit timeout.
2742  * \since 12.8.0
2743  *
2744  * \param bridge_channel Channel to determine how long can wait.
2745  *
2746  * \retval ms Number of milliseconds to wait.
2747  * \retval -1 to wait forever.
2748  */
2749 static int bridge_channel_feature_timeout(struct ast_bridge_channel *bridge_channel)
2750 {
2751  int ms;
2752 
2753  if (bridge_channel->dtmf_hook_state.collected[0]) {
2754  ms = ast_tvdiff_ms(bridge_channel->dtmf_hook_state.interdigit_timeout,
2755  ast_tvnow());
2756  if (ms < 0) {
2757  /* Expire immediately. */
2758  ms = 0;
2759  }
2760  } else {
2761  /* Timer is not active so wait forever. */
2762  ms = -1;
2763  }
2764 
2765  return ms;
2766 }
2767 
2768 /*!
2769  * \internal
2770  * \brief Determine how long till a timeout.
2771  * \since 12.8.0
2772  *
2773  * \param bridge_channel Channel to determine how long can wait.
2774  *
2775  * \retval ms Number of milliseconds to wait.
2776  * \retval -1 to wait forever.
2777  */
2778 static int bridge_channel_next_timeout(struct ast_bridge_channel *bridge_channel)
2779 {
2780  int ms_interval;
2781  int ms;
2782 
2783  ms_interval = bridge_channel_next_interval(bridge_channel);
2784  ms = bridge_channel_feature_timeout(bridge_channel);
2785  if (ms < 0 || (0 <= ms_interval && ms_interval < ms)) {
2786  /* Interval hook timeout is next. */
2787  ms = ms_interval;
2788  }
2789 
2790  return ms;
2791 }
2792 
2793 /*!
2794  * \internal
2795  * \brief Wait for something to happen on the bridge channel and handle it.
2796  * \since 12.0.0
2797  *
2798  * \param bridge_channel Channel to wait.
2799  *
2800  * \note Each channel does writing/reading in their own thread.
2801  *
2802  * \return Nothing
2803  */
2804 static void bridge_channel_wait(struct ast_bridge_channel *bridge_channel)
2805 {
2806  int ms;
2807  int outfd;
2808  struct ast_channel *chan;
2809 
2810  /* Wait for data to either come from the channel or us to be signaled */
2811  ast_bridge_channel_lock(bridge_channel);
2812  if (bridge_channel->state != BRIDGE_CHANNEL_STATE_WAIT) {
2813  } else if (bridge_channel->suspended) {
2814 /* XXX ASTERISK-21271 the external party use of suspended will go away as will these references because this is the bridge channel thread */
2815  ast_debug(1, "Bridge %s: %p(%s) is going into a signal wait\n",
2816  bridge_channel->bridge->uniqueid, bridge_channel,
2817  ast_channel_name(bridge_channel->chan));
2818  ast_cond_wait(&bridge_channel->cond, ao2_object_get_lockaddr(bridge_channel));
2819  } else {
2820  ast_bridge_channel_unlock(bridge_channel);
2821  outfd = -1;
2822  ms = bridge_channel_next_timeout(bridge_channel);
2823  chan = ast_waitfor_nandfds(&bridge_channel->chan, 1,
2824  &bridge_channel->alert_pipe[0], 1, NULL, &outfd, &ms);
2825  if (ast_channel_unbridged(bridge_channel->chan)) {
2826  ast_channel_set_unbridged(bridge_channel->chan, 0);
2827  ast_bridge_channel_lock_bridge(bridge_channel);
2828  bridge_channel->bridge->reconfigured = 1;
2829  bridge_reconfigured(bridge_channel->bridge, 0);
2830  ast_bridge_unlock(bridge_channel->bridge);
2831  }
2832  ast_bridge_channel_lock(bridge_channel);
2833  bridge_channel->activity = BRIDGE_CHANNEL_THREAD_FRAME;
2834  ast_bridge_channel_unlock(bridge_channel);
2835  if (!bridge_channel->suspended
2836  && bridge_channel->state == BRIDGE_CHANNEL_STATE_WAIT) {
2837  if (chan) {
2838  bridge_handle_trip(bridge_channel);
2839  } else if (ms == 0) {
2840  /* An interdigit timeout or interval expired. */
2841  bridge_channel_handle_feature_timeout(bridge_channel);
2842  bridge_channel_handle_interval(bridge_channel);
2843  } else if (-1 < outfd) {
2844  /*
2845  * Must do this after checking timeouts or may have
2846  * an infinite loop due to deferring write queue
2847  * actions while trying to match DTMF feature hooks.
2848  */
2849  bridge_channel_handle_write(bridge_channel);
2850  }
2851  }
2852  bridge_channel->activity = BRIDGE_CHANNEL_THREAD_IDLE;
2853  return;
2854  }
2855  ast_bridge_channel_unlock(bridge_channel);
2856 }
2857 
2858 /*!
2859  * \internal
2860  * \brief Handle bridge channel join/leave event.
2861  * \since 12.0.0
2862  *
2863  * \param bridge_channel Which channel is involved.
2864  * \param type Specified join/leave event.
2865  *
2866  * \return Nothing
2867  */
2869 {
2870  struct ast_bridge_features *features = bridge_channel->features;
2871  struct ast_bridge_hook *hook;
2872  struct ao2_iterator iter;
2873 
2874  /* Run the specified hooks. */
2875  iter = ao2_iterator_init(features->other_hooks, 0);
2876  for (; (hook = ao2_iterator_next(&iter)); ao2_ref(hook, -1)) {
2877  if (hook->type == type) {
2878  break;
2879  }
2880  }
2881  if (hook) {
2882  /* Found the first specified hook to run. */
2883  bridge_channel_suspend(bridge_channel);
2884  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
2885  do {
2886  if (hook->type == type) {
2887  hook->callback(bridge_channel, hook->hook_pvt);
2888  ao2_unlink(features->other_hooks, hook);
2889  }
2890  ao2_ref(hook, -1);
2891  } while ((hook = ao2_iterator_next(&iter)));
2892  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCUPDATE);
2893  bridge_channel_unsuspend(bridge_channel);
2894  }
2895  ao2_iterator_destroy(&iter);
2896 }
2897 
2899 {
2900  int res = 0;
2901  uint8_t indicate_src_change = 0;
2902  struct ast_bridge_features *channel_features;
2903  struct ast_channel *swap;
2904 
2905  ast_debug(1, "Bridge %s: %p(%s) is joining\n",
2906  bridge_channel->bridge->uniqueid,
2907  bridge_channel, ast_channel_name(bridge_channel->chan));
2908 
2909  /*
2910  * Directly locking the bridge is safe here because nobody else
2911  * knows about this bridge_channel yet.
2912  */
2913  ast_bridge_lock(bridge_channel->bridge);
2914 
2915  ast_channel_lock(bridge_channel->chan);
2916 
2917  bridge_channel->read_format = ao2_bump(ast_channel_readformat(bridge_channel->chan));
2918  bridge_channel->write_format = ao2_bump(ast_channel_writeformat(bridge_channel->chan));
2919 
2920  /* Make sure we're still good to be put into a bridge */
2921  if (ast_channel_internal_bridge(bridge_channel->chan)
2922  || ast_test_flag(ast_channel_flags(bridge_channel->chan), AST_FLAG_ZOMBIE)) {
2923  ast_channel_unlock(bridge_channel->chan);
2924  ast_bridge_unlock(bridge_channel->bridge);
2925  ast_debug(1, "Bridge %s: %p(%s) failed to join Bridge\n",
2926  bridge_channel->bridge->uniqueid,
2927  bridge_channel,
2928  ast_channel_name(bridge_channel->chan));
2929  return -1;
2930  }
2931  ast_channel_internal_bridge_set(bridge_channel->chan, bridge_channel->bridge);
2932 
2933  /* Attach features requested by the channel */
2934  channel_features = ast_channel_feature_hooks_get(bridge_channel->chan);
2935  if (channel_features) {
2936  ast_bridge_features_merge(bridge_channel->features, channel_features);
2937  }
2938  ast_channel_unlock(bridge_channel->chan);
2939 
2940  /* Add the jitterbuffer if the channel requires it */
2941  ast_jb_enable_for_channel(bridge_channel->chan);
2942 
2943  if (!bridge_channel->bridge->callid) {
2944  bridge_channel->bridge->callid = ast_read_threadstorage_callid();
2945  }
2946 
2947  /* Take the swap channel ref from the bridge_channel struct. */
2948  swap = bridge_channel->swap;
2949 
2950  if (bridge_channel_internal_push(bridge_channel)) {
2951  int cause = bridge_channel->bridge->cause;
2952 
2953  ast_bridge_unlock(bridge_channel->bridge);
2954  ast_bridge_channel_kick(bridge_channel, cause);
2955  ast_bridge_channel_lock_bridge(bridge_channel);
2956  ast_bridge_features_remove(bridge_channel->features,
2958  bridge_channel_dissolve_check(bridge_channel);
2959  res = -1;
2960  }
2961  bridge_reconfigured(bridge_channel->bridge, !bridge_channel->inhibit_colp);
2962 
2963  if (bridge_channel->state == BRIDGE_CHANNEL_STATE_WAIT) {
2964  /*
2965  * Indicate a source change since this channel is entering the
2966  * bridge system only if the bridge technology is not MULTIMIX
2967  * capable. The MULTIMIX technology has already done it.
2968  */
2969  if (!(bridge_channel->bridge->technology->capabilities
2971  indicate_src_change = 1;
2972  }
2973 
2974  bridge_channel_impart_signal(bridge_channel->chan);
2975  ast_bridge_unlock(bridge_channel->bridge);
2976 
2977  /* Must release any swap ref after unlocking the bridge. */
2978  ao2_t_cleanup(swap, "Bridge push with swap successful");
2979  swap = NULL;
2980 
2981  if (indicate_src_change) {
2982  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCCHANGE);
2983  }
2984 
2986 
2987  while (bridge_channel->state == BRIDGE_CHANNEL_STATE_WAIT) {
2988  /* Wait for something to do. */
2989  bridge_channel_wait(bridge_channel);
2990  }
2991 
2992  /* Force a timeout on any accumulated DTMF hook digits. */
2993  ast_bridge_channel_feature_digit(bridge_channel, 0);
2994 
2996  ast_bridge_channel_lock_bridge(bridge_channel);
2997  }
2998 
2999  bridge_channel_internal_pull(bridge_channel);
3000  bridge_channel_settle_owed_events(bridge_channel->bridge, bridge_channel);
3001  bridge_reconfigured(bridge_channel->bridge, 1);
3002 
3003  /* Remove ourselves if we are the video source */
3004  ast_bridge_remove_video_src(bridge_channel->bridge, bridge_channel->chan);
3005 
3006  ast_bridge_unlock(bridge_channel->bridge);
3007 
3008  /* Must release any swap ref after unlocking the bridge. */
3009  ao2_t_cleanup(swap, "Bridge push with swap failed or exited immediately");
3010 
3011  /* Complete any active hold before exiting the bridge. */
3012  if (ast_channel_hold_state(bridge_channel->chan) == AST_CONTROL_HOLD) {
3013  ast_debug(1, "Channel %s simulating UNHOLD for bridge end.\n",
3014  ast_channel_name(bridge_channel->chan));
3015  ast_indicate(bridge_channel->chan, AST_CONTROL_UNHOLD);
3016  }
3017 
3018  /* Complete any partial DTMF digit before exiting the bridge. */
3019  if (ast_channel_sending_dtmf_digit(bridge_channel->chan)) {
3020  ast_channel_end_dtmf(bridge_channel->chan,
3021  ast_channel_sending_dtmf_digit(bridge_channel->chan),
3022  ast_channel_sending_dtmf_tv(bridge_channel->chan), "bridge end");
3023  }
3024 
3025  /* Complete any T.38 session before exiting the bridge. */
3026  if (ast_channel_is_t38_active(bridge_channel->chan)) {
3027  struct ast_control_t38_parameters t38_parameters = {
3029  };
3030 
3031  ast_debug(1, "Channel %s simulating T.38 terminate for bridge end.\n",
3032  ast_channel_name(bridge_channel->chan));
3034  &t38_parameters, sizeof(t38_parameters));
3035  }
3036 
3037  /* Indicate a source change since this channel is leaving the bridge system. */
3038  ast_indicate(bridge_channel->chan, AST_CONTROL_SRCCHANGE);
3039 
3040  /*
3041  * Wait for any dual redirect to complete.
3042  *
3043  * Must be done while "still in the bridge" for ast_async_goto()
3044  * to work right.
3045  */
3047  sched_yield();
3048  }
3049  ast_channel_lock(bridge_channel->chan);
3050  ast_channel_internal_bridge_set(bridge_channel->chan, NULL);
3051  ast_channel_unlock(bridge_channel->chan);
3052 
3053  ast_bridge_channel_restore_formats(bridge_channel);
3054 
3055  return res;
3056 }
3057 
3059  const char *exten, const char *context,
3060  transfer_channel_cb new_channel_cb, void *user_data)
3061 {
3062  RAII_VAR(struct ast_bridge_channel *, transferee_bridge_channel, NULL, ao2_cleanup);
3063  struct blind_transfer_data blind_data;
3064 
3065  ast_channel_lock(transferee);
3066  transferee_bridge_channel = ast_channel_get_bridge_channel(transferee);
3067  ast_channel_unlock(transferee);
3068 
3069  if (!transferee_bridge_channel) {
3070  return -1;
3071  }
3072 
3073  if (new_channel_cb) {
3074  new_channel_cb(transferee, user_data, AST_BRIDGE_TRANSFER_SINGLE_PARTY);
3075  }
3076 
3077  ast_copy_string(blind_data.exten, exten, sizeof(blind_data.exten));
3078  ast_copy_string(blind_data.context, context, sizeof(blind_data.context));
3079 
3080  return bridge_channel_queue_action_data(transferee_bridge_channel,
3081  BRIDGE_CHANNEL_ACTION_BLIND_TRANSFER, &blind_data, sizeof(blind_data));
3082 }
3083 
3085  struct ast_channel *unbridged_chan)
3086 {
3087  RAII_VAR(struct ast_bridge_channel *, transferee_bridge_channel, NULL, ao2_cleanup);
3088  char unbridged_chan_name[AST_CHANNEL_NAME];
3089 
3090  ast_channel_lock(transferee);
3091  transferee_bridge_channel = ast_channel_get_bridge_channel(transferee);
3092  ast_channel_unlock(transferee);
3093 
3094  if (!transferee_bridge_channel) {
3095  return -1;
3096  }
3097 
3098  ast_copy_string(unbridged_chan_name, ast_channel_name(unbridged_chan),
3099  sizeof(unbridged_chan_name));
3100 
3101  return bridge_channel_queue_action_data(transferee_bridge_channel,
3102  BRIDGE_CHANNEL_ACTION_ATTENDED_TRANSFER, unbridged_chan_name,
3103  sizeof(unbridged_chan_name));
3104 }
3105 
3107 {
3108  return bridge_channel->in_bridge
3109  && AST_LIST_EMPTY(&bridge_channel->wr_queue);
3110 }
3111 
3112 /* Destroy elements of the bridge channel structure and the bridge channel structure itself */
3113 static void bridge_channel_destroy(void *obj)
3114 {
3115  struct ast_bridge_channel *bridge_channel = obj;
3116  struct ast_frame *fr;
3117 
3118  if (bridge_channel->callid) {
3119  bridge_channel->callid = 0;
3120  }
3121 
3122  if (bridge_channel->bridge) {
3123  ao2_ref(bridge_channel->bridge, -1);
3124  bridge_channel->bridge = NULL;
3125  }
3126 
3127  /* Flush any unhandled wr_queue frames. */
3128  while ((fr = AST_LIST_REMOVE_HEAD(&bridge_channel->wr_queue, frame_list))) {
3129  bridge_frame_free(fr);
3130  }
3131  ast_alertpipe_close(bridge_channel->alert_pipe);
3132 
3133  /* Flush any unhandled deferred_queue frames. */
3134  while ((fr = AST_LIST_REMOVE_HEAD(&bridge_channel->deferred_queue, frame_list))) {
3135  ast_frfree(fr);
3136  }
3137 
3138  ast_cond_destroy(&bridge_channel->cond);
3139 
3140  ao2_cleanup(bridge_channel->write_format);
3141  ao2_cleanup(bridge_channel->read_format);
3142 
3143  AST_VECTOR_FREE(&bridge_channel->stream_map.to_bridge);
3144  AST_VECTOR_FREE(&bridge_channel->stream_map.to_channel);
3145 }
3146 
3148 {
3149  struct ast_bridge_channel *bridge_channel;
3150 
3151  bridge_channel = ao2_alloc(sizeof(struct ast_bridge_channel), bridge_channel_destroy);
3152  if (!bridge_channel) {
3153  return NULL;
3154  }
3155  ast_cond_init(&bridge_channel->cond, NULL);
3156  if (ast_alertpipe_init(bridge_channel->alert_pipe)) {
3157  ao2_ref(bridge_channel, -1);
3158  return NULL;
3159  }
3160  if (bridge) {
3161  bridge_channel->bridge = bridge;
3162  ao2_ref(bridge_channel->bridge, +1);
3163  }
3164 
3165  /* The stream_map is initialized later - see ast_bridge_channel_stream_map */
3166 
3167  return bridge_channel;
3168 }
3169 
3171 {
3172  ast_bridge_channel_lock(bridge_channel);
3173  ast_channel_lock(bridge_channel->chan);
3175  &bridge_channel->bridge->media_types, &bridge_channel->stream_map.to_bridge,
3176  &bridge_channel->stream_map.to_channel);
3177  ast_channel_unlock(bridge_channel->chan);
3178  ast_bridge_channel_unlock(bridge_channel);
3179 }
static void bridge_channel_handle_control(struct ast_bridge_channel *bridge_channel, struct ast_frame *fr)
struct stasis_message_type * ast_channel_hold_type(void)
Message type for when a channel is placed on hold.
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
void ast_bridge_publish_leave(struct ast_bridge *bridge, struct ast_channel *chan)
Publish a bridge channel leave event.
ast_bridge_custom_play_fn custom_play
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
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:904
#define PLAYBACK_TIMEOUT
Failsafe for synchronous bridge action waiting.
static const char type[]
Definition: chan_ooh323.c:109
void ast_party_connected_line_init(struct ast_party_connected_line *init)
Initialize the given connected line structure.
Definition: channel.c:2008
char digit
#define ast_channel_lock(chan)
Definition: channel.h:2890
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
struct bridge_sync::@348 list
Music on hold handling.
enum bridge_channel_thread_state activity
The bridge channel thread activity.
int ast_connected_line_build_data(unsigned char *data, size_t datalen, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Build the connected line information data frame.
Definition: channel.c:8646
#define ast_frdup(fr)
Copies a frame.
int ast_bridge_queue_everyone_else(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
Queue the given frame to everyone else.
#define ao2_t_cleanup(obj, tag)
Definition: astobj2.h:1959
int ast_channel_hold_state(const struct ast_channel *chan)
struct ast_sem sem
Feature configuration relating to transfers.
void ast_bridge_channel_clear_roles(struct ast_bridge_channel *bridge_channel)
Clear all roles from a bridge_channel&#39;s role list.
Definition: bridge_roles.c:495
int ast_sem_destroy(struct ast_sem *sem)
Destroy a semaphore.
Asterisk main include file. File version handling, generic pbx functions.
struct ast_flags feature_flags
Definition: bridge.h:373
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
static int bridge_channel_write_frame(struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
const ast_string_field uniqueid
Definition: bridge.h:405
int ast_channel_connected_line_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *connected_info, int is_caller, int frame)
Run a connected line interception macro and update a channel&#39;s connected line information.
Definition: channel.c:10288
static void bridge_channel_blind_transfer(struct ast_bridge_channel *bridge_channel, struct blind_transfer_data *blind_data)
struct ast_bridge_features * features
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:296
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static void bridge_channel_do_callback(struct ast_bridge_channel *bridge_channel, struct bridge_custom_callback *data)
int(* ast_bridge_talking_indicate_callback)(struct ast_bridge_channel *bridge_channel, void *hook_pvt, int talking)
Talking indicator callback.
struct stasis_message_type * ast_channel_unhold_type(void)
Message type for when a channel is removed from hold.
unsigned int num_active
Definition: bridge.h:379
int ast_channel_is_multistream(struct ast_channel *chan)
Determine if a channel is multi-stream capable.
static int bridge_channel_write_action_data(struct ast_bridge_channel *bridge_channel, enum bridge_channel_action_type action, const void *data, size_t datalen)
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
int bridge_channel_internal_join(struct ast_bridge_channel *bridge_channel)
int(* ast_bridge_channel_post_action_data)(struct ast_bridge_channel *bridge_channel, enum bridge_channel_action_type action, const void *data, size_t datalen)
Used to queue an action frame onto a bridge channel and write an action frame into a bridge...
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
Definition: linkedlists.h:332
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition: pbx_app.c:471
unsigned int option_dtmfminduration
Definition: options.c:83
struct ast_stream_topology * ast_channel_get_stream_topology(const struct ast_channel *chan)
Retrieve the topology of streams on a channel.
bridge_channel_state
State information about a bridged channel.
static void bridge_channel_wait(struct ast_bridge_channel *bridge_channel)
void bridge_channel_internal_suspend_nolock(struct ast_bridge_channel *bridge_channel)
void ast_bridge_vars_set(struct ast_channel *chan, const char *name, const char *pvtid)
Sets BRIDGECHANNEL and BRIDGEPVTCALLID for a channel.
Definition: bridge.c:1242
Call Parking API.
static void bridge_channel_update_accountcodes_leaving(struct ast_bridge_channel *leaving)
void ast_party_id_reset(struct ast_party_id *id)
Destroy and initialize the given party id structure.
Definition: channel.c:1882
Structure that contains features information.
int bridge_channel_internal_push(struct ast_bridge_channel *bridge_channel)
struct ast_bridge_channel::@224 wr_queue
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2926
#define ast_set2_flag(p, value, flag)
Definition: utils.h:94
#define ast_test_flag(p, flag)
Definition: utils.h:63
char ast_channel_sending_dtmf_digit(const struct ast_channel *chan)
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4291
void(* suspend)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
Suspend a channel on a bridging technology instance for a bridge.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
void ast_channel_publish_cached_blob(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
Publish a channel blob message using the latest snapshot from the cache.
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...
#define ast_heap_unlock(h)
Definition: heap.h:248
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
const char * name
Definition: bridge.h:263
void ast_bridge_channel_leave_bridge(struct ast_bridge_channel *bridge_channel, enum bridge_channel_state new_state, int cause)
Set bridge channel state to leave bridge (if not leaving already).
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
Configuration for the builtin features.
int ast_sem_post(struct ast_sem *sem)
Increments the semaphore, unblocking a waiter if necessary.
int ast_check_hangup_locked(struct ast_channel *chan)
Definition: channel.c:455
int(* stream_topology_request_change)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
Callback for when a request has been made to change a stream topology on a channel.
#define LOG_WARNING
Definition: logger.h:274
static void channel_fill_empty_accountcode(struct ast_channel *dest, struct ast_channel *src)
ast_callid callid
Definition: bridge.h:365
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
union ast_frame::@257 data
static void channel_set_empty_accountcodes(struct ast_channel *c0, struct ast_channel *c1)
unsigned int dissolved
Definition: bridge.h:394
unsigned int id
unsigned int reconfigured
Definition: bridge.h:392
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int ast_sem_timedwait(struct ast_sem *sem, const struct timespec *abs_timeout)
Decrements the semaphore, waiting until abs_timeout.
static int bridge_channel_next_interval(struct ast_bridge_channel *bridge_channel)
static int payload_helper_playfile(ast_bridge_channel_post_action_data post_it, struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
#define AST_LOG_WARNING
Definition: logger.h:279
static void sendtext_safe(struct ast_channel *chan, const struct ast_frame *f)
static int run_app_helper(struct ast_channel *chan, const char *app_name, const char *app_args)
void ast_bridge_channel_restore_formats(struct ast_bridge_channel *bridge_channel)
Restore the formats of a bridge channel&#39;s channel to how they were before bridge_channel_internal_joi...
enum bridge_channel_state state
static void channel_update_peeraccount(struct ast_channel *dest, struct ast_channel *src)
unsigned int suspended
struct ast_bridge_hook generic
static void bridge_sync_wait(struct bridge_sync *sync_struct)
Wait for a synchronous bridge action to complete.
void ast_channel_clear_flag(struct ast_channel *chan, unsigned int flag)
Definition: channel.c:11085
struct ast_features_xfer_config * ast_get_chan_features_xfer_config(struct ast_channel *chan)
Get the transfer configuration options for a channel.
static void bridge_sync_init(struct bridge_sync *sync_struct, unsigned int id)
initialize a synchronous bridge object.
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
Test Framework API.
struct ast_channel * ast_bridge_channel_get_chan(struct ast_bridge_channel *bridge_channel)
Get a ref to the bridge_channel&#39;s ast_channel.
Definition: heap.c:36
enum ast_control_t38 request_response
int ast_bridge_channel_write_app(struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class)
Write a bridge action run application frame into the bridge.
struct ast_bridge_channel * bridge_channel_internal_alloc(struct ast_bridge *bridge)
struct ast_frame * ast_read_stream(struct ast_channel *chan)
Reads a frame, but does not filter to just the default streams.
Definition: channel.c:4276
static void bridge_channel_event_join_leave(struct ast_bridge_channel *bridge_channel, enum ast_bridge_hook_type type)
Structure used to transport a message through the frame core.
Definition: message.c:1369
ast_channel_state
ast_channel states
Definition: channelstate.h:35
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:4667
void(* stream_topology_changed)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
Callback for when a stream topology changes on the channel.
void(* ast_bridge_custom_callback_fn)(struct ast_bridge_channel *bridge_channel, const void *payload, size_t payload_size)
Custom callback run on a bridge channel.
struct ao2_container * dtmf_hooks
static void bridge_channel_dissolve_check(struct ast_bridge_channel *bridge_channel)
static void bridge_channel_run_app(struct ast_bridge_channel *bridge_channel, struct bridge_run_app *data)
static int bridge_channel_queue_action_data(struct ast_bridge_channel *bridge_channel, enum bridge_channel_action_type action, const void *data, size_t datalen)
int bridge_channel_internal_queue_blind_transfer(struct ast_channel *transferee, const char *exten, const char *context, transfer_channel_cb new_channel_cb, void *user_data)
#define ast_cond_wait(cond, mutex)
Definition: lock.h:203
#define ast_cond_init(cond, attr)
Definition: lock.h:199
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
void ast_bridge_channel_feature_digit(struct ast_bridge_channel *bridge_channel, int digit)
Add a DTMF digit to the collected digits to match against DTMF features.
ast_control_frame_type
Internal control frame subtype field values.
General features configuration items.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
static void bridge_channel_talking(struct ast_bridge_channel *bridge_channel, int talking)
struct ast_bridge * ast_channel_internal_bridge(const struct ast_channel *chan)
int ast_bridge_channel_queue_frame(struct ast_bridge_channel *bridge_channel, struct ast_frame *fr)
Write a frame to the specified bridge_channel.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
#define ast_assert(a)
Definition: utils.h:650
#define ao2_unlock(a)
Definition: astobj2.h:730
struct ast_bridge_channel * ast_bridge_channel_peer(struct ast_bridge_channel *bridge_channel)
Get the peer bridge channel of a two party bridge.
char * text
Definition: app_queue.c:1511
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:98
int ast_sendtext_data(struct ast_channel *chan, struct ast_msg_data *msg)
Sends text to a channel in an ast_msg_data structure wrapper with ast_sendtext as fallback...
Definition: channel.c:4765
#define AST_OPTION_TDD
void ast_party_connected_line_free(struct ast_party_connected_line *doomed)
Destroy the connected line information contents.
Definition: channel.c:2058
static void bridge_handle_trip(struct ast_bridge_channel *bridge_channel)
struct ast_bridge_channel * bridge_find_channel(struct ast_bridge *bridge, struct ast_channel *chan)
Definition: bridge.c:1469
static const char * controls[]
#define NULL
Definition: resample.c:96
int ast_bridge_channel_queue_app(struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class)
Queue a bridge action run application frame onto the bridge channel.
static int payload_helper_park(ast_bridge_channel_post_action_data post_it, struct ast_bridge_channel *bridge_channel, const char *parkee_uuid, const char *parker_uuid, const char *app_data)
int ast_channel_move(struct ast_channel *dest, struct ast_channel *source)
Move a channel from its current location to a new location.
Definition: channel.c:10720
Out-of-call text message support.
int ast_bridge_channel_establish_roles(struct ast_bridge_channel *bridge_channel)
Clone the roles from a bridge_channel&#39;s attached ast_channel onto the bridge_channel&#39;s role list...
Definition: bridge_roles.c:447
#define AST_LIST_REMOVE(head, elm, field)
Removes a specific entry from a list.
Definition: linkedlists.h:855
#define LOG_DEBUG
Definition: logger.h:241
char collected[MAXIMUM_DTMF_FEATURE_STRING]
int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block)
Sets an option on a channel.
Definition: channel.c:7381
int ast_bridge_channel_queue_playfile(struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
Queue a bridge action play file frame onto the bridge channel.
int ast_bridge_channel_write_control_data(struct ast_bridge_channel *bridge_channel, enum ast_control_frame_type control, const void *data, size_t datalen)
Write a control frame into the bridge with data.
int ast_bridge_channel_write_callback(struct ast_bridge_channel *bridge_channel, enum ast_bridge_channel_custom_callback_option flags, ast_bridge_custom_callback_fn callback, const void *payload, size_t payload_size)
Write a bridge action custom callback frame into the bridge.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
const char * ast_channel_call_forward(const struct ast_channel *chan)
#define ast_cond_signal(cond)
Definition: lock.h:201
struct ast_channel * ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms)
Waits for activity on a group of channels.
Definition: channel.c:2983
ast_bridge_custom_callback_fn callback
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:259
#define ast_verb(level,...)
Definition: logger.h:455
void ast_bridge_channel_stream_map(struct ast_bridge_channel *bridge_channel)
Maps a channel&#39;s stream topology to and from the bridge.
int ast_write_stream(struct ast_channel *chan, int stream_num, struct ast_frame *frame)
Write a frame to a stream This function writes the given frame to the indicated stream on the channel...
Definition: channel.c:5093
int ast_bridge_channel_queue_callback(struct ast_bridge_channel *bridge_channel, enum ast_bridge_channel_custom_callback_option flags, ast_bridge_custom_callback_fn callback, const void *payload, size_t payload_size)
Queue a bridge action custom callback frame onto the bridge channel.
int ast_atomic_fetchadd_int(volatile int *p, int v)
Atomically add v to *p and return the previous value of *p.
Definition: lock.h:755
struct timeval dtmf_tv
static void bridge_channel_dtmf_stream(struct ast_bridge_channel *bridge_channel, const char *dtmf)
Internal function that plays back DTMF on a bridge channel.
struct ast_vector_int to_bridge
struct ast_bridge * bridge
Bridge this channel is participating in.
struct ast_frame_subclass subclass
Media Stream API.
ast_callid ast_read_threadstorage_callid(void)
extracts the callerid from the thread
Definition: logger.c:1922
Frame payload for synchronous bridge actions.
void ast_alertpipe_close(int alert_pipe[2])
Close an alert pipe.
Definition: alertpipe.c:79
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
Asterisk semaphore API.
ast_bridge_after_cb_reason
Definition: bridge_after.h:37
ssize_t ast_alertpipe_write(int alert_pipe[2])
Write an event to an alert pipe.
Definition: alertpipe.c:120
#define ao2_bump(obj)
Definition: astobj2.h:491
Data specifying where a blind transfer is going to.
void * ao2_object_get_lockaddr(void *obj)
Return the mutex lock address of an object.
Definition: astobj2.c:476
struct ast_features_general_config * ast_get_chan_features_general_config(struct ast_channel *chan)
Get the general configuration options for a channel.
struct ast_bridge_technology * technology
Definition: bridge.h:359
struct ast_flags feature_flags
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
unsigned int text_messaging
void ast_bridge_remove_video_src(struct ast_bridge *bridge, struct ast_channel *chan)
remove a channel as a source of video for the bridge.
Definition: bridge.c:3975
int ast_bridge_channel_write_unhold(struct ast_bridge_channel *bridge_channel)
Write an unhold frame into the bridge.
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:444
Max Heap data structure.
#define ast_log
Definition: astobj2.c:42
int ast_bridge_channel_notify_talking(struct ast_bridge_channel *bridge_channel, int started_talking)
Lets the bridging indicate when a bridge channel has stopped or started talking.
void(* leave)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
Remove a channel from a bridging technology instance for a bridge.
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1120
#define ast_heap_push(h, elm)
Definition: heap.h:126
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
#define ast_bridge_channel_lock(bridge_channel)
Lock the bridge_channel.
void ast_bridge_channel_leave_bridge_nolock(struct ast_bridge_channel *bridge_channel, enum bridge_channel_state new_state, int cause)
Set bridge channel state to leave bridge (if not leaving already).
static void bridge_channel_handle_interval(struct ast_bridge_channel *bridge_channel)
void ast_channel_queue_connected_line_update(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update)
Queue a connected line update frame on a channel.
Definition: channel.c:9055
enum ast_bridge_hook_type type
const char * ast_channel_latest_musicclass(const struct ast_channel *chan)
General Asterisk PBX channel definitions.
ast_bridge_hook_type
const char * ast_channel_accountcode(const struct ast_channel *chan)
const char * src
void ast_jb_enable_for_channel(struct ast_channel *chan)
Sets a jitterbuffer frame hook on the channel based on the channel&#39;s stored jitterbuffer configuratio...
Definition: abstract_jb.c:585
void ast_bridge_channel_kick(struct ast_bridge_channel *bridge_channel, int cause)
Kick the channel out of the bridge.
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
Definition: channel.c:5744
#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:851
#define AST_OPTION_RELAXDTMF
void ast_channel_internal_bridge_set(struct ast_channel *chan, struct ast_bridge *value)
int(* write)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
Write a frame into the bridging technology instance for a bridge.
void bridge_reconfigured(struct ast_bridge *bridge, unsigned int colp_update)
Definition: bridge.c:1443
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
static int channel_set_cause(struct ast_channel *chan, int cause)
void(* ast_bridge_custom_play_fn)(struct ast_bridge_channel *bridge_channel, const char *playfile)
Custom interpretation of the playfile name.
#define AST_MAX_EXTENSION
Definition: channel.h:135
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
int ast_channel_redirecting_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *redirecting_info, int is_frame)
Run a redirecting interception subroutine and update a channel&#39;s redirecting information.
Definition: channel.c:10437
static unsigned int bridge_channel_feature_digit_timeout(struct ast_bridge_channel *bridge_channel)
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
#define ao2_ref(o, delta)
Definition: astobj2.h:464
int ast_softhangup(struct ast_channel *chan, int reason)
Softly hangup up a channel.
Definition: channel.c:2462
#define ao2_lock(a)
Definition: astobj2.h:718
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:238
Private Bridging Channel API.
struct ast_frame * ast_read_stream_noaudio(struct ast_channel *chan)
Reads a frame, but does not filter to just the default streams, returning AST_FRAME_NULL frame if aud...
Definition: channel.c:4286
struct ast_bridge_hook_dtmf_parms dtmf
void ast_bridge_channel_update_linkedids(struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap)
char parkee_uuid[0]
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
int ast_alertpipe_init(int alert_pipe[2])
Initialize an alert pipe.
Definition: alertpipe.c:38
void bridge_channel_queue_deferred_frames(struct ast_bridge_channel *bridge_channel)
void ast_bridge_channel_run_app(struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class)
Run an application on the bridge channel.
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Definition: channel.c:5785
struct timeval interdigit_timeout
static void bridge_channel_destroy(void *obj)
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
int ast_app_exec_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const char *macro_args)
Run a macro on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:273
int ast_channel_is_t38_active(struct ast_channel *chan)
This function will check if T.38 is active on the channel.
unsigned int just_joined
static int sync_ids
Counter used for assigning synchronous bridge action IDs.
Core PBX routines and definitions.
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel&#39;s frame queue.
Definition: channel.c:1135
int ast_channel_is_leaving_bridge(struct ast_channel *chan)
Determine if a channel is leaving a bridge, but not hung up.
Definition: channel.c:10604
struct ast_heap * interval_hooks
static void bridge_channel_suspend(struct ast_bridge_channel *bridge_channel)
void ast_bridge_channel_feature_digit_add(struct ast_bridge_channel *bridge_channel, int digit)
Add a DTMF digit to the collected digits.
struct ast_format * write_format
int bridge_channel_internal_push_full(struct ast_bridge_channel *bridge_channel, int optimized)
#define ast_test_suite_event_notify(s, f,...)
Definition: test.h:196
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
ast_frame_type
Frame types.
void ast_bridge_features_merge(struct ast_bridge_features *into, const struct ast_bridge_features *from)
Merge one ast_bridge_features into another.
Definition: bridge.c:3662
#define ast_bridge_channel_unlock(bridge_channel)
Unlock the bridge_channel.
const struct ast_bridge_methods * v_table
Definition: bridge.h:355
static void after_bridge_move_channel_fail(enum ast_bridge_after_cb_reason reason, void *data)
unsigned int dtmf_passthrough
struct ast_vector_int to_channel
#define AST_OPTION_DIGIT_DETECT
Structure that contains information about a bridge.
Definition: bridge.h:353
#define LOG_ERROR
Definition: logger.h:285
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
ast_alert_status_t ast_alertpipe_read(int alert_pipe[2])
Read an event from an alert pipe.
Definition: alertpipe.c:102
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
void bridge_merge_inhibit_nolock(struct ast_bridge *bridge, int request)
Definition: bridge.c:3052
struct ast_bridge_channel::@225 deferred_queue
unsigned int num_lonely
Definition: bridge.h:381
#define ao2_unlink(container, obj)
Definition: astobj2.h:1598
List holding active synchronous action objects.
int ast_channel_connected_line_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const void *connected_info, int frame)
Run a connected line interception subroutine and update a channel&#39;s connected line information...
Definition: channel.c:10392
#define AST_DIGIT_NONE
Definition: file.h:47
ast_bridge_hook_callback callback
void bridge_channel_internal_pull(struct ast_bridge_channel *bridge_channel)
const char * ast_msg_data_get_attribute(struct ast_msg_data *msg, enum ast_msg_data_attribute_type attribute_type)
Get attribute from ast_msg_data.
Definition: message.c:1496
static int payload_helper_app(ast_bridge_channel_post_action_data post_it, struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class)
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2283
Connected Line/Party information.
Definition: channel.h:457
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:7725
struct sla_ringing_trunk * first
Definition: app_meetme.c:1092
static void after_bridge_move_channel(struct ast_channel *chan_bridged, void *data)
#define ast_strndup(str, len)
A wrapper for strndup()
Definition: astmm.h:258
enum ast_frame_read_action action
const char * app_name(struct ast_app *app)
Definition: pbx_app.c:463
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
#define ast_cond_destroy(cond)
Definition: lock.h:200
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
#define AST_LIST_LAST(head)
Returns the last entry contained in a list.
Definition: linkedlists.h:428
struct ast_format * read_format
void ast_bridge_publish_enter(struct ast_bridge *bridge, struct ast_channel *chan, struct ast_channel *swap)
Publish a bridge channel enter event.
static void bridge_channel_poke(struct ast_bridge_channel *bridge_channel)
void ast_channel_publish_dial_forward(struct ast_channel *caller, struct ast_channel *peer, struct ast_channel *forwarded, const char *dialstring, const char *dialstatus, const char *forward)
Publish in the ast_channel_topic or ast_channel_topic_all topics a stasis message for the channels in...
int ast_bridge_channel_write_playfile(struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
Write a bridge action play file frame into the bridge.
const char * ast_channel_peeraccount(const struct ast_channel *chan)
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:409
#define ast_strlen_zero(a)
Definition: muted.c:73
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
unsigned int in_bridge
struct ast_bridge_features * ast_channel_feature_hooks_get(struct ast_channel *chan)
Gets the channel-attached features a channel has access to upon being bridged.
Definition: channel.c:10954
int ast_parking_provider_registered(void)
Check whether a parking provider is registered.
Definition: parking.c:241
#define ast_channel_unlock(chan)
Definition: channel.h:2891
#define ast_bridge_unlock(bridge)
Unlock the bridge.
Definition: bridge.h:489
#define AST_MAX_CONTEXT
Definition: channel.h:136
static void bridge_channel_attended_transfer(struct ast_bridge_channel *bridge_channel, const char *target_chan_name)
#define ast_free(a)
Definition: astmm.h:182
static void channel_fill_empty_peeraccount(struct ast_channel *dest, struct ast_channel *src)
unsigned int inhibit_colp
#define AST_CHANNEL_NAME
Definition: channel.h:172
int bridge_channel_internal_queue_attended_transfer(struct ast_channel *transferee, struct ast_channel *unbridged_chan)
int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *digits)
stream file until digit If the file name is non-empty, try to play it.
Definition: file.c:1813
#define AST_OPTION_AUDIO_MODE
struct ast_bridge_hook_timer_parms timer
int ast_sem_init(struct ast_sem *sem, int pshared, unsigned int value)
Initialize a semaphore.
int ast_bridge_channel_write_park(struct ast_bridge_channel *bridge_channel, const char *parkee_uuid, const char *parker_uuid, const char *app_data)
Have a bridge channel park a channel in the bridge.
int ast_parking_park_bridge_channel(struct ast_bridge_channel *parkee, const char *parkee_uuid, const char *parker_uuid, const char *app_data)
Perform a direct park on a channel in a bridge.
Definition: parking.c:126
void ast_channel_end_dtmf(struct ast_channel *chan, char digit, struct timeval start, const char *why)
Simulate a DTMF end on a broken bridge channel.
Definition: channel.c:10920
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
static int request(void *obj)
Definition: chan_pjsip.c:2641
struct ast_channel * swap
void ast_bridge_features_remove(struct ast_bridge_features *features, enum ast_bridge_hook_remove_flags flags)
Remove marked bridge channel feature hooks.
Definition: bridge.c:3568
static void bridge_channel_cancel_owed_events(struct ast_bridge_channel *bridge_channel)
struct ast_bridge * ast_bridge_channel_merge_inhibit(struct ast_bridge_channel *bridge_channel, int request)
Adjust the bridge_channel&#39;s bridge merge inhibit request count.
struct ast_bridge_hook generic
#define ast_clear_flag(p, flag)
Definition: utils.h:77
int cause
Definition: bridge.h:390
void bridge_channel_internal_unsuspend_nolock(struct ast_bridge_channel *bridge_channel)
struct ast_bridge_channel * ast_channel_get_bridge_channel(struct ast_channel *chan)
Get a reference to the channel&#39;s bridge pointer.
Definition: channel.c:10636
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...
static void bridge_channel_handle_write(struct ast_bridge_channel *bridge_channel)
#define ast_bridge_lock(bridge)
Lock the bridge.
Definition: bridge.h:476
struct ast_frame ast_null_frame
Definition: main/frame.c:79
struct timeval ast_channel_sending_dtmf_tv(const struct ast_channel *chan)
void ast_channel_internal_copy_linkedid(struct ast_channel *dest, struct ast_channel *source)
Copy the full linkedid channel id structure from one channel to another.
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2897
#define LOG_DTMF
Definition: logger.h:307
struct ast_bridge_channels_list channels
Definition: bridge.h:367
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:740
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
void bridge_dissolve(struct ast_bridge *bridge, int cause)
Definition: bridge.c:319
struct ast_channel * chan
void * ast_heap_remove(struct ast_heap *h, void *elm)
Remove a specific element from a heap.
Definition: heap.c:251
Structure that contains information regarding a channel in a bridge.
void ast_party_connected_line_copy(struct ast_party_connected_line *dest, const struct ast_party_connected_line *src)
Copy the source connected line information to the destination connected line.
Definition: channel.c:2017
#define AST_OPTION_FAX_DETECT
After Bridge Execution API.
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2915
Definition: sem.h:81
void bridge_channel_impart_signal(struct ast_channel *chan)
Signal imparting threads to wake up.
Definition: bridge.c:1626
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static void bridge_channel_park(struct ast_bridge_channel *bridge_channel, struct bridge_park *payload)
int ast_channel_hangupcause(const struct ast_channel *chan)
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
bridge_channel_action_type
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:8242
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
ast_app: A registered application
Definition: pbx_app.c:45
struct ao2_container * other_hooks
int ast_bridge_channel_write_hold(struct ast_bridge_channel *bridge_channel, const char *moh_class)
Write a hold frame into the bridge.
const char * ast_channel_name(const struct ast_channel *chan)
static void testsuite_notify_feature_success(struct ast_channel *chan, const char *dtmf)
void ast_bridge_channel_update_accountcodes(struct ast_bridge_channel *joining, struct ast_bridge_channel *leaving)
static int payload_helper_cb(ast_bridge_channel_post_action_data post_it, struct ast_bridge_channel *bridge_channel, enum ast_bridge_channel_custom_callback_option flags, ast_bridge_custom_callback_fn callback, const void *payload, size_t payload_size)
char exten[AST_MAX_EXTENSION]
static int bridge_channel_write_dtmf_stream(struct ast_bridge_channel *bridge_channel, const char *dtmf)
static int bridge_channel_queue_action_data_sync(struct ast_bridge_channel *bridge_channel, enum bridge_channel_action_type action, const void *data, size_t datalen)
int ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
Set the channel to next execute the specified dialplan location.
Definition: pbx.c:7011
#define ast_frfree(fr)
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:2800
int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen)
Queue a control frame with payload.
Definition: channel.c:1234
struct ast_vector_int media_types
Definition: bridge.h:408
int ast_is_deferrable_frame(const struct ast_frame *frame)
Should we keep this frame for later?
Definition: channel.c:1463
char context[AST_MAX_CONTEXT]
int ast_bridge_channel_queue_playfile_sync(struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
Synchronously queue a bridge action play file frame onto the bridge channel.
void * ast_heap_peek(struct ast_heap *h, unsigned int index)
Peek at an element on a heap.
Definition: heap.c:267
#define AST_OPTION_FLAG_REQUEST
Data structure associated with a single frame of data.
int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:370
Internal Asterisk hangup causes.
Abstract JSON element (object, array, string, int, ...).
static void bridge_sync_cleanup(struct bridge_sync *sync_struct)
Clean up a syncrhonization bridge object.
int ast_channel_unbridged(struct ast_channel *chan)
This function will check if the bridge needs to be re-evaluated due to external changes.
#define AST_OPTION_TONE_VERIFY
static void bridge_channel_update_accountcodes_joining(struct ast_bridge_channel *joining, struct ast_bridge_channel *swap)
Synchronous bridge action object.
void ast_bridge_channel_playfile(struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class)
Play a file on the bridge channel.
Definition: search.h:40
void(* transfer_channel_cb)(struct ast_channel *chan, struct transfer_channel_data *user_data, enum ast_transfer_type transfer_type)
Callback function type called during blind transfers.
Definition: bridge.h:1146
ast_bridge_pull_channel_fn pull
Definition: bridge.h:271
struct ast_bridge_channel::@230 stream_map
ast_bridge_push_channel_fn push
Definition: bridge.h:269
unsigned int interval_sequence
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
void ast_stream_topology_map(const struct ast_stream_topology *topology, struct ast_vector_int *types, struct ast_vector_int *v0, struct ast_vector_int *v1)
Map a given topology&#39;s streams to the given types.
Definition: stream.c:985
enum ast_frame_type frametype
Private Bridging API.
static void bridge_sync_signal(struct bridge_sync *sync_struct)
Signal that waiting for a synchronous bridge action is no longer necessary.
static void bridge_frame_free(struct ast_frame *frame)
static void bridge_channel_playfile(struct ast_bridge_channel *bridge_channel, struct bridge_playfile *payload)
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
struct ast_bridge_channel::@227 dtmf_hook_state
int ast_queue_frame_head(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to the head of a channel&#39;s frame queue.
Definition: channel.c:1140
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition: ael_main.c:165
void(* unsuspend)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
Unsuspend a channel on a bridging technology instance for a bridge.
int ast_bridge_channel_queue_control_data(struct ast_bridge_channel *bridge_channel, enum ast_control_frame_type control, const void *data, size_t datalen)
Queue a control frame onto the bridge channel with data.
#define DEBUG_ATLEAST(level)
Definition: logger.h:433
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1450
Bridging API.
static const char app[]
Definition: app_mysql.c:62
struct ast_party_connected_line * ast_channel_connected_indicated(struct ast_channel *chan)
ast_bridge_channel_custom_callback_option
void bridge_channel_settle_owed_events(struct ast_bridge *orig_bridge, struct ast_bridge_channel *bridge_channel)
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
struct ast_featuremap_config * ast_get_chan_featuremap_config(struct ast_channel *chan)
Get the featuremap configuration options for a channel.
static void bridge_channel_handle_action(struct ast_bridge_channel *bridge_channel, enum bridge_channel_action_type action, void *data)
static void channel_update_peeraccounts(struct ast_channel *c0, struct ast_channel *c1)
void ast_bridge_channel_lock_bridge(struct ast_bridge_channel *bridge_channel)
Lock the bridge associated with the bridge channel.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
struct ast_party_id priv
Private connected party ID.
Definition: channel.h:469
char code[MAXIMUM_DTMF_FEATURE_STRING]
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
Structure that is the essence of a feature hook.
unsigned int num_channels
Definition: bridge.h:377
static void bridge_channel_unsuspend(struct ast_bridge_channel *bridge_channel)
static void bridge_channel_handle_feature_timeout(struct ast_bridge_channel *bridge_channel)
struct ast_bridge_channel::@226 owed
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611
Timing source management.
#define ast_heap_wrlock(h)
Definition: heap.h:246
unsigned char data[0]
unsigned int id
void ast_channel_set_unbridged(struct ast_channel *chan, int value)
Sets the unbridged flag and queues a NULL frame on the channel to trigger a check by bridge_channel_w...
int ast_channel_redirecting_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const void *redirecting_info, int is_caller, int is_frame)
Run a redirecting interception macro and update a channel&#39;s redirecting information.
Definition: channel.c:10340
static int bridge_channel_feature_timeout(struct ast_bridge_channel *bridge_channel)
static int bridge_channel_next_timeout(struct ast_bridge_channel *bridge_channel)
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620
struct ast_channel * ast_channel_internal_oldest_linkedid(struct ast_channel *a, struct ast_channel *b)
Determine which channel has an older linkedid.
static int bridge_channel_feature_digit_add(struct ast_bridge_channel *bridge_channel, int digit, size_t dtmf_len)
int ast_sendtext(struct ast_channel *chan, const char *text)
Sends text to a channel.
Definition: channel.c:4823
static int frame_size[4]
Definition: format_g726.c:52
static struct ast_frame * bridge_handle_dtmf(struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
Internal function to handle DTMF from a channel.
int bridge_channel_internal_allows_optimization(struct ast_bridge_channel *bridge_channel)