Sat Mar 26 11:15:44 2011

Asterisk developer's documentation


chan_local.c File Reference

Local Proxy Channel. More...

#include "asterisk.h"
#include <fcntl.h>
#include <sys/signal.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/rtp.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/file.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
#include "asterisk/musiconhold.h"
#include "asterisk/manager.h"
#include "asterisk/stringfields.h"
#include "asterisk/devicestate.h"
#include "asterisk/astobj2.h"

Include dependency graph for chan_local.c:

Go to the source code of this file.

Data Structures

struct  local_pvt

Defines

#define IS_OUTBOUND(a, b)   (a == b->chan ? 1 : 0)
#define LOCAL_ALREADY_MASQED   (1 << 0)
#define LOCAL_BRIDGE   (1 << 3)
#define LOCAL_LAUNCHED_PBX   (1 << 1)
#define LOCAL_MOH_PASSTHRU   (1 << 4)
#define LOCAL_NO_OPTIMIZATION   (1 << 2)

Functions

static void __reg_module (void)
static void __unreg_module (void)
static void check_bridge (struct local_pvt *p)
static int load_module (void)
 Load module into PBX, register channel.
static struct local_pvt * local_alloc (const char *data, int format)
 Create a call structure.
static int local_answer (struct ast_channel *ast)
static struct ast_channel * local_bridgedchannel (struct ast_channel *chan, struct ast_channel *bridge)
 Return the bridged channel of a Local channel.
static int local_call (struct ast_channel *ast, char *dest, int timeout)
 Initiate new call, part of PBX interface dest is the dial string.
static int local_devicestate (void *data)
 Adds devicestate to local channels.
static int local_digit_begin (struct ast_channel *ast, char digit)
static int local_digit_end (struct ast_channel *ast, char digit, unsigned int duration)
static int local_fixup (struct ast_channel *oldchan, struct ast_channel *newchan)
static int local_hangup (struct ast_channel *ast)
 Hangup a call through the local proxy channel.
static int local_indicate (struct ast_channel *ast, int condition, const void *data, size_t datalen)
static struct ast_channel * local_new (struct local_pvt *p, int state)
 Start new local channel.
static int local_queryoption (struct ast_channel *ast, int option, void *data, int *datalen)
static int local_queue_frame (struct local_pvt *p, int isoutbound, struct ast_frame *f, struct ast_channel *us, int us_locked)
 queue a frame on a to either the p->owner or p->chan
static struct ast_frame * local_read (struct ast_channel *ast)
static struct ast_channel * local_request (const char *type, int format, void *data, int *cause)
 Part of PBX interface.
static int local_sendhtml (struct ast_channel *ast, int subclass, const char *data, int datalen)
static int local_sendtext (struct ast_channel *ast, const char *text)
static int local_setoption (struct ast_channel *chan, int option, void *data, int datalen)
static int local_write (struct ast_channel *ast, struct ast_frame *f)
static int locals_cmp_cb (void *obj, void *arg, int flags)
static char * locals_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command "local show channels".
static int unload_module (void)
 Unload the local proxy channel from Asterisk.

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Local Proxy Channel (Note: used internally by other modules)" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
static struct ast_module_info * ast_module_info = &__mod_info
static const int BUCKET_SIZE = 1
static struct ast_cli_entry cli_local []
static struct ast_jb_conf g_jb_conf
static struct ast_channel_tech local_tech
static struct ao2_container * locals
static const char tdesc [] = "Local Proxy Channel Driver"


Detailed Description

Local Proxy Channel.

Author:
Mark Spencer <markster@digium.com>

Definition in file chan_local.c.


Define Documentation

#define IS_OUTBOUND ( a,
b   )     (a == b->chan ? 1 : 0)

#define LOCAL_ALREADY_MASQED   (1 << 0)

Already masqueraded

Definition at line 127 of file chan_local.c.

Referenced by check_bridge(), and local_write().

#define LOCAL_BRIDGE   (1 << 3)

Report back the "true" channel as being bridged to

Definition at line 130 of file chan_local.c.

Referenced by local_alloc(), and local_bridgedchannel().

#define LOCAL_LAUNCHED_PBX   (1 << 1)

PBX was launched

Definition at line 128 of file chan_local.c.

Referenced by local_call(), and local_hangup().

#define LOCAL_MOH_PASSTHRU   (1 << 4)

Pass through music on hold start/stop frames

Definition at line 131 of file chan_local.c.

Referenced by local_alloc(), and local_indicate().

#define LOCAL_NO_OPTIMIZATION   (1 << 2)

Do not optimize using masquerading

Definition at line 129 of file chan_local.c.

Referenced by check_bridge(), and local_alloc().


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 1064 of file chan_local.c.

01064 : used internally by other modules)");

static void __unreg_module ( void   )  [static]

Definition at line 1064 of file chan_local.c.

01064 : used internally by other modules)");

static void check_bridge ( struct local_pvt *  p  )  [static]

Definition at line 409 of file chan_local.c.

References ast_channel::_bridge, ast_app_group_update(), ast_bridged_channel(), ast_channel_masquerade(), ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), AST_LIST_EMPTY, ast_set_flag, ast_test_flag, ast_channel::audiohooks, local_pvt::chan, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_ani2, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_pres, ast_callerid::cid_rdnis, ast_callerid::cid_tns, ast_callerid::cid_ton, LOCAL_ALREADY_MASQED, LOCAL_NO_OPTIMIZATION, ast_channel::monitor, local_pvt::owner, and ast_channel::readq.

Referenced by local_write().

