Asterisk - The Open Source Telephony Project  18.5.0
Functions
core_local.h File Reference

Local proxy channel special access. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct stasis_message_typeast_local_bridge_type (void)
 Message type for when two local channel halves are bridged together. More...
 
struct ast_channelast_local_get_peer (struct ast_channel *ast)
 Get the other local channel in the pair. More...
 
void ast_local_lock_all (struct ast_channel *chan, void **tech_pvt, struct ast_channel **base_chan, struct ast_channel **base_owner)
 Add a reference to the local channel's private tech, lock the local channel's private base, and add references and lock both sides of the local channel. More...
 
struct stasis_message_typeast_local_optimization_begin_type (void)
 Message type for when a local channel optimization begins. More...
 
struct stasis_message_typeast_local_optimization_end_type (void)
 Message type for when a local channel optimization completes. More...
 
int ast_local_setup_bridge (struct ast_channel *ast, struct ast_bridge *bridge, struct ast_channel *swap, struct ast_bridge_features *features)
 Setup the outgoing local channel to join a bridge on ast_call(). More...
 
int ast_local_setup_masquerade (struct ast_channel *ast, struct ast_channel *masq)
 Setup the outgoing local channel to masquerade into a channel on ast_call(). More...
 
void ast_local_unlock_all (void *tech_pvt, struct ast_channel *base_chan, struct ast_channel *base_owner)
 Remove a reference to the given local channel's private tech, unlock the given local channel's private base, and remove references and unlock both sides of given the local channel. More...
 

Detailed Description

Local proxy channel special access.

Author
Richard Mudgett rmudg.nosp@m.ett@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

See Also:

Definition in file core_local.h.

Function Documentation

◆ ast_local_bridge_type()

struct stasis_message_type* ast_local_bridge_type ( void  )

Message type for when two local channel halves are bridged together.

Since
12.0.0
Note
Payloads for the ast_local_bridge_type are a ast_multi_channel_blob. Roles for the channels in the ast_multi_channel_blob are "1" and "2", reflecting the two halves. Unlike most other bridges, the 'bridge' between two local channels is not part of the bridge framework; as such, the message simply references the two local channel halves that are now bridged.
Return values
AStasis Message Bus API message type

Referenced by ast_local_init(), local_message_to_ami(), local_shutdown(), and publish_local_bridge_message().

◆ ast_local_get_peer()

struct ast_channel* ast_local_get_peer ( struct ast_channel ast)

Get the other local channel in the pair.

Since
12.0.0
Parameters
astLocal channel to get peer.
Note
On entry, ast must be locked.
Return values
peerreffed on success.
NULLif no peer or error.

Definition at line 276 of file core_local.c.

References ao2_find, ao2_lock, ao2_ref, ao2_unlock, ast_channel_ref, ast_channel_tech_pvt(), local_pvt::base, ast_unreal_pvt::chan, NULL, and ast_unreal_pvt::owner.

Referenced by ari_channels_handle_originate_with_id(), and park_local_transfer().

277 {
278  struct local_pvt *p = ast_channel_tech_pvt(ast);
279  struct local_pvt *found;
280  struct ast_channel *peer;
281 
282  if (!p) {
283  return NULL;
284  }
285 
286  found = p ? ao2_find(locals, p, 0) : NULL;
287  if (!found) {
288  /* ast is either not a local channel or it has alredy been hungup */
289  return NULL;
290  }
291  ao2_lock(found);
292  if (ast == p->base.owner) {
293  peer = p->base.chan;
294  } else if (ast == p->base.chan) {
295  peer = p->base.owner;
296  } else {
297  peer = NULL;
298  }
299  if (peer) {
300  ast_channel_ref(peer);
301  }
302  ao2_unlock(found);
303  ao2_ref(found, -1);
304  return peer;
305 }
Main Channel structure associated with a channel.
void * ast_channel_tech_pvt(const struct ast_channel *chan)
struct ast_channel * owner
Definition: core_unreal.h:93
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
struct ast_unreal_pvt base
Definition: core_local.c:225
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
struct ast_channel * chan
Definition: core_unreal.h:94
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2970
the local pvt structure for all channels
Definition: core_local.c:223
static struct ao2_container * locals
Definition: core_local.c:138

◆ ast_local_lock_all()

void ast_local_lock_all ( struct ast_channel chan,
void **  tech_pvt,
struct ast_channel **  base_chan,
struct ast_channel **  base_owner 
)

Add a reference to the local channel's private tech, lock the local channel's private base, and add references and lock both sides of the local channel.

Note
None of these locks should be held prior to calling this function.
To undo this process call ast_local_unlock_all2.
Since
13.17.0, 14.6.0
Parameters
chanMust be a local channel
tech_pvt[out] channel's private tech (ref and lock added)
base_chan[out] One side of the local channel (ref and lock added)
base_owner[out] Other side of the local channel (ref and lock added)

