2003-04-06 02:41:42 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2003-04-06 02:41:42 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
2003-04-06 02:41:42 +00:00
|
|
|
*
|
2005-07-25 18:09:04 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
2003-04-06 02:41:42 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
2003-04-06 02:41:42 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
|
|
|
* \author Mark Spencer <markster@digium.com>
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Local Proxy Channel
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-11-06 15:09:47 +00:00
|
|
|
* \ingroup channel_drivers
|
2003-04-06 02:41:42 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-06-06 21:09:59 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#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"
|
2006-02-01 23:05:28 +00:00
|
|
|
#include "asterisk/stringfields.h"
|
2006-05-19 07:56:56 +00:00
|
|
|
#include "asterisk/devicestate.h"
|
2003-04-06 02:41:42 +00:00
|
|
|
|
2005-03-04 06:47:24 +00:00
|
|
|
static const char tdesc[] = "Local Proxy Channel Driver";
|
2003-04-06 02:41:42 +00:00
|
|
|
|
|
|
|
#define IS_OUTBOUND(a,b) (a == b->chan ? 1 : 0)
|
|
|
|
|
2007-10-09 15:10:14 +00:00
|
|
|
static struct ast_jb_conf g_jb_conf = {
|
|
|
|
.flags = 0,
|
|
|
|
.max_size = -1,
|
|
|
|
.resync_threshold = -1,
|
|
|
|
.impl = "",
|
|
|
|
};
|
|
|
|
|
2005-03-04 06:47:24 +00:00
|
|
|
static struct ast_channel *local_request(const char *type, int format, void *data, int *cause);
|
2006-08-31 01:59:02 +00:00
|
|
|
static int local_digit_begin(struct ast_channel *ast, char digit);
|
Merged revisions 51311 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r51311 | russell | 2007-01-19 11:49:38 -0600 (Fri, 19 Jan 2007) | 23 lines
Merge the changes from the /team/group/vldtmf_fixup branch.
The main bug being addressed here is a problem introduced when two SIP
channels using SIP INFO dtmf have their media directly bridged. So, when a
DTMF END frame comes into Asterisk from an incoming INFO message, Asterisk
would try to emulate a digit of some length by first sending a DTMF BEGIN
frame and sending a DTMF END later timed off of incoming audio. However,
since there was no audio coming in, the DTMF_END was never generated. This
caused DTMF based features to no longer work.
To fix this, the core now knows when a channel doesn't care about DTMF BEGIN
frames (such as a SIP channel sending INFO dtmf). If this is the case, then
Asterisk will not emulate a digit of some length, and will instead just pass
through the single DTMF END event.
Channel drivers also now get passed the length of the digit to their digit_end
callback. This improves SIP INFO support even further by enabling us to put
the real digit duration in the INFO message instead of a hard coded 250ms.
Also, for an incoming INFO message, the duration is read from the frame and
passed into the core instead of just getting ignored.
(issue #8597, maybe others...)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@51314 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-01-19 18:06:03 +00:00
|
|
|
static int local_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
|
2005-03-04 06:47:24 +00:00
|
|
|
static int local_call(struct ast_channel *ast, char *dest, int timeout);
|
|
|
|
static int local_hangup(struct ast_channel *ast);
|
|
|
|
static int local_answer(struct ast_channel *ast);
|
|
|
|
static struct ast_frame *local_read(struct ast_channel *ast);
|
|
|
|
static int local_write(struct ast_channel *ast, struct ast_frame *f);
|
2006-05-10 12:24:11 +00:00
|
|
|
static int local_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
|
2005-03-04 06:47:24 +00:00
|
|
|
static int local_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
|
2005-03-28 20:48:24 +00:00
|
|
|
static int local_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen);
|
2006-05-19 08:20:01 +00:00
|
|
|
static int local_sendtext(struct ast_channel *ast, const char *text);
|
2006-05-19 07:56:56 +00:00
|
|
|
static int local_devicestate(void *data);
|
2008-04-10 20:28:40 +00:00
|
|
|
static struct ast_channel *local_bridgedchannel(struct ast_channel *chan, struct ast_channel *bridge);
|
2005-03-04 06:47:24 +00:00
|
|
|
|
2005-07-25 18:09:04 +00:00
|
|
|
/* PBX interface structure for channel registration */
|
2005-03-04 06:47:24 +00:00
|
|
|
static const struct ast_channel_tech local_tech = {
|
2006-02-01 23:05:28 +00:00
|
|
|
.type = "Local",
|
2005-03-04 06:47:24 +00:00
|
|
|
.description = tdesc,
|
|
|
|
.capabilities = -1,
|
|
|
|
.requester = local_request,
|
2006-08-31 01:59:02 +00:00
|
|
|
.send_digit_begin = local_digit_begin,
|
|
|
|
.send_digit_end = local_digit_end,
|
2005-03-04 06:47:24 +00:00
|
|
|
.call = local_call,
|
|
|
|
.hangup = local_hangup,
|
|
|
|
.answer = local_answer,
|
|
|
|
.read = local_read,
|
|
|
|
.write = local_write,
|
2006-05-19 08:03:28 +00:00
|
|
|
.write_video = local_write,
|
2005-03-04 06:47:24 +00:00
|
|
|
.exception = local_read,
|
|
|
|
.indicate = local_indicate,
|
|
|
|
.fixup = local_fixup,
|
|
|
|
.send_html = local_sendhtml,
|
2006-05-19 08:20:01 +00:00
|
|
|
.send_text = local_sendtext,
|
2006-05-19 07:56:56 +00:00
|
|
|
.devicestate = local_devicestate,
|
2008-04-10 20:28:40 +00:00
|
|
|
.bridged_channel = local_bridgedchannel,
|
2005-03-04 06:47:24 +00:00
|
|
|
};
|
|
|
|
|
2006-02-10 00:20:43 +00:00
|
|
|
struct local_pvt {
|
2005-07-10 23:49:57 +00:00
|
|
|
ast_mutex_t lock; /* Channel private lock */
|
After some study, thought, comparing, etc. I've backed out the previous universal mod to make ast_flags a 64 bit thing. Instead, I added a 64-bit version of ast_flags (ast_flags64), and 64-bit versions of the test-flag, set-flag, etc. macros, and an app_parse_options64 routine, and I use these in app_dial alone, to eliminate the 30-option limit it had grown to meet. There is room now for 32 more options and flags. I was heavily tempted to implement some of the other ideas that were presented, but this solution does not intro any new versions of dial, doesn't have a different API, has a minimal/zero impact on code outside of dial, and doesn't seriously (I hope) affect the code structure of dial. It's the best I can think of right now. My goal was NOT to rewrite dial. I leave that to a future, coordinated effort.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@75983 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-07-19 23:24:27 +00:00
|
|
|
unsigned int flags; /* Private flags */
|
2005-07-10 23:49:57 +00:00
|
|
|
char context[AST_MAX_CONTEXT]; /* Context to call */
|
2003-04-06 02:41:42 +00:00
|
|
|
char exten[AST_MAX_EXTENSION]; /* Extension to call */
|
2005-07-10 23:49:57 +00:00
|
|
|
int reqformat; /* Requested format */
|
2007-10-09 15:10:14 +00:00
|
|
|
struct ast_jb_conf jb_conf; /*!< jitterbuffer configuration for this local channel */
|
2005-07-10 23:49:57 +00:00
|
|
|
struct ast_channel *owner; /* Master Channel */
|
|
|
|
struct ast_channel *chan; /* Outbound channel */
|
2006-08-21 02:11:39 +00:00
|
|
|
struct ast_module_user *u_owner; /*! reference to keep the module loaded while in use */
|
|
|
|
struct ast_module_user *u_chan; /*! reference to keep the module loaded while in use */
|
2006-02-10 00:20:43 +00:00
|
|
|
AST_LIST_ENTRY(local_pvt) list; /* Next entity */
|
|
|
|
};
|
|
|
|
|
2006-09-07 21:11:07 +00:00
|
|
|
#define LOCAL_GLARE_DETECT (1 << 0) /*!< Detect glare on hangup */
|
|
|
|
#define LOCAL_CANCEL_QUEUE (1 << 1) /*!< Cancel queue */
|
|
|
|
#define LOCAL_ALREADY_MASQED (1 << 2) /*!< Already masqueraded */
|
|
|
|
#define LOCAL_LAUNCHED_PBX (1 << 3) /*!< PBX was launched */
|
|
|
|
#define LOCAL_NO_OPTIMIZATION (1 << 4) /*!< Do not optimize using masquerading */
|
2008-04-10 20:28:40 +00:00
|
|
|
#define LOCAL_BRIDGE (1 << 5) /*!< Report back the "true" channel as being bridged to */
|
2006-09-07 21:11:07 +00:00
|
|
|
|
2006-02-10 00:20:43 +00:00
|
|
|
static AST_LIST_HEAD_STATIC(locals, local_pvt);
|
2003-04-06 02:41:42 +00:00
|
|
|
|
2006-05-19 07:56:56 +00:00
|
|
|
/*! \brief Adds devicestate to local channels */
|
|
|
|
static int local_devicestate(void *data)
|
|
|
|
{
|
2006-09-07 19:50:59 +00:00
|
|
|
char *exten = ast_strdupa(data);
|
2006-09-26 20:20:34 +00:00
|
|
|
char *context = NULL, *opts = NULL;
|
2006-05-19 07:56:56 +00:00
|
|
|
int res;
|
2007-05-02 15:46:49 +00:00
|
|
|
struct local_pvt *lp;
|
2006-06-16 12:55:18 +00:00
|
|
|
|
2006-09-07 19:50:59 +00:00
|
|
|
if (!(context = strchr(exten, '@'))) {
|
2006-06-16 12:55:18 +00:00
|
|
|
ast_log(LOG_WARNING, "Someone used Local/%s somewhere without a @context. This is bad.\n", exten);
|
|
|
|
return AST_DEVICE_INVALID;
|
2006-05-19 07:56:56 +00:00
|
|
|
}
|
2006-06-16 12:55:18 +00:00
|
|
|
|
2006-09-07 19:50:59 +00:00
|
|
|
*context++ = '\0';
|
2006-06-16 12:55:18 +00:00
|
|
|
|
2006-09-26 20:20:34 +00:00
|
|
|
/* Strip options if they exist */
|
|
|
|
if ((opts = strchr(context, '/')))
|
|
|
|
*opts = '\0';
|
|
|
|
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(3, "Checking if extension %s@%s exists (devicestate)\n", exten, context);
|
2007-05-02 15:46:49 +00:00
|
|
|
|
2006-05-19 07:56:56 +00:00
|
|
|
res = ast_exists_extension(NULL, context, exten, 1, NULL);
|
2006-09-07 19:50:59 +00:00
|
|
|
if (!res)
|
2006-06-14 22:39:19 +00:00
|
|
|
return AST_DEVICE_INVALID;
|
2007-05-02 15:46:49 +00:00
|
|
|
|
|
|
|
res = AST_DEVICE_NOT_INUSE;
|
|
|
|
AST_LIST_LOCK(&locals);
|
|
|
|
AST_LIST_TRAVERSE(&locals, lp, list) {
|
|
|
|
if (!strcmp(exten, lp->exten) && !strcmp(context, lp->context) && lp->owner) {
|
|
|
|
res = AST_DEVICE_INUSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_UNLOCK(&locals);
|
|
|
|
|
|
|
|
return res;
|
2006-05-19 07:56:56 +00:00
|
|
|
}
|
|
|
|
|
2008-03-03 17:17:27 +00:00
|
|
|
/*!
|
|
|
|
* \note Assumes the pvt is no longer in the pvts list
|
|
|
|
*/
|
2008-03-03 17:06:35 +00:00
|
|
|
static struct local_pvt *local_pvt_destroy(struct local_pvt *pvt)
|
|
|
|
{
|
|
|
|
ast_mutex_destroy(&pvt->lock);
|
|
|
|
ast_free(pvt);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-04-10 20:28:40 +00:00
|
|
|
/*! \brief Return the bridged channel of a Local channel */
|
|
|
|
static struct ast_channel *local_bridgedchannel(struct ast_channel *chan, struct ast_channel *bridge)
|
|
|
|
{
|
|
|
|
struct local_pvt *p = bridge->tech_pvt;
|
|
|
|
struct ast_channel *bridged = bridge;
|
|
|
|
|
|
|
|
ast_mutex_lock(&p->lock);
|
|
|
|
|
|
|
|
if (ast_test_flag(p, LOCAL_BRIDGE)) {
|
|
|
|
/* Find the opposite channel */
|
|
|
|
bridged = (bridge == p->owner ? p->chan : p->owner);
|
|
|
|
|
|
|
|
/* Now see if the opposite channel is bridged to anything */
|
2008-04-14 15:36:02 +00:00
|
|
|
if (!bridged) {
|
|
|
|
bridged = bridge;
|
|
|
|
} else if (bridged->_bridge) {
|
2008-04-10 20:28:40 +00:00
|
|
|
bridged = bridged->_bridge;
|
2008-04-14 15:36:02 +00:00
|
|
|
}
|
2008-04-10 20:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ast_mutex_unlock(&p->lock);
|
|
|
|
|
|
|
|
return bridged;
|
|
|
|
}
|
|
|
|
|
2008-05-13 21:18:55 +00:00
|
|
|
static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_frame *f,
|
|
|
|
struct ast_channel *us, int us_locked)
|
2003-04-06 02:41:42 +00:00
|
|
|
{
|
2006-09-07 19:50:59 +00:00
|
|
|
struct ast_channel *other = NULL;
|
|
|
|
|
2003-12-02 15:52:37 +00:00
|
|
|
/* Recalculate outbound channel */
|
2006-09-07 19:50:59 +00:00
|
|
|
other = isoutbound ? p->owner : p->chan;
|
|
|
|
|
2003-12-02 15:52:37 +00:00
|
|
|
/* Set glare detection */
|
2006-09-07 21:11:07 +00:00
|
|
|
ast_set_flag(p, LOCAL_GLARE_DETECT);
|
|
|
|
if (ast_test_flag(p, LOCAL_CANCEL_QUEUE)) {
|
2003-07-01 03:32:14 +00:00
|
|
|
/* We had a glare on the hangup. Forget all this business,
|
|
|
|
return and destroy p. */
|
2003-08-13 15:25:16 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
2008-03-03 17:06:35 +00:00
|
|
|
p = local_pvt_destroy(p);
|
2003-07-01 03:32:14 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-12-02 15:52:37 +00:00
|
|
|
if (!other) {
|
2006-09-07 21:11:07 +00:00
|
|
|
ast_clear_flag(p, LOCAL_GLARE_DETECT);
|
2003-12-02 15:52:37 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-01-28 17:21:24 +00:00
|
|
|
|
2009-01-19 15:54:06 +00:00
|
|
|
/* do not queue frame if generator is on both local channels */
|
|
|
|
if (us && us->generator && other->generator)
|
|
|
|
return 0;
|
|
|
|
|
2008-01-28 17:21:24 +00:00
|
|
|
/* Ensure that we have both channels locked */
|
2008-02-19 20:06:23 +00:00
|
|
|
while (other && ast_channel_trylock(other)) {
|
2008-06-27 12:28:38 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
2008-05-13 21:18:55 +00:00
|
|
|
if (us && us_locked) {
|
2008-06-27 12:28:38 +00:00
|
|
|
do {
|
|
|
|
CHANNEL_DEADLOCK_AVOIDANCE(us);
|
|
|
|
} while (ast_mutex_trylock(&p->lock));
|
2008-06-25 02:34:11 +00:00
|
|
|
} else {
|
|
|
|
usleep(1);
|
2008-06-27 12:28:38 +00:00
|
|
|
ast_mutex_lock(&p->lock);
|
2008-05-13 21:18:55 +00:00
|
|
|
}
|
2008-02-19 20:06:23 +00:00
|
|
|
other = isoutbound ? p->owner : p->chan;
|
2003-04-06 02:41:42 +00:00
|
|
|
}
|
2008-01-28 17:21:24 +00:00
|
|
|
|
2008-02-19 20:06:23 +00:00
|
|
|
if (other) {
|
|
|
|
ast_queue_frame(other, f);
|
|
|
|
ast_channel_unlock(other);
|
|
|
|
}
|
2008-01-28 17:21:24 +00:00
|
|
|
|
2006-09-07 21:11:07 +00:00
|
|
|
ast_clear_flag(p, LOCAL_GLARE_DETECT);
|
2008-01-28 17:21:24 +00:00
|
|
|
|
2003-04-06 02:41:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int local_answer(struct ast_channel *ast)
|
|
|
|
{
|
2005-03-04 06:47:24 +00:00
|
|
|
struct local_pvt *p = ast->tech_pvt;
|
2004-06-22 04:54:52 +00:00
|
|
|
int isoutbound;
|
2003-04-06 02:41:42 +00:00
|
|
|
int res = -1;
|
2005-07-25 18:09:04 +00:00
|
|
|
|
2006-11-16 18:32:27 +00:00
|
|
|
if (!p)
|
|
|
|
return -1;
|
|
|
|
|
2003-08-13 15:25:16 +00:00
|
|
|
ast_mutex_lock(&p->lock);
|
2004-06-22 04:54:52 +00:00
|
|
|
isoutbound = IS_OUTBOUND(ast, p);
|
2003-04-06 02:41:42 +00:00
|
|
|
if (isoutbound) {
|
|
|
|
/* Pass along answer since somebody answered us */
|
|
|
|
struct ast_frame answer = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
|
2008-05-13 21:18:55 +00:00
|
|
|
res = local_queue_frame(p, isoutbound, &answer, ast, 1);
|
2003-04-06 02:41:42 +00:00
|
|
|
} else
|
|
|
|
ast_log(LOG_WARNING, "Huh? Local is being asked to answer?\n");
|
2007-04-09 02:44:37 +00:00
|
|
|
if (!res)
|
|
|
|
ast_mutex_unlock(&p->lock);
|
2003-04-06 02:41:42 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-04-06 06:11:25 +00:00
|
|
|
static void check_bridge(struct local_pvt *p, int isoutbound)
|
|
|
|
{
|
2008-01-21 23:56:40 +00:00
|
|
|
struct ast_channel_monitor *tmp;
|
2007-03-01 22:23:26 +00:00
|
|
|
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)))
|
2005-10-19 03:45:49 +00:00
|
|
|
return;
|
2006-06-12 16:07:32 +00:00
|
|
|
|
|
|
|
/* only do the masquerade if we are being called on the outbound channel,
|
|
|
|
if it has been bridged to another channel and if there are no pending
|
|
|
|
frames on the owner channel (because they would be transferred to the
|
|
|
|
outbound channel during the masquerade)
|
|
|
|
*/
|
2006-08-29 20:50:36 +00:00
|
|
|
if (isoutbound && p->chan->_bridge /* Not ast_bridged_channel! Only go one step! */ && AST_LIST_EMPTY(&p->owner->readq)) {
|
2003-04-06 06:11:25 +00:00
|
|
|
/* Masquerade bridged channel into owner */
|
2003-08-14 13:12:39 +00:00
|
|
|
/* Lock everything we need, one by one, and give up if
|
|
|
|
we can't get everything. Remember, we'll get another
|
|
|
|
chance in just a little bit */
|
2007-09-17 22:59:36 +00:00
|
|
|
if (!ast_channel_trylock(p->chan->_bridge)) {
|
2007-08-01 15:39:54 +00:00
|
|
|
if (!ast_check_hangup(p->chan->_bridge)) {
|
2007-09-17 22:59:36 +00:00
|
|
|
if (!ast_channel_trylock(p->owner)) {
|
2007-08-01 15:39:54 +00:00
|
|
|
if (!ast_check_hangup(p->owner)) {
|
2008-11-18 18:31:08 +00:00
|
|
|
if (p->owner->monitor && !p->chan->_bridge->monitor) {
|
2008-01-21 23:56:40 +00:00
|
|
|
/* If a local channel is being monitored, we don't want a masquerade
|
|
|
|
* to cause the monitor to go away. Since the masquerade swaps the monitors,
|
|
|
|
* pre-swapping the monitors before the masquerade will ensure that the monitor
|
|
|
|
* ends up where it is expected.
|
|
|
|
*/
|
|
|
|
tmp = p->owner->monitor;
|
|
|
|
p->owner->monitor = p->chan->_bridge->monitor;
|
|
|
|
p->chan->_bridge->monitor = tmp;
|
|
|
|
}
|
2008-11-18 18:31:08 +00:00
|
|
|
if (p->chan->audiohooks) {
|
|
|
|
struct ast_audiohook_list *audiohooks_swapper;
|
|
|
|
audiohooks_swapper = p->chan->audiohooks;
|
|
|
|
p->chan->audiohooks = p->owner->audiohooks;
|
|
|
|
p->owner->audiohooks = audiohooks_swapper;
|
|
|
|
}
|
2005-10-19 03:45:49 +00:00
|
|
|
ast_channel_masquerade(p->owner, p->chan->_bridge);
|
2006-09-07 21:11:07 +00:00
|
|
|
ast_set_flag(p, LOCAL_ALREADY_MASQED);
|
2005-10-19 03:45:49 +00:00
|
|
|
}
|
2007-09-17 22:59:36 +00:00
|
|
|
ast_channel_unlock(p->owner);
|
2005-10-19 03:45:49 +00:00
|
|
|
}
|
2007-09-17 22:59:36 +00:00
|
|
|
ast_channel_unlock(p->chan->_bridge);
|
2003-08-14 13:12:39 +00:00
|
|
|
}
|
|
|
|
}
|
2006-06-12 16:07:32 +00:00
|
|
|
/* We only allow masquerading in one 'direction'... it's important to preserve the state
|
|
|
|
(group variables, etc.) that live on p->chan->_bridge (and were put there by the dialplan)
|
|
|
|
when the local channels go away.
|
|
|
|
*/
|
|
|
|
#if 0
|
2006-08-29 20:50:36 +00:00
|
|
|
} else if (!isoutbound && p->owner && p->owner->_bridge && p->chan && AST_LIST_EMPTY(&p->chan->readq)) {
|
2003-04-06 06:11:25 +00:00
|
|
|
/* Masquerade bridged channel into chan */
|
2005-02-14 23:20:01 +00:00
|
|
|
if (!ast_mutex_trylock(&(p->owner->_bridge)->lock)) {
|
2007-08-01 15:39:54 +00:00
|
|
|
if (!ast_check_hangup(p->owner->_bridge)) {
|
2005-10-19 03:45:49 +00:00
|
|
|
if (!ast_mutex_trylock(&p->chan->lock)) {
|
2007-08-01 15:39:54 +00:00
|
|
|
if (!ast_check_hangup(p->chan)) {
|
2005-10-19 03:45:49 +00:00
|
|
|
ast_channel_masquerade(p->chan, p->owner->_bridge);
|
2006-09-07 21:11:07 +00:00
|
|
|
ast_set_flag(p, LOCAL_ALREADY_MASQED);
|
2005-10-19 03:45:49 +00:00
|
|
|
}
|
|
|
|
ast_mutex_unlock(&p->chan->lock);
|
|
|
|
}
|
2003-08-14 13:12:39 +00:00
|
|
|
}
|
2005-02-14 23:20:01 +00:00
|
|
|
ast_mutex_unlock(&(p->owner->_bridge)->lock);
|
2003-08-14 13:12:39 +00:00
|
|
|
}
|
2006-06-12 16:07:32 +00:00
|
|
|
#endif
|
2003-04-06 06:11:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-06 02:41:42 +00:00
|
|
|
static struct ast_frame *local_read(struct ast_channel *ast)
|
|
|
|
{
|
2006-01-31 17:57:12 +00:00
|
|
|
return &ast_null_frame;
|
2003-04-06 02:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int local_write(struct ast_channel *ast, struct ast_frame *f)
|
|
|
|
{
|
2005-03-04 06:47:24 +00:00
|
|
|
struct local_pvt *p = ast->tech_pvt;
|
2003-04-06 02:41:42 +00:00
|
|
|
int res = -1;
|
2004-06-22 04:54:52 +00:00
|
|
|
int isoutbound;
|
2003-04-06 02:41:42 +00:00
|
|
|
|
2006-11-16 18:32:27 +00:00
|
|
|
if (!p)
|
|
|
|
return -1;
|
|
|
|
|
2003-04-06 02:41:42 +00:00
|
|
|
/* Just queue for delivery to the other side */
|
2003-08-13 15:25:16 +00:00
|
|
|
ast_mutex_lock(&p->lock);
|
2004-06-22 04:54:52 +00:00
|
|
|
isoutbound = IS_OUTBOUND(ast, p);
|
2006-05-19 08:03:28 +00:00
|
|
|
if (f && (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO))
|
2005-03-05 04:35:23 +00:00
|
|
|
check_bridge(p, isoutbound);
|
2006-09-07 21:11:07 +00:00
|
|
|
if (!ast_test_flag(p, LOCAL_ALREADY_MASQED))
|
2008-05-13 21:18:55 +00:00
|
|
|
res = local_queue_frame(p, isoutbound, f, ast, 1);
|
2005-03-05 04:35:23 +00:00
|
|
|
else {
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(1, "Not posting to queue since already masked on '%s'\n", ast->name);
|
2005-03-05 04:35:23 +00:00
|
|
|
res = 0;
|
|
|
|
}
|
2007-04-09 02:44:37 +00:00
|
|
|
if (!res)
|
|
|
|
ast_mutex_unlock(&p->lock);
|
2003-04-06 02:41:42 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-04-06 22:17:32 +00:00
|
|
|
static int local_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
|
2003-04-06 02:41:42 +00:00
|
|
|
{
|
2005-03-04 06:47:24 +00:00
|
|
|
struct local_pvt *p = newchan->tech_pvt;
|
2006-11-15 22:32:51 +00:00
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return -1;
|
|
|
|
|
2004-04-06 22:17:32 +00:00
|
|
|
ast_mutex_lock(&p->lock);
|
2005-07-25 18:09:04 +00:00
|
|
|
|
2003-04-06 02:41:42 +00:00
|
|
|
if ((p->owner != oldchan) && (p->chan != oldchan)) {
|
2005-07-25 18:09:04 +00:00
|
|
|
ast_log(LOG_WARNING, "Old channel wasn't %p but was %p/%p\n", oldchan, p->owner, p->chan);
|
2004-04-06 22:17:32 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
2003-04-06 02:41:42 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (p->owner == oldchan)
|
|
|
|
p->owner = newchan;
|
|
|
|
else
|
2005-07-25 18:09:04 +00:00
|
|
|
p->chan = newchan;
|
2004-04-06 22:17:32 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
2003-04-06 02:41:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-05-10 12:24:11 +00:00
|
|
|
static int local_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
|
2003-04-06 02:41:42 +00:00
|
|
|
{
|
2005-03-04 06:47:24 +00:00
|
|
|
struct local_pvt *p = ast->tech_pvt;
|
2006-11-07 20:16:02 +00:00
|
|
|
int res = 0;
|
2003-04-06 02:41:42 +00:00
|
|
|
struct ast_frame f = { AST_FRAME_CONTROL, };
|
2004-06-22 04:54:52 +00:00
|
|
|
int isoutbound;
|
2005-07-25 18:09:04 +00:00
|
|
|
|
2006-11-16 18:32:27 +00:00
|
|
|
if (!p)
|
|
|
|
return -1;
|
|
|
|
|
2006-11-07 20:12:30 +00:00
|
|
|
/* If this is an MOH hold or unhold, do it on the Local channel versus real channel */
|
|
|
|
if (condition == AST_CONTROL_HOLD) {
|
|
|
|
ast_moh_start(ast, data, NULL);
|
|
|
|
} else if (condition == AST_CONTROL_UNHOLD) {
|
|
|
|
ast_moh_stop(ast);
|
|
|
|
} else {
|
|
|
|
/* Queue up a frame representing the indication as a control frame */
|
|
|
|
ast_mutex_lock(&p->lock);
|
|
|
|
isoutbound = IS_OUTBOUND(ast, p);
|
|
|
|
f.subclass = condition;
|
2008-05-22 16:29:54 +00:00
|
|
|
f.data.ptr = (void*)data;
|
2006-11-07 20:12:30 +00:00
|
|
|
f.datalen = datalen;
|
2008-05-13 21:18:55 +00:00
|
|
|
if (!(res = local_queue_frame(p, isoutbound, &f, ast, 1)))
|
2007-04-09 02:44:37 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
2006-11-07 20:12:30 +00:00
|
|
|
}
|
|
|
|
|
2003-04-06 02:41:42 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-08-31 01:59:02 +00:00
|
|
|
static int local_digit_begin(struct ast_channel *ast, char digit)
|
2003-04-06 02:41:42 +00:00
|
|
|
{
|
2005-03-04 06:47:24 +00:00
|
|
|
struct local_pvt *p = ast->tech_pvt;
|
2003-04-06 02:41:42 +00:00
|
|
|
int res = -1;
|
2006-08-31 01:59:02 +00:00
|
|
|
struct ast_frame f = { AST_FRAME_DTMF_BEGIN, };
|
2004-06-22 04:54:52 +00:00
|
|
|
int isoutbound;
|
2005-07-25 18:09:04 +00:00
|
|
|
|
2006-11-16 18:32:27 +00:00
|
|
|
if (!p)
|
|
|
|
return -1;
|
|
|
|
|
2003-08-13 15:25:16 +00:00
|
|
|
ast_mutex_lock(&p->lock);
|
2004-06-22 04:54:52 +00:00
|
|
|
isoutbound = IS_OUTBOUND(ast, p);
|
2003-04-06 02:41:42 +00:00
|
|
|
f.subclass = digit;
|
2008-05-13 21:18:55 +00:00
|
|
|
if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0)))
|
2007-04-09 02:44:37 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
2006-08-31 01:59:02 +00:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
Merged revisions 51311 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r51311 | russell | 2007-01-19 11:49:38 -0600 (Fri, 19 Jan 2007) | 23 lines
Merge the changes from the /team/group/vldtmf_fixup branch.
The main bug being addressed here is a problem introduced when two SIP
channels using SIP INFO dtmf have their media directly bridged. So, when a
DTMF END frame comes into Asterisk from an incoming INFO message, Asterisk
would try to emulate a digit of some length by first sending a DTMF BEGIN
frame and sending a DTMF END later timed off of incoming audio. However,
since there was no audio coming in, the DTMF_END was never generated. This
caused DTMF based features to no longer work.
To fix this, the core now knows when a channel doesn't care about DTMF BEGIN
frames (such as a SIP channel sending INFO dtmf). If this is the case, then
Asterisk will not emulate a digit of some length, and will instead just pass
through the single DTMF END event.
Channel drivers also now get passed the length of the digit to their digit_end
callback. This improves SIP INFO support even further by enabling us to put
the real digit duration in the INFO message instead of a hard coded 250ms.
Also, for an incoming INFO message, the duration is read from the frame and
passed into the core instead of just getting ignored.
(issue #8597, maybe others...)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@51314 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-01-19 18:06:03 +00:00
|
|
|
static int local_digit_end(struct ast_channel *ast, char digit, unsigned int duration)
|
2006-08-31 01:59:02 +00:00
|
|
|
{
|
|
|
|
struct local_pvt *p = ast->tech_pvt;
|
|
|
|
int res = -1;
|
|
|
|
struct ast_frame f = { AST_FRAME_DTMF_END, };
|
|
|
|
int isoutbound;
|
|
|
|
|
2006-11-16 18:32:27 +00:00
|
|
|
if (!p)
|
|
|
|
return -1;
|
|
|
|
|
2006-08-31 01:59:02 +00:00
|
|
|
ast_mutex_lock(&p->lock);
|
|
|
|
isoutbound = IS_OUTBOUND(ast, p);
|
|
|
|
f.subclass = digit;
|
Merged revisions 51311 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r51311 | russell | 2007-01-19 11:49:38 -0600 (Fri, 19 Jan 2007) | 23 lines
Merge the changes from the /team/group/vldtmf_fixup branch.
The main bug being addressed here is a problem introduced when two SIP
channels using SIP INFO dtmf have their media directly bridged. So, when a
DTMF END frame comes into Asterisk from an incoming INFO message, Asterisk
would try to emulate a digit of some length by first sending a DTMF BEGIN
frame and sending a DTMF END later timed off of incoming audio. However,
since there was no audio coming in, the DTMF_END was never generated. This
caused DTMF based features to no longer work.
To fix this, the core now knows when a channel doesn't care about DTMF BEGIN
frames (such as a SIP channel sending INFO dtmf). If this is the case, then
Asterisk will not emulate a digit of some length, and will instead just pass
through the single DTMF END event.
Channel drivers also now get passed the length of the digit to their digit_end
callback. This improves SIP INFO support even further by enabling us to put
the real digit duration in the INFO message instead of a hard coded 250ms.
Also, for an incoming INFO message, the duration is read from the frame and
passed into the core instead of just getting ignored.
(issue #8597, maybe others...)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@51314 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-01-19 18:06:03 +00:00
|
|
|
f.len = duration;
|
2008-05-13 21:18:55 +00:00
|
|
|
if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0)))
|
2007-04-09 02:44:37 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
|
|
|
|
2003-04-06 02:41:42 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-05-19 08:20:01 +00:00
|
|
|
static int local_sendtext(struct ast_channel *ast, const char *text)
|
|
|
|
{
|
|
|
|
struct local_pvt *p = ast->tech_pvt;
|
|
|
|
int res = -1;
|
|
|
|
struct ast_frame f = { AST_FRAME_TEXT, };
|
|
|
|
int isoutbound;
|
|
|
|
|
2006-11-16 18:32:27 +00:00
|
|
|
if (!p)
|
|
|
|
return -1;
|
|
|
|
|
2006-05-19 08:20:01 +00:00
|
|
|
ast_mutex_lock(&p->lock);
|
|
|
|
isoutbound = IS_OUTBOUND(ast, p);
|
2008-05-22 16:29:54 +00:00
|
|
|
f.data.ptr = (char *) text;
|
2006-05-19 08:20:01 +00:00
|
|
|
f.datalen = strlen(text) + 1;
|
2008-05-13 21:18:55 +00:00
|
|
|
if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0)))
|
2007-04-09 02:44:37 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
2006-05-19 08:20:01 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-03-28 20:48:24 +00:00
|
|
|
static int local_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen)
|
2005-02-28 06:06:42 +00:00
|
|
|
{
|
2005-03-04 06:47:24 +00:00
|
|
|
struct local_pvt *p = ast->tech_pvt;
|
2005-02-28 06:06:42 +00:00
|
|
|
int res = -1;
|
|
|
|
struct ast_frame f = { AST_FRAME_HTML, };
|
|
|
|
int isoutbound;
|
2005-07-25 18:09:04 +00:00
|
|
|
|
2006-11-16 18:32:27 +00:00
|
|
|
if (!p)
|
|
|
|
return -1;
|
|
|
|
|
2005-02-28 06:06:42 +00:00
|
|
|
ast_mutex_lock(&p->lock);
|
|
|
|
isoutbound = IS_OUTBOUND(ast, p);
|
|
|
|
f.subclass = subclass;
|
2008-05-22 16:29:54 +00:00
|
|
|
f.data.ptr = (char *)data;
|
2005-02-28 06:06:42 +00:00
|
|
|
f.datalen = datalen;
|
2008-05-13 21:18:55 +00:00
|
|
|
if (!(res = local_queue_frame(p, isoutbound, &f, ast, 0)))
|
2007-04-09 02:44:37 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
2005-02-28 06:06:42 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Initiate new call, part of PBX interface
|
|
|
|
* dest is the dial string */
|
2003-04-06 02:41:42 +00:00
|
|
|
static int local_call(struct ast_channel *ast, char *dest, int timeout)
|
|
|
|
{
|
2005-03-04 06:47:24 +00:00
|
|
|
struct local_pvt *p = ast->tech_pvt;
|
2003-08-19 19:36:52 +00:00
|
|
|
int res;
|
Merged revisions 7265-7266,7268-7275 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r7265 | oej | 2005-12-01 17:18:14 -0600 (Thu, 01 Dec 2005) | 2 lines
Changing bug report address to the Asterisk issue tracker
........
r7266 | kpfleming | 2005-12-01 17:18:29 -0600 (Thu, 01 Dec 2005) | 3 lines
Makefile 'update' target now supports updating from Subversion repositories (issue #5875)
remove support for 'patches' subdirectory, it's no longer useful
........
r7268 | kpfleming | 2005-12-01 17:34:58 -0600 (Thu, 01 Dec 2005) | 2 lines
ensure channel's scheduling context is freed (issue #5788)
........
r7269 | kpfleming | 2005-12-01 17:49:44 -0600 (Thu, 01 Dec 2005) | 2 lines
don't block waiting for the Festival server forever when it goes away (issue #5882)
........
r7270 | kpfleming | 2005-12-01 18:26:12 -0600 (Thu, 01 Dec 2005) | 2 lines
allow variables to exist on both 'halves' of the Local channel (issue #5810)
........
r7271 | kpfleming | 2005-12-01 18:28:48 -0600 (Thu, 01 Dec 2005) | 2 lines
protect agent_bridgedchannel() from segfaulting when there is no bridged channel (issue #5879)
........
r7272 | kpfleming | 2005-12-01 18:39:00 -0600 (Thu, 01 Dec 2005) | 3 lines
properly handle password changes when mailbox is last line of config file and not followed by a newline (issue #5870)
reformat password changing code to conform to coding guidelines (issue #5870)
........
r7273 | kpfleming | 2005-12-01 18:42:40 -0600 (Thu, 01 Dec 2005) | 2 lines
allow previous context-searching behavior to be used if desired (issue #5899)
........
r7274 | kpfleming | 2005-12-01 18:51:15 -0600 (Thu, 01 Dec 2005) | 2 lines
inherit channel variables into channels created by Page() application (issue #5888)
........
r7275 | oej | 2005-12-01 18:52:13 -0600 (Thu, 01 Dec 2005) | 2 lines
Bug #5907. Improve SIP INFO DTMF debugging output. (1.2 & Trunk)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7276 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2005-12-02 01:01:11 +00:00
|
|
|
struct ast_var_t *varptr = NULL, *new;
|
|
|
|
size_t len, namelen;
|
2006-11-16 18:32:27 +00:00
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return -1;
|
2003-08-19 19:36:52 +00:00
|
|
|
|
|
|
|
ast_mutex_lock(&p->lock);
|
2004-10-02 00:58:31 +00:00
|
|
|
|
2007-08-17 17:45:01 +00:00
|
|
|
/*
|
|
|
|
* Note that cid_num and cid_name aren't passed in the ast_channel_alloc
|
|
|
|
* call, so it's done here instead.
|
|
|
|
*/
|
2008-10-27 21:34:04 +00:00
|
|
|
p->chan->cid.cid_dnid = ast_strdup(p->owner->cid.cid_dnid);
|
2007-08-17 17:45:01 +00:00
|
|
|
p->chan->cid.cid_num = ast_strdup(p->owner->cid.cid_num);
|
|
|
|
p->chan->cid.cid_name = ast_strdup(p->owner->cid.cid_name);
|
2006-01-11 01:20:29 +00:00
|
|
|
p->chan->cid.cid_rdnis = ast_strdup(p->owner->cid.cid_rdnis);
|
|
|
|
p->chan->cid.cid_ani = ast_strdup(p->owner->cid.cid_ani);
|
2006-05-22 16:36:13 +00:00
|
|
|
p->chan->cid.cid_pres = p->owner->cid.cid_pres;
|
2008-10-27 21:34:04 +00:00
|
|
|
p->chan->cid.cid_ani2 = p->owner->cid.cid_ani2;
|
|
|
|
p->chan->cid.cid_ton = p->owner->cid.cid_ton;
|
|
|
|
p->chan->cid.cid_tns = p->owner->cid.cid_tns;
|
2006-02-01 23:05:28 +00:00
|
|
|
ast_string_field_set(p->chan, language, p->owner->language);
|
|
|
|
ast_string_field_set(p->chan, accountcode, p->owner->accountcode);
|
2008-12-31 19:34:28 +00:00
|
|
|
ast_string_field_set(p->chan, musicclass, p->owner->musicclass);
|
2008-04-24 19:54:57 +00:00
|
|
|
ast_cdr_update(p->chan);
|
2004-07-12 14:46:10 +00:00
|
|
|
p->chan->cdrflags = p->owner->cdrflags;
|
Merged revisions 7265-7266,7268-7275 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r7265 | oej | 2005-12-01 17:18:14 -0600 (Thu, 01 Dec 2005) | 2 lines
Changing bug report address to the Asterisk issue tracker
........
r7266 | kpfleming | 2005-12-01 17:18:29 -0600 (Thu, 01 Dec 2005) | 3 lines
Makefile 'update' target now supports updating from Subversion repositories (issue #5875)
remove support for 'patches' subdirectory, it's no longer useful
........
r7268 | kpfleming | 2005-12-01 17:34:58 -0600 (Thu, 01 Dec 2005) | 2 lines
ensure channel's scheduling context is freed (issue #5788)
........
r7269 | kpfleming | 2005-12-01 17:49:44 -0600 (Thu, 01 Dec 2005) | 2 lines
don't block waiting for the Festival server forever when it goes away (issue #5882)
........
r7270 | kpfleming | 2005-12-01 18:26:12 -0600 (Thu, 01 Dec 2005) | 2 lines
allow variables to exist on both 'halves' of the Local channel (issue #5810)
........
r7271 | kpfleming | 2005-12-01 18:28:48 -0600 (Thu, 01 Dec 2005) | 2 lines
protect agent_bridgedchannel() from segfaulting when there is no bridged channel (issue #5879)
........
r7272 | kpfleming | 2005-12-01 18:39:00 -0600 (Thu, 01 Dec 2005) | 3 lines
properly handle password changes when mailbox is last line of config file and not followed by a newline (issue #5870)
reformat password changing code to conform to coding guidelines (issue #5870)
........
r7273 | kpfleming | 2005-12-01 18:42:40 -0600 (Thu, 01 Dec 2005) | 2 lines
allow previous context-searching behavior to be used if desired (issue #5899)
........
r7274 | kpfleming | 2005-12-01 18:51:15 -0600 (Thu, 01 Dec 2005) | 2 lines
inherit channel variables into channels created by Page() application (issue #5888)
........
r7275 | oej | 2005-12-01 18:52:13 -0600 (Thu, 01 Dec 2005) | 2 lines
Bug #5907. Improve SIP INFO DTMF debugging output. (1.2 & Trunk)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7276 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2005-12-02 01:01:11 +00:00
|
|
|
|
2008-10-06 16:52:14 +00:00
|
|
|
if (!ast_exists_extension(NULL, p->chan->context, p->chan->exten, 1, p->owner->cid.cid_num)) {
|
|
|
|
ast_log(LOG_NOTICE, "No such extension/context %s@%s while calling Local channel\n", p->chan->exten, p->chan->context);
|
2008-10-30 19:45:52 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
2008-10-06 16:52:14 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
Merged revisions 7265-7266,7268-7275 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r7265 | oej | 2005-12-01 17:18:14 -0600 (Thu, 01 Dec 2005) | 2 lines
Changing bug report address to the Asterisk issue tracker
........
r7266 | kpfleming | 2005-12-01 17:18:29 -0600 (Thu, 01 Dec 2005) | 3 lines
Makefile 'update' target now supports updating from Subversion repositories (issue #5875)
remove support for 'patches' subdirectory, it's no longer useful
........
r7268 | kpfleming | 2005-12-01 17:34:58 -0600 (Thu, 01 Dec 2005) | 2 lines
ensure channel's scheduling context is freed (issue #5788)
........
r7269 | kpfleming | 2005-12-01 17:49:44 -0600 (Thu, 01 Dec 2005) | 2 lines
don't block waiting for the Festival server forever when it goes away (issue #5882)
........
r7270 | kpfleming | 2005-12-01 18:26:12 -0600 (Thu, 01 Dec 2005) | 2 lines
allow variables to exist on both 'halves' of the Local channel (issue #5810)
........
r7271 | kpfleming | 2005-12-01 18:28:48 -0600 (Thu, 01 Dec 2005) | 2 lines
protect agent_bridgedchannel() from segfaulting when there is no bridged channel (issue #5879)
........
r7272 | kpfleming | 2005-12-01 18:39:00 -0600 (Thu, 01 Dec 2005) | 3 lines
properly handle password changes when mailbox is last line of config file and not followed by a newline (issue #5870)
reformat password changing code to conform to coding guidelines (issue #5870)
........
r7273 | kpfleming | 2005-12-01 18:42:40 -0600 (Thu, 01 Dec 2005) | 2 lines
allow previous context-searching behavior to be used if desired (issue #5899)
........
r7274 | kpfleming | 2005-12-01 18:51:15 -0600 (Thu, 01 Dec 2005) | 2 lines
inherit channel variables into channels created by Page() application (issue #5888)
........
r7275 | oej | 2005-12-01 18:52:13 -0600 (Thu, 01 Dec 2005) | 2 lines
Bug #5907. Improve SIP INFO DTMF debugging output. (1.2 & Trunk)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7276 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2005-12-02 01:01:11 +00:00
|
|
|
/* copy the channel variables from the incoming channel to the outgoing channel */
|
|
|
|
/* Note that due to certain assumptions, they MUST be in the same order */
|
|
|
|
AST_LIST_TRAVERSE(&p->owner->varshead, varptr, entries) {
|
|
|
|
namelen = strlen(varptr->name);
|
|
|
|
len = sizeof(struct ast_var_t) + namelen + strlen(varptr->value) + 2;
|
2006-01-11 01:20:29 +00:00
|
|
|
if ((new = ast_calloc(1, len))) {
|
Merged revisions 7265-7266,7268-7275 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r7265 | oej | 2005-12-01 17:18:14 -0600 (Thu, 01 Dec 2005) | 2 lines
Changing bug report address to the Asterisk issue tracker
........
r7266 | kpfleming | 2005-12-01 17:18:29 -0600 (Thu, 01 Dec 2005) | 3 lines
Makefile 'update' target now supports updating from Subversion repositories (issue #5875)
remove support for 'patches' subdirectory, it's no longer useful
........
r7268 | kpfleming | 2005-12-01 17:34:58 -0600 (Thu, 01 Dec 2005) | 2 lines
ensure channel's scheduling context is freed (issue #5788)
........
r7269 | kpfleming | 2005-12-01 17:49:44 -0600 (Thu, 01 Dec 2005) | 2 lines
don't block waiting for the Festival server forever when it goes away (issue #5882)
........
r7270 | kpfleming | 2005-12-01 18:26:12 -0600 (Thu, 01 Dec 2005) | 2 lines
allow variables to exist on both 'halves' of the Local channel (issue #5810)
........
r7271 | kpfleming | 2005-12-01 18:28:48 -0600 (Thu, 01 Dec 2005) | 2 lines
protect agent_bridgedchannel() from segfaulting when there is no bridged channel (issue #5879)
........
r7272 | kpfleming | 2005-12-01 18:39:00 -0600 (Thu, 01 Dec 2005) | 3 lines
properly handle password changes when mailbox is last line of config file and not followed by a newline (issue #5870)
reformat password changing code to conform to coding guidelines (issue #5870)
........
r7273 | kpfleming | 2005-12-01 18:42:40 -0600 (Thu, 01 Dec 2005) | 2 lines
allow previous context-searching behavior to be used if desired (issue #5899)
........
r7274 | kpfleming | 2005-12-01 18:51:15 -0600 (Thu, 01 Dec 2005) | 2 lines
inherit channel variables into channels created by Page() application (issue #5888)
........
r7275 | oej | 2005-12-01 18:52:13 -0600 (Thu, 01 Dec 2005) | 2 lines
Bug #5907. Improve SIP INFO DTMF debugging output. (1.2 & Trunk)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7276 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2005-12-02 01:01:11 +00:00
|
|
|
memcpy(new, varptr, len);
|
|
|
|
new->value = &(new->name[0]) + namelen + 1;
|
|
|
|
AST_LIST_INSERT_TAIL(&p->chan->varshead, new, entries);
|
|
|
|
}
|
|
|
|
}
|
Merged revisions 90735 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r90735 | mmichelson | 2007-12-03 17:12:17 -0600 (Mon, 03 Dec 2007) | 22 lines
A big one...
This is the merge of the forward-loop branch. The main change here is that call-forwards can no longer loop.
This is accomplished by creating a datastore on the calling channel which has a linked list of all devices
dialed. If a forward happens, then the local channel which is created inherits the datastore. If, through this
progression of forwards and datastore inheritance, a device is attempted to be dialed a second time, it will simply
be skipped and a warning message will be printed to the CLI. After the dialing has been completed, the datastore
is detached from the channel and destroyed.
This change also introduces some side effects to the code which I shall enumerate here:
1. Datastore inheritance has been backported from trunk into 1.4
2. A large chunk of code has been removed from app_dial. This chunk is the section of code
which handles the call forward case after the channel has been requested but before it has
been called. This was removed because call-forwarding still works fine without it, it makes the
code less error-prone should it need changing, and it made this set of changes much less painful
to just have the forwarding handled in one place in each module.
3. Two new files, global_datastores.h and .c have been added. These are necessary since the datastore
which is attached to the channel may be created and attached in either app_dial or app_queue, so they
need a common place to find the datastore info. This approach was taken in case similar datastores are
needed in the future, there will be a common place to add them.
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@90873 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2007-12-04 17:08:36 +00:00
|
|
|
ast_channel_datastore_inherit(p->owner, p->chan);
|
Merged revisions 7265-7266,7268-7275 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r7265 | oej | 2005-12-01 17:18:14 -0600 (Thu, 01 Dec 2005) | 2 lines
Changing bug report address to the Asterisk issue tracker
........
r7266 | kpfleming | 2005-12-01 17:18:29 -0600 (Thu, 01 Dec 2005) | 3 lines
Makefile 'update' target now supports updating from Subversion repositories (issue #5875)
remove support for 'patches' subdirectory, it's no longer useful
........
r7268 | kpfleming | 2005-12-01 17:34:58 -0600 (Thu, 01 Dec 2005) | 2 lines
ensure channel's scheduling context is freed (issue #5788)
........
r7269 | kpfleming | 2005-12-01 17:49:44 -0600 (Thu, 01 Dec 2005) | 2 lines
don't block waiting for the Festival server forever when it goes away (issue #5882)
........
r7270 | kpfleming | 2005-12-01 18:26:12 -0600 (Thu, 01 Dec 2005) | 2 lines
allow variables to exist on both 'halves' of the Local channel (issue #5810)
........
r7271 | kpfleming | 2005-12-01 18:28:48 -0600 (Thu, 01 Dec 2005) | 2 lines
protect agent_bridgedchannel() from segfaulting when there is no bridged channel (issue #5879)
........
r7272 | kpfleming | 2005-12-01 18:39:00 -0600 (Thu, 01 Dec 2005) | 3 lines
properly handle password changes when mailbox is last line of config file and not followed by a newline (issue #5870)
reformat password changing code to conform to coding guidelines (issue #5870)
........
r7273 | kpfleming | 2005-12-01 18:42:40 -0600 (Thu, 01 Dec 2005) | 2 lines
allow previous context-searching behavior to be used if desired (issue #5899)
........
r7274 | kpfleming | 2005-12-01 18:51:15 -0600 (Thu, 01 Dec 2005) | 2 lines
inherit channel variables into channels created by Page() application (issue #5888)
........
r7275 | oej | 2005-12-01 18:52:13 -0600 (Thu, 01 Dec 2005) | 2 lines
Bug #5907. Improve SIP INFO DTMF debugging output. (1.2 & Trunk)
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7276 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2005-12-02 01:01:11 +00:00
|
|
|
|
2003-04-06 02:41:42 +00:00
|
|
|
/* Start switch on sub channel */
|
2007-07-05 13:28:41 +00:00
|
|
|
if (!(res = ast_pbx_start(p->chan)))
|
|
|
|
ast_set_flag(p, LOCAL_LAUNCHED_PBX);
|
|
|
|
|
2003-08-19 19:36:52 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
|
|
|
return res;
|
2003-04-06 02:41:42 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Hangup a call through the local proxy channel */
|
2003-04-06 02:41:42 +00:00
|
|
|
static int local_hangup(struct ast_channel *ast)
|
|
|
|
{
|
2005-03-04 06:47:24 +00:00
|
|
|
struct local_pvt *p = ast->tech_pvt;
|
2004-06-22 04:54:52 +00:00
|
|
|
int isoutbound;
|
2008-05-22 16:29:54 +00:00
|
|
|
struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP, .data.uint32 = ast->hangupcause };
|
2003-05-19 23:37:38 +00:00
|
|
|
struct ast_channel *ochan = NULL;
|
2007-04-09 02:44:37 +00:00
|
|
|
int glaredetect = 0, res = 0;
|
2005-07-25 18:09:04 +00:00
|
|
|
|
2006-11-16 18:32:27 +00:00
|
|
|
if (!p)
|
|
|
|
return -1;
|
|
|
|
|
2008-06-27 16:00:05 +00:00
|
|
|
ast_mutex_lock(&p->lock);
|
2008-06-27 12:28:38 +00:00
|
|
|
|
2007-07-09 08:27:37 +00:00
|
|
|
if (p->chan && ast_test_flag(ast, AST_FLAG_ANSWERED_ELSEWHERE))
|
|
|
|
ast_set_flag(p->chan, AST_FLAG_ANSWERED_ELSEWHERE);
|
2004-06-22 04:54:52 +00:00
|
|
|
isoutbound = IS_OUTBOUND(ast, p);
|
2003-08-19 19:36:52 +00:00
|
|
|
if (isoutbound) {
|
2006-03-31 10:13:22 +00:00
|
|
|
const char *status = pbx_builtin_getvar_helper(p->chan, "DIALSTATUS");
|
2008-01-16 17:21:49 +00:00
|
|
|
if ((status) && (p->owner)) {
|
|
|
|
/* Deadlock avoidance */
|
2008-02-20 21:41:31 +00:00
|
|
|
while (p->owner && ast_channel_trylock(p->owner)) {
|
2008-01-16 17:21:49 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
2008-04-24 20:06:06 +00:00
|
|
|
if (ast) {
|
|
|
|
ast_channel_unlock(ast);
|
|
|
|
}
|
2008-01-16 17:21:49 +00:00
|
|
|
usleep(1);
|
2008-04-24 20:06:06 +00:00
|
|
|
if (ast) {
|
|
|
|
ast_channel_lock(ast);
|
|
|
|
}
|
2008-01-16 17:21:49 +00:00
|
|
|
ast_mutex_lock(&p->lock);
|
|
|
|
}
|
2008-02-20 21:41:31 +00:00
|
|
|
if (p->owner) {
|
|
|
|
pbx_builtin_setvar_helper(p->owner, "CHANLOCALSTATUS", status);
|
|
|
|
ast_channel_unlock(p->owner);
|
|
|
|
}
|
2008-01-16 17:21:49 +00:00
|
|
|
}
|
2003-04-06 02:41:42 +00:00
|
|
|
p->chan = NULL;
|
2006-09-07 21:11:07 +00:00
|
|
|
ast_clear_flag(p, LOCAL_LAUNCHED_PBX);
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_remove(p->u_chan);
|
|
|
|
} else {
|
2003-04-06 02:41:42 +00:00
|
|
|
p->owner = NULL;
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_remove(p->u_owner);
|
2008-10-14 17:38:06 +00:00
|
|
|
while (p->chan && ast_channel_trylock(p->chan)) {
|
|
|
|
DEADLOCK_AVOIDANCE(&p->lock);
|
|
|
|
}
|
2008-06-20 20:17:04 +00:00
|
|
|
if (p->chan) {
|
|
|
|
ast_queue_hangup(p->chan);
|
2008-10-14 17:38:06 +00:00
|
|
|
ast_channel_unlock(p->chan);
|
2008-06-20 20:17:04 +00:00
|
|
|
}
|
2006-08-21 02:11:39 +00:00
|
|
|
}
|
2003-05-19 23:37:38 +00:00
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
ast->tech_pvt = NULL;
|
2004-12-11 04:46:49 +00:00
|
|
|
|
2003-04-06 02:41:42 +00:00
|
|
|
if (!p->owner && !p->chan) {
|
|
|
|
/* Okay, done with the private part now, too. */
|
2006-09-07 21:11:07 +00:00
|
|
|
glaredetect = ast_test_flag(p, LOCAL_GLARE_DETECT);
|
2003-07-01 03:32:14 +00:00
|
|
|
/* If we have a queue holding, don't actually destroy p yet, but
|
|
|
|
let local_queue do it. */
|
2006-09-07 21:11:07 +00:00
|
|
|
if (glaredetect)
|
|
|
|
ast_set_flag(p, LOCAL_CANCEL_QUEUE);
|
2003-08-13 15:25:16 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
2003-04-08 13:50:04 +00:00
|
|
|
/* Remove from list */
|
2006-02-10 00:20:43 +00:00
|
|
|
AST_LIST_LOCK(&locals);
|
|
|
|
AST_LIST_REMOVE(&locals, p, list);
|
|
|
|
AST_LIST_UNLOCK(&locals);
|
2004-11-06 21:33:01 +00:00
|
|
|
/* Grab / release lock just in case */
|
|
|
|
ast_mutex_lock(&p->lock);
|
|
|
|
ast_mutex_unlock(&p->lock);
|
2003-04-08 13:50:04 +00:00
|
|
|
/* And destroy */
|
2004-06-22 17:42:14 +00:00
|
|
|
if (!glaredetect) {
|
2008-03-03 17:06:35 +00:00
|
|
|
p = local_pvt_destroy(p);
|
2004-06-22 17:42:14 +00:00
|
|
|
}
|
2003-04-06 02:41:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2006-09-07 21:11:07 +00:00
|
|
|
if (p->chan && !ast_test_flag(p, LOCAL_LAUNCHED_PBX))
|
2003-05-19 23:37:38 +00:00
|
|
|
/* Need to actually hangup since there is no PBX */
|
|
|
|
ochan = p->chan;
|
|
|
|
else
|
2008-05-13 21:18:55 +00:00
|
|
|
res = local_queue_frame(p, isoutbound, &f, NULL, 1);
|
2007-04-09 02:44:37 +00:00
|
|
|
if (!res)
|
|
|
|
ast_mutex_unlock(&p->lock);
|
2003-05-19 23:37:38 +00:00
|
|
|
if (ochan)
|
|
|
|
ast_hangup(ochan);
|
2003-04-06 02:41:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Create a call structure */
|
2006-04-21 17:53:39 +00:00
|
|
|
static struct local_pvt *local_alloc(const char *data, int format)
|
2003-04-06 02:41:42 +00:00
|
|
|
{
|
2006-09-07 19:50:59 +00:00
|
|
|
struct local_pvt *tmp = NULL;
|
|
|
|
char *c = NULL, *opts = NULL;
|
2005-07-25 18:09:04 +00:00
|
|
|
|
2006-01-11 01:20:29 +00:00
|
|
|
if (!(tmp = ast_calloc(1, sizeof(*tmp))))
|
|
|
|
return NULL;
|
2006-09-07 19:50:59 +00:00
|
|
|
|
|
|
|
/* Initialize private structure information */
|
2006-01-11 01:20:29 +00:00
|
|
|
ast_mutex_init(&tmp->lock);
|
2006-04-21 17:53:39 +00:00
|
|
|
ast_copy_string(tmp->exten, data, sizeof(tmp->exten));
|
2006-09-07 19:50:59 +00:00
|
|
|
|
2007-10-09 15:10:14 +00:00
|
|
|
memcpy(&tmp->jb_conf, &g_jb_conf, sizeof(tmp->jb_conf));
|
|
|
|
|
2006-09-07 19:50:59 +00:00
|
|
|
/* Look for options */
|
|
|
|
if ((opts = strchr(tmp->exten, '/'))) {
|
2006-04-21 17:53:39 +00:00
|
|
|
*opts++ = '\0';
|
2006-01-11 01:20:29 +00:00
|
|
|
if (strchr(opts, 'n'))
|
2006-09-07 21:11:07 +00:00
|
|
|
ast_set_flag(tmp, LOCAL_NO_OPTIMIZATION);
|
2007-10-09 15:10:14 +00:00
|
|
|
if (strchr(opts, 'j')) {
|
|
|
|
if (ast_test_flag(tmp, LOCAL_NO_OPTIMIZATION))
|
|
|
|
ast_set_flag(&tmp->jb_conf, AST_JB_ENABLED);
|
|
|
|
else {
|
|
|
|
ast_log(LOG_ERROR, "You must use the 'n' option for chan_local "
|
|
|
|
"to use the 'j' option to enable the jitterbuffer\n");
|
|
|
|
}
|
|
|
|
}
|
2008-04-10 20:28:40 +00:00
|
|
|
if (strchr(opts, 'b')) {
|
|
|
|
ast_set_flag(tmp, LOCAL_BRIDGE);
|
|
|
|
}
|
2003-04-06 02:41:42 +00:00
|
|
|
}
|
2006-09-07 19:50:59 +00:00
|
|
|
|
|
|
|
/* Look for a context */
|
|
|
|
if ((c = strchr(tmp->exten, '@')))
|
2006-04-21 17:53:39 +00:00
|
|
|
*c++ = '\0';
|
2006-09-07 19:50:59 +00:00
|
|
|
|
2006-04-21 17:53:39 +00:00
|
|
|
ast_copy_string(tmp->context, c ? c : "default", sizeof(tmp->context));
|
2006-09-07 19:50:59 +00:00
|
|
|
|
2006-01-11 01:20:29 +00:00
|
|
|
tmp->reqformat = format;
|
2006-09-07 19:50:59 +00:00
|
|
|
|
2008-10-06 16:52:14 +00:00
|
|
|
#if 0
|
|
|
|
/* We can't do this check here, because we don't know the CallerID yet, and
|
|
|
|
* the CallerID could potentially affect what step is actually taken (or
|
|
|
|
* even if that step exists). */
|
2006-01-11 01:20:29 +00:00
|
|
|
if (!ast_exists_extension(NULL, tmp->context, tmp->exten, 1, NULL)) {
|
|
|
|
ast_log(LOG_NOTICE, "No such extension/context %s@%s creating local channel\n", tmp->exten, tmp->context);
|
2008-03-03 17:06:35 +00:00
|
|
|
tmp = local_pvt_destroy(tmp);
|
2006-01-11 01:20:29 +00:00
|
|
|
} else {
|
2008-10-06 16:52:14 +00:00
|
|
|
#endif
|
2006-01-11 01:20:29 +00:00
|
|
|
/* Add to list */
|
2006-02-10 00:20:43 +00:00
|
|
|
AST_LIST_LOCK(&locals);
|
|
|
|
AST_LIST_INSERT_HEAD(&locals, tmp, list);
|
|
|
|
AST_LIST_UNLOCK(&locals);
|
2008-10-06 16:52:14 +00:00
|
|
|
#if 0
|
2006-01-11 01:20:29 +00:00
|
|
|
}
|
2008-10-06 16:52:14 +00:00
|
|
|
#endif
|
2006-01-11 01:20:29 +00:00
|
|
|
|
2003-04-06 02:41:42 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Start new local channel */
|
2003-04-06 02:41:42 +00:00
|
|
|
static struct ast_channel *local_new(struct local_pvt *p, int state)
|
|
|
|
{
|
2006-09-07 19:50:59 +00:00
|
|
|
struct ast_channel *tmp = NULL, *tmp2 = NULL;
|
|
|
|
int randnum = ast_random() & 0xffff, fmt = 0;
|
2007-05-14 14:13:45 +00:00
|
|
|
const char *t;
|
|
|
|
int ama;
|
2005-07-25 18:09:04 +00:00
|
|
|
|
2006-09-07 19:50:59 +00:00
|
|
|
/* Allocate two new Asterisk channels */
|
2007-05-14 14:13:45 +00:00
|
|
|
/* safe accountcode */
|
|
|
|
if (p->owner && p->owner->accountcode)
|
|
|
|
t = p->owner->accountcode;
|
|
|
|
else
|
|
|
|
t = "";
|
|
|
|
|
|
|
|
if (p->owner)
|
|
|
|
ama = p->owner->amaflags;
|
|
|
|
else
|
|
|
|
ama = 0;
|
2007-07-23 19:51:41 +00:00
|
|
|
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))
|
|
|
|
|| !(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))) {
|
2003-04-06 02:41:42 +00:00
|
|
|
if (tmp)
|
|
|
|
ast_channel_free(tmp);
|
|
|
|
if (tmp2)
|
|
|
|
ast_channel_free(tmp2);
|
2005-07-25 18:09:04 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to allocate channel structure(s)\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp2->tech = tmp->tech = &local_tech;
|
2006-09-07 19:50:59 +00:00
|
|
|
|
2005-07-25 18:09:04 +00:00
|
|
|
tmp->nativeformats = p->reqformat;
|
|
|
|
tmp2->nativeformats = p->reqformat;
|
2006-09-07 19:50:59 +00:00
|
|
|
|
|
|
|
/* Determine our read/write format and set it on each channel */
|
|
|
|
fmt = ast_best_codec(p->reqformat);
|
|
|
|
tmp->writeformat = fmt;
|
|
|
|
tmp2->writeformat = fmt;
|
|
|
|
tmp->rawwriteformat = fmt;
|
|
|
|
tmp2->rawwriteformat = fmt;
|
|
|
|
tmp->readformat = fmt;
|
|
|
|
tmp2->readformat = fmt;
|
|
|
|
tmp->rawreadformat = fmt;
|
|
|
|
tmp2->rawreadformat = fmt;
|
|
|
|
|
2005-07-25 18:09:04 +00:00
|
|
|
tmp->tech_pvt = p;
|
|
|
|
tmp2->tech_pvt = p;
|
2006-09-07 19:50:59 +00:00
|
|
|
|
2005-07-25 18:09:04 +00:00
|
|
|
p->owner = tmp;
|
|
|
|
p->chan = tmp2;
|
2006-08-21 02:11:39 +00:00
|
|
|
p->u_owner = ast_module_user_add(p->owner);
|
|
|
|
p->u_chan = ast_module_user_add(p->chan);
|
2006-09-07 19:50:59 +00:00
|
|
|
|
2005-07-25 18:09:04 +00:00
|
|
|
ast_copy_string(tmp->context, p->context, sizeof(tmp->context));
|
|
|
|
ast_copy_string(tmp2->context, p->context, sizeof(tmp2->context));
|
|
|
|
ast_copy_string(tmp2->exten, p->exten, sizeof(tmp->exten));
|
|
|
|
tmp->priority = 1;
|
|
|
|
tmp2->priority = 1;
|
|
|
|
|
2007-10-09 15:10:14 +00:00
|
|
|
ast_jb_configure(tmp, &p->jb_conf);
|
|
|
|
|
2003-04-06 02:41:42 +00:00
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Part of PBX interface */
|
2004-10-26 22:25:43 +00:00
|
|
|
static struct ast_channel *local_request(const char *type, int format, void *data, int *cause)
|
2003-04-06 02:41:42 +00:00
|
|
|
{
|
2006-09-07 19:50:59 +00:00
|
|
|
struct local_pvt *p = NULL;
|
2003-04-06 02:41:42 +00:00
|
|
|
struct ast_channel *chan = NULL;
|
2005-07-25 18:09:04 +00:00
|
|
|
|
2006-09-07 19:50:59 +00:00
|
|
|
/* Allocate a new private structure and then Asterisk channel */
|
2008-03-03 17:06:35 +00:00
|
|
|
if ((p = local_alloc(data, format))) {
|
2008-03-03 17:17:27 +00:00
|
|
|
if (!(chan = local_new(p, AST_STATE_DOWN))) {
|
|
|
|
AST_LIST_LOCK(&locals);
|
|
|
|
AST_LIST_REMOVE(&locals, p, list);
|
|
|
|
AST_LIST_UNLOCK(&locals);
|
2008-03-03 17:06:35 +00:00
|
|
|
p = local_pvt_destroy(p);
|
2008-03-03 17:17:27 +00:00
|
|
|
}
|
2008-03-03 17:06:35 +00:00
|
|
|
}
|
2006-09-07 19:50:59 +00:00
|
|
|
|
2003-04-06 02:41:42 +00:00
|
|
|
return chan;
|
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief CLI command "local show channels" */
|
2007-09-18 22:43:45 +00:00
|
|
|
static char *locals_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
2003-04-06 02:41:42 +00:00
|
|
|
{
|
2006-09-07 19:50:59 +00:00
|
|
|
struct local_pvt *p = NULL;
|
2003-04-06 02:41:42 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case CLI_INIT:
|
|
|
|
e->command = "local show channels";
|
|
|
|
e->usage =
|
|
|
|
"Usage: local show channels\n"
|
|
|
|
" Provides summary information on active local proxy channels.\n";
|
|
|
|
return NULL;
|
|
|
|
case CLI_GENERATE:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a->argc != 3)
|
|
|
|
return CLI_SHOWUSAGE;
|
2006-09-07 19:50:59 +00:00
|
|
|
|
2006-02-10 00:20:43 +00:00
|
|
|
AST_LIST_LOCK(&locals);
|
2006-09-07 19:50:59 +00:00
|
|
|
if (!AST_LIST_EMPTY(&locals)) {
|
|
|
|
AST_LIST_TRAVERSE(&locals, p, list) {
|
|
|
|
ast_mutex_lock(&p->lock);
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, "%s -- %s@%s\n", p->owner ? p->owner->name : "<unowned>", p->exten, p->context);
|
2006-09-07 19:50:59 +00:00
|
|
|
ast_mutex_unlock(&p->lock);
|
|
|
|
}
|
|
|
|
} else
|
2007-09-18 22:43:45 +00:00
|
|
|
ast_cli(a->fd, "No local channels in use\n");
|
2006-02-10 00:20:43 +00:00
|
|
|
AST_LIST_UNLOCK(&locals);
|
2006-09-07 19:50:59 +00:00
|
|
|
|
2007-09-18 22:43:45 +00:00
|
|
|
return CLI_SUCCESS;
|
2003-04-06 02:41:42 +00:00
|
|
|
}
|
|
|
|
|
2006-09-18 19:54:18 +00:00
|
|
|
static struct ast_cli_entry cli_local[] = {
|
2007-10-22 20:05:18 +00:00
|
|
|
AST_CLI_DEFINE(locals_show, "List status of local channels"),
|
2006-09-18 19:54:18 +00:00
|
|
|
};
|
2003-04-06 02:41:42 +00:00
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Load module into PBX, register channel */
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2003-04-06 02:41:42 +00:00
|
|
|
{
|
2005-03-04 06:47:24 +00:00
|
|
|
/* Make sure we can register our channel type */
|
|
|
|
if (ast_channel_register(&local_tech)) {
|
2006-02-01 23:05:28 +00:00
|
|
|
ast_log(LOG_ERROR, "Unable to register channel class 'Local'\n");
|
2007-10-26 21:37:02 +00:00
|
|
|
return AST_MODULE_LOAD_FAILURE;
|
2003-04-06 02:41:42 +00:00
|
|
|
}
|
2006-09-18 19:54:18 +00:00
|
|
|
ast_cli_register_multiple(cli_local, sizeof(cli_local) / sizeof(struct ast_cli_entry));
|
2007-10-26 21:37:02 +00:00
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
2003-04-06 02:41:42 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 00:18:42 +00:00
|
|
|
/*! \brief Unload the local proxy channel from Asterisk */
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2003-04-06 02:41:42 +00:00
|
|
|
{
|
2006-09-07 19:50:59 +00:00
|
|
|
struct local_pvt *p = NULL;
|
2005-07-25 18:09:04 +00:00
|
|
|
|
2003-04-06 02:41:42 +00:00
|
|
|
/* First, take us out of the channel loop */
|
2006-09-18 19:54:18 +00:00
|
|
|
ast_cli_unregister_multiple(cli_local, sizeof(cli_local) / sizeof(struct ast_cli_entry));
|
2005-03-04 06:47:24 +00:00
|
|
|
ast_channel_unregister(&local_tech);
|
2006-02-10 00:20:43 +00:00
|
|
|
if (!AST_LIST_LOCK(&locals)) {
|
2003-04-06 02:41:42 +00:00
|
|
|
/* Hangup all interfaces if they have an owner */
|
2006-02-10 00:20:43 +00:00
|
|
|
AST_LIST_TRAVERSE(&locals, p, list) {
|
2003-04-06 02:41:42 +00:00
|
|
|
if (p->owner)
|
|
|
|
ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
|
|
|
|
}
|
2006-02-10 00:20:43 +00:00
|
|
|
AST_LIST_UNLOCK(&locals);
|
2003-04-06 02:41:42 +00:00
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Unable to lock the monitor\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-22 17:46:43 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Local Proxy Channel (Note: used internally by other modules)");
|