00410 {
00411    struct ast_channel_monitor *tmp;
00412    if (ast_test_flag(p, LOCAL_ALREADY_MASQED) || ast_test_flag(p, LOCAL_NO_OPTIMIZATION) || !p->chan || !p->owner || (p->chan->_bridge != ast_bridged_channel(p->chan)))
00413       return;
00414 
00415    /* only do the masquerade if we are being called on the outbound channel,
00416       if it has been bridged to another channel and if there are no pending
00417       frames on the owner channel (because they would be transferred to the
00418       outbound channel during the masquerade)
00419    */
00420    if (p->chan->_bridge /* Not ast_bridged_channel!  Only go one step! */ && AST_LIST_EMPTY(&p->owner->readq)) {
00421       /* Masquerade bridged channel into owner */
00422       /* Lock everything we need, one by one, and give up if
00423          we can't get everything.  Remember, we'll get another
00424          chance in just a little bit */
00425       if (!ast_channel_trylock(p->chan->_bridge)) {
00426          if (!ast_check_hangup(p->chan->_bridge)) {
00427             if (!ast_channel_trylock(p->owner)) {
00428                if (!ast_check_hangup(p->owner)) {
00429                   if (p->owner->monitor && !p->chan->_bridge->monitor) {
00430                      /* If a local channel is being monitored, we don't want a masquerade
00431                       * to cause the monitor to go away. Since the masquerade swaps the monitors,
00432                       * pre-swapping the monitors before the masquerade will ensure that the monitor
00433                       * ends up where it is expected.
00434                       */
00435                      tmp = p->owner->monitor;
00436                      p->owner->monitor = p->chan->_bridge->monitor;
00437                      p->chan->_bridge->monitor = tmp;
00438                   }
00439                   if (p->chan->audiohooks) {
00440                      struct ast_audiohook_list *audiohooks_swapper;
00441                      audiohooks_swapper = p->chan->audiohooks;
00442                      p->chan->audiohooks = p->owner->audiohooks;
00443                      p->owner->audiohooks = audiohooks_swapper;
00444                   }
00445 
00446                   /* If any Caller ID was set, preserve it after masquerade like above. We must check
00447                    * to see if Caller ID was set because otherwise we'll mistakingly copy info not
00448                    * set from the dialplan and will overwrite the real channel Caller ID. The reason
00449                    * for this whole preswapping action is because the Caller ID is set on the channel
00450                    * thread (which is the to be masqueraded away local channel) before both local
00451                    * channels are optimized away.
00452                    */
00453                   if (p->owner->cid.cid_dnid || p->owner->cid.cid_num ||
00454                      p->owner->cid.cid_name || p->owner->cid.cid_ani ||
00455                      p->owner->cid.cid_rdnis || p->owner->cid.cid_pres ||  
00456                      p->owner->cid.cid_ani2 || p->owner->cid.cid_ton ||  
00457                      p->owner->cid.cid_tns) {
00458 
00459                      struct ast_callerid tmpcid;
00460                      tmpcid = p->owner->cid;
00461                      p->owner->cid = p->chan->_bridge->cid;
00462                      p->chan->_bridge->cid = tmpcid;
00463                   }
00464 
00465                   ast_app_group_update(p->chan, p->owner);
00466                   ast_channel_masquerade(p->owner, p->chan->_bridge);
00467                   ast_set_flag(p, LOCAL_ALREADY_MASQED);
00468                }
00469                ast_channel_unlock(p->owner);
00470             }
00471             ast_channel_unlock(p->chan->_bridge);
00472          }
00473       }
00474    }
00475 }

static int load_module ( void   )  [static]

Load module into PBX, register channel.

Definition at line 1026 of file chan_local.c.

References ao2_container_alloc, ao2_ref, ast_channel_register(), ast_cli_register_multiple(), ast_log(), AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, cli_local, locals_cmp_cb(), and LOG_ERROR.

01027 {
01028    if (!(locals = ao2_container_alloc(BUCKET_SIZE, NULL, locals_cmp_cb))) {
01029       return AST_MODULE_LOAD_FAILURE;
01030    }
01031 
01032    /* Make sure we can register our channel type */
01033    if (ast_channel_register(&local_tech)) {
01034       ast_log(LOG_ERROR, "Unable to register channel class 'Local'\n");
01035       ao2_ref(locals, -1);
01036       return AST_MODULE_LOAD_FAILURE;
01037    }
01038    ast_cli_register_multiple(cli_local, sizeof(cli_local) / sizeof(struct ast_cli_entry));
01039    return AST_MODULE_LOAD_SUCCESS;
01040 }

static struct local_pvt* local_alloc ( const char *  data,
int  format 
) [static, read]

Create a call structure.

Definition at line 838 of file chan_local.c.

References ao2_alloc, ao2_link, ast_copy_string(), ast_exists_extension(), AST_JB_ENABLED, ast_log(), ast_set_flag, ast_test_flag, local_pvt::context, local_pvt::exten, local_pvt::jb_conf, LOCAL_BRIDGE, LOCAL_MOH_PASSTHRU, LOCAL_NO_OPTIMIZATION, LOG_ERROR, LOG_NOTICE, and local_pvt::reqformat.

Referenced by local_request().

00839 {
00840    struct local_pvt *tmp = NULL;
00841    char *c = NULL, *opts = NULL;
00842 
00843    if (!(tmp = ao2_alloc(sizeof(*tmp), NULL))) {
00844       return NULL;
00845    }
00846 
00847    /* Initialize private structure information */
00848    ast_copy_string(tmp->exten, data, sizeof(tmp->exten));
00849 
00850    memcpy(&tmp->jb_conf, &g_jb_conf, sizeof(tmp->jb_conf));
00851 
00852    /* Look for options */
00853    if ((opts = strchr(tmp->exten, '/'))) {
00854       *opts++ = '\0';
00855       if (strchr(opts, 'n'))
00856          ast_set_flag(tmp, LOCAL_NO_OPTIMIZATION);
00857       if (strchr(opts, 'j')) {
00858          if (ast_test_flag(tmp, LOCAL_NO_OPTIMIZATION))
00859             ast_set_flag(&tmp->jb_conf, AST_JB_ENABLED);
00860          else {
00861             ast_log(LOG_ERROR, "You must use the 'n' option for chan_local "
00862                "to use the 'j' option to enable the jitterbuffer\n");
00863          }
00864       }
00865       if (strchr(opts, 'b')) {
00866          ast_set_flag(tmp, LOCAL_BRIDGE);
00867       }
00868       if (strchr(opts, 'm')) {
00869          ast_set_flag(tmp, LOCAL_MOH_PASSTHRU);
00870       }
00871    }
00872 
00873    /* Look for a context */
00874    if ((c = strchr(tmp->exten, '@')))
00875       *c++ = '\0';
00876 
00877    ast_copy_string(tmp->context, c ? c : "default", sizeof(tmp->context));
00878 
00879    tmp->reqformat = format;
00880 
00881 #if 0
00882    /* We can't do this check here, because we don't know the CallerID yet, and
00883     * the CallerID could potentially affect what step is actually taken (or
00884     * even if that step exists). */
00885    if (!ast_exists_extension(NULL, tmp->context, tmp->exten, 1, NULL)) {
00886       ast_log(LOG_NOTICE, "No such extension/context %s@%s creating local channel\n", tmp->exten, tmp->context);
00887       tmp = local_pvt_destroy(tmp);
00888    } else {
00889 #endif
00890       /* Add to list */
00891       ao2_link(locals, tmp);
00892 #if 0
00893    }
00894 #endif
00895    return tmp; /* this is returned with a ref */
00896 }