Definition at line 241 of file core_local.c.

References ao2_bump, ast_channel_tech_pvt(), ast_unreal_lock_all(), local_pvt::base, and NULL.

Referenced by attended_transfer_bridge().

243 {
244  struct local_pvt *p = ast_channel_tech_pvt(chan);
245 
246  *tech_pvt = NULL;
247  *base_chan = NULL;
248  *base_owner = NULL;
249 
250  if (p) {
251  *tech_pvt = ao2_bump(p);
252  ast_unreal_lock_all(&p->base, base_chan, base_owner);
253  }
254 }
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define NULL
Definition: resample.c:96
#define ao2_bump(obj)
Definition: astobj2.h:491
struct ast_unreal_pvt base
Definition: core_local.c:225
the local pvt structure for all channels
Definition: core_local.c:223
void ast_unreal_lock_all(struct ast_unreal_pvt *p, struct ast_channel **outchan, struct ast_channel **outowner)
Send an unreal pvt in with no locks held and get all locks.
Definition: core_unreal.c:47

◆ ast_local_optimization_begin_type()

struct stasis_message_type* ast_local_optimization_begin_type ( void  )

Message type for when a local channel optimization begins.

Since
12.0.0
Note
Payloads for the ast_local_optimization_begin_type are a ast_multi_channel_blob. Roles for the channels in the ast_multi_channel_blob are "1" and "2", reflecting the two halves.
Return values
AStasis Message Bus API message type

Referenced by ast_local_init(), AST_TEST_DEFINE(), local_message_to_ami(), local_optimization_started_cb(), local_shutdown(), and setup_stasis_subs().

◆ ast_local_optimization_end_type()

struct stasis_message_type* ast_local_optimization_end_type ( void  )

Message type for when a local channel optimization completes.

Since
12.0.0
Note
Payloads for the ast_local_optimization_end_type are a ast_multi_channel_blob. Roles for the channels in the ast_multi_channel_blob are "1" and "2", reflecting the two halves.
Return values
AStasis Message Bus API message type

Referenced by ast_local_init(), AST_TEST_DEFINE(), create_routes(), local_message_to_ami(), local_optimization_finished_cb(), local_shutdown(), and setup_stasis_subs().

◆ ast_local_setup_bridge()

int ast_local_setup_bridge ( struct ast_channel ast,
struct ast_bridge bridge,
struct ast_channel swap,
struct ast_bridge_features features 
)

Setup the outgoing local channel to join a bridge on ast_call().

Since
12.0.0
Parameters
astEither channel of a local channel pair.
bridgeBridge to join.
swapChannel to swap with when joining.
featuresBridge features structure.
Note
The features parameter must be NULL or obtained by ast_bridge_features_new(). You must not dereference features after calling even if the call fails.
Intended to be called after ast_request() and before ast_call() on a local channel.
Return values
0on success.
-1on error.

Definition at line 599 of file core_local.c.

References local_pvt::action, ao2_find, ao2_lock, ao2_ref, ao2_unlock, ast_bridge_features_destroy(), ast_channel_lock, ast_channel_ref, ast_channel_tech_pvt(), ast_channel_unlock, ast_test_flag, AST_UNREAL_CARETAKER_THREAD, local_pvt::base, local_pvt::bridge, ast_unreal_pvt::chan, local_bridge::features, local_bridge::join, LOCAL_CALL_ACTION_BRIDGE, LOCAL_CALL_ACTION_DIALPLAN, NULL, ast_unreal_pvt::owner, local_bridge::swap, and local_pvt::type.

Referenced by attended_transfer_bridge().

