Sat Mar 26 11:07:06 2011

Asterisk developer's documentation


chan_local.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \author Mark Spencer <markster@digium.com>
00022  *
00023  * \brief Local Proxy Channel
00024  * 
00025  * \ingroup channel_drivers
00026  */
00027 
00028 #include "asterisk.h"
00029 
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 288748 $")
00031 
00032 #include <fcntl.h>
00033 #include <sys/signal.h>
00034 
00035 #include "asterisk/lock.h"
00036 #include "asterisk/channel.h"
00037 #include "asterisk/config.h"
00038 #include "asterisk/module.h"
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/sched.h"
00041 #include "asterisk/io.h"
00042 #include "asterisk/acl.h"
00043 #include "asterisk/callerid.h"
00044 #include "asterisk/file.h"
00045 #include "asterisk/cli.h"
00046 #include "asterisk/app.h"
00047 #include "asterisk/musiconhold.h"
00048 #include "asterisk/manager.h"
00049 #include "asterisk/stringfields.h"
00050 #include "asterisk/devicestate.h"
00051 
00052 /*** DOCUMENTATION
00053    <manager name="LocalOptimizeAway" language="en_US">
00054       <synopsis>
00055          Optimize away a local channel when possible.
00056       </synopsis>
00057       <syntax>
00058          <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
00059          <parameter name="Channel" required="true">
00060             <para>The channel name to optimize away.</para>
00061          </parameter>
00062       </syntax>
00063       <description>
00064          <para>A local channel created with "/n" will not automatically optimize away.
00065          Calling this command on the local channel will clear that flag and allow
00066          it to optimize away if it's bridged or when it becomes bridged.</para>
00067       </description>
00068    </manager>
00069  ***/
00070 
00071 static const char tdesc[] = "Local Proxy Channel Driver";
00072 
00073 #define IS_OUTBOUND(a,b) (a == b->chan ? 1 : 0)
00074 
00075 static struct ast_jb_conf g_jb_conf = {
00076    .flags = 0,
00077    .max_size = -1,
00078    .resync_threshold = -1,
00079    .impl = "",
00080    .target_extra = -1,
00081 };
00082 
00083 static struct ast_channel *local_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
00084 static int local_digit_begin(struct ast_channel *ast, char digit);
00085 static int local_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
00086 static int local_call(struct ast_channel *ast, char *dest, int timeout);
00087 static int local_hangup(struct ast_channel *ast);
00088 static int local_answer(struct ast_channel *ast);
00089 static struct ast_frame *local_read(struct ast_channel *ast);
00090 static int local_write(struct ast_channel *ast, struct ast_frame *f);
00091 static int local_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
00092 static int local_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
00093 static int local_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen);
00094 static int local_sendtext(struct ast_channel *ast, const char *text);
00095 static int local_devicestate(void *data);
00096 static struct ast_channel *local_bridgedchannel(struct ast_channel *chan, struct ast_channel *bridge);
00097 static int local_queryoption(struct ast_channel *ast, int option, void *data, int *datalen);
00098 static int local_setoption(struct ast_channel *chan, int option, void *data, int datalen);
00099 
00100 /* PBX interface structure for channel registration */
00101 static const struct ast_channel_tech local_tech = {
00102    .type = "Local",
00103    .description = tdesc,
00104    .capabilities = -1,
00105    .requester = local_request,
00106    .send_digit_begin = local_digit_begin,
00107    .send_digit_end = local_digit_end,
00108    .call = local_call,
00109    .hangup = local_hangup,
00110    .answer = local_answer,
00111    .read = local_read,
00112    .write = local_write,
00113    .write_video = local_write,
00114    .exception = local_read,
00115    .indicate = local_indicate,
00116    .fixup = local_fixup,
00117    .send_html = local_sendhtml,
00118    .send_text = local_sendtext,
00119    .devicestate = local_devicestate,
00120    .bridged_channel = local_bridgedchannel,
00121    .queryoption = local_queryoption,
00122    .setoption = local_setoption,
00123 };
00124 
00125 /*! \brief the local pvt structure for all channels
00126 
00127    The local channel pvt has two ast_chan objects - the "owner" and the "next channel", the outbound channel
00128 
00129    ast_chan owner -> local_pvt -> ast_chan chan -> yet-another-pvt-depending-on-channel-type
00130 
00131 */
00132 struct local_pvt {
00133    ast_mutex_t lock;       /*!< Channel private lock */
00134    unsigned int flags;                     /*!< Private flags */
00135    char context[AST_MAX_CONTEXT];      /*!< Context to call */
00136    char exten[AST_MAX_EXTENSION];      /*!< Extension to call */
00137    int reqformat;          /*!< Requested format */
00138    struct ast_jb_conf jb_conf;      /*!< jitterbuffer configuration for this local channel */
00139    struct ast_channel *owner;    /*!< Master Channel - Bridging happens here */
00140    struct ast_channel *chan;     /*!< Outbound channel - PBX is run here */
00141    struct ast_module_user *u_owner; /*!< reference to keep the module loaded while in use */
00142    struct ast_module_user *u_chan;     /*!< reference to keep the module loaded while in use */
00143    AST_LIST_ENTRY(local_pvt) list;     /*!< Next entity */
00144 };
00145 
00146 #define LOCAL_GLARE_DETECT    (1 << 0) /*!< Detect glare on hangup */
00147 #define LOCAL_CANCEL_QUEUE    (1 << 1) /*!< Cancel queue */
00148 #define LOCAL_ALREADY_MASQED  (1 << 2) /*!< Already masqueraded */
00149 #define LOCAL_LAUNCHED_PBX    (1 << 3) /*!< PBX was launched */
00150 #define LOCAL_NO_OPTIMIZATION (1 << 4) /*!< Do not optimize using masquerading */
00151 #define LOCAL_BRIDGE          (1 << 5) /*!< Report back the "true" channel as being bridged to */
00152 #define LOCAL_MOH_PASSTHRU    (1 << 6) /*!< Pass through music on hold start/stop frames */
00153 
00154 static AST_LIST_HEAD_STATIC(locals, local_pvt);
00155 
00156 static int local_setoption(struct ast_channel *chan, int option, void * data, int datalen)
00157 {
00158    int res;
00159    struct local_pvt *p;
00160    struct ast_channel *otherchan;
00161    ast_chan_write_info_t *write_info;
00162 
00163    if (option != AST_OPTION_CHANNEL_WRITE) {
00164       return -1;
00165    }
00166 
00167    write_info = data;
00168 
00169    if (write_info->version != AST_CHAN_WRITE_INFO_T_VERSION) {
00170       ast_log(LOG_ERROR, "The chan_write_info_t type has changed, and this channel hasn't been updated!\n");
00171       return -1;
00172    }
00173 
00174 
00175 startover:
00176    ast_channel_lock(chan);
00177 
00178    p = chan->tech_pvt;
00179    if (!p) {
00180       ast_channel_unlock(chan);
00181       ast_log(LOG_WARNING, "Could not update other side of %s, local_pvt went away.\n", chan->name);
00182       return -1;
00183    }
00184 
00185    while (ast_mutex_trylock(&p->lock)) {
00186       ast_channel_unlock(chan);
00187       sched_yield();
00188       ast_channel_lock(chan);
00189       p = chan->tech_pvt;
00190       if (!p) {
00191          ast_channel_unlock(chan);
00192          ast_log(LOG_WARNING, "Could not update other side of %s, local_pvt went away.\n", chan->name);
00193          return -1;
00194       }
00195    }
00196 
00197    otherchan = (write_info->chan == p->owner) ? p->chan : p->owner;
00198 
00199    if (!otherchan || otherchan == write_info->chan) {
00200       ast_mutex_unlock(&p->lock);
00201       ast_channel_unlock(chan);
00202       ast_log(LOG_WARNING, "Could not update other side of %s, other side went away.\n", chan->name);
00203       return 0;
00204    }
00205 
00206    if (ast_channel_trylock(otherchan)) {
00207       ast_mutex_unlock(&p->lock);
00208       ast_channel_unlock(chan);
00209       goto startover;
00210    }
00211 
00212    res = write_info->write_fn(otherchan, write_info->function, write_info->data, write_info->value);
00213 
00214    ast_channel_unlock(otherchan);
00215    ast_mutex_unlock(&p->lock);
00216    ast_channel_unlock(chan);
00217 
00218    return res;
00219 }
00220 
00221 /*! \brief Adds devicestate to local channels */
00222 static int local_devicestate(void *data)
00223 {
00224    char *exten = ast_strdupa(data);
00225    char *context = NULL, *opts = NULL;
00226    int res;
00227    struct local_pvt *lp;
00228 
00229    if (!(context = strchr(exten, '@'))) {
00230       ast_log(LOG_WARNING, "Someone used Local/%s somewhere without a @context. This is bad.\n", exten);
00231       return AST_DEVICE_INVALID; 
00232    }
00233 
00234    *context++ = '\0';
00235 
00236    /* Strip options if they exist */
00237    if ((opts = strchr(context, '/')))
00238       *opts = '\0';
00239 
00240    ast_debug(3, "Checking if extension %s@%s exists (devicestate)\n", exten, context);
00241 
00242    res = ast_exists_extension(NULL, context, exten, 1, NULL);
00243    if (!res)      
00244       return AST_DEVICE_INVALID;
00245    
00246    res = AST_DEVICE_NOT_INUSE;
00247    AST_LIST_LOCK(&locals);
00248    AST_LIST_TRAVERSE(&locals, lp, list) {
00249       if (!strcmp(exten, lp->exten) && !strcmp(context, lp->context) && lp->owner) {
00250          res = AST_DEVICE_INUSE;
00251          break;
00252       }
00253    }
00254    AST_LIST_UNLOCK(&locals);
00255 
00256    return res;
00257 }
00258 
00259 /*!
00260  * \note Assumes the pvt is no longer in the pvts list
00261  */
00262 static struct local_pvt *local_pvt_destroy(struct local_pvt *pvt)
00263 {
00264    ast_mutex_destroy(&pvt->lock);
00265    ast_free(pvt);
00266    return NULL;
00267 }
00268 
00269 /*! \brief Return the bridged channel of a Local channel */
00270 static struct ast_channel *local_bridgedchannel(struct ast_channel *chan, struct ast_channel *bridge)
00271 {
00272    struct local_pvt *p = bridge->tech_pvt;
00273    struct ast_channel *bridged = bridge;
00274 
00275    if (!p) {
00276       ast_debug(1, "Asked for bridged channel on '%s'/'%s', returning <none>\n",
00277          chan->name, bridge->name);
00278       return NULL;
00279    }
00280 
00281    ast_mutex_lock(&p->lock);
00282 
00283    if (ast_test_flag(p, LOCAL_BRIDGE)) {
00284       /* Find the opposite channel */
00285       bridged = (bridge == p->owner ? p->chan : p->owner);
00286       
00287       /* Now see if the opposite channel is bridged to anything */
00288       if (!bridged) {
00289          bridged = bridge;
00290       } else if (bridged->_bridge) {
00291          bridged = bridged->_bridge;
00292       }
00293    }
00294 
00295    ast_mutex_unlock(&p->lock);
00296 
00297    return bridged;
00298 }
00299 
00300 static int local_queryoption(struct ast_channel *ast, int option, void *data, int *datalen)
00301 {
00302    struct local_pvt *p = ast->tech_pvt;
00303    struct ast_channel *chan, *bridged;
00304    int res;
00305 
00306    if (!p) {
00307       return -1;
00308    }
00309 
00310    if (option != AST_OPTION_T38_STATE) {
00311       /* AST_OPTION_T38_STATE is the only supported option at this time */
00312       return -1;
00313    }
00314 
00315    ast_mutex_lock(&p->lock);
00316    chan = IS_OUTBOUND(ast, p) ? p->owner : p->chan;
00317 
00318 try_again:
00319    if (!chan) {
00320       ast_mutex_unlock(&p->lock);
00321       return -1;
00322    }
00323 
00324    if (ast_channel_trylock(chan)) {
00325       DEADLOCK_AVOIDANCE(&p->lock);
00326       chan = IS_OUTBOUND(ast, p) ? p->owner : p->chan;
00327       goto try_again;
00328    }
00329 
00330    bridged = ast_bridged_channel(chan);
00331    if (!bridged) {
00332       /* can't query channel unless we are bridged */
00333       ast_mutex_unlock(&p->lock);
00334       ast_channel_unlock(chan);
00335       return -1;
00336    }
00337 
00338    if (ast_channel_trylock(bridged)) {
00339       ast_channel_unlock(chan);
00340       DEADLOCK_AVOIDANCE(&p->lock);
00341       chan = IS_OUTBOUND(ast, p) ? p->owner : p->chan;
00342       goto try_again;
00343    }
00344 
00345    res = ast_channel_queryoption(bridged, option, data, datalen, 0);
00346    ast_mutex_unlock(&p->lock);
00347    ast_channel_unlock(chan);
00348    ast_channel_unlock(bridged);
00349    return res;
00350 }
00351 
00352 static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_frame *f, 
00353    struct ast_channel *us, int us_locked)
00354 {
00355    struct ast_channel *other = NULL;
00356 
00357    /* Recalculate outbound channel */
00358    other = isoutbound ? p->owner : p->chan;
00359 
00360    if (!other) {
00361       return 0;
00362    }
00363 
00364    /* do not queue frame if generator is on both local channels */
00365    if (us && us->generator && other->generator) {
00366       return 0;
00367    }
00368 
00369    /* Set glare detection */
00370    ast_set_flag(p, LOCAL_GLARE_DETECT);
00371 
00372    /* Ensure that we have both channels locked */
00373    while (other && ast_channel_trylock(other)) {
00374       int res;
00375       if ((res = ast_mutex_unlock(&p->lock))) {
00376          ast_log(LOG_ERROR, "chan_local bug! '&p->lock' was not locked when entering local_queue_frame! (%s)\n", strerror(res));
00377          return -1;
00378       }
00379       if (us && us_locked) {
00380          do {
00381             CHANNEL_DEADLOCK_AVOIDANCE(us);
00382          } while (ast_mutex_trylock(&p->lock));
00383       } else {
00384          usleep(1);
00385          ast_mutex_lock(&p->lock);
00386       }
00387       other = isoutbound ? p->owner : p->chan;
00388    }
00389 
00390    /* Since glare detection only occurs within this function, and because
00391     * a pvt flag cannot be set without having the pvt lock, this is the only
00392     * location where we could detect a cancelling of the queue. */
00393    if (ast_test_flag(p, LOCAL_CANCEL_QUEUE)) {
00394       /* We had a glare on the hangup.  Forget all this business,
00395       return and destroy p.  */
00396       ast_mutex_unlock(&p->lock);
00397       p = local_pvt_destroy(p);
00398       if (other) {
00399          ast_channel_unlock(other);
00400       }
00401       return -1;
00402    }
00403 
00404    if (other) {
00405       if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_RINGING) {
00406          ast_setstate(other, AST_STATE_RINGING);
00407       }
00408       ast_queue_frame(other, f);
00409       ast_channel_unlock(other);
00410    }
00411 
00412    ast_clear_flag(p, LOCAL_GLARE_DETECT);
00413 
00414    return 0;
00415 }
00416 
00417 static int local_answer(struct ast_channel *ast)
00418 {
00419    struct local_pvt *p = ast->tech_pvt;
00420    int isoutbound;
00421    int res = -1;
00422 
00423    if (!p)
00424       return -1;
00425 
00426    ast_mutex_lock(&p->lock);
00427    isoutbound = IS_OUTBOUND(ast, p);
00428    if (isoutbound) {
00429       /* Pass along answer since somebody answered us */
00430       struct ast_frame answer = { AST_FRAME_CONTROL, { AST_CONTROL_ANSWER } };
00431       res = local_queue_frame(p, isoutbound, &answer, ast, 1);
00432    } else
00433       ast_log(LOG_WARNING, "Huh?  Local is being asked to answer?\n");
00434    if (!res)
00435       ast_mutex_unlock(&p->lock);
00436    return res;
00437 }
00438 
00439 /*!
00440  * \internal
00441  * \note This function assumes that we're only called from the "outbound" local channel side
00442  */
00443 static void check_bridge(struct local_pvt *p)
00444 {
00445    struct ast_channel_monitor *tmp;
00446    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)))
00447       return;
00448 
00449    /* only do the masquerade if we are being called on the outbound channel,
00450       if it has been bridged to another channel and if there are no pending
00451       frames on the owner channel (because they would be transferred to the
00452       outbound channel during the masquerade)
00453    */
00454    if (p->chan->_bridge /* Not ast_bridged_channel!  Only go one step! */ && AST_LIST_EMPTY(&p->owner->readq)) {
00455       /* Masquerade bridged channel into owner */
00456       /* Lock everything we need, one by one, and give up if
00457          we can't get everything.  Remember, we'll get another
00458          chance in just a little bit */
00459       if (!ast_channel_trylock(p->chan->_bridge)) {
00460          if (!ast_check_hangup(p->chan->_bridge)) {
00461             if (!ast_channel_trylock(p->owner)) {
00462                if (!ast_check_hangup(p->owner)) {
00463                   if (p->owner->monitor && !p->chan->_bridge->monitor) {
00464                      /* If a local channel is being monitored, we don't want a masquerade
00465                       * to cause the monitor to go away. Since the masquerade swaps the monitors,
00466                       * pre-swapping the monitors before the masquerade will ensure that the monitor
00467                       * ends up where it is expected.
00468                       */
00469                      tmp = p->owner->monitor;
00470                      p->owner->monitor = p->chan->_bridge->monitor;
00471                      p->chan->_bridge->monitor = tmp;
00472                   }
00473                   if (p->chan->audiohooks) {
00474                      struct ast_audiohook_list *audiohooks_swapper;
00475                      audiohooks_swapper = p->chan->audiohooks;
00476                      p->chan->audiohooks = p->owner->audiohooks;
00477                      p->owner->audiohooks = audiohooks_swapper;
00478                   }
00479 
00480                   /* If any Caller ID was set, preserve it after masquerade like above. We must check
00481                    * to see if Caller ID was set because otherwise we'll mistakingly copy info not
00482                    * set from the dialplan and will overwrite the real channel Caller ID. The reason
00483                    * for this whole preswapping action is because the Caller ID is set on the channel
00484                    * thread (which is the to be masqueraded away local channel) before both local
00485                    * channels are optimized away.
00486                    */
00487                   if (p->owner->caller.id.name.valid || p->owner->caller.id.number.valid
00488                      || p->owner->caller.id.subaddress.valid || p->owner->caller.ani.name.valid
00489                      || p->owner->caller.ani.number.valid || p->owner->caller.ani.subaddress.valid) {
00490                      struct ast_party_caller tmp;
00491                      tmp = p->owner->caller;
00492                      p->owner->caller = p->chan->_bridge->caller;
00493                      p->chan->_bridge->caller = tmp;
00494                   }
00495                   if (p->owner->redirecting.from.name.valid || p->owner->redirecting.from.number.valid
00496                      || p->owner->redirecting.from.subaddress.valid || p->owner->redirecting.to.name.valid
00497                      || p->owner->redirecting.to.number.valid || p->owner->redirecting.to.subaddress.valid) {
00498                      struct ast_party_redirecting tmp;
00499                      tmp = p->owner->redirecting;
00500                      p->owner->redirecting = p->chan->_bridge->redirecting;
00501                      p->chan->_bridge->redirecting = tmp;
00502                   }
00503                   if (p->owner->dialed.number.str || p->owner->dialed.subaddress.valid) {
00504                      struct ast_party_dialed tmp;
00505                      tmp = p->owner->dialed;
00506                      p->owner->dialed = p->chan->_bridge->dialed;
00507                      p->chan->_bridge->dialed = tmp;
00508                   }
00509 
00510 
00511                   ast_app_group_update(p->chan, p->owner);
00512                   ast_channel_masquerade(p->owner, p->chan->_bridge);
00513                   ast_set_flag(p, LOCAL_ALREADY_MASQED);
00514                }
00515                ast_channel_unlock(p->owner);
00516             }
00517             ast_channel_unlock(p->chan->_bridge);
00518          }
00519       }
00520    }
00521 }
00522 
00523 static struct ast_frame  *local_read(struct ast_channel *ast)
00524 {
00525    return &ast_null_frame;
00526 }
00527 
00528 static int local_write(struct ast_channel *ast, struct ast_frame *f)
00529 {
00530    struct local_pvt *p = ast->tech_pvt;
00531    int res = -1;
00532    int isoutbound;
00533 
00534    if (!p)
00535       return -1;
00536 
00537    /* Just queue for delivery to the other side */
00538    ast_mutex_lock(&p->lock);
00539    isoutbound = IS_OUTBOUND(ast, p);
00540    if (isoutbound && f && (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO))
00541       check_bridge(p);
00542    if (!ast_test_flag(p, LOCAL_ALREADY_MASQED))
00543       res = local_queue_frame(p, isoutbound, f, ast, 1);
00544    else {
00545       ast_debug(1, "Not posting to queue since already masked on '%s'\n", ast->name);
00546       res = 0;
00547    }
00548    if (!res)
00549       ast_mutex_unlock(&p->lock);
00550    return res;
00551 }
00552 
00553 static int local_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
00554 {
00555    struct local_pvt *p = newchan->tech_pvt;
00556 
00557    if (!p)
00558       return -1;
00559 
00560    ast_mutex_lock(&p->lock);
00561 
00562    if ((p->owner != oldchan) && (p->chan != oldchan)) {
00563       ast_log(LOG_WARNING, "Old channel wasn't %p but was %p/%p\n", oldchan, p->owner, p->chan);
00564       ast_mutex_unlock(&p->lock);
00565       return -1;
00566    }
00567    if (p->owner == oldchan)
00568       p->owner = newchan;
00569    else
00570       p->chan = newchan;
00571 
00572    /* Do not let a masquerade cause a Local channel to be bridged to itself! */
00573    if (!ast_check_hangup(newchan) && (p->owner->_bridge == p->chan || p->chan->_bridge == p->owner)) {
00574       ast_log(LOG_WARNING, "You can not bridge a Local channel to itself!\n");
00575       ast_mutex_unlock(&p->lock);
00576       ast_queue_hangup(newchan);
00577       return -1;
00578    }
00579 
00580    ast_mutex_unlock(&p->lock);
00581    return 0;
00582 }
00583 
00584 static int local_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
00585 {
00586    struct local_pvt *p = ast->tech_pvt;
00587    int res = 0;
00588    struct ast_frame f = { AST_FRAME_CONTROL, };
00589    int isoutbound;
00590 
00591    if (!p)
00592       return -1;
00593 
00594    /* If this is an MOH hold or unhold, do it on the Local channel versus real channel */
00595    if (!ast_test_flag(p, LOCAL_MOH_PASSTHRU) && condition == AST_CONTROL_HOLD) {
00596       ast_moh_start(ast, data, NULL);
00597    } else if (!ast_test_flag(p, LOCAL_MOH_PASSTHRU) && condition == AST_CONTROL_UNHOLD) {
00598       ast_moh_stop(ast);
00599    } else if (condition == AST_CONTROL_CONNECTED_LINE || condition == AST_CONTROL_REDIRECTING) {
00600       struct ast_channel *this_channel;
00601       struct ast_channel *the_other_channel;
00602       /* A connected line update frame may only contain a partial amount of data, such
00603        * as just a source, or just a ton, and not the full amount of information. However,
00604        * the collected information is all stored in the outgoing channel's connectedline
00605        * structure, so when receiving a connected line update on an outgoing local channel,
00606        * we need to transmit the collected connected line information instead of whatever
00607        * happens to be in this control frame. The same applies for redirecting information, which
00608        * is why it is handled here as well.*/
00609       ast_mutex_lock(&p->lock);
00610       isoutbound = IS_OUTBOUND(ast, p);
00611       if (isoutbound) {
00612          this_channel = p->chan;
00613          the_other_channel = p->owner;
00614       } else {
00615          this_channel = p->owner;
00616          the_other_channel = p->chan;
00617       }
00618       if (the_other_channel) {
00619          unsigned char frame_data[1024];
00620          if (condition == AST_CONTROL_CONNECTED_LINE) {
00621             if (isoutbound) {
00622                ast_connected_line_copy_to_caller(&the_other_channel->caller, &this_channel->connected);
00623             }
00624             f.datalen = ast_connected_line_build_data(frame_data, sizeof(frame_data), &this_channel->connected, NULL);
00625          } else {
00626             f.datalen = ast_redirecting_build_data(frame_data, sizeof(frame_data), &this_channel->redirecting, NULL);
00627          }
00628          f.subclass.integer = condition;
00629          f.data.ptr = frame_data;
00630          if (!(res = local_queue_frame(p, isoutbound, &f, ast, 1))) {
00631             ast_mutex_unlock(&p->lock);
00632          }
00633       } else {
00634          ast_mutex_unlock(&p->lock);
00635       }
00636    } else {
00637       /* Queue up a frame representing the indication as a control frame */
00638       ast_mutex_lock(&p->lock);
00639       isoutbound = IS_OUTBOUND(ast, p);
00640       f.subclass.integer = condition;
00641       f.data.ptr = (void*)data;
00642       f.datalen = datalen;
00643       if (!(res = local_queue_frame(p, isoutbound, &f, ast, 1)))
00644          ast_mutex_unlock(&p->lock);
00645    }
00646 
00647    return res;
00648 }
00649 
00650 static int local_digit_begin(struct ast_channel *ast, char digit)
00651 {
00652    struct local_pvt *p = ast->tech_pvt;
00653    int res = -1;
00654    struct ast_frame f = { AST_FRAME_DTMF_BEGIN, };
00655    int isoutbound;
00656 
00657    if (!p)
00658       return -1;
00659 
00660    ast_mutex_lock(&p->lock);
00661    isoutbound = IS_OUTBOUND(ast, p);
00662    f.subclass.integer = digit;
00663    if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0)))
00664       ast_mutex_unlock(&p->lock);
00665 
00666    return res;
00667 }
00668 
00669 static int local_digit_end(struct ast_channel *ast, char digit, unsigned int duration)
00670 {
00671    struct local_pvt *p = ast->tech_pvt;
00672    int res = -1;
00673    struct ast_frame f = { AST_FRAME_DTMF_END, };
00674    int isoutbound;
00675 
00676    if (!p)
00677       return -1;
00678 
00679    ast_mutex_lock(&p->lock);
00680    isoutbound = IS_OUTBOUND(ast, p);
00681    f.subclass.integer = digit;
00682    f.len = duration;
00683    if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0)))
00684       ast_mutex_unlock(&p->lock);
00685 
00686    return res;
00687 }
00688 
00689 static int local_sendtext(struct ast_channel *ast, const char *text)
00690 {
00691    struct local_pvt *p = ast->tech_pvt;
00692    int res = -1;
00693    struct ast_frame f = { AST_FRAME_TEXT, };
00694    int isoutbound;
00695 
00696    if (!p)
00697       return -1;
00698 
00699    ast_mutex_lock(&p->lock);
00700    isoutbound = IS_OUTBOUND(ast, p);
00701    f.data.ptr = (char *) text;
00702    f.datalen = strlen(text) + 1;
00703    if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0)))
00704       ast_mutex_unlock(&p->lock);
00705    return res;
00706 }
00707 
00708 static int local_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen)
00709 {
00710    struct local_pvt *p = ast->tech_pvt;
00711    int res = -1;
00712    struct ast_frame f = { AST_FRAME_HTML, };
00713    int isoutbound;
00714 
00715    if (!p)
00716       return -1;
00717    
00718    ast_mutex_lock(&p->lock);
00719    isoutbound = IS_OUTBOUND(ast, p);
00720    f.subclass.integer = subclass;
00721    f.data.ptr = (char *)data;
00722    f.datalen = datalen;
00723    if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0)))
00724       ast_mutex_unlock(&p->lock);
00725    return res;
00726 }
00727 
00728 /*! \brief Initiate new call, part of PBX interface 
00729  *    dest is the dial string */
00730 static int local_call(struct ast_channel *ast, char *dest, int timeout)
00731 {
00732    struct local_pvt *p = ast->tech_pvt;
00733    int res;
00734    struct ast_var_t *varptr = NULL, *new;
00735    size_t len, namelen;
00736    char *reduced_dest = ast_strdupa(dest);
00737    char *slash;
00738 
00739    if (!p)
00740       return -1;
00741 
00742    /* If you value your sanity, please don't look at this code */
00743 start_over:
00744    while (ast_channel_trylock(p->chan)) {
00745       ast_channel_unlock(p->owner);
00746       usleep(1);
00747       ast_channel_lock(p->owner);
00748    }
00749 
00750    /* p->owner and p->chan are locked now. Let's get p locked */
00751    if (ast_mutex_trylock(&p->lock)) {
00752       /* @#$&$@ */
00753       ast_channel_unlock(p->chan);
00754       ast_channel_unlock(p->owner);
00755       usleep(1);
00756       ast_channel_lock(p->owner);
00757       goto start_over;
00758    }
00759 
00760    /*
00761     * Note that cid_num and cid_name aren't passed in the ast_channel_alloc
00762     * call, so it's done here instead.
00763     *
00764     * All these failure points just return -1. The individual strings will
00765     * be cleared when we destroy the channel.
00766     */
00767    ast_party_redirecting_copy(&p->chan->redirecting, &p->owner->redirecting);
00768 
00769    ast_party_dialed_copy(&p->chan->dialed, &p->owner->dialed);
00770 
00771    ast_connected_line_copy_to_caller(&p->chan->caller, &p->owner->connected);
00772    ast_connected_line_copy_from_caller(&p->chan->connected, &p->owner->caller);
00773 
00774    ast_string_field_set(p->chan, language, p->owner->language);
00775    ast_string_field_set(p->chan, accountcode, p->owner->accountcode);
00776    ast_string_field_set(p->chan, musicclass, p->owner->musicclass);
00777    ast_cdr_update(p->chan);
00778 
00779    ast_channel_cc_params_init(p->chan, ast_channel_get_cc_config_params(p->owner));
00780 
00781    if (!ast_exists_extension(NULL, p->chan->context, p->chan->exten, 1,
00782       S_COR(p->owner->caller.id.number.valid, p->owner->caller.id.number.str, NULL))) {
00783       ast_log(LOG_NOTICE, "No such extension/context %s@%s while calling Local channel\n", p->chan->exten, p->chan->context);
00784       ast_mutex_unlock(&p->lock);
00785       ast_channel_unlock(p->chan);
00786       return -1;
00787    }
00788 
00789    /* Make sure we inherit the ANSWERED_ELSEWHERE flag if it's set on the queue/dial call request in the dialplan */
00790    if (ast_test_flag(ast, AST_FLAG_ANSWERED_ELSEWHERE)) {
00791       ast_set_flag(p->chan, AST_FLAG_ANSWERED_ELSEWHERE);
00792    }
00793 
00794    /* copy the channel variables from the incoming channel to the outgoing channel */
00795    /* Note that due to certain assumptions, they MUST be in the same order */
00796    AST_LIST_TRAVERSE(&p->owner->varshead, varptr, entries) {
00797       namelen = strlen(varptr->name);
00798       len = sizeof(struct ast_var_t) + namelen + strlen(varptr->value) + 2;
00799       if ((new = ast_calloc(1, len))) {
00800          memcpy(new, varptr, len);
00801          new->value = &(new->name[0]) + namelen + 1;
00802          AST_LIST_INSERT_TAIL(&p->chan->varshead, new, entries);
00803       }
00804    }
00805    ast_channel_datastore_inherit(p->owner, p->chan);
00806    /* If the local channel has /n or /b on the end of it,
00807     * we need to lop that off for our argument to setting
00808     * up the CC_INTERFACES variable
00809     */
00810    if ((slash = strrchr(reduced_dest, '/'))) {
00811       *slash = '\0';
00812    }
00813    ast_set_cc_interfaces_chanvar(p->chan, reduced_dest);
00814 
00815    /* Start switch on sub channel */
00816    if (!(res = ast_pbx_start(p->chan)))
00817       ast_set_flag(p, LOCAL_LAUNCHED_PBX);
00818 
00819    ast_mutex_unlock(&p->lock);
00820    ast_channel_unlock(p->chan);
00821    return res;
00822 }
00823 
00824 /*! \brief Hangup a call through the local proxy channel */
00825 static int local_hangup(struct ast_channel *ast)
00826 {
00827    struct local_pvt *p = ast->tech_pvt;
00828    int isoutbound;
00829    struct ast_frame f = { AST_FRAME_CONTROL, { AST_CONTROL_HANGUP }, .data.uint32 = ast->hangupcause };
00830    struct ast_channel *ochan = NULL;
00831    int glaredetect = 0, res = 0;
00832 
00833    if (!p)
00834       return -1;
00835 
00836    ast_mutex_lock(&p->lock);
00837 
00838    isoutbound = IS_OUTBOUND(ast, p);
00839 
00840    if (p->chan && ast_test_flag(ast, AST_FLAG_ANSWERED_ELSEWHERE)) {
00841       ast_set_flag(p->chan, AST_FLAG_ANSWERED_ELSEWHERE);
00842       ast_debug(2, "This local call has the ANSWERED_ELSEWHERE flag set.\n");
00843    }
00844 
00845    if (isoutbound) {
00846       const char *status = pbx_builtin_getvar_helper(p->chan, "DIALSTATUS");
00847       if ((status) && (p->owner)) {
00848          /* Deadlock avoidance */
00849          while (p->owner && ast_channel_trylock(p->owner)) {
00850             ast_mutex_unlock(&p->lock);
00851             if (p->chan) {
00852                ast_channel_unlock(p->chan);
00853             }
00854             usleep(1);
00855             if (p->chan) {
00856                ast_channel_lock(p->chan);
00857             }
00858             ast_mutex_lock(&p->lock);
00859          }
00860          if (p->owner) {
00861             pbx_builtin_setvar_helper(p->owner, "CHANLOCALSTATUS", status);
00862             ast_channel_unlock(p->owner);
00863          }
00864       }
00865       p->chan = NULL;
00866       ast_clear_flag(p, LOCAL_LAUNCHED_PBX);
00867       ast_module_user_remove(p->u_chan);
00868    } else {
00869       ast_module_user_remove(p->u_owner);
00870       while (p->chan && ast_channel_trylock(p->chan)) {
00871             ast_mutex_unlock(&p->lock);
00872             if (p->owner) {
00873                ast_channel_unlock(p->owner);
00874             }
00875             usleep(1);
00876             if (p->owner) {
00877                ast_channel_lock(p->owner);
00878             }
00879             ast_mutex_lock(&p->lock);
00880       }
00881 
00882       p->owner = NULL;
00883       if (p->chan) {
00884          ast_queue_hangup(p->chan);
00885          ast_channel_unlock(p->chan);
00886       }
00887    }
00888    
00889    ast->tech_pvt = NULL;
00890    
00891    if (!p->owner && !p->chan) {
00892       /* Okay, done with the private part now, too. */
00893       glaredetect = ast_test_flag(p, LOCAL_GLARE_DETECT);
00894       /* If we have a queue holding, don't actually destroy p yet, but
00895          let local_queue do it. */
00896       if (glaredetect)
00897          ast_set_flag(p, LOCAL_CANCEL_QUEUE);
00898       /* Remove from list */
00899       AST_LIST_LOCK(&locals);
00900       AST_LIST_REMOVE(&locals, p, list);
00901       AST_LIST_UNLOCK(&locals);
00902       ast_mutex_unlock(&p->lock);
00903       /* And destroy */
00904       if (!glaredetect) {
00905          p = local_pvt_destroy(p);
00906       }
00907       return 0;
00908    }
00909    if (p->chan && !ast_test_flag(p, LOCAL_LAUNCHED_PBX))
00910       /* Need to actually hangup since there is no PBX */
00911       ochan = p->chan;
00912    else
00913       res = local_queue_frame(p, isoutbound, &f, NULL, 1);
00914    if (!res)
00915       ast_mutex_unlock(&p->lock);
00916    if (ochan)
00917       ast_hangup(ochan);
00918    return 0;
00919 }
00920 
00921 /*! \brief Create a call structure */
00922 static struct local_pvt *local_alloc(const char *data, int format)
00923 {
00924    struct local_pvt *tmp = NULL;
00925    char *c = NULL, *opts = NULL;
00926 
00927    if (!(tmp = ast_calloc(1, sizeof(*tmp))))
00928       return NULL;
00929 
00930    /* Initialize private structure information */
00931    ast_mutex_init(&tmp->lock);
00932    ast_copy_string(tmp->exten, data, sizeof(tmp->exten));
00933 
00934    memcpy(&tmp->jb_conf, &g_jb_conf, sizeof(tmp->jb_conf));
00935 
00936    /* Look for options */
00937    if ((opts = strchr(tmp->exten, '/'))) {
00938       *opts++ = '\0';
00939       if (strchr(opts, 'n'))
00940          ast_set_flag(tmp, LOCAL_NO_OPTIMIZATION);
00941       if (strchr(opts, 'j')) {
00942          if (ast_test_flag(tmp, LOCAL_NO_OPTIMIZATION))
00943             ast_set_flag(&tmp->jb_conf, AST_JB_ENABLED);
00944          else {
00945             ast_log(LOG_ERROR, "You must use the 'n' option for chan_local "
00946                "to use the 'j' option to enable the jitterbuffer\n");
00947          }
00948       }
00949       if (strchr(opts, 'b')) {
00950          ast_set_flag(tmp, LOCAL_BRIDGE);
00951       }
00952       if (strchr(opts, 'm')) {
00953          ast_set_flag(tmp, LOCAL_MOH_PASSTHRU);
00954       }
00955    }
00956 
00957    /* Look for a context */
00958    if ((c = strchr(tmp->exten, '@')))
00959       *c++ = '\0';
00960 
00961    ast_copy_string(tmp->context, c ? c : "default", sizeof(tmp->context));
00962 
00963    tmp->reqformat = format;
00964 
00965 #if 0
00966    /* We can't do this check here, because we don't know the CallerID yet, and
00967     * the CallerID could potentially affect what step is actually taken (or
00968     * even if that step exists). */
00969    if (!ast_exists_extension(NULL, tmp->context, tmp->exten, 1, NULL)) {
00970       ast_log(LOG_NOTICE, "No such extension/context %s@%s creating local channel\n", tmp->exten, tmp->context);
00971       tmp = local_pvt_destroy(tmp);
00972    } else {
00973 #endif
00974       /* Add to list */
00975       AST_LIST_LOCK(&locals);
00976       AST_LIST_INSERT_HEAD(&locals, tmp, list);
00977       AST_LIST_UNLOCK(&locals);
00978 #if 0
00979    }
00980 #endif
00981    
00982    return tmp;
00983 }
00984 
00985 /*! \brief Start new local channel */
00986 static struct ast_channel *local_new(struct local_pvt *p, int state, const char *linkedid)
00987 {
00988    struct ast_channel *tmp = NULL, *tmp2 = NULL;
00989    int randnum = ast_random() & 0xffff, fmt = 0;
00990    const char *t;
00991    int ama;
00992 
00993    /* Allocate two new Asterisk channels */
00994    /* safe accountcode */
00995    if (p->owner && p->owner->accountcode)
00996       t = p->owner->accountcode;
00997    else
00998       t = "";
00999 
01000    if (p->owner)
01001       ama = p->owner->amaflags;
01002    else
01003       ama = 0;
01004    if (!(tmp = ast_channel_alloc(1, state, 0, 0, t, p->exten, p->context, linkedid, ama, "Local/%s@%s-%04x;1", p->exten, p->context, randnum)) 
01005       || !(tmp2 = ast_channel_alloc(1, AST_STATE_RING, 0, 0, t, p->exten, p->context, linkedid, ama, "Local/%s@%s-%04x;2", p->exten, p->context, randnum))) {
01006       if (tmp) {
01007          tmp = ast_channel_release(tmp);
01008       }
01009       ast_log(LOG_WARNING, "Unable to allocate channel structure(s)\n");
01010       return NULL;
01011    }
01012 
01013    tmp2->tech = tmp->tech = &local_tech;
01014 
01015    tmp->nativeformats = p->reqformat;
01016    tmp2->nativeformats = p->reqformat;
01017 
01018    /* Determine our read/write format and set it on each channel */
01019    fmt = ast_best_codec(p->reqformat);
01020    tmp->writeformat = fmt;
01021    tmp2->writeformat = fmt;
01022    tmp->rawwriteformat = fmt;
01023    tmp2->rawwriteformat = fmt;
01024    tmp->readformat = fmt;
01025    tmp2->readformat = fmt;
01026    tmp->rawreadformat = fmt;
01027    tmp2->rawreadformat = fmt;
01028 
01029    tmp->tech_pvt = p;
01030    tmp2->tech_pvt = p;
01031 
01032    p->owner = tmp;
01033    p->chan = tmp2;
01034    p->u_owner = ast_module_user_add(p->owner);
01035    p->u_chan = ast_module_user_add(p->chan);
01036 
01037    ast_copy_string(tmp->context, p->context, sizeof(tmp->context));
01038    ast_copy_string(tmp2->context, p->context, sizeof(tmp2->context));
01039    ast_copy_string(tmp2->exten, p->exten, sizeof(tmp->exten));
01040    tmp->priority = 1;
01041    tmp2->priority = 1;
01042 
01043    ast_jb_configure(tmp, &p->jb_conf);
01044 
01045    return tmp;
01046 }
01047 
01048 /*! \brief Part of PBX interface */
01049 static struct ast_channel *local_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause)
01050 {
01051    struct local_pvt *p = NULL;
01052    struct ast_channel *chan = NULL;
01053 
01054    /* Allocate a new private structure and then Asterisk channel */
01055    if ((p = local_alloc(data, format))) {
01056       if (!(chan = local_new(p, AST_STATE_DOWN, requestor ? requestor->linkedid : NULL))) {
01057          AST_LIST_LOCK(&locals);
01058          AST_LIST_REMOVE(&locals, p, list);
01059          AST_LIST_UNLOCK(&locals);
01060          p = local_pvt_destroy(p);
01061       }
01062       if (chan && ast_channel_cc_params_init(chan, requestor ? ast_channel_get_cc_config_params((struct ast_channel *)requestor) : NULL)) {
01063          chan = ast_channel_release(chan);
01064          p = local_pvt_destroy(p);
01065       }
01066    }
01067 
01068    return chan;
01069 }
01070 
01071 /*! \brief CLI command "local show channels" */
01072 static char *locals_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
01073 {
01074    struct local_pvt *p = NULL;
01075 
01076    switch (cmd) {
01077    case CLI_INIT:
01078       e->command = "local show channels";
01079       e->usage =
01080          "Usage: local show channels\n"
01081          "       Provides summary information on active local proxy channels.\n";
01082       return NULL;
01083    case CLI_GENERATE:
01084       return NULL;
01085    }
01086 
01087    if (a->argc != 3)
01088       return CLI_SHOWUSAGE;
01089 
01090    AST_LIST_LOCK(&locals);
01091    if (!AST_LIST_EMPTY(&locals)) {
01092       AST_LIST_TRAVERSE(&locals, p, list) {
01093          ast_mutex_lock(&p->lock);
01094          ast_cli(a->fd, "%s -- %s@%s\n", p->owner ? p->owner->name : "<unowned>", p->exten, p->context);
01095          ast_mutex_unlock(&p->lock);
01096       }
01097    } else
01098       ast_cli(a->fd, "No local channels in use\n");
01099    AST_LIST_UNLOCK(&locals);
01100 
01101    return CLI_SUCCESS;
01102 }
01103 
01104 static struct ast_cli_entry cli_local[] = {
01105    AST_CLI_DEFINE(locals_show, "List status of local channels"),
01106 };
01107 
01108 static int manager_optimize_away(struct mansession *s, const struct message *m)
01109 {
01110    const char *channel;
01111    struct local_pvt *p, *tmp = NULL;
01112    struct ast_channel *c;
01113    int found = 0;
01114 
01115    channel = astman_get_header(m, "Channel");
01116 
01117    if (ast_strlen_zero(channel)) {
01118       astman_send_error(s, m, "'Channel' not specified.");
01119       return 0;
01120    }
01121 
01122    c = ast_channel_get_by_name(channel);
01123    if (!c) {
01124       astman_send_error(s, m, "Channel does not exist.");
01125       return 0;
01126    }
01127 
01128    p = c->tech_pvt;
01129    ast_channel_unref(c);
01130    c = NULL;
01131 
01132    if (AST_LIST_LOCK(&locals)) {
01133       astman_send_error(s, m, "Unable to lock the monitor");
01134       return 0;
01135    }
01136 
01137 
01138    AST_LIST_TRAVERSE(&locals, tmp, list) {
01139       if (tmp == p) {
01140          ast_mutex_lock(&tmp->lock);
01141          found = 1;
01142          ast_clear_flag(tmp, LOCAL_NO_OPTIMIZATION);
01143          ast_mutex_unlock(&tmp->lock);
01144          break;
01145       }
01146    }
01147    AST_LIST_UNLOCK(&locals);
01148 
01149    if (found) {
01150       astman_send_ack(s, m, "Queued channel to be optimized away");
01151    } else {
01152       astman_send_error(s, m, "Unable to find channel");
01153    }
01154 
01155    return 0;
01156 }
01157 
01158 
01159 /*! \brief Load module into PBX, register channel */
01160 static int load_module(void)
01161 {
01162    /* Make sure we can register our channel type */
01163    if (ast_channel_register(&local_tech)) {
01164       ast_log(LOG_ERROR, "Unable to register channel class 'Local'\n");
01165       return AST_MODULE_LOAD_FAILURE;
01166    }
01167    ast_cli_register_multiple(cli_local, sizeof(cli_local) / sizeof(struct ast_cli_entry));
01168    ast_manager_register_xml("LocalOptimizeAway", EVENT_FLAG_SYSTEM|EVENT_FLAG_CALL, manager_optimize_away);
01169 
01170    return AST_MODULE_LOAD_SUCCESS;
01171 }
01172 
01173 /*! \brief Unload the local proxy channel from Asterisk */
01174 static int unload_module(void)
01175 {
01176    struct local_pvt *p = NULL;
01177 
01178    /* First, take us out of the channel loop */
01179    ast_cli_unregister_multiple(cli_local, sizeof(cli_local) / sizeof(struct ast_cli_entry));
01180    ast_manager_unregister("LocalOptimizeAway");
01181    ast_channel_unregister(&local_tech);
01182    if (!AST_LIST_LOCK(&locals)) {
01183       /* Hangup all interfaces if they have an owner */
01184       AST_LIST_TRAVERSE(&locals, p, list) {
01185          if (p->owner)
01186             ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
01187       }
01188       AST_LIST_UNLOCK(&locals);
01189    } else {
01190       ast_log(LOG_WARNING, "Unable to lock the monitor\n");
01191       return -1;
01192    }     
01193    return 0;
01194 }
01195 
01196 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Local Proxy Channel (Note: used internally by other modules)",
01197       .load = load_module,
01198       .unload = unload_module,
01199       .load_pri = AST_MODPRI_CHANNEL_DRIVER,
01200    );

Generated on Sat Mar 26 11:07:06 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.9