static int local_answer ( struct ast_channel *  ast  )  [static]

Definition at line 381 of file chan_local.c.

References ao2_lock(), ao2_ref, ao2_unlock(), AST_CONTROL_ANSWER, AST_FRAME_CONTROL, ast_log(), IS_OUTBOUND, local_queue_frame(), LOG_WARNING, and ast_channel::tech_pvt.

00382 {
00383    struct local_pvt *p = ast->tech_pvt;
00384    int isoutbound;
00385    int res = -1;
00386 
00387    if (!p)
00388       return -1;
00389 
00390    ao2_lock(p);
00391    ao2_ref(p, 1);
00392    isoutbound = IS_OUTBOUND(ast, p);
00393    if (isoutbound) {
00394       /* Pass along answer since somebody answered us */
00395       struct ast_frame answer = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
00396       res = local_queue_frame(p, isoutbound, &answer, ast, 1);
00397    } else {
00398       ast_log(LOG_WARNING, "Huh?  Local is being asked to answer?\n");
00399    }
00400    ao2_unlock(p);
00401    ao2_ref(p, -1);
00402    return res;
00403 }

static struct ast_channel * local_bridgedchannel ( struct ast_channel *  chan,
struct ast_channel *  bridge 
) [static, read]

Return the bridged channel of a Local channel.

Definition at line 241 of file chan_local.c.

References ast_channel::_bridge, ao2_lock(), ao2_unlock(), ast_debug, ast_test_flag, local_pvt::chan, LOCAL_BRIDGE, ast_channel::name, local_pvt::owner, and ast_channel::tech_pvt.

00242 {
00243    struct local_pvt *p = bridge->tech_pvt;
00244    struct ast_channel *bridged = bridge;
00245 
00246    if (!p) {
00247       ast_debug(1, "Asked for bridged channel on '%s'/'%s', returning <none>\n",
00248          chan->name, bridge->name);
00249       return NULL;
00250    }
00251 
00252    ao2_lock(p);
00253 
00254    if (ast_test_flag(p, LOCAL_BRIDGE)) {
00255       /* Find the opposite channel */
00256       bridged = (bridge == p->owner ? p->chan : p->owner);
00257       
00258       /* Now see if the opposite channel is bridged to anything */
00259       if (!bridged) {
00260          bridged = bridge;
00261       } else if (bridged->_bridge) {
00262          bridged = bridged->_bridge;
00263       }
00264    }
00265 
00266    ao2_unlock(p);
00267 
00268    return bridged;
00269 }

static int local_call ( struct ast_channel *  ast,
char *  dest,
int  timeout 
) [static]

Initiate new call, part of PBX interface dest is the dial string.

Definition at line 660 of file chan_local.c.

References ast_channel::accountcode, accountcode, ao2_lock(), ao2_unlock(), ast_calloc, ast_cdr_update(), ast_channel_datastore_inherit(), ast_exists_extension(), AST_FLAG_ANSWERED_ELSEWHERE, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), ast_pbx_start(), ast_set_flag, ast_strdup, ast_string_field_set, ast_test_flag, ast_channel::cdrflags, local_pvt::chan, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_ani2, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, ast_callerid::cid_pres, ast_callerid::cid_rdnis, ast_callerid::cid_tns, ast_callerid::cid_ton, ast_channel::context, ast_var_t::entries, ast_channel::exten, ast_channel::language, language, len(), LOCAL_LAUNCHED_PBX, LOG_NOTICE, ast_channel::musicclass, musicclass, ast_var_t::name, local_pvt::owner, ast_channel::tech_pvt, and ast_channel::varshead.

00661 {
00662    struct local_pvt *p = ast->tech_pvt;
00663    int res = 0;
00664    struct ast_var_t *varptr = NULL, *new;
00665    size_t len, namelen;
00666 
00667    if (!p)
00668       return -1;
00669 
00670    ao2_lock(p);
00671 
00672    /*
00673     * Note that cid_num and cid_name aren't passed in the ast_channel_alloc
00674     * call, so it's done here instead.
00675     */
00676    p->chan->cid.cid_dnid = ast_strdup(p->owner->cid.cid_dnid);
00677    p->chan->cid.cid_num = ast_strdup(p->owner->cid.cid_num);
00678    p->chan->cid.cid_name = ast_strdup(p->owner->cid.cid_name);
00679    p->chan->cid.cid_rdnis = ast_strdup(p->owner->cid.cid_rdnis);
00680    p->chan->cid.cid_ani = ast_strdup(p->owner->cid.cid_ani);
00681    p->chan->cid.cid_pres = p->owner->cid.cid_pres;
00682    p->chan->cid.cid_ani2 = p->owner->cid.cid_ani2;
00683    p->chan->cid.cid_ton = p->owner->cid.cid_ton;
00684    p->chan->cid.cid_tns = p->owner->cid.cid_tns;
00685    ast_string_field_set(p->chan, language, p->owner->language);
00686    ast_string_field_set(p->chan, accountcode, p->owner->accountcode);
00687    ast_string_field_set(p->chan, musicclass, p->owner->musicclass);
00688    ast_cdr_update(p->chan);
00689    p->chan->cdrflags = p->owner->cdrflags;
00690 
00691    if (!ast_exists_extension(NULL, p->chan->context, p->chan->exten, 1, p->owner->cid.cid_num)) {
00692       ast_log(LOG_NOTICE, "No such extension/context %s@%s while calling Local channel\n", p->chan->exten, p->chan->context);
00693       ao2_unlock(p);
00694       return -1;
00695    }
00696 
00697    /* Make sure we inherit the ANSWERED_ELSEWHERE flag if it's set on the queue/dial call request in the dialplan */
00698    if (ast_test_flag(ast, AST_FLAG_ANSWERED_ELSEWHERE)) {
00699       ast_set_flag(p->chan, AST_FLAG_ANSWERED_ELSEWHERE);
00700    }
00701 
00702    /* copy the channel variables from the incoming channel to the outgoing channel */
00703    /* Note that due to certain assumptions, they MUST be in the same order */
00704    AST_LIST_TRAVERSE(&p->owner->varshead, varptr, entries) {
00705       namelen = strlen(varptr->name);
00706       len = sizeof(struct ast_var_t) + namelen + strlen(varptr->value) + 2;
00707       if ((new = ast_calloc(1, len))) {
00708          memcpy(new, varptr, len);
00709          new->value = &(new->name[0]) + namelen + 1;
00710          AST_LIST_INSERT_TAIL(&p->chan->varshead, new, entries);
00711       }
00712    }
00713    ast_channel_datastore_inherit(p->owner, p->chan);
00714 
00715    /* Start switch on sub channel */
00716    if (!(res = ast_pbx_start(p->chan)))
00717       ast_set_flag(p, LOCAL_LAUNCHED_PBX);
00718 
00719    ao2_unlock(p);
00720    return res;
00721 }

