dect
/
asterisk
Archived
13
0
Fork 0
This repository has been archived on 2022-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
asterisk/channels/chan_local.c

1260 lines
36 KiB
C
Raw Normal View History

/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 1999 - 2005, Digium, Inc.
*
* Mark Spencer <markster@digium.com>
*
* 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.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*! \file
*
* \author Mark Spencer <markster@digium.com>
*
* \brief Local Proxy Channel
*
* \ingroup channel_drivers
*/
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <fcntl.h>
#include <sys/signal.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/file.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
#include "asterisk/musiconhold.h"
#include "asterisk/manager.h"
#include "asterisk/stringfields.h"
#include "asterisk/devicestate.h"
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
#include "asterisk/astobj2.h"
/*** DOCUMENTATION
<manager name="LocalOptimizeAway" language="en_US">
<synopsis>
Optimize away a local channel when possible.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="Channel" required="true">
<para>The channel name to optimize away.</para>
</parameter>
</syntax>
<description>
<para>A local channel created with "/n" will not automatically optimize away.
Calling this command on the local channel will clear that flag and allow
it to optimize away if it's bridged or when it becomes bridged.</para>
</description>
</manager>
***/
static const char tdesc[] = "Local Proxy Channel Driver";
#define IS_OUTBOUND(a,b) (a == b->chan ? 1 : 0)
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
/* right now we are treating the locals astobj2 container as a
* list. If there is ever a reason to make this more efficient
* increasing the bucket size would help. */
static const int BUCKET_SIZE = 1;
static struct ao2_container *locals;
static struct ast_jb_conf g_jb_conf = {
.flags = 0,
.max_size = -1,
.resync_threshold = -1,
.impl = "",
.target_extra = -1,
};
static struct ast_channel *local_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
static int local_digit_begin(struct ast_channel *ast, char digit);
2007-01-19 18:06:03 +00:00
static int local_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
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);
static int local_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
static int local_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
static int local_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen);
static int local_sendtext(struct ast_channel *ast, const char *text);
static int local_devicestate(void *data);
static struct ast_channel *local_bridgedchannel(struct ast_channel *chan, struct ast_channel *bridge);
static int local_queryoption(struct ast_channel *ast, int option, void *data, int *datalen);
static int local_setoption(struct ast_channel *chan, int option, void *data, int datalen);
/* PBX interface structure for channel registration */
static struct ast_channel_tech local_tech = {
.type = "Local",
.description = tdesc,
.requester = local_request,
.send_digit_begin = local_digit_begin,
.send_digit_end = local_digit_end,
.call = local_call,
.hangup = local_hangup,
.answer = local_answer,
.read = local_read,
.write = local_write,
.write_video = local_write,
.exception = local_read,
.indicate = local_indicate,
.fixup = local_fixup,
.send_html = local_sendhtml,
.send_text = local_sendtext,
.devicestate = local_devicestate,
.bridged_channel = local_bridgedchannel,
.queryoption = local_queryoption,
.setoption = local_setoption,
};
/*! \brief the local pvt structure for all channels
The local channel pvt has two ast_chan objects - the "owner" and the "next channel", the outbound channel
ast_chan owner -> local_pvt -> ast_chan chan -> yet-another-pvt-depending-on-channel-type
*/
struct local_pvt {
unsigned int flags; /*!< Private flags */
char context[AST_MAX_CONTEXT]; /*!< Context to call */
char exten[AST_MAX_EXTENSION]; /*!< Extension to call */
struct ast_format_cap *reqcap; /*!< Requested format capabilities */
struct ast_jb_conf jb_conf; /*!< jitterbuffer configuration for this local channel */
struct ast_channel *owner; /*!< Master Channel - Bridging happens here */
struct ast_channel *chan; /*!< Outbound channel - PBX is run here */
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 */
};
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
#define LOCAL_ALREADY_MASQED (1 << 0) /*!< Already masqueraded */
#define LOCAL_LAUNCHED_PBX (1 << 1) /*!< PBX was launched */
#define LOCAL_NO_OPTIMIZATION (1 << 2) /*!< Do not optimize using masquerading */
#define LOCAL_BRIDGE (1 << 3) /*!< Report back the "true" channel as being bridged to */
#define LOCAL_MOH_PASSTHRU (1 << 4) /*!< Pass through music on hold start/stop frames */
static int local_setoption(struct ast_channel *chan, int option, void * data, int datalen)
{
int res;
struct local_pvt *p;
struct ast_channel *otherchan;
ast_chan_write_info_t *write_info;
if (option != AST_OPTION_CHANNEL_WRITE) {
return -1;
}
write_info = data;
if (write_info->version != AST_CHAN_WRITE_INFO_T_VERSION) {
ast_log(LOG_ERROR, "The chan_write_info_t type has changed, and this channel hasn't been updated!\n");
return -1;
}
startover:
ast_channel_lock(chan);
p = chan->tech_pvt;
if (!p) {
ast_channel_unlock(chan);
ast_log(LOG_WARNING, "Could not update other side of %s, local_pvt went away.\n", chan->name);
return -1;
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
while (ao2_trylock(p)) {
ast_channel_unlock(chan);
sched_yield();
ast_channel_lock(chan);
p = chan->tech_pvt;
if (!p) {
ast_channel_unlock(chan);
ast_log(LOG_WARNING, "Could not update other side of %s, local_pvt went away.\n", chan->name);
return -1;
}
}
otherchan = (write_info->chan == p->owner) ? p->chan : p->owner;
if (!otherchan || otherchan == write_info->chan) {
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
ast_channel_unlock(chan);
ast_log(LOG_WARNING, "Could not update other side of %s, other side went away.\n", chan->name);
return 0;
}
if (ast_channel_trylock(otherchan)) {
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
ast_channel_unlock(chan);
goto startover;
}
res = write_info->write_fn(otherchan, write_info->function, write_info->data, write_info->value);
ast_channel_unlock(otherchan);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
ast_channel_unlock(chan);
return res;
}
/*! \brief Adds devicestate to local channels */
static int local_devicestate(void *data)
{
char *exten = ast_strdupa(data);
char *context = NULL, *opts = NULL;
int res;
struct local_pvt *lp;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
struct ao2_iterator it;
if (!(context = strchr(exten, '@'))) {
ast_log(LOG_WARNING, "Someone used Local/%s somewhere without a @context. This is bad.\n", exten);
return AST_DEVICE_INVALID;
}
*context++ = '\0';
/* Strip options if they exist */
if ((opts = strchr(context, '/')))
*opts = '\0';
ast_debug(3, "Checking if extension %s@%s exists (devicestate)\n", exten, context);
res = ast_exists_extension(NULL, context, exten, 1, NULL);
if (!res)
return AST_DEVICE_INVALID;
res = AST_DEVICE_NOT_INUSE;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
it = ao2_iterator_init(locals, 0);
while ((lp = ao2_iterator_next(&it))) {
if (!strcmp(exten, lp->exten) && !strcmp(context, lp->context) && lp->owner) {
res = AST_DEVICE_INUSE;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_ref(lp, -1);
break;
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_ref(lp, -1);
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_iterator_destroy(&it);
return res;
}
/*! \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;
if (!p) {
ast_debug(1, "Asked for bridged channel on '%s'/'%s', returning <none>\n",
chan->name, bridge->name);
return NULL;
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_lock(p);
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 */
if (!bridged) {
bridged = bridge;
} else if (bridged->_bridge) {
bridged = bridged->_bridge;
}
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
return bridged;
}
static int local_queryoption(struct ast_channel *ast, int option, void *data, int *datalen)
{
struct local_pvt *p = ast->tech_pvt;
struct ast_channel *chan, *bridged;
int res;
if (!p) {
return -1;
}
if (option != AST_OPTION_T38_STATE) {
/* AST_OPTION_T38_STATE is the only supported option at this time */
return -1;
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_lock(p);
chan = IS_OUTBOUND(ast, p) ? p->owner : p->chan;
try_again:
if (!chan) {
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
return -1;
}
if (ast_channel_trylock(chan)) {
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
sched_yield();
ao2_lock(p);
chan = IS_OUTBOUND(ast, p) ? p->owner : p->chan;
goto try_again;
}
bridged = ast_bridged_channel(chan);
if (!bridged) {
/* can't query channel unless we are bridged */
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
ast_channel_unlock(chan);
return -1;
}
if (ast_channel_trylock(bridged)) {
ast_channel_unlock(chan);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
sched_yield();
ao2_lock(p);
chan = IS_OUTBOUND(ast, p) ? p->owner : p->chan;
goto try_again;
}
res = ast_channel_queryoption(bridged, option, data, datalen, 0);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
ast_channel_unlock(chan);
ast_channel_unlock(bridged);
return res;
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
/*! \brief queue a frame on a to either the p->owner or p->chan
*
* \note the local_pvt MUST have it's ref count bumped before entering this function and
* decremented after this function is called. This is a side effect of the deadlock
* avoidance that is necessary to lock 2 channels and a tech_pvt. Without a ref counted
* local_pvt, it is impossible to guarantee it will not be destroyed by another thread
* during deadlock avoidance.
*/
Merged revisions 116038 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r116038 | russell | 2008-05-13 16:17:23 -0500 (Tue, 13 May 2008) | 24 lines Fix a deadlock involving channel autoservice and chan_local that was debugged and fixed by mmichelson and me. We observed a system that had a bunch of threads stuck in ast_autoservice_stop(). The reason these threads were waiting around is because this function waits to ensure that the channel list in the autoservice thread gets rebuilt before the stop() function returns. However, the autoservice thread was also locked, so the autoservice channel list was never getting rebuilt. The autoservice thread was stuck waiting for the channel lock on a local channel. However, the local channel was locked by a thread that was stuck in the autoservice stop function. It turned out that the issue came down to the local_queue_frame() function in chan_local. This function assumed that one of the channels passed in as an argument was locked when called. However, that was not always the case. There were multiple cases in which this channel was not locked when the function was called. We fixed up chan_local to indicate to this function whether this channel was locked or not. The previous assumption had caused local_queue_frame() to improperly return with the channel locked, where it would then never get unlocked. (closes issue #12584) (related to issue #12603) ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@116039 f38db490-d61c-443f-a65b-d21fe96a405b
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)
{
struct ast_channel *other = NULL;
/* Recalculate outbound channel */
other = isoutbound ? p->owner : p->chan;
if (!other) {
return 0;
}
/* do not queue frame if generator is on both local channels */
if (us && us->generator && other->generator) {
return 0;
}
/* Ensure that we have both channels locked */
while (other && ast_channel_trylock(other)) {
int res;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
if ((res = ao2_unlock(p))) {
ast_log(LOG_ERROR, "chan_local bug! '&p->lock' was not locked when entering local_queue_frame! (%s)\n", strerror(res));
return -1;
}
Merged revisions 116038 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r116038 | russell | 2008-05-13 16:17:23 -0500 (Tue, 13 May 2008) | 24 lines Fix a deadlock involving channel autoservice and chan_local that was debugged and fixed by mmichelson and me. We observed a system that had a bunch of threads stuck in ast_autoservice_stop(). The reason these threads were waiting around is because this function waits to ensure that the channel list in the autoservice thread gets rebuilt before the stop() function returns. However, the autoservice thread was also locked, so the autoservice channel list was never getting rebuilt. The autoservice thread was stuck waiting for the channel lock on a local channel. However, the local channel was locked by a thread that was stuck in the autoservice stop function. It turned out that the issue came down to the local_queue_frame() function in chan_local. This function assumed that one of the channels passed in as an argument was locked when called. However, that was not always the case. There were multiple cases in which this channel was not locked when the function was called. We fixed up chan_local to indicate to this function whether this channel was locked or not. The previous assumption had caused local_queue_frame() to improperly return with the channel locked, where it would then never get unlocked. (closes issue #12584) (related to issue #12603) ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@116039 f38db490-d61c-443f-a65b-d21fe96a405b
2008-05-13 21:18:55 +00:00
if (us && us_locked) {
do {
CHANNEL_DEADLOCK_AVOIDANCE(us);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
} while (ao2_trylock(p));
} else {
usleep(1);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_lock(p);
Merged revisions 116038 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r116038 | russell | 2008-05-13 16:17:23 -0500 (Tue, 13 May 2008) | 24 lines Fix a deadlock involving channel autoservice and chan_local that was debugged and fixed by mmichelson and me. We observed a system that had a bunch of threads stuck in ast_autoservice_stop(). The reason these threads were waiting around is because this function waits to ensure that the channel list in the autoservice thread gets rebuilt before the stop() function returns. However, the autoservice thread was also locked, so the autoservice channel list was never getting rebuilt. The autoservice thread was stuck waiting for the channel lock on a local channel. However, the local channel was locked by a thread that was stuck in the autoservice stop function. It turned out that the issue came down to the local_queue_frame() function in chan_local. This function assumed that one of the channels passed in as an argument was locked when called. However, that was not always the case. There were multiple cases in which this channel was not locked when the function was called. We fixed up chan_local to indicate to this function whether this channel was locked or not. The previous assumption had caused local_queue_frame() to improperly return with the channel locked, where it would then never get unlocked. (closes issue #12584) (related to issue #12603) ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@116039 f38db490-d61c-443f-a65b-d21fe96a405b
2008-05-13 21:18:55 +00:00
}
other = isoutbound ? p->owner : p->chan;
}
if (other) {
if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_RINGING) {
ast_setstate(other, AST_STATE_RINGING);
}
ast_queue_frame(other, f);
ast_channel_unlock(other);
}
return 0;
}
static int local_answer(struct ast_channel *ast)
{
struct local_pvt *p = ast->tech_pvt;
int isoutbound;
int res = -1;
if (!p)
return -1;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_lock(p);
ao2_ref(p, 1);
isoutbound = IS_OUTBOUND(ast, p);
if (isoutbound) {
/* Pass along answer since somebody answered us */
struct ast_frame answer = { AST_FRAME_CONTROL, { AST_CONTROL_ANSWER } };
Merged revisions 116038 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r116038 | russell | 2008-05-13 16:17:23 -0500 (Tue, 13 May 2008) | 24 lines Fix a deadlock involving channel autoservice and chan_local that was debugged and fixed by mmichelson and me. We observed a system that had a bunch of threads stuck in ast_autoservice_stop(). The reason these threads were waiting around is because this function waits to ensure that the channel list in the autoservice thread gets rebuilt before the stop() function returns. However, the autoservice thread was also locked, so the autoservice channel list was never getting rebuilt. The autoservice thread was stuck waiting for the channel lock on a local channel. However, the local channel was locked by a thread that was stuck in the autoservice stop function. It turned out that the issue came down to the local_queue_frame() function in chan_local. This function assumed that one of the channels passed in as an argument was locked when called. However, that was not always the case. There were multiple cases in which this channel was not locked when the function was called. We fixed up chan_local to indicate to this function whether this channel was locked or not. The previous assumption had caused local_queue_frame() to improperly return with the channel locked, where it would then never get unlocked. (closes issue #12584) (related to issue #12603) ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@116039 f38db490-d61c-443f-a65b-d21fe96a405b
2008-05-13 21:18:55 +00:00
res = local_queue_frame(p, isoutbound, &answer, ast, 1);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
} else {
ast_log(LOG_WARNING, "Huh? Local is being asked to answer?\n");
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
}
ao2_unlock(p);
ao2_ref(p, -1);
return res;
}
/*!
* \internal
* \note This function assumes that we're only called from the "outbound" local channel side
*/
static void check_bridge(struct local_pvt *p)
{
struct ast_channel_monitor *tmp;
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)))
return;
/* 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)
*/
if (p->chan->_bridge /* Not ast_bridged_channel! Only go one step! */ && AST_LIST_EMPTY(&p->owner->readq)) {
/* Masquerade bridged channel into owner */
/* 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 */
if (!ast_channel_trylock(p->chan->_bridge)) {
if (!ast_check_hangup(p->chan->_bridge)) {
if (!ast_channel_trylock(p->owner)) {
if (!ast_check_hangup(p->owner)) {
if (p->owner->monitor && !p->chan->_bridge->monitor) {
/* 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;
}
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;
}
/* If any Caller ID was set, preserve it after masquerade like above. We must check
* to see if Caller ID was set because otherwise we'll mistakingly copy info not
* set from the dialplan and will overwrite the real channel Caller ID. The reason
* for this whole preswapping action is because the Caller ID is set on the channel
* thread (which is the to be masqueraded away local channel) before both local
* channels are optimized away.
*/
if (p->owner->caller.id.name.valid || p->owner->caller.id.number.valid
|| p->owner->caller.id.subaddress.valid || p->owner->caller.ani.name.valid
|| p->owner->caller.ani.number.valid || p->owner->caller.ani.subaddress.valid) {
struct ast_party_caller tmp;
tmp = p->owner->caller;
p->owner->caller = p->chan->_bridge->caller;
p->chan->_bridge->caller = tmp;
}
if (p->owner->redirecting.from.name.valid || p->owner->redirecting.from.number.valid
|| p->owner->redirecting.from.subaddress.valid || p->owner->redirecting.to.name.valid
|| p->owner->redirecting.to.number.valid || p->owner->redirecting.to.subaddress.valid) {
struct ast_party_redirecting tmp;
tmp = p->owner->redirecting;
p->owner->redirecting = p->chan->_bridge->redirecting;
p->chan->_bridge->redirecting = tmp;
}
if (p->owner->dialed.number.str || p->owner->dialed.subaddress.valid) {
struct ast_party_dialed tmp;
tmp = p->owner->dialed;
p->owner->dialed = p->chan->_bridge->dialed;
p->chan->_bridge->dialed = tmp;
}
ast_app_group_update(p->chan, p->owner);
ast_channel_masquerade(p->owner, p->chan->_bridge);
ast_set_flag(p, LOCAL_ALREADY_MASQED);
}
ast_channel_unlock(p->owner);
}
ast_channel_unlock(p->chan->_bridge);
}
}
}
}
static struct ast_frame *local_read(struct ast_channel *ast)
{
return &ast_null_frame;
}
static int local_write(struct ast_channel *ast, struct ast_frame *f)
{
struct local_pvt *p = ast->tech_pvt;
int res = -1;
int isoutbound;
if (!p)
return -1;
/* Just queue for delivery to the other side */
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_lock(p);
ao2_ref(p, 1); /* ref for local_queue_frame */
isoutbound = IS_OUTBOUND(ast, p);
if (isoutbound && f && (f->frametype == AST_FRAME_VOICE || f->frametype == AST_FRAME_VIDEO))
check_bridge(p);
if (!ast_test_flag(p, LOCAL_ALREADY_MASQED))
Merged revisions 116038 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r116038 | russell | 2008-05-13 16:17:23 -0500 (Tue, 13 May 2008) | 24 lines Fix a deadlock involving channel autoservice and chan_local that was debugged and fixed by mmichelson and me. We observed a system that had a bunch of threads stuck in ast_autoservice_stop(). The reason these threads were waiting around is because this function waits to ensure that the channel list in the autoservice thread gets rebuilt before the stop() function returns. However, the autoservice thread was also locked, so the autoservice channel list was never getting rebuilt. The autoservice thread was stuck waiting for the channel lock on a local channel. However, the local channel was locked by a thread that was stuck in the autoservice stop function. It turned out that the issue came down to the local_queue_frame() function in chan_local. This function assumed that one of the channels passed in as an argument was locked when called. However, that was not always the case. There were multiple cases in which this channel was not locked when the function was called. We fixed up chan_local to indicate to this function whether this channel was locked or not. The previous assumption had caused local_queue_frame() to improperly return with the channel locked, where it would then never get unlocked. (closes issue #12584) (related to issue #12603) ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@116039 f38db490-d61c-443f-a65b-d21fe96a405b
2008-05-13 21:18:55 +00:00
res = local_queue_frame(p, isoutbound, f, ast, 1);
else {
ast_debug(1, "Not posting to queue since already masked on '%s'\n", ast->name);
res = 0;
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
ao2_ref(p, -1);
return res;
}
static int local_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
{
struct local_pvt *p = newchan->tech_pvt;
if (!p)
return -1;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_lock(p);
if ((p->owner != oldchan) && (p->chan != oldchan)) {
ast_log(LOG_WARNING, "Old channel wasn't %p but was %p/%p\n", oldchan, p->owner, p->chan);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
return -1;
}
if (p->owner == oldchan)
p->owner = newchan;
else
p->chan = newchan;
/* Do not let a masquerade cause a Local channel to be bridged to itself! */
if (!ast_check_hangup(newchan) && (p->owner->_bridge == p->chan || p->chan->_bridge == p->owner)) {
ast_log(LOG_WARNING, "You can not bridge a Local channel to itself!\n");
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
ast_queue_hangup(newchan);
return -1;
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
return 0;
}
static int local_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
{
struct local_pvt *p = ast->tech_pvt;
int res = 0;
struct ast_frame f = { AST_FRAME_CONTROL, };
int isoutbound;
if (!p)
return -1;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_ref(p, 1); /* ref for local_queue_frame */
/* If this is an MOH hold or unhold, do it on the Local channel versus real channel */
if (!ast_test_flag(p, LOCAL_MOH_PASSTHRU) && condition == AST_CONTROL_HOLD) {
ast_moh_start(ast, data, NULL);
} else if (!ast_test_flag(p, LOCAL_MOH_PASSTHRU) && condition == AST_CONTROL_UNHOLD) {
ast_moh_stop(ast);
} else if (condition == AST_CONTROL_CONNECTED_LINE || condition == AST_CONTROL_REDIRECTING) {
struct ast_channel *this_channel;
struct ast_channel *the_other_channel;
/* A connected line update frame may only contain a partial amount of data, such
* as just a source, or just a ton, and not the full amount of information. However,
* the collected information is all stored in the outgoing channel's connectedline
* structure, so when receiving a connected line update on an outgoing local channel,
* we need to transmit the collected connected line information instead of whatever
* happens to be in this control frame. The same applies for redirecting information, which
* is why it is handled here as well.*/
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_lock(p);
isoutbound = IS_OUTBOUND(ast, p);
if (isoutbound) {
this_channel = p->chan;
the_other_channel = p->owner;
} else {
this_channel = p->owner;
the_other_channel = p->chan;
}
if (the_other_channel) {
unsigned char frame_data[1024];
if (condition == AST_CONTROL_CONNECTED_LINE) {
Enhancements to connected line and redirecting work. From reviewboard: Digium has a commercial customer who has made extensive use of the connected party and redirecting information present in later versions of Asterisk Business Edition and which is to be in the upcoming 1.8 release. Through their use of the feature, new problems and solutions have come about. This patch adds several enhancements to maximize usage of the connected party and redirecting information functionality. First, Asterisk trunk already had connected line interception macros. These macros allow you to manipulate connected line information before it was sent out to its target. This patch adds the same feature except for redirecting information instead. Second, the ast_callerid and ast_party_id structures have been enhanced to provide a "tag." This tag can be set with func_callerid, func_connectedline, func_redirecting, and in the case of DAHDI, mISDN, and SIP channels, can be set in a configuration file. The idea behind the callerid tag is that it can be set to whatever value the administrator likes. Later, when running connected line and redirecting macros, the admin can read the tag off the appropriate structure to determine what action to take. You can think of this sort of like a channel variable, except that instead of having the variable associated with a channel, the variable is associated with a specific identity within Asterisk. Third, app_dial has two new options, s and u. The s option lets a dialplan writer force a specific caller ID tag to be placed on the outgoing channel. The u option allows the dialplan writer to force a specific calling presentation value on the outgoing channel. Fourth, there is a new control frame subclass called AST_CONTROL_READ_ACTION added. This was added to correct a very specific situation. In the case of SIP semi-attended (blond) transfers, the party being transferred would not have the opportunity to run a connected line interception macro to possibly alter the transfer target's connected line information. The issue here was that during a blond transfer, the SIP transfer code has no bridged channel on which to queue the connected line update. The way this was corrected was to add this new control frame subclass. Now, we queue an AST_CONTROL_READ_ACTION frame on the channel on which the connected line interception macro should be run. When ast_read is called to read the frame, ast_read responds by calling a callback function associated with the specific read action the control frame describes. In this case, the action taken is to run the connected line interception macro on the transferee's channel. Review: https://reviewboard.asterisk.org/r/652/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@263541 f38db490-d61c-443f-a65b-d21fe96a405b
2010-05-17 15:36:31 +00:00
if (isoutbound) {
ast_callerid restructuring The purpose of this patch is to eliminate struct ast_callerid since it has turned into a miscellaneous collection of various party information. Eliminate struct ast_callerid and replace it with the following struct organization: struct ast_party_name { char *str; int char_set; int presentation; unsigned char valid; }; struct ast_party_number { char *str; int plan; int presentation; unsigned char valid; }; struct ast_party_subaddress { char *str; int type; unsigned char odd_even_indicator; unsigned char valid; }; struct ast_party_id { struct ast_party_name name; struct ast_party_number number; struct ast_party_subaddress subaddress; char *tag; }; struct ast_party_dialed { struct { char *str; int plan; } number; struct ast_party_subaddress subaddress; int transit_network_select; }; struct ast_party_caller { struct ast_party_id id; char *ani; int ani2; }; The new organization adds some new information as well. * The party name and number now have their own presentation value that can be manipulated independently. ISDN supplies the presentation value for the name and number at different times with the possibility that they could be different. * The party name and number now have a valid flag. Before this change the name or number string could be empty if the presentation were restricted. Most channel drivers assume that the name or number is then simply not available instead of indicating that the name or number was restricted. * The party name now has a character set value. SIP and Q.SIG have the ability to indicate what character set a name string is using so it could be presented properly. * The dialed party now has a numbering plan value that could be useful to have available. The various channel drivers will need to be updated to support the new core features as needed. They have simply been converted to supply current functionality at this time. The following items of note were either corrected or enhanced: * The CONNECTEDLINE() and REDIRECTING() dialplan functions were consolidated into func_callerid.c to share party id handling code. * CALLERPRES() is now deprecated because the name and number have their own presentation values. * Fixed app_alarmreceiver.c write_metadata(). The workstring[] could contain garbage. It also can only contain the caller id number so using ast_callerid_parse() on it is silly. There was also a typo in the CALLERNAME if test. * Fixed app_rpt.c using ast_callerid_parse() on the channel's caller id number string. ast_callerid_parse() alters the given buffer which in this case is the channel's caller id number string. Then using ast_shrink_phone_number() could alter it even more. * Fixed caller ID name and number memory leak in chan_usbradio.c. * Fixed uninitialized char arrays cid_num[] and cid_name[] in sig_analog.c. * Protected access to a caller channel with lock in chan_sip.c. * Clarified intent of code in app_meetme.c sla_ring_station() and dial_trunk(). Also made save all caller ID data instead of just the name and number strings. * Simplified cdr.c set_one_cid(). It hand coded the ast_callerid_merge() function. * Corrected some weirdness with app_privacy.c's use of caller presentation. Review: https://reviewboard.asterisk.org/r/702/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@276347 f38db490-d61c-443f-a65b-d21fe96a405b
2010-07-14 15:48:36 +00:00
ast_connected_line_copy_to_caller(&the_other_channel->caller, &this_channel->connected);
Enhancements to connected line and redirecting work. From reviewboard: Digium has a commercial customer who has made extensive use of the connected party and redirecting information present in later versions of Asterisk Business Edition and which is to be in the upcoming 1.8 release. Through their use of the feature, new problems and solutions have come about. This patch adds several enhancements to maximize usage of the connected party and redirecting information functionality. First, Asterisk trunk already had connected line interception macros. These macros allow you to manipulate connected line information before it was sent out to its target. This patch adds the same feature except for redirecting information instead. Second, the ast_callerid and ast_party_id structures have been enhanced to provide a "tag." This tag can be set with func_callerid, func_connectedline, func_redirecting, and in the case of DAHDI, mISDN, and SIP channels, can be set in a configuration file. The idea behind the callerid tag is that it can be set to whatever value the administrator likes. Later, when running connected line and redirecting macros, the admin can read the tag off the appropriate structure to determine what action to take. You can think of this sort of like a channel variable, except that instead of having the variable associated with a channel, the variable is associated with a specific identity within Asterisk. Third, app_dial has two new options, s and u. The s option lets a dialplan writer force a specific caller ID tag to be placed on the outgoing channel. The u option allows the dialplan writer to force a specific calling presentation value on the outgoing channel. Fourth, there is a new control frame subclass called AST_CONTROL_READ_ACTION added. This was added to correct a very specific situation. In the case of SIP semi-attended (blond) transfers, the party being transferred would not have the opportunity to run a connected line interception macro to possibly alter the transfer target's connected line information. The issue here was that during a blond transfer, the SIP transfer code has no bridged channel on which to queue the connected line update. The way this was corrected was to add this new control frame subclass. Now, we queue an AST_CONTROL_READ_ACTION frame on the channel on which the connected line interception macro should be run. When ast_read is called to read the frame, ast_read responds by calling a callback function associated with the specific read action the control frame describes. In this case, the action taken is to run the connected line interception macro on the transferee's channel. Review: https://reviewboard.asterisk.org/r/652/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@263541 f38db490-d61c-443f-a65b-d21fe96a405b
2010-05-17 15:36:31 +00:00
}
ast_callerid restructuring The purpose of this patch is to eliminate struct ast_callerid since it has turned into a miscellaneous collection of various party information. Eliminate struct ast_callerid and replace it with the following struct organization: struct ast_party_name { char *str; int char_set; int presentation; unsigned char valid; }; struct ast_party_number { char *str; int plan; int presentation; unsigned char valid; }; struct ast_party_subaddress { char *str; int type; unsigned char odd_even_indicator; unsigned char valid; }; struct ast_party_id { struct ast_party_name name; struct ast_party_number number; struct ast_party_subaddress subaddress; char *tag; }; struct ast_party_dialed { struct { char *str; int plan; } number; struct ast_party_subaddress subaddress; int transit_network_select; }; struct ast_party_caller { struct ast_party_id id; char *ani; int ani2; }; The new organization adds some new information as well. * The party name and number now have their own presentation value that can be manipulated independently. ISDN supplies the presentation value for the name and number at different times with the possibility that they could be different. * The party name and number now have a valid flag. Before this change the name or number string could be empty if the presentation were restricted. Most channel drivers assume that the name or number is then simply not available instead of indicating that the name or number was restricted. * The party name now has a character set value. SIP and Q.SIG have the ability to indicate what character set a name string is using so it could be presented properly. * The dialed party now has a numbering plan value that could be useful to have available. The various channel drivers will need to be updated to support the new core features as needed. They have simply been converted to supply current functionality at this time. The following items of note were either corrected or enhanced: * The CONNECTEDLINE() and REDIRECTING() dialplan functions were consolidated into func_callerid.c to share party id handling code. * CALLERPRES() is now deprecated because the name and number have their own presentation values. * Fixed app_alarmreceiver.c write_metadata(). The workstring[] could contain garbage. It also can only contain the caller id number so using ast_callerid_parse() on it is silly. There was also a typo in the CALLERNAME if test. * Fixed app_rpt.c using ast_callerid_parse() on the channel's caller id number string. ast_callerid_parse() alters the given buffer which in this case is the channel's caller id number string. Then using ast_shrink_phone_number() could alter it even more. * Fixed caller ID name and number memory leak in chan_usbradio.c. * Fixed uninitialized char arrays cid_num[] and cid_name[] in sig_analog.c. * Protected access to a caller channel with lock in chan_sip.c. * Clarified intent of code in app_meetme.c sla_ring_station() and dial_trunk(). Also made save all caller ID data instead of just the name and number strings. * Simplified cdr.c set_one_cid(). It hand coded the ast_callerid_merge() function. * Corrected some weirdness with app_privacy.c's use of caller presentation. Review: https://reviewboard.asterisk.org/r/702/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@276347 f38db490-d61c-443f-a65b-d21fe96a405b
2010-07-14 15:48:36 +00:00
f.datalen = ast_connected_line_build_data(frame_data, sizeof(frame_data), &this_channel->connected, NULL);
} else {
ast_callerid restructuring The purpose of this patch is to eliminate struct ast_callerid since it has turned into a miscellaneous collection of various party information. Eliminate struct ast_callerid and replace it with the following struct organization: struct ast_party_name { char *str; int char_set; int presentation; unsigned char valid; }; struct ast_party_number { char *str; int plan; int presentation; unsigned char valid; }; struct ast_party_subaddress { char *str; int type; unsigned char odd_even_indicator; unsigned char valid; }; struct ast_party_id { struct ast_party_name name; struct ast_party_number number; struct ast_party_subaddress subaddress; char *tag; }; struct ast_party_dialed { struct { char *str; int plan; } number; struct ast_party_subaddress subaddress; int transit_network_select; }; struct ast_party_caller { struct ast_party_id id; char *ani; int ani2; }; The new organization adds some new information as well. * The party name and number now have their own presentation value that can be manipulated independently. ISDN supplies the presentation value for the name and number at different times with the possibility that they could be different. * The party name and number now have a valid flag. Before this change the name or number string could be empty if the presentation were restricted. Most channel drivers assume that the name or number is then simply not available instead of indicating that the name or number was restricted. * The party name now has a character set value. SIP and Q.SIG have the ability to indicate what character set a name string is using so it could be presented properly. * The dialed party now has a numbering plan value that could be useful to have available. The various channel drivers will need to be updated to support the new core features as needed. They have simply been converted to supply current functionality at this time. The following items of note were either corrected or enhanced: * The CONNECTEDLINE() and REDIRECTING() dialplan functions were consolidated into func_callerid.c to share party id handling code. * CALLERPRES() is now deprecated because the name and number have their own presentation values. * Fixed app_alarmreceiver.c write_metadata(). The workstring[] could contain garbage. It also can only contain the caller id number so using ast_callerid_parse() on it is silly. There was also a typo in the CALLERNAME if test. * Fixed app_rpt.c using ast_callerid_parse() on the channel's caller id number string. ast_callerid_parse() alters the given buffer which in this case is the channel's caller id number string. Then using ast_shrink_phone_number() could alter it even more. * Fixed caller ID name and number memory leak in chan_usbradio.c. * Fixed uninitialized char arrays cid_num[] and cid_name[] in sig_analog.c. * Protected access to a caller channel with lock in chan_sip.c. * Clarified intent of code in app_meetme.c sla_ring_station() and dial_trunk(). Also made save all caller ID data instead of just the name and number strings. * Simplified cdr.c set_one_cid(). It hand coded the ast_callerid_merge() function. * Corrected some weirdness with app_privacy.c's use of caller presentation. Review: https://reviewboard.asterisk.org/r/702/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@276347 f38db490-d61c-443f-a65b-d21fe96a405b
2010-07-14 15:48:36 +00:00
f.datalen = ast_redirecting_build_data(frame_data, sizeof(frame_data), &this_channel->redirecting, NULL);
}
f.subclass.integer = condition;
f.data.ptr = frame_data;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
res = local_queue_frame(p, isoutbound, &f, ast, 1);
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
} else {
/* Queue up a frame representing the indication as a control frame */
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_lock(p);
isoutbound = IS_OUTBOUND(ast, p);
f.subclass.integer = condition;
f.data.ptr = (void*)data;
f.datalen = datalen;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
res = local_queue_frame(p, isoutbound, &f, ast, 1);
ao2_unlock(p);
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_ref(p, -1);
return res;
}
static int local_digit_begin(struct ast_channel *ast, char digit)
{
struct local_pvt *p = ast->tech_pvt;
int res = -1;
struct ast_frame f = { AST_FRAME_DTMF_BEGIN, };
int isoutbound;
if (!p)
return -1;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_ref(p, 1); /* ref for local_queue_frame */
ao2_lock(p);
isoutbound = IS_OUTBOUND(ast, p);
f.subclass.integer = digit;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
res = local_queue_frame(p, isoutbound, &f, ast, 0);
ao2_unlock(p);
ao2_ref(p, -1);
return res;
}
2007-01-19 18:06:03 +00:00
static int local_digit_end(struct ast_channel *ast, char digit, unsigned int duration)
{
struct local_pvt *p = ast->tech_pvt;
int res = -1;
struct ast_frame f = { AST_FRAME_DTMF_END, };
int isoutbound;
if (!p)
return -1;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_ref(p, 1); /* ref for local_queue_frame */
ao2_lock(p);
isoutbound = IS_OUTBOUND(ast, p);
f.subclass.integer = digit;
2007-01-19 18:06:03 +00:00
f.len = duration;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
res = local_queue_frame(p, isoutbound, &f, ast, 0);
ao2_unlock(p);
ao2_ref(p, -1);
return res;
}
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;
if (!p)
return -1;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_lock(p);
ao2_ref(p, 1); /* ref for local_queue_frame */
isoutbound = IS_OUTBOUND(ast, p);
f.data.ptr = (char *) text;
f.datalen = strlen(text) + 1;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
res = local_queue_frame(p, isoutbound, &f, ast, 0);
ao2_unlock(p);
ao2_ref(p, -1);
return res;
}
static int local_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen)
{
struct local_pvt *p = ast->tech_pvt;
int res = -1;
struct ast_frame f = { AST_FRAME_HTML, };
int isoutbound;
if (!p)
return -1;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_lock(p);
ao2_ref(p, 1); /* ref for local_queue_frame */
isoutbound = IS_OUTBOUND(ast, p);
f.subclass.integer = subclass;
f.data.ptr = (char *)data;
f.datalen = datalen;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
res = local_queue_frame(p, isoutbound, &f, ast, 0);
ao2_unlock(p);
ao2_ref(p, -1);
return res;
}
/*! \brief Initiate new call, part of PBX interface
* dest is the dial string */
static int local_call(struct ast_channel *ast, char *dest, int timeout)
{
struct local_pvt *p = ast->tech_pvt;
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: http://svn.digium.com/svn/asterisk/trunk@7276 f38db490-d61c-443f-a65b-d21fe96a405b
2005-12-02 01:01:11 +00:00
struct ast_var_t *varptr = NULL, *new;
size_t len, namelen;
Merge Call completion support into trunk. From Reviewboard: CCSS stands for Call Completion Supplementary Services. An admittedly out-of-date overview of the architecture can be found in the file doc/CCSS_architecture.pdf in the CCSS branch. Off the top of my head, the big differences between what is implemented and what is in the document are as follows: 1. We did not end up modifying the Hangup application at all. 2. The document states that a single call completion monitor may be used across multiple calls to the same device. This proved to not be such a good idea when implementing protocol-specific monitors, and so we ended up using one monitor per-device per-call. 3. There are some configuration options which were conceived after the document was written. These are documented in the ccss.conf.sample that is on this review request. For some basic understanding of terminology used throughout this code, see the ccss.tex document that is on this review. This implements CCBS and CCNR in several flavors. First up is a "generic" implementation, which can work over any channel technology provided that the channel technology can accurately report device state. Call completion is requested using the dialplan application CallCompletionRequest and can be canceled using CallCompletionCancel. Device state subscriptions are used in order to monitor the state of called parties. Next, there is a SIP-specific implementation of call completion. This method uses the methods outlined in draft-ietf-bliss-call-completion-06 to implement call completion using SIP signaling. There are a few things to note here: * The agent/monitor terminology used throughout Asterisk sometimes is the reverse of what is defined in the referenced draft. * Implementation of the draft required support for SIP PUBLISH. I attempted to write this in a generic-enough fashion such that if someone were to want to write PUBLISH support for other event packages, such as dialog-state or presence, most of the effort would be in writing callbacks specific to the event package. * A subportion of supporting PUBLISH reception was that we had to implement a PIDF parser. The PIDF support added is a bit minimal. I first wrote a validation routine to ensure that the PIDF document is formatted properly. The rest of the PIDF reading is done in-line in the call-completion-specific PUBLISH-handling code. In other words, while there is PIDF support here, it is not in any state where it could easily be applied to other event packages as is. Finally, there are a variety of ISDN-related call completion protocols supported. These were written by Richard Mudgett, and as such I can't really say much about their implementation. There are notes in the CHANGES file that indicate the ISDN protocols over which call completion is supported. Review: https://reviewboard.asterisk.org/r/523 git-svn-id: http://svn.digium.com/svn/asterisk/trunk@256528 f38db490-d61c-443f-a65b-d21fe96a405b
2010-04-09 15:31:32 +00:00
char *reduced_dest = ast_strdupa(dest);
char *slash;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
if (!p || p->owner != ast) {
return -1;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
}
/* since we are letting go of channel locks that were locked coming into
* this function, then we need to give the tech pvt a ref */
ao2_ref(p, 1);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
while (ao2_trylock(p)) {
ast_channel_unlock(ast);
sched_yield();
ast_channel_lock(ast);
}
while ((p->chan && p->owner) && ast_channel_trylock(p->chan)) {
ao2_unlock(p);
if (p->owner) {
ast_channel_unlock(p->owner);
}
sched_yield();
if (p->owner) {
ast_channel_lock(p->owner);
}
ao2_lock(p);
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
if (!p->owner || !p->chan) {
/* someone went away during the locking madness.
* time to bail. */
if (p->chan) {
ast_channel_unlock(p->chan);
}
ao2_unlock(p);
ao2_ref(p,-1);
return -1;
}
/*
* Note that cid_num and cid_name aren't passed in the ast_channel_alloc
* call, so it's done here instead.
*
* All these failure points just return -1. The individual strings will
* be cleared when we destroy the channel.
*/
ast_party_redirecting_copy(&p->chan->redirecting, &p->owner->redirecting);
ast_callerid restructuring The purpose of this patch is to eliminate struct ast_callerid since it has turned into a miscellaneous collection of various party information. Eliminate struct ast_callerid and replace it with the following struct organization: struct ast_party_name { char *str; int char_set; int presentation; unsigned char valid; }; struct ast_party_number { char *str; int plan; int presentation; unsigned char valid; }; struct ast_party_subaddress { char *str; int type; unsigned char odd_even_indicator; unsigned char valid; }; struct ast_party_id { struct ast_party_name name; struct ast_party_number number; struct ast_party_subaddress subaddress; char *tag; }; struct ast_party_dialed { struct { char *str; int plan; } number; struct ast_party_subaddress subaddress; int transit_network_select; }; struct ast_party_caller { struct ast_party_id id; char *ani; int ani2; }; The new organization adds some new information as well. * The party name and number now have their own presentation value that can be manipulated independently. ISDN supplies the presentation value for the name and number at different times with the possibility that they could be different. * The party name and number now have a valid flag. Before this change the name or number string could be empty if the presentation were restricted. Most channel drivers assume that the name or number is then simply not available instead of indicating that the name or number was restricted. * The party name now has a character set value. SIP and Q.SIG have the ability to indicate what character set a name string is using so it could be presented properly. * The dialed party now has a numbering plan value that could be useful to have available. The various channel drivers will need to be updated to support the new core features as needed. They have simply been converted to supply current functionality at this time. The following items of note were either corrected or enhanced: * The CONNECTEDLINE() and REDIRECTING() dialplan functions were consolidated into func_callerid.c to share party id handling code. * CALLERPRES() is now deprecated because the name and number have their own presentation values. * Fixed app_alarmreceiver.c write_metadata(). The workstring[] could contain garbage. It also can only contain the caller id number so using ast_callerid_parse() on it is silly. There was also a typo in the CALLERNAME if test. * Fixed app_rpt.c using ast_callerid_parse() on the channel's caller id number string. ast_callerid_parse() alters the given buffer which in this case is the channel's caller id number string. Then using ast_shrink_phone_number() could alter it even more. * Fixed caller ID name and number memory leak in chan_usbradio.c. * Fixed uninitialized char arrays cid_num[] and cid_name[] in sig_analog.c. * Protected access to a caller channel with lock in chan_sip.c. * Clarified intent of code in app_meetme.c sla_ring_station() and dial_trunk(). Also made save all caller ID data instead of just the name and number strings. * Simplified cdr.c set_one_cid(). It hand coded the ast_callerid_merge() function. * Corrected some weirdness with app_privacy.c's use of caller presentation. Review: https://reviewboard.asterisk.org/r/702/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@276347 f38db490-d61c-443f-a65b-d21fe96a405b
2010-07-14 15:48:36 +00:00
ast_party_dialed_copy(&p->chan->dialed, &p->owner->dialed);
ast_callerid restructuring The purpose of this patch is to eliminate struct ast_callerid since it has turned into a miscellaneous collection of various party information. Eliminate struct ast_callerid and replace it with the following struct organization: struct ast_party_name { char *str; int char_set; int presentation; unsigned char valid; }; struct ast_party_number { char *str; int plan; int presentation; unsigned char valid; }; struct ast_party_subaddress { char *str; int type; unsigned char odd_even_indicator; unsigned char valid; }; struct ast_party_id { struct ast_party_name name; struct ast_party_number number; struct ast_party_subaddress subaddress; char *tag; }; struct ast_party_dialed { struct { char *str; int plan; } number; struct ast_party_subaddress subaddress; int transit_network_select; }; struct ast_party_caller { struct ast_party_id id; char *ani; int ani2; }; The new organization adds some new information as well. * The party name and number now have their own presentation value that can be manipulated independently. ISDN supplies the presentation value for the name and number at different times with the possibility that they could be different. * The party name and number now have a valid flag. Before this change the name or number string could be empty if the presentation were restricted. Most channel drivers assume that the name or number is then simply not available instead of indicating that the name or number was restricted. * The party name now has a character set value. SIP and Q.SIG have the ability to indicate what character set a name string is using so it could be presented properly. * The dialed party now has a numbering plan value that could be useful to have available. The various channel drivers will need to be updated to support the new core features as needed. They have simply been converted to supply current functionality at this time. The following items of note were either corrected or enhanced: * The CONNECTEDLINE() and REDIRECTING() dialplan functions were consolidated into func_callerid.c to share party id handling code. * CALLERPRES() is now deprecated because the name and number have their own presentation values. * Fixed app_alarmreceiver.c write_metadata(). The workstring[] could contain garbage. It also can only contain the caller id number so using ast_callerid_parse() on it is silly. There was also a typo in the CALLERNAME if test. * Fixed app_rpt.c using ast_callerid_parse() on the channel's caller id number string. ast_callerid_parse() alters the given buffer which in this case is the channel's caller id number string. Then using ast_shrink_phone_number() could alter it even more. * Fixed caller ID name and number memory leak in chan_usbradio.c. * Fixed uninitialized char arrays cid_num[] and cid_name[] in sig_analog.c. * Protected access to a caller channel with lock in chan_sip.c. * Clarified intent of code in app_meetme.c sla_ring_station() and dial_trunk(). Also made save all caller ID data instead of just the name and number strings. * Simplified cdr.c set_one_cid(). It hand coded the ast_callerid_merge() function. * Corrected some weirdness with app_privacy.c's use of caller presentation. Review: https://reviewboard.asterisk.org/r/702/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@276347 f38db490-d61c-443f-a65b-d21fe96a405b
2010-07-14 15:48:36 +00:00
ast_connected_line_copy_to_caller(&p->chan->caller, &p->owner->connected);
ast_connected_line_copy_from_caller(&p->chan->connected, &p->owner->caller);
ast_string_field_set(p->chan, language, p->owner->language);
ast_string_field_set(p->chan, accountcode, p->owner->accountcode);
ast_string_field_set(p->chan, musicclass, p->owner->musicclass);
ast_cdr_update(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: http://svn.digium.com/svn/asterisk/trunk@7276 f38db490-d61c-443f-a65b-d21fe96a405b
2005-12-02 01:01:11 +00:00
Merge Call completion support into trunk. From Reviewboard: CCSS stands for Call Completion Supplementary Services. An admittedly out-of-date overview of the architecture can be found in the file doc/CCSS_architecture.pdf in the CCSS branch. Off the top of my head, the big differences between what is implemented and what is in the document are as follows: 1. We did not end up modifying the Hangup application at all. 2. The document states that a single call completion monitor may be used across multiple calls to the same device. This proved to not be such a good idea when implementing protocol-specific monitors, and so we ended up using one monitor per-device per-call. 3. There are some configuration options which were conceived after the document was written. These are documented in the ccss.conf.sample that is on this review request. For some basic understanding of terminology used throughout this code, see the ccss.tex document that is on this review. This implements CCBS and CCNR in several flavors. First up is a "generic" implementation, which can work over any channel technology provided that the channel technology can accurately report device state. Call completion is requested using the dialplan application CallCompletionRequest and can be canceled using CallCompletionCancel. Device state subscriptions are used in order to monitor the state of called parties. Next, there is a SIP-specific implementation of call completion. This method uses the methods outlined in draft-ietf-bliss-call-completion-06 to implement call completion using SIP signaling. There are a few things to note here: * The agent/monitor terminology used throughout Asterisk sometimes is the reverse of what is defined in the referenced draft. * Implementation of the draft required support for SIP PUBLISH. I attempted to write this in a generic-enough fashion such that if someone were to want to write PUBLISH support for other event packages, such as dialog-state or presence, most of the effort would be in writing callbacks specific to the event package. * A subportion of supporting PUBLISH reception was that we had to implement a PIDF parser. The PIDF support added is a bit minimal. I first wrote a validation routine to ensure that the PIDF document is formatted properly. The rest of the PIDF reading is done in-line in the call-completion-specific PUBLISH-handling code. In other words, while there is PIDF support here, it is not in any state where it could easily be applied to other event packages as is. Finally, there are a variety of ISDN-related call completion protocols supported. These were written by Richard Mudgett, and as such I can't really say much about their implementation. There are notes in the CHANGES file that indicate the ISDN protocols over which call completion is supported. Review: https://reviewboard.asterisk.org/r/523 git-svn-id: http://svn.digium.com/svn/asterisk/trunk@256528 f38db490-d61c-443f-a65b-d21fe96a405b
2010-04-09 15:31:32 +00:00
ast_channel_cc_params_init(p->chan, ast_channel_get_cc_config_params(p->owner));
/* Make sure we inherit the ANSWERED_ELSEWHERE flag if it's set on the queue/dial call request in the dialplan */
if (ast_test_flag(ast, AST_FLAG_ANSWERED_ELSEWHERE)) {
ast_set_flag(p->chan, AST_FLAG_ANSWERED_ELSEWHERE);
}
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: http://svn.digium.com/svn/asterisk/trunk@7276 f38db490-d61c-443f-a65b-d21fe96a405b
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;
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: http://svn.digium.com/svn/asterisk/trunk@7276 f38db490-d61c-443f-a65b-d21fe96a405b
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: http://svn.digium.com/svn/asterisk/trunk@90873 f38db490-d61c-443f-a65b-d21fe96a405b
2007-12-04 17:08:36 +00:00
ast_channel_datastore_inherit(p->owner, p->chan);
Merge Call completion support into trunk. From Reviewboard: CCSS stands for Call Completion Supplementary Services. An admittedly out-of-date overview of the architecture can be found in the file doc/CCSS_architecture.pdf in the CCSS branch. Off the top of my head, the big differences between what is implemented and what is in the document are as follows: 1. We did not end up modifying the Hangup application at all. 2. The document states that a single call completion monitor may be used across multiple calls to the same device. This proved to not be such a good idea when implementing protocol-specific monitors, and so we ended up using one monitor per-device per-call. 3. There are some configuration options which were conceived after the document was written. These are documented in the ccss.conf.sample that is on this review request. For some basic understanding of terminology used throughout this code, see the ccss.tex document that is on this review. This implements CCBS and CCNR in several flavors. First up is a "generic" implementation, which can work over any channel technology provided that the channel technology can accurately report device state. Call completion is requested using the dialplan application CallCompletionRequest and can be canceled using CallCompletionCancel. Device state subscriptions are used in order to monitor the state of called parties. Next, there is a SIP-specific implementation of call completion. This method uses the methods outlined in draft-ietf-bliss-call-completion-06 to implement call completion using SIP signaling. There are a few things to note here: * The agent/monitor terminology used throughout Asterisk sometimes is the reverse of what is defined in the referenced draft. * Implementation of the draft required support for SIP PUBLISH. I attempted to write this in a generic-enough fashion such that if someone were to want to write PUBLISH support for other event packages, such as dialog-state or presence, most of the effort would be in writing callbacks specific to the event package. * A subportion of supporting PUBLISH reception was that we had to implement a PIDF parser. The PIDF support added is a bit minimal. I first wrote a validation routine to ensure that the PIDF document is formatted properly. The rest of the PIDF reading is done in-line in the call-completion-specific PUBLISH-handling code. In other words, while there is PIDF support here, it is not in any state where it could easily be applied to other event packages as is. Finally, there are a variety of ISDN-related call completion protocols supported. These were written by Richard Mudgett, and as such I can't really say much about their implementation. There are notes in the CHANGES file that indicate the ISDN protocols over which call completion is supported. Review: https://reviewboard.asterisk.org/r/523 git-svn-id: http://svn.digium.com/svn/asterisk/trunk@256528 f38db490-d61c-443f-a65b-d21fe96a405b
2010-04-09 15:31:32 +00:00
/* If the local channel has /n or /b on the end of it,
* we need to lop that off for our argument to setting
* up the CC_INTERFACES variable
*/
if ((slash = strrchr(reduced_dest, '/'))) {
*slash = '\0';
}
ast_set_cc_interfaces_chanvar(p->chan, reduced_dest);
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: http://svn.digium.com/svn/asterisk/trunk@7276 f38db490-d61c-443f-a65b-d21fe96a405b
2005-12-02 01:01:11 +00:00
if (!ast_exists_extension(p->chan, p->chan->context, p->chan->exten, 1,
S_COR(p->owner->caller.id.number.valid, p->owner->caller.id.number.str, NULL))) {
ast_log(LOG_NOTICE, "No such extension/context %s@%s while calling Local channel\n", p->chan->exten, p->chan->context);
ao2_unlock(p);
ast_channel_unlock(p->chan);
ao2_ref(p, -1);
return -1;
}
/* Start switch on sub channel */
if (!(res = ast_pbx_start(p->chan)))
ast_set_flag(p, LOCAL_LAUNCHED_PBX);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
ast_channel_unlock(p->chan);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_ref(p, -1);
return res;
}
/*! \brief Hangup a call through the local proxy channel */
static int local_hangup(struct ast_channel *ast)
{
struct local_pvt *p = ast->tech_pvt;
int isoutbound;
struct ast_frame f = { AST_FRAME_CONTROL, { AST_CONTROL_HANGUP }, .data.uint32 = ast->hangupcause };
struct ast_channel *ochan = NULL;
if (!p)
return -1;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
/* we MUST give the tech_pvt a ref here since we are unlocking the
* channel during deadlock avoidance. */
ao2_ref(p, 1);
ao2_lock(p);
isoutbound = IS_OUTBOUND(ast, p);
if (p->chan && ast_test_flag(ast, AST_FLAG_ANSWERED_ELSEWHERE)) {
ast_set_flag(p->chan, AST_FLAG_ANSWERED_ELSEWHERE);
ast_debug(2, "This local call has the ANSWERED_ELSEWHERE flag set.\n");
}
if (isoutbound) {
const char *status = pbx_builtin_getvar_helper(p->chan, "DIALSTATUS");
if ((status) && (p->owner)) {
/* Deadlock avoidance */
while (p->owner && ast_channel_trylock(p->owner)) {
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
Merged revisions 259858 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r259858 | dvossel | 2010-04-28 16:16:03 -0500 (Wed, 28 Apr 2010) | 33 lines resolves deadlocks in chan_local Issue_1. In the local_hangup() 3 locks must be held at the same time... pvt, pvt->chan, and pvt->owner. Proper deadlock avoidance is done when the channel to hangup is the outbound chan_local channel, but when it is not the outbound channel we have an issue... We attempt to do deadlock avoidance only on the tech pvt, when both the tech pvt and the pvt->owner are locked coming into that loop. By never giving up the pvt->owner channel deadlock avoidance is not entirely possible. This patch resolves that by doing deadlock avoidance on both the pvt->owner and the pvt when trying to get the pvt->chan lock. Issue_2. ast_prod() is used in ast_activate_generator() to queue a frame on the channel and make the channel's read function get called. This function is used in ast_activate_generator() while the channel is locked, which mean's the channel will have a lock both from the generator code and the frame_queue code by the time it gets to chan_local.c's local_queue_frame code... local_queue_frame contains some of the same crazy deadlock avoidance that local_hangup requires, and this recursive lock prevents that deadlock avoidance from happening correctly. This patch removes ast_prod() from the channel lock so only one lock is held during the local_queue_frame function. (closes issue #17185) Reported by: schmoozecom Patches: issue_17185_v1.diff uploaded by dvossel (license 671) issue_17185_v2.diff uploaded by dvossel (license 671) Tested by: schmoozecom, GameGamer43 Review: https://reviewboard.asterisk.org/r/631/ ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@259870 f38db490-d61c-443f-a65b-d21fe96a405b
2010-04-28 21:20:03 +00:00
if (p->chan) {
ast_channel_unlock(p->chan);
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
sched_yield();
Merged revisions 259858 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r259858 | dvossel | 2010-04-28 16:16:03 -0500 (Wed, 28 Apr 2010) | 33 lines resolves deadlocks in chan_local Issue_1. In the local_hangup() 3 locks must be held at the same time... pvt, pvt->chan, and pvt->owner. Proper deadlock avoidance is done when the channel to hangup is the outbound chan_local channel, but when it is not the outbound channel we have an issue... We attempt to do deadlock avoidance only on the tech pvt, when both the tech pvt and the pvt->owner are locked coming into that loop. By never giving up the pvt->owner channel deadlock avoidance is not entirely possible. This patch resolves that by doing deadlock avoidance on both the pvt->owner and the pvt when trying to get the pvt->chan lock. Issue_2. ast_prod() is used in ast_activate_generator() to queue a frame on the channel and make the channel's read function get called. This function is used in ast_activate_generator() while the channel is locked, which mean's the channel will have a lock both from the generator code and the frame_queue code by the time it gets to chan_local.c's local_queue_frame code... local_queue_frame contains some of the same crazy deadlock avoidance that local_hangup requires, and this recursive lock prevents that deadlock avoidance from happening correctly. This patch removes ast_prod() from the channel lock so only one lock is held during the local_queue_frame function. (closes issue #17185) Reported by: schmoozecom Patches: issue_17185_v1.diff uploaded by dvossel (license 671) issue_17185_v2.diff uploaded by dvossel (license 671) Tested by: schmoozecom, GameGamer43 Review: https://reviewboard.asterisk.org/r/631/ ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@259870 f38db490-d61c-443f-a65b-d21fe96a405b
2010-04-28 21:20:03 +00:00
if (p->chan) {
ast_channel_lock(p->chan);
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_lock(p);
}
if (p->owner) {
pbx_builtin_setvar_helper(p->owner, "CHANLOCALSTATUS", status);
ast_channel_unlock(p->owner);
}
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
if (!p->chan) {
/* chan was == to ast and was !NULL before deadlock avoidance started, if chan
* is NULL now, then we should bail because that channel
* hungup already. This is possible because we let go of the
* lock given to the ast channel passed to this function during
* deadlock avoidance. */
ao2_unlock(p);
ao2_ref(p, -1);
return 0;
}
p->chan = NULL;
ast_clear_flag(p, LOCAL_LAUNCHED_PBX);
ast_module_user_remove(p->u_chan);
} else {
ast_module_user_remove(p->u_owner);
while (p->chan && ast_channel_trylock(p->chan)) {
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
Merged revisions 259858 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r259858 | dvossel | 2010-04-28 16:16:03 -0500 (Wed, 28 Apr 2010) | 33 lines resolves deadlocks in chan_local Issue_1. In the local_hangup() 3 locks must be held at the same time... pvt, pvt->chan, and pvt->owner. Proper deadlock avoidance is done when the channel to hangup is the outbound chan_local channel, but when it is not the outbound channel we have an issue... We attempt to do deadlock avoidance only on the tech pvt, when both the tech pvt and the pvt->owner are locked coming into that loop. By never giving up the pvt->owner channel deadlock avoidance is not entirely possible. This patch resolves that by doing deadlock avoidance on both the pvt->owner and the pvt when trying to get the pvt->chan lock. Issue_2. ast_prod() is used in ast_activate_generator() to queue a frame on the channel and make the channel's read function get called. This function is used in ast_activate_generator() while the channel is locked, which mean's the channel will have a lock both from the generator code and the frame_queue code by the time it gets to chan_local.c's local_queue_frame code... local_queue_frame contains some of the same crazy deadlock avoidance that local_hangup requires, and this recursive lock prevents that deadlock avoidance from happening correctly. This patch removes ast_prod() from the channel lock so only one lock is held during the local_queue_frame function. (closes issue #17185) Reported by: schmoozecom Patches: issue_17185_v1.diff uploaded by dvossel (license 671) issue_17185_v2.diff uploaded by dvossel (license 671) Tested by: schmoozecom, GameGamer43 Review: https://reviewboard.asterisk.org/r/631/ ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@259870 f38db490-d61c-443f-a65b-d21fe96a405b
2010-04-28 21:20:03 +00:00
if (p->owner) {
ast_channel_unlock(p->owner);
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
sched_yield();
Merged revisions 259858 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r259858 | dvossel | 2010-04-28 16:16:03 -0500 (Wed, 28 Apr 2010) | 33 lines resolves deadlocks in chan_local Issue_1. In the local_hangup() 3 locks must be held at the same time... pvt, pvt->chan, and pvt->owner. Proper deadlock avoidance is done when the channel to hangup is the outbound chan_local channel, but when it is not the outbound channel we have an issue... We attempt to do deadlock avoidance only on the tech pvt, when both the tech pvt and the pvt->owner are locked coming into that loop. By never giving up the pvt->owner channel deadlock avoidance is not entirely possible. This patch resolves that by doing deadlock avoidance on both the pvt->owner and the pvt when trying to get the pvt->chan lock. Issue_2. ast_prod() is used in ast_activate_generator() to queue a frame on the channel and make the channel's read function get called. This function is used in ast_activate_generator() while the channel is locked, which mean's the channel will have a lock both from the generator code and the frame_queue code by the time it gets to chan_local.c's local_queue_frame code... local_queue_frame contains some of the same crazy deadlock avoidance that local_hangup requires, and this recursive lock prevents that deadlock avoidance from happening correctly. This patch removes ast_prod() from the channel lock so only one lock is held during the local_queue_frame function. (closes issue #17185) Reported by: schmoozecom Patches: issue_17185_v1.diff uploaded by dvossel (license 671) issue_17185_v2.diff uploaded by dvossel (license 671) Tested by: schmoozecom, GameGamer43 Review: https://reviewboard.asterisk.org/r/631/ ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@259870 f38db490-d61c-443f-a65b-d21fe96a405b
2010-04-28 21:20:03 +00:00
if (p->owner) {
ast_channel_lock(p->owner);
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_lock(p);
}
if (p->chan) {
ast_queue_hangup(p->chan);
ast_channel_unlock(p->chan);
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
if (!p->owner) {
/* owner was == to ast and was !NULL before deadlock avoidance started, if
* owner is NULL now, then we should bail because that channel
* hungup already. This is possible because we let go of the
* lock given to the ast channel passed to this function during
* deadlock avoidance. */
ao2_unlock(p);
ao2_ref(p, -1);
return 0;
}
p->owner = NULL;
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ast->tech_pvt = NULL;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
if (!p->owner && !p->chan) {
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(p);
/* Remove from list */
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlink(locals, p);
ao2_ref(p, -1);
return 0;
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
if (p->chan && !ast_test_flag(p, LOCAL_LAUNCHED_PBX)) {
/* Need to actually hangup since there is no PBX */
ochan = p->chan;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
} else {
local_queue_frame(p, isoutbound, &f, NULL, 1);
}
ao2_unlock(p);
if (ochan) {
ast_hangup(ochan);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
}
ao2_ref(p, -1);
return 0;
}
static void local_destroy(void *obj)
{
struct local_pvt *pvt = obj;
pvt->reqcap = ast_format_cap_destroy(pvt->reqcap);
}
/*! \brief Create a call structure */
static struct local_pvt *local_alloc(const char *data, struct ast_format_cap *cap)
{
struct local_pvt *tmp = NULL;
char *c = NULL, *opts = NULL;
if (!(tmp = ao2_alloc(sizeof(*tmp), local_destroy))) {
return NULL;
}
if (!(tmp->reqcap = ast_format_cap_dup(cap))) {
ao2_ref(tmp, -1);
return NULL;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
}
/* Initialize private structure information */
ast_copy_string(tmp->exten, data, sizeof(tmp->exten));
memcpy(&tmp->jb_conf, &g_jb_conf, sizeof(tmp->jb_conf));
/* Look for options */
if ((opts = strchr(tmp->exten, '/'))) {
*opts++ = '\0';
if (strchr(opts, 'n'))
ast_set_flag(tmp, LOCAL_NO_OPTIMIZATION);
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");
}
}
if (strchr(opts, 'b')) {
ast_set_flag(tmp, LOCAL_BRIDGE);
}
if (strchr(opts, 'm')) {
ast_set_flag(tmp, LOCAL_MOH_PASSTHRU);
}
}
/* Look for a context */
if ((c = strchr(tmp->exten, '@')))
*c++ = '\0';
ast_copy_string(tmp->context, c ? c : "default", sizeof(tmp->context));
#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). */
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);
tmp = local_pvt_destroy(tmp);
} else {
#endif
/* Add to list */
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_link(locals, tmp);
#if 0
}
#endif
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
return tmp; /* this is returned with a ref */
}
/*! \brief Start new local channel */
static struct ast_channel *local_new(struct local_pvt *p, int state, const char *linkedid)
{
struct ast_channel *tmp = NULL, *tmp2 = NULL;
int randnum = ast_random() & 0xffff;
struct ast_format fmt;
const char *t;
int ama;
/* Allocate two new Asterisk channels */
/* safe accountcode */
if (p->owner && p->owner->accountcode)
t = p->owner->accountcode;
else
t = "";
if (p->owner)
ama = p->owner->amaflags;
else
ama = 0;
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))
|| !(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))) {
Convert the ast_channel data structure over to the astobj2 framework. There is a lot that could be said about this, but the patch is a big improvement for performance, stability, code maintainability, and ease of future code development. The channel list is no longer an unsorted linked list. The main container for channels is an astobj2 hash table. All of the code related to searching for channels or iterating active channels has been rewritten. Let n be the number of active channels. Iterating the channel list has gone from O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1). Searching for a channel by extension is still O(n), but uses a new method for doing so, which is more efficient. The ast_channel object is now a reference counted object. The benefits here are plentiful. Some benefits directly related to issues in the previous code include: 1) When threads other than the channel thread owning a channel wanted access to a channel, it had to hold the lock on it to ensure that it didn't go away. This is no longer a requirement. Holding a reference is sufficient. 2) There are places that now require less dealing with channel locks. 3) There are places where channel locks are held for much shorter periods of time. 4) There are places where dealing with more than one channel at a time becomes _MUCH_ easier. ChanSpy is a great example of this. Writing code in the future that deals with multiple channels will be much easier. Some additional information regarding channel locking and reference count handling can be found in channel.h, where a new section has been added that discusses some of the rules associated with it. Mark Michelson also assisted with the development of this patch. He did the conversion of ChanSpy and introduced a new API, ast_autochan, which makes it much easier to deal with holding on to a channel pointer for an extended period of time and having it get automatically updated if the channel gets masqueraded. Mark was also a huge help in the code review process. Thanks to David Vossel for his assistance with this branch, as well. David did the conversion of the DAHDIScan application by making it become a wrapper for ChanSpy internally. The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch. Review: http://reviewboard.digium.com/r/203/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@190423 f38db490-d61c-443f-a65b-d21fe96a405b
2009-04-24 14:04:26 +00:00
if (tmp) {
tmp = ast_channel_release(tmp);
}
ast_log(LOG_WARNING, "Unable to allocate channel structure(s)\n");
return NULL;
Convert the ast_channel data structure over to the astobj2 framework. There is a lot that could be said about this, but the patch is a big improvement for performance, stability, code maintainability, and ease of future code development. The channel list is no longer an unsorted linked list. The main container for channels is an astobj2 hash table. All of the code related to searching for channels or iterating active channels has been rewritten. Let n be the number of active channels. Iterating the channel list has gone from O(n^2) to O(n). Searching for a channel by name went from O(n) to O(1). Searching for a channel by extension is still O(n), but uses a new method for doing so, which is more efficient. The ast_channel object is now a reference counted object. The benefits here are plentiful. Some benefits directly related to issues in the previous code include: 1) When threads other than the channel thread owning a channel wanted access to a channel, it had to hold the lock on it to ensure that it didn't go away. This is no longer a requirement. Holding a reference is sufficient. 2) There are places that now require less dealing with channel locks. 3) There are places where channel locks are held for much shorter periods of time. 4) There are places where dealing with more than one channel at a time becomes _MUCH_ easier. ChanSpy is a great example of this. Writing code in the future that deals with multiple channels will be much easier. Some additional information regarding channel locking and reference count handling can be found in channel.h, where a new section has been added that discusses some of the rules associated with it. Mark Michelson also assisted with the development of this patch. He did the conversion of ChanSpy and introduced a new API, ast_autochan, which makes it much easier to deal with holding on to a channel pointer for an extended period of time and having it get automatically updated if the channel gets masqueraded. Mark was also a huge help in the code review process. Thanks to David Vossel for his assistance with this branch, as well. David did the conversion of the DAHDIScan application by making it become a wrapper for ChanSpy internally. The changes come from the svn/asterisk/team/russell/ast_channel_ao2 branch. Review: http://reviewboard.digium.com/r/203/ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@190423 f38db490-d61c-443f-a65b-d21fe96a405b
2009-04-24 14:04:26 +00:00
}
tmp2->tech = tmp->tech = &local_tech;
ast_format_cap_copy(tmp->nativeformats, p->reqcap);
ast_format_cap_copy(tmp2->nativeformats, p->reqcap);
/* Determine our read/write format and set it on each channel */
ast_best_codec(p->reqcap, &fmt);
ast_format_copy(&tmp->writeformat, &fmt);
ast_format_copy(&tmp2->writeformat, &fmt);
ast_format_copy(&tmp->rawwriteformat, &fmt);
ast_format_copy(&tmp2->rawwriteformat, &fmt);
ast_format_copy(&tmp->readformat, &fmt);
ast_format_copy(&tmp2->readformat, &fmt);
ast_format_copy(&tmp->rawreadformat, &fmt);
ast_format_copy(&tmp2->rawreadformat, &fmt);
tmp->tech_pvt = p;
tmp2->tech_pvt = p;
p->owner = tmp;
p->chan = tmp2;
p->u_owner = ast_module_user_add(p->owner);
p->u_chan = ast_module_user_add(p->chan);
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;
ast_jb_configure(tmp, &p->jb_conf);
return tmp;
}
/*! \brief Part of PBX interface */
static struct ast_channel *local_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause)
{
struct local_pvt *p = NULL;
struct ast_channel *chan = NULL;
/* Allocate a new private structure and then Asterisk channel */
if ((p = local_alloc(data, cap))) {
if (!(chan = local_new(p, AST_STATE_DOWN, requestor ? requestor->linkedid : NULL))) {
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlink(locals, p);
}
if (chan && ast_channel_cc_params_init(chan, requestor ? ast_channel_get_cc_config_params((struct ast_channel *)requestor) : NULL)) {
Merge Call completion support into trunk. From Reviewboard: CCSS stands for Call Completion Supplementary Services. An admittedly out-of-date overview of the architecture can be found in the file doc/CCSS_architecture.pdf in the CCSS branch. Off the top of my head, the big differences between what is implemented and what is in the document are as follows: 1. We did not end up modifying the Hangup application at all. 2. The document states that a single call completion monitor may be used across multiple calls to the same device. This proved to not be such a good idea when implementing protocol-specific monitors, and so we ended up using one monitor per-device per-call. 3. There are some configuration options which were conceived after the document was written. These are documented in the ccss.conf.sample that is on this review request. For some basic understanding of terminology used throughout this code, see the ccss.tex document that is on this review. This implements CCBS and CCNR in several flavors. First up is a "generic" implementation, which can work over any channel technology provided that the channel technology can accurately report device state. Call completion is requested using the dialplan application CallCompletionRequest and can be canceled using CallCompletionCancel. Device state subscriptions are used in order to monitor the state of called parties. Next, there is a SIP-specific implementation of call completion. This method uses the methods outlined in draft-ietf-bliss-call-completion-06 to implement call completion using SIP signaling. There are a few things to note here: * The agent/monitor terminology used throughout Asterisk sometimes is the reverse of what is defined in the referenced draft. * Implementation of the draft required support for SIP PUBLISH. I attempted to write this in a generic-enough fashion such that if someone were to want to write PUBLISH support for other event packages, such as dialog-state or presence, most of the effort would be in writing callbacks specific to the event package. * A subportion of supporting PUBLISH reception was that we had to implement a PIDF parser. The PIDF support added is a bit minimal. I first wrote a validation routine to ensure that the PIDF document is formatted properly. The rest of the PIDF reading is done in-line in the call-completion-specific PUBLISH-handling code. In other words, while there is PIDF support here, it is not in any state where it could easily be applied to other event packages as is. Finally, there are a variety of ISDN-related call completion protocols supported. These were written by Richard Mudgett, and as such I can't really say much about their implementation. There are notes in the CHANGES file that indicate the ISDN protocols over which call completion is supported. Review: https://reviewboard.asterisk.org/r/523 git-svn-id: http://svn.digium.com/svn/asterisk/trunk@256528 f38db490-d61c-443f-a65b-d21fe96a405b
2010-04-09 15:31:32 +00:00
chan = ast_channel_release(chan);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlink(locals, p);
Merge Call completion support into trunk. From Reviewboard: CCSS stands for Call Completion Supplementary Services. An admittedly out-of-date overview of the architecture can be found in the file doc/CCSS_architecture.pdf in the CCSS branch. Off the top of my head, the big differences between what is implemented and what is in the document are as follows: 1. We did not end up modifying the Hangup application at all. 2. The document states that a single call completion monitor may be used across multiple calls to the same device. This proved to not be such a good idea when implementing protocol-specific monitors, and so we ended up using one monitor per-device per-call. 3. There are some configuration options which were conceived after the document was written. These are documented in the ccss.conf.sample that is on this review request. For some basic understanding of terminology used throughout this code, see the ccss.tex document that is on this review. This implements CCBS and CCNR in several flavors. First up is a "generic" implementation, which can work over any channel technology provided that the channel technology can accurately report device state. Call completion is requested using the dialplan application CallCompletionRequest and can be canceled using CallCompletionCancel. Device state subscriptions are used in order to monitor the state of called parties. Next, there is a SIP-specific implementation of call completion. This method uses the methods outlined in draft-ietf-bliss-call-completion-06 to implement call completion using SIP signaling. There are a few things to note here: * The agent/monitor terminology used throughout Asterisk sometimes is the reverse of what is defined in the referenced draft. * Implementation of the draft required support for SIP PUBLISH. I attempted to write this in a generic-enough fashion such that if someone were to want to write PUBLISH support for other event packages, such as dialog-state or presence, most of the effort would be in writing callbacks specific to the event package. * A subportion of supporting PUBLISH reception was that we had to implement a PIDF parser. The PIDF support added is a bit minimal. I first wrote a validation routine to ensure that the PIDF document is formatted properly. The rest of the PIDF reading is done in-line in the call-completion-specific PUBLISH-handling code. In other words, while there is PIDF support here, it is not in any state where it could easily be applied to other event packages as is. Finally, there are a variety of ISDN-related call completion protocols supported. These were written by Richard Mudgett, and as such I can't really say much about their implementation. There are notes in the CHANGES file that indicate the ISDN protocols over which call completion is supported. Review: https://reviewboard.asterisk.org/r/523 git-svn-id: http://svn.digium.com/svn/asterisk/trunk@256528 f38db490-d61c-443f-a65b-d21fe96a405b
2010-04-09 15:31:32 +00:00
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_ref(p, -1); /* kill the ref from the alloc */
}
return chan;
}
/*! \brief CLI command "local show channels" */
static char *locals_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct local_pvt *p = NULL;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
struct ao2_iterator it;
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;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
if (ao2_container_count(locals) == 0) {
ast_cli(a->fd, "No local channels in use\n");
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
return RESULT_SUCCESS;
}
it = ao2_iterator_init(locals, 0);
while ((p = ao2_iterator_next(&it))) {
ao2_lock(p);
ast_cli(a->fd, "%s -- %s@%s\n", p->owner ? p->owner->name : "<unowned>", p->exten, p->context);
ao2_unlock(p);
ao2_ref(p, -1);
}
ao2_iterator_destroy(&it);
return CLI_SUCCESS;
}
static struct ast_cli_entry cli_local[] = {
AST_CLI_DEFINE(locals_show, "List status of local channels"),
};
static int manager_optimize_away(struct mansession *s, const struct message *m)
{
const char *channel;
struct local_pvt *p, *tmp = NULL;
struct ast_channel *c;
int found = 0;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
struct ao2_iterator it;
channel = astman_get_header(m, "Channel");
if (ast_strlen_zero(channel)) {
astman_send_error(s, m, "'Channel' not specified.");
return 0;
}
c = ast_channel_get_by_name(channel);
if (!c) {
astman_send_error(s, m, "Channel does not exist.");
return 0;
}
p = c->tech_pvt;
ast_channel_unref(c);
c = NULL;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
it = ao2_iterator_init(locals, 0);
while ((tmp = ao2_iterator_next(&it))) {
if (tmp == p) {
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_lock(tmp);
found = 1;
ast_clear_flag(tmp, LOCAL_NO_OPTIMIZATION);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_unlock(tmp);
ao2_ref(tmp, -1);
break;
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_ref(tmp, -1);
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_iterator_destroy(&it);
if (found) {
astman_send_ack(s, m, "Queued channel to be optimized away");
} else {
astman_send_error(s, m, "Unable to find channel");
}
return 0;
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
static int locals_cmp_cb(void *obj, void *arg, int flags)
{
return (obj == arg) ? CMP_MATCH : 0;
}
/*! \brief Load module into PBX, register channel */
static int load_module(void)
{
if (!(local_tech.capabilities = ast_format_cap_alloc())) {
return AST_MODULE_LOAD_FAILURE;
}
ast_format_cap_add_all(local_tech.capabilities);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
if (!(locals = ao2_container_alloc(BUCKET_SIZE, NULL, locals_cmp_cb))) {
ast_format_cap_destroy(local_tech.capabilities);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
return AST_MODULE_LOAD_FAILURE;
}
/* Make sure we can register our channel type */
if (ast_channel_register(&local_tech)) {
ast_log(LOG_ERROR, "Unable to register channel class 'Local'\n");
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_ref(locals, -1);
ast_format_cap_destroy(local_tech.capabilities);
return AST_MODULE_LOAD_FAILURE;
}
ast_cli_register_multiple(cli_local, sizeof(cli_local) / sizeof(struct ast_cli_entry));
ast_manager_register_xml("LocalOptimizeAway", EVENT_FLAG_SYSTEM|EVENT_FLAG_CALL, manager_optimize_away);
return AST_MODULE_LOAD_SUCCESS;
}
/*! \brief Unload the local proxy channel from Asterisk */
static int unload_module(void)
{
struct local_pvt *p = NULL;
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
struct ao2_iterator it;
/* First, take us out of the channel loop */
ast_cli_unregister_multiple(cli_local, sizeof(cli_local) / sizeof(struct ast_cli_entry));
ast_manager_unregister("LocalOptimizeAway");
ast_channel_unregister(&local_tech);
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
it = ao2_iterator_init(locals, 0);
while ((p = ao2_iterator_next(&it))) {
if (p->owner) {
ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
}
Merged revisions 292868 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.8 ................ r292868 | dvossel | 2010-10-25 14:07:50 -0500 (Mon, 25 Oct 2010) | 39 lines Merged revisions 292867 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.6.2 ................ r292867 | dvossel | 2010-10-25 14:06:21 -0500 (Mon, 25 Oct 2010) | 32 lines Merged revisions 292866 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r292866 | dvossel | 2010-10-25 14:05:07 -0500 (Mon, 25 Oct 2010) | 27 lines This patch turns chan_local pvts into astobj2 objects. chan_local does some dangerous things involving deadlock avoidance. tech_pvt functions like hangup and queue_frame are provided with a locked channel upon entry. Those functions are completely safe as long as you don't attempt to give up that channel lock, but that is impossible to guarantee due to the required deadlock avoidance necessary to lock both the tech_pvt and both channels involved. In the past, we have tried to account for this by doing things like setting a "glare" flag that indicates what function should destroy the pvt. This was used in local_hangup and local_queue_frame to decided who should destroy the pvt if they collided in separate threads. I have removed the need to do this by converting all chan_local tech_pvts to astobj2. This means we can ref a pvt before deadlock avoidance and not have to worry about that pvt possibly getting destroyed under us. It also cleans up where we destroy the tech_pvt. The only unlink from the tech_pvt container occurs in local_hangup now, which is where it should occur. Since there still may be thread collisions on some functions like local_hangup after deadlock avoidance, I have added some checks to detect those collisions and exit appropriately. I think this patch is going to solve quite a bit of weirdness we have had with local channels in the past. ........ ................ ................ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@292869 f38db490-d61c-443f-a65b-d21fe96a405b
2010-10-25 19:11:42 +00:00
ao2_ref(p, -1);
}
ao2_iterator_destroy(&it);
ao2_ref(locals, -1);
ast_format_cap_destroy(local_tech.capabilities);
return 0;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Local Proxy Channel (Note: used internally by other modules)",
.load = load_module,
.unload = unload_module,
.load_pri = AST_MODPRI_CHANNEL_DRIVER,
);