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