static int local_devicestate ( void *  data  )  [static]

Adds devicestate to local channels.

Definition at line 199 of file chan_local.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_debug, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, ast_exists_extension(), ast_log(), ast_strdupa, local_pvt::context, local_pvt::exten, LOG_WARNING, and local_pvt::owner.

00200 {
00201    char *exten = ast_strdupa(data);
00202    char *context = NULL, *opts = NULL;
00203    int res;
00204    struct local_pvt *lp;
00205    struct ao2_iterator it;
00206 
00207    if (!(context = strchr(exten, '@'))) {
00208       ast_log(LOG_WARNING, "Someone used Local/%s somewhere without a @context. This is bad.\n", exten);
00209       return AST_DEVICE_INVALID; 
00210    }
00211 
00212    *context++ = '\0';
00213 
00214    /* Strip options if they exist */
00215    if ((opts = strchr(context, '/')))
00216       *opts = '\0';
00217 
00218    ast_debug(3, "Checking if extension %s@%s exists (devicestate)\n", exten, context);
00219 
00220    res = ast_exists_extension(NULL, context, exten, 1, NULL);
00221    if (!res)      
00222       return AST_DEVICE_INVALID;
00223    
00224    res = AST_DEVICE_NOT_INUSE;
00225 
00226    it = ao2_iterator_init(locals, 0);
00227    while ((lp = ao2_iterator_next(&it))) {
00228       if (!strcmp(exten, lp->exten) && !strcmp(context, lp->context) && lp->owner) {
00229          res = AST_DEVICE_INUSE;
00230          ao2_ref(lp, -1);
00231          break;
00232       }
00233       ao2_ref(lp, -1);
00234    }
00235    ao2_iterator_destroy(&it);
00236 
00237    return res;
00238 }

static int local_digit_begin ( struct ast_channel *  ast,
char  digit 
) [static]

Definition at line 572 of file chan_local.c.

References ao2_lock(), ao2_ref, ao2_unlock(), AST_FRAME_DTMF_BEGIN, IS_OUTBOUND, local_queue_frame(), ast_frame::subclass, and ast_channel::tech_pvt.

00573 {
00574    struct local_pvt *p = ast->tech_pvt;
00575    int res = -1;
00576    struct ast_frame f = { AST_FRAME_DTMF_BEGIN, };
00577    int isoutbound;
00578 
00579    if (!p)
00580       return -1;
00581 
00582    ao2_ref(p, 1); /* ref for local_queue_frame */
00583    ao2_lock(p);
00584    isoutbound = IS_OUTBOUND(ast, p);
00585    f.subclass = digit;
00586    res = local_queue_frame(p, isoutbound, &f, ast, 0);
00587    ao2_unlock(p);
00588    ao2_ref(p, -1);
00589 
00590    return res;
00591 }

static int local_digit_end ( struct ast_channel *  ast,
char  digit,
unsigned int  duration 
) [static]

Definition at line 593 of file chan_local.c.

References ao2_lock(), ao2_ref, ao2_unlock(), AST_FRAME_DTMF_END, IS_OUTBOUND, ast_frame::len, local_queue_frame(), ast_frame::subclass, and ast_channel::tech_pvt.

00594 {
00595    struct local_pvt *p = ast->tech_pvt;
00596    int res = -1;
00597    struct ast_frame f = { AST_FRAME_DTMF_END, };
00598    int isoutbound;
00599 
00600    if (!p)
00601       return -1;
00602 
00603    ao2_lock(p);
00604    ao2_ref(p, 1); /* ref for local_queue_frame */
00605    isoutbound = IS_OUTBOUND(ast, p);
00606    f.subclass = digit;
00607    f.len = duration;
00608    res = local_queue_frame(p, isoutbound, &f, ast, 0);
00609    ao2_unlock(p);
00610    ao2_ref(p, -1);
00611 
00612    return res;
00613 }

static int local_fixup ( struct ast_channel *  oldchan,
struct ast_channel *  newchan 
) [static]

Definition at line 509 of file chan_local.c.

References ast_channel::_bridge, ao2_lock(), ao2_unlock(), ast_check_hangup(), ast_log(), ast_queue_hangup(), local_pvt::chan, LOG_WARNING, local_pvt::owner, and ast_channel::tech_pvt.

00510 {
00511    struct local_pvt *p = newchan->tech_pvt;
00512 
00513    if (!p)
00514       return -1;
00515 
00516    ao2_lock(p);
00517 
00518    if ((p->owner != oldchan) && (p->chan != oldchan)) {
00519       ast_log(LOG_WARNING, "Old channel wasn't %p but was %p/%p\n", oldchan, p->owner, p->chan);
00520       ao2_unlock(p);
00521       return -1;
00522    }
00523    if (p->owner == oldchan)
00524       p->owner = newchan;
00525    else
00526       p->chan = newchan;
00527 
00528    /* Do not let a masquerade cause a Local channel to be bridged to itself! */
00529    if (!ast_check_hangup(newchan) && (p->owner->_bridge == p->chan || p->chan->_bridge == p->owner)) {
00530       ast_log(LOG_WARNING, "You can not bridge a Local channel to itself!\n");
00531       ao2_unlock(p);
00532       ast_queue_hangup(newchan);
00533       return -1;
00534    }
00535 
00536    ao2_unlock(p);
00537    return 0;
00538 }

static int local_hangup ( struct ast_channel *  ast  )  [static]

Hangup a call through the local proxy channel.

Definition at line 724 of file chan_local.c.