600 {
601  struct local_pvt *p;
602  struct local_pvt *found;
603  int res = -1;
604 
605  /* Sanity checks. */
606  if (!ast || !bridge) {
607  ast_bridge_features_destroy(features);
608  return -1;
609  }
610 
611  ast_channel_lock(ast);
612  p = ast_channel_tech_pvt(ast);
613  ast_channel_unlock(ast);
614 
615  found = p ? ao2_find(locals, p, 0) : NULL;
616  if (found) {
617  ao2_lock(found);
618  if (found->type == LOCAL_CALL_ACTION_DIALPLAN
619  && found->base.owner
620  && found->base.chan
622  ao2_ref(bridge, +1);
623  if (swap) {
624  ast_channel_ref(swap);
625  }
627  found->action.bridge.join = bridge;
628  found->action.bridge.swap = swap;
629  found->action.bridge.features = features;
630  res = 0;
631  } else {
632  ast_bridge_features_destroy(features);
633  }
634  ao2_unlock(found);
635  ao2_ref(found, -1);
636  }
637 
638  return res;
639 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define ast_test_flag(p, flag)
Definition: utils.h:63
struct ast_channel * owner
Definition: core_unreal.h:93
struct ast_channel * swap
Definition: core_local.c:211
#define AST_UNREAL_CARETAKER_THREAD
Definition: core_unreal.h:107
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
void ast_bridge_features_destroy(struct ast_bridge_features *features)
Destroy an allocated bridge features struct.
Definition: bridge.c:3741
struct ast_unreal_pvt base
Definition: core_local.c:225
struct ast_bridge_features * features
Definition: core_local.c:213
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
struct ast_channel * chan
Definition: core_unreal.h:94
enum local_call_action type
Definition: core_local.c:234
union local_pvt::@376 action
#define ast_channel_unlock(chan)
Definition: channel.h:2946
struct ast_bridge * join
Definition: core_local.c:209
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2970
the local pvt structure for all channels
Definition: core_local.c:223
static struct ao2_container * locals
Definition: core_local.c:138
struct local_bridge bridge
Definition: core_local.c:229

◆ ast_local_setup_masquerade()

int ast_local_setup_masquerade ( struct ast_channel ast,
struct ast_channel masq 
)

Setup the outgoing local channel to masquerade into a channel on ast_call().

Since
12.0.0
Parameters
astEither channel of a local channel pair.
masqChannel to masquerade into.
Note
Intended to be called after ast_request() and before ast_call() on a local channel.
Return values
0on success.
-1on error.

Definition at line 641 of file core_local.c.

References local_pvt::action, ao2_find, ao2_lock, ao2_ref, ao2_unlock, ast_channel_lock, ast_channel_ref, ast_channel_tech_pvt(), ast_channel_unlock, ast_test_flag, AST_UNREAL_CARETAKER_THREAD, local_pvt::base, ast_unreal_pvt::chan, LOCAL_CALL_ACTION_DIALPLAN, LOCAL_CALL_ACTION_MASQUERADE, local_pvt::masq, NULL, ast_unreal_pvt::owner, and local_pvt::type.

Referenced by attended_transfer_bridge().

642 {
643  struct local_pvt *p;
644  struct local_pvt *found;
645  int res = -1;
646 
647  /* Sanity checks. */
648  if (!ast || !masq) {
649  return -1;
650  }
651 
652  ast_channel_lock(ast);
653  p = ast_channel_tech_pvt(ast);
654  ast_channel_unlock(ast);
655 
656  found = p ? ao2_find(locals, p, 0) : NULL;
657  if (found) {
658  ao2_lock(found);
659  if (found->type == LOCAL_CALL_ACTION_DIALPLAN
660  && found->base.owner
661  && found->base.chan
663  ast_channel_ref(masq);
665  found->action.masq = masq;
666  res = 0;
667  }
668  ao2_unlock(found);
669  ao2_ref(found, -1);
670  }
671 
672  return res;
673 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define ast_test_flag(p, flag)
Definition: utils.h:63
struct ast_channel * owner
Definition: core_unreal.h:93
#define AST_UNREAL_CARETAKER_THREAD
Definition: core_unreal.h:107
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
struct ast_unreal_pvt base
Definition: core_local.c:225
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
struct ast_channel * chan
Definition: core_unreal.h:94
enum local_call_action type
Definition: core_local.c:234
union local_pvt::@376 action
#define ast_channel_unlock(chan)
Definition: channel.h:2946
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2970
the local pvt structure for all channels
Definition: core_local.c:223
struct ast_channel * masq
Definition: core_local.c:231
static struct ao2_container * locals
Definition: core_local.c:138

◆ ast_local_unlock_all()

void ast_local_unlock_all ( void *  tech_pvt,
struct ast_channel base_chan,
struct ast_channel base_owner 
)

Remove a reference to the given local channel's private tech, unlock the given local channel's private base, and remove references and unlock both sides of given the local channel.

Note
This function should be used in conjunction with ast_local_lock_all2.
Since
13.17.0, 14.6.0
Parameters
tech_pvtchannel's private tech (ref and lock removed)
base_chanOne side of the local channel (ref and lock removed)
base_ownerOther side of the local channel (ref and lock removed)

Definition at line 256 of file core_local.c.

References ao2_ref, ao2_unlock, ast_channel_unlock, ast_channel_unref, and local_pvt::base.

Referenced by attended_transfer_bridge().

258 {
259  if (base_chan) {
260  ast_channel_unlock(base_chan);
261  ast_channel_unref(base_chan);
262  }
263 
264  if (base_owner) {
265  ast_channel_unlock(base_owner);
266  ast_channel_unref(base_owner);
267  }
268 
269  if (tech_pvt) {
270  struct local_pvt *p = tech_pvt;
271  ao2_unlock(&p->base);
272  ao2_ref(tech_pvt, -1);
273  }
274 }
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
#define ao2_unlock(a)
Definition: astobj2.h:730
struct ast_unreal_pvt base
Definition: core_local.c:225
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_channel_unlock(chan)
Definition: channel.h:2946
the local pvt structure for all channels
Definition: core_local.c:223