References ao2_lock(), ao2_ref, ao2_unlink, ao2_unlock(), ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_clear_flag, AST_CONTROL_HANGUP, ast_debug, AST_FLAG_ANSWERED_ELSEWHERE, AST_FRAME_CONTROL, ast_hangup(), ast_module_user_remove, ast_queue_hangup(), ast_set_flag, ast_test_flag, local_pvt::chan, ast_channel::hangupcause, IS_OUTBOUND, LOCAL_LAUNCHED_PBX, local_queue_frame(), local_pvt::owner, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), status, ast_channel::tech_pvt, local_pvt::u_chan, and local_pvt::u_owner.

00725 {
00726    struct local_pvt *p = ast->tech_pvt;
00727    int isoutbound;
00728    struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP, .data.uint32 = ast->hangupcause };
00729    struct ast_channel *ochan = NULL;
00730 
00731    if (!p)
00732       return -1;
00733 
00734    /* we MUST give the tech_pvt a ref here since we are unlocking the
00735     * channel during deadlock avoidance. */
00736    ao2_ref(p, 1);
00737 
00738    ao2_lock(p);
00739 
00740    isoutbound = IS_OUTBOUND(ast, p);
00741 
00742    if (p->chan && ast_test_flag(ast, AST_FLAG_ANSWERED_ELSEWHERE)) {
00743       ast_set_flag(p->chan, AST_FLAG_ANSWERED_ELSEWHERE);
00744       ast_debug(2, "This local call has the ANSWERED_ELSEWHERE flag set.\n");
00745    }
00746 
00747    if (isoutbound) {
00748       const char *status = pbx_builtin_getvar_helper(p->chan, "DIALSTATUS");
00749       if ((status) && (p->owner)) {
00750          /* Deadlock avoidance */
00751          while (p->owner && ast_channel_trylock(p->owner)) {
00752             ao2_unlock(p);
00753             if (p->chan) {
00754                ast_channel_unlock(p->chan);
00755             }
00756             sched_yield();
00757             if (p->chan) {
00758                ast_channel_lock(p->chan);
00759             }
00760             ao2_lock(p);
00761          }
00762          if (p->owner) {
00763             pbx_builtin_setvar_helper(p->owner, "CHANLOCALSTATUS", status);
00764             ast_channel_unlock(p->owner);
00765          }
00766       }
00767       if (!p->chan) {
00768          /* chan was == to ast and was !NULL before deadlock avoidance started, if chan
00769           * is NULL now, then we should bail because that channel
00770           * hungup already. This is possible because we let go of the
00771           * lock given to the ast channel passed to this function during
00772           * deadlock avoidance. */
00773          ao2_unlock(p);
00774          ao2_ref(p, -1);
00775          return 0;
00776       }
00777       p->chan = NULL;
00778       ast_clear_flag(p, LOCAL_LAUNCHED_PBX);
00779       ast_module_user_remove(p->u_chan);
00780    } else {
00781       ast_module_user_remove(p->u_owner);
00782       while (p->chan && ast_channel_trylock(p->chan)) {
00783             ao2_unlock(p);
00784             if (p->owner) {
00785                ast_channel_unlock(p->owner);
00786             }
00787             sched_yield();
00788             if (p->owner) {
00789                ast_channel_lock(p->owner);
00790             }
00791             ao2_lock(p);
00792       }
00793       if (p->chan) {
00794          ast_queue_hangup(p->chan);
00795          ast_channel_unlock(p->chan);
00796       }
00797 
00798       if (!p->owner) {
00799          /* owner was == to ast and was !NULL before deadlock avoidance started, if
00800           * owner is NULL now, then we should bail because that channel
00801           * hungup already. This is possible because we let go of the
00802           * lock given to the ast channel passed to this function during
00803           * deadlock avoidance. */
00804          ao2_unlock(p);
00805          ao2_ref(p, -1);
00806          return 0;
00807       }
00808       p->owner = NULL;
00809    }
00810 
00811    ast->tech_pvt = NULL;
00812 
00813    if (!p->owner && !p->chan) {
00814       ao2_unlock(p);
00815 
00816       /* Remove from list */
00817       ao2_unlink(locals, p);
00818       ao2_ref(p, -1);
00819       return 0;
00820    }
00821    if (p->chan && !ast_test_flag(p, LOCAL_LAUNCHED_PBX)) {
00822       /* Need to actually hangup since there is no PBX */
00823       ochan = p->chan;
00824    } else {
00825       local_queue_frame(p, isoutbound, &f, NULL, 1);
00826    }
00827 
00828    ao2_unlock(p);
00829    if (ochan) {
00830       ast_hangup(ochan);
00831    }
00832 
00833    ao2_ref(p, -1);
00834    return 0;
00835 }

static int local_indicate ( struct ast_channel *  ast,
int  condition,
const void *  data,
size_t  datalen 
) [static]

Definition at line 540 of file chan_local.c.

References ao2_lock(), ao2_ref, ao2_unlock(), AST_CONTROL_HOLD, AST_CONTROL_UNHOLD, AST_FRAME_CONTROL, ast_moh_start(), ast_moh_stop(), ast_test_flag, ast_frame::data, ast_frame::datalen, IS_OUTBOUND, LOCAL_MOH_PASSTHRU, local_queue_frame(), ast_frame::ptr, ast_frame::subclass, and ast_channel::tech_pvt.

00541 {
00542    struct local_pvt *p = ast->tech_pvt;
00543    int res = 0;
00544    struct ast_frame f = { AST_FRAME_CONTROL, };
00545    int isoutbound;
00546 
00547    if (!p)
00548       return -1;
00549 
00550    ao2_ref(p, 1); /* ref for local_queue_frame */
00551 
00552    /* If this is an MOH hold or unhold, do it on the Local channel versus real channel */
00553    if (!ast_test_flag(p, LOCAL_MOH_PASSTHRU) && condition == AST_CONTROL_HOLD) {
00554       ast_moh_start(ast, data, NULL);
00555    } else if (!ast_test_flag(p, LOCAL_MOH_PASSTHRU) && condition == AST_CONTROL_UNHOLD) {
00556       ast_moh_stop(ast);
00557    } else {
00558       /* Queue up a frame representing the indication as a control frame */
00559       ao2_lock(p);
00560       isoutbound = IS_OUTBOUND(ast, p);
00561       f.subclass = condition;
00562       f.data.ptr = (void*)data;
00563       f.datalen = datalen;
00564       res = local_queue_frame(p, isoutbound, &f, ast, 1);
00565       ao2_unlock(p);
00566    }
00567 
00568    ao2_ref(p, -1);
00569    return res;
00570 }

static struct ast_channel* local_new ( struct local_pvt *  p,
int  state 
) [static, read]

Start new local channel.

Definition at line 899 of file chan_local.c.

References ast_channel::accountcode, ast_channel::amaflags, ast_best_codec(), ast_channel_alloc, ast_channel_free(), ast_copy_string(), ast_jb_configure(), ast_log(), ast_module_user_add, ast_random(), AST_STATE_RING, local_pvt::chan, ast_channel::context, local_pvt::context, ast_channel::exten, local_pvt::exten, local_pvt::jb_conf, LOG_WARNING, ast_channel::nativeformats, local_pvt::owner, ast_channel::priority, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, local_pvt::reqformat, ast_channel::tech, ast_channel::tech_pvt, local_pvt::u_chan, local_pvt::u_owner, and ast_channel::writeformat.

Referenced by local_request().

00900 {
00901    struct ast_channel *tmp = NULL, *tmp2 = NULL;
00902    int randnum = ast_random() & 0xffff, fmt = 0;
00903    const char *t;
00904    int ama;
00905 
00906    /* Allocate two new Asterisk channels */
00907    /* safe accountcode */
00908    if (p->owner && p->owner->accountcode)
00909       t = p->owner->accountcode;
00910    else
00911       t = "";
00912 
00913    if (p->owner)
00914       ama = p->owner->amaflags;
00915    else
00916       ama = 0;
00917    if (!(tmp = ast_channel_alloc(1, state, 0, 0, t, p->exten, p->context, ama, "Local/%s@%s-%04x;1", p->exten, p->context, randnum)) 
00918          || !(tmp2 = ast_channel_alloc(1, AST_STATE_RING, 0, 0, t, p->exten, p->context, ama, "Local/%s@%s-%04x;2", p->exten, p->context, randnum))) {
00919       if (tmp)
00920          ast_channel_free(tmp);
00921       if (tmp2)
00922          ast_channel_free(tmp2);
00923       ast_log(LOG_WARNING, "Unable to allocate channel structure(s)\n");
00924       return NULL;
00925    } 
00926 
00927    tmp2->tech = tmp->tech = &local_tech;
00928 
00929    tmp->nativeformats = p->reqformat;
00930    tmp2->nativeformats = p->reqformat;
00931 
00932    /* Determine our read/write format and set it on each channel */
00933    fmt = ast_best_codec(p->reqformat);
00934    tmp->writeformat = fmt;
00935    tmp2->writeformat = fmt;
00936    tmp->rawwriteformat = fmt;
00937    tmp2->rawwriteformat = fmt;
00938    tmp->readformat = fmt;
00939    tmp2->readformat = fmt;
00940    tmp->rawreadformat = fmt;
00941    tmp2->rawreadformat = fmt;
00942 
00943    tmp->tech_pvt = p;
00944    tmp2->tech_pvt = p;
00945 
00946    p->owner = tmp;
00947    p->chan = tmp2;
00948    p->u_owner = ast_module_user_add(p->owner);
00949    p->u_chan = ast_module_user_add(p->chan);
00950 
00951    ast_copy_string(tmp->context, p->context, sizeof(tmp->context));
00952    ast_copy_string(tmp2->context, p->context, sizeof(tmp2->context));
00953    ast_copy_string(tmp2->exten, p->exten, sizeof(tmp->exten));
00954    tmp->priority = 1;
00955    tmp2->priority = 1;
00956 
00957    ast_jb_configure(tmp, &p->jb_conf);
00958 
00959    return tmp;
00960 }

static int local_queryoption ( struct ast_channel *  ast,
int  option,
void *  data,
int *  datalen 
) [static]

Definition at line 271 of file chan_local.c.

References ao2_lock(), ao2_unlock(), ast_bridged_channel(), ast_channel_queryoption(), ast_channel_trylock, ast_channel_unlock, AST_OPTION_T38_STATE, local_pvt::chan, IS_OUTBOUND, local_pvt::owner, and ast_channel::tech_pvt.

00272 {
00273    struct local_pvt *p = ast->tech_pvt;
00274    struct ast_channel *chan, *bridged;
00275    int res;
00276 
00277    if (!p) {
00278       return -1;
00279    }
00280 
00281    if (option != AST_OPTION_T38_STATE) {
00282       /* AST_OPTION_T38_STATE is the only supported option at this time */
00283       return -1;
00284    }
00285 
00286    ao2_lock(p);
00287    chan = IS_OUTBOUND(ast, p) ? p->owner : p->chan;
00288 
00289 try_again:
00290    if (!chan) {
00291       ao2_unlock(p);
00292       return -1;
00293    }
00294 
00295    if (ast_channel_trylock(chan)) {
00296       ao2_unlock(p);
00297       sched_yield();
00298       ao2_lock(p);
00299       chan = IS_OUTBOUND(ast, p) ? p->owner : p->chan;
00300       goto try_again;
00301    }
00302 
00303    bridged = ast_bridged_channel(chan);
00304    if (!bridged) {
00305       /* can't query channel unless we are bridged */
00306       ao2_unlock(p);
00307       ast_channel_unlock(chan);
00308       return -1;
00309    }
00310 
00311    if (ast_channel_trylock(bridged)) {
00312       ast_channel_unlock(chan);
00313       ao2_unlock(p);
00314       sched_yield();
00315       ao2_lock(p);
00316       chan = IS_OUTBOUND(ast, p) ? p->owner : p->chan;
00317       goto try_again;
00318    }
00319 
00320    res = ast_channel_queryoption(bridged, option, data, datalen, 0);
00321    ao2_unlock(p);
00322    ast_channel_unlock(chan);
00323    ast_channel_unlock(bridged);
00324    return res;
00325 }

static int local_queue_frame ( struct local_pvt *  p,
int  isoutbound,
struct ast_frame *  f,
struct ast_channel *  us,
int  us_locked 
) [static]

queue a frame on a to either the p->owner or p->chan

Note:
the local_pvt MUST have it's ref count bumped before entering this function and decremented after this function is called. This is a side effect of the deadlock avoidance that is necessary to lock 2 channels and a tech_pvt. Without a ref counted local_pvt, it is impossible to guarantee it will not be destroyed by another thread during deadlock avoidance.

Definition at line 335 of file chan_local.c.

References ao2_lock(), ao2_trylock(), ao2_unlock(), ast_channel_trylock, ast_channel_unlock, AST_CONTROL_RINGING, AST_FRAME_CONTROL, ast_log(), ast_queue_frame(), ast_setstate(), AST_STATE_RINGING, local_pvt::chan, CHANNEL_DEADLOCK_AVOIDANCE, ast_frame::frametype, ast_channel::generator, LOG_ERROR, local_pvt::owner, and ast_frame::subclass.

Referenced by local_answer(), local_digit_begin(), local_digit_end(), local_hangup(), local_indicate(), local_sendhtml(), local_sendtext(), and local_write().

00337 {
00338    struct ast_channel *other = NULL;
00339 
00340    /* Recalculate outbound channel */
00341    other = isoutbound ? p->owner : p->chan;
00342 
00343    if (!other) {
00344       return 0;
00345    }
00346 
00347    /* do not queue frame if generator is on both local channels */
00348    if (us && us->generator && other->generator) {
00349       return 0;
00350    }
00351 
00352    /* Ensure that we have both channels locked */
00353    while (other && ast_channel_trylock(other)) {
00354       int res;
00355       if ((res = ao2_unlock(p))) {
00356          ast_log(LOG_ERROR, "chan_local bug! '&p->lock' was not locked when entering local_queue_frame! (%s)\n", strerror(res));
00357          return -1;
00358       }
00359       if (us && us_locked) {
00360          do {
00361             CHANNEL_DEADLOCK_AVOIDANCE(us);
00362          } while (ao2_trylock(p));
00363       } else {
00364          usleep(1);
00365          ao2_lock(p);
00366       }
00367       other = isoutbound ? p->owner : p->chan;
00368    }
00369 
00370    if (other) {
00371       if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_RINGING) {
00372          ast_setstate(other, AST_STATE_RINGING);
00373       }
00374       ast_queue_frame(other, f);
00375       ast_channel_unlock(other);
00376    }
00377 
00378    return 0;
00379 }

static struct ast_frame * local_read ( struct ast_channel *  ast  )  [static, read]

Definition at line 477 of file chan_local.c.

References ast_null_frame.

00478 {
00479    return &ast_null_frame;
00480 }

static struct ast_channel * local_request ( const char *  type,
int  format,
void *  data,
int *  cause 
) [static, read]

Part of PBX interface.

Definition at line 963 of file chan_local.c.

References ao2_ref, ao2_unlink, AST_STATE_DOWN, local_pvt::chan, local_alloc(), and local_new().

00964 {
00965    struct local_pvt *p = NULL;
00966    struct ast_channel *chan = NULL;
00967 
00968    /* Allocate a new private structure and then Asterisk channel */
00969    if ((p = local_alloc(data, format))) {
00970       if (!(chan = local_new(p, AST_STATE_DOWN))) {
00971          ao2_unlink(locals, p);
00972       }
00973       ao2_ref(p, -1); /* kill the ref from the alloc */
00974    }
00975 
00976    return chan;
00977 }

static int local_sendhtml ( struct ast_channel *  ast,
int  subclass,
const char *  data,
int  datalen 
) [static]

Definition at line 636 of file chan_local.c.

References ao2_lock(), ao2_ref, ao2_unlock(), AST_FRAME_HTML, ast_frame::data, ast_frame::datalen, IS_OUTBOUND, local_queue_frame(), ast_frame::ptr, ast_frame::subclass, and ast_channel::tech_pvt.

00637 {
00638    struct local_pvt *p = ast->tech_pvt;
00639    int res = -1;
00640    struct ast_frame f = { AST_FRAME_HTML, };
00641    int isoutbound;
00642 
00643    if (!p)
00644       return -1;
00645    
00646    ao2_lock(p);
00647    ao2_ref(p, 1); /* ref for local_queue_frame */
00648    isoutbound = IS_OUTBOUND(ast, p);
00649    f.subclass = subclass;
00650    f.data.ptr = (char *)data;
00651    f.datalen = datalen;
00652    res = local_queue_frame(p, isoutbound, &f, ast, 0);
00653    ao2_unlock(p);
00654    ao2_ref(p, -1);
00655    return res;
00656 }

static int local_sendtext ( struct ast_channel *  ast,
const char *  text 
) [static]

Definition at line 615 of file chan_local.c.

References ao2_lock(), ao2_ref, ao2_unlock(), AST_FRAME_TEXT, ast_frame::data, ast_frame::datalen, IS_OUTBOUND, local_queue_frame(), ast_frame::ptr, and ast_channel::tech_pvt.

00616 {
00617    struct local_pvt *p = ast->tech_pvt;
00618    int res = -1;
00619    struct ast_frame f = { AST_FRAME_TEXT, };
00620    int isoutbound;
00621 
00622    if (!p)
00623       return -1;
00624 
00625    ao2_lock(p);
00626    ao2_ref(p, 1); /* ref for local_queue_frame */
00627    isoutbound = IS_OUTBOUND(ast, p);
00628    f.data.ptr = (char *) text;
00629    f.datalen = strlen(text) + 1;
00630    res = local_queue_frame(p, isoutbound, &f, ast, 0);
00631    ao2_unlock(p);
00632    ao2_ref(p, -1);
00633    return res;
00634 }

static int local_setoption ( struct ast_channel *  chan,
int  option,
void *  data,
int  datalen 
) [static]

Definition at line 133 of file chan_local.c.

References ao2_trylock(), ao2_unlock(), AST_CHAN_WRITE_INFO_T_VERSION, ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_log(), AST_OPTION_CHANNEL_WRITE, local_pvt::chan, ast_chan_write_info_t::chan, ast_chan_write_info_t::data, ast_chan_write_info_t::function, LOG_ERROR, LOG_WARNING, ast_channel::name, local_pvt::owner, ast_channel::tech_pvt, ast_chan_write_info_t::value, ast_chan_write_info_t::version, and ast_chan_write_info_t::write_fn.

00134 {
00135    int res;
00136    struct local_pvt *p;
00137    struct ast_channel *otherchan;
00138    ast_chan_write_info_t *write_info;
00139 
00140    if (option != AST_OPTION_CHANNEL_WRITE) {
00141       return -1;
00142    }
00143 
00144    write_info = data;
00145 
00146    if (write_info->version != AST_CHAN_WRITE_INFO_T_VERSION) {
00147       ast_log(LOG_ERROR, "The chan_write_info_t type has changed, and this channel hasn't been updated!\n");
00148       return -1;
00149    }
00150 
00151 
00152 startover:
00153    ast_channel_lock(chan);
00154 
00155    p = chan->tech_pvt;
00156    if (!p) {
00157       ast_channel_unlock(chan);
00158       ast_log(LOG_WARNING, "Could not update other side of %s, local_pvt went away.\n", chan->name);
00159       return -1;
00160    }
00161 
00162    while (ao2_trylock(p)) {
00163       ast_channel_unlock(chan);
00164       sched_yield();
00165       ast_channel_lock(chan);
00166       p = chan->tech_pvt;
00167       if (!p) {
00168          ast_channel_unlock(chan);
00169          ast_log(LOG_WARNING, "Could not update other side of %s, local_pvt went away.\n", chan->name);
00170          return -1;
00171       }
00172    }
00173 
00174    otherchan = (write_info->chan == p->owner) ? p->chan : p->owner;
00175 
00176    if (!otherchan || otherchan == write_info->chan) {
00177       ao2_unlock(p);
00178       ast_channel_unlock(chan);
00179       ast_log(LOG_WARNING, "Could not update other side of %s, other side went away.\n", chan->name);
00180       return 0;
00181    }
00182 
00183    if (ast_channel_trylock(otherchan)) {
00184       ao2_unlock(p);
00185       ast_channel_unlock(chan);
00186       goto startover;
00187    }
00188 
00189    res = write_info->write_fn(otherchan, write_info->function, write_info->data, write_info->value);
00190 
00191    ast_channel_unlock(otherchan);
00192    ao2_unlock(p);
00193    ast_channel_unlock(chan);
00194 
00195    return res;
00196 }

static int local_write ( struct ast_channel *  ast,
struct ast_frame *  f 
) [static]

Definition at line 482 of file chan_local.c.

References ao2_lock(), ao2_ref, ao2_unlock(), ast_debug, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_test_flag, check_bridge(), ast_frame::frametype, IS_OUTBOUND, LOCAL_ALREADY_MASQED, local_queue_frame(), ast_channel::name, and ast_channel::tech_pvt.

00483 {
00484    struct local_pvt *p = ast->tech_pvt;
00485    int res = -1;
00486    int isoutbound;
00487 
00488    if (!p)
00489       return -1;
00490 
00491    /* Just queue for delivery to the other side */
00492    ao2_lock(p);
00493    ao2_ref(p, 1); /* ref for local_queue_frame */
00494    isoutbound = IS_OUTBOUND(ast, p);
00495    if (isoutbound && f && (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO))
00496       check_bridge(p);
00497    if (!ast_test_flag(p, LOCAL_ALREADY_MASQED))
00498       res = local_queue_frame(p, isoutbound, f, ast, 1);
00499    else {
00500       ast_debug(1, "Not posting to queue since already masked on '%s'\n", ast->name);
00501       res = 0;
00502    }
00503    ao2_unlock(p);
00504    ao2_ref(p, -1);
00505 
00506    return res;
00507 }

static int locals_cmp_cb ( void *  obj,
void *  arg,
int  flags 
) [static]

Definition at line 1020 of file chan_local.c.

References CMP_MATCH.

Referenced by load_module().

01021 {
01022    return (obj == arg) ? CMP_MATCH : 0;
01023 }

static char* locals_show ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

CLI command "local show channels".

Definition at line 980 of file chan_local.c.

References ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock(), ao2_ref, ao2_unlock(), ast_cli_args::argc, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, local_pvt::context, local_pvt::exten, ast_cli_args::fd, ast_channel::name, local_pvt::owner, RESULT_SUCCESS, and ast_cli_entry::usage.

00981 {
00982    struct local_pvt *p = NULL;
00983    struct ao2_iterator it;
00984 
00985    switch (cmd) {
00986    case CLI_INIT:
00987       e->command = "local show channels";
00988       e->usage =
00989          "Usage: local show channels\n"
00990          "       Provides summary information on active local proxy channels.\n";
00991       return NULL;
00992    case CLI_GENERATE:
00993       return NULL;
00994    }
00995 
00996    if (a->argc != 3)
00997       return CLI_SHOWUSAGE;
00998 
00999    if (ao2_container_count(locals) == 0) {
01000       ast_cli(a->fd, "No local channels in use\n");
01001       return RESULT_SUCCESS;
01002    }
01003 
01004    it = ao2_iterator_init(locals, 0);
01005    while ((p = ao2_iterator_next(&it))) {
01006       ao2_lock(p);
01007       ast_cli(a->fd, "%s -- %s@%s\n", p->owner ? p->owner->name : "<unowned>", p->exten, p->context);
01008       ao2_unlock(p);
01009       ao2_ref(p, -1);
01010    }
01011    ao2_iterator_destroy(&it);
01012 
01013    return CLI_SUCCESS;
01014 }

static int unload_module ( void   )  [static]

Unload the local proxy channel from Asterisk.

Definition at line 1043 of file chan_local.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_channel_unregister(), ast_cli_unregister_multiple(), ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, cli_local, and local_pvt::owner.

01044 {
01045    struct local_pvt *p = NULL;
01046    struct ao2_iterator it;
01047 
01048    /* First, take us out of the channel loop */
01049    ast_cli_unregister_multiple(cli_local, sizeof(cli_local) / sizeof(struct ast_cli_entry));
01050    ast_channel_unregister(&local_tech);
01051 
01052    it = ao2_iterator_init(locals, 0);
01053    while ((p = ao2_iterator_next(&it))) {
01054       if (p->owner) {
01055          ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
01056       }
01057       ao2_ref(p, -1);
01058    }
01059    ao2_iterator_destroy(&it);
01060    ao2_ref(locals, -1);
01061    return 0;
01062 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Local Proxy Channel (Note: used internally by other modules)" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static]

Definition at line 1064 of file chan_local.c.

Definition at line 1064 of file chan_local.c.

const int BUCKET_SIZE = 1 [static]

Definition at line 60 of file chan_local.c.

struct ast_cli_entry cli_local[] [static]

Initial value:

 {
   AST_CLI_DEFINE(locals_show, "List status of local channels"),
}

Definition at line 1016 of file chan_local.c.

Referenced by load_module(), and unload_module().

struct ast_jb_conf g_jb_conf [static]

Definition at line 64 of file chan_local.c.

struct ast_channel_tech local_tech [static]

Definition at line 90 of file chan_local.c.

struct ao2_container* locals [static]

Definition at line 62 of file chan_local.c.

const char tdesc[] = "Local Proxy Channel Driver" [static]

Definition at line 54 of file chan_local.c.


Generated on Sat Mar 26 11:15:47 2011 for Asterisk - the Open Source PBX by  doxygen 1.5.9