2005-09-15 20:28:23 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005, Joshua Colp
|
|
|
|
*
|
2006-04-06 17:01:47 +00:00
|
|
|
* Joshua Colp <jcolp@digium.com>
|
2005-09-15 20:28:23 +00:00
|
|
|
*
|
2008-04-25 18:32:22 +00:00
|
|
|
* Portions merged from app_pickupchan, which was
|
|
|
|
* Copyright (C) 2008, Gary Cook
|
|
|
|
*
|
2005-09-15 20:28:23 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-15 20:28:23 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Directed Call Pickup Support
|
2005-09-15 20:28:23 +00:00
|
|
|
*
|
2006-05-22 16:08:23 +00:00
|
|
|
* \author Joshua Colp <jcolp@digium.com>
|
2008-04-25 18:32:22 +00:00
|
|
|
* \author Gary Cook
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
2005-11-06 15:09:47 +00:00
|
|
|
* \ingroup applications
|
2005-09-15 20:28:23 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-14 20:28:54 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-09-15 20:28:23 +00:00
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/app.h"
|
2013-08-02 02:32:44 +00:00
|
|
|
#include "asterisk/pickup.h"
|
2010-01-15 21:04:34 +00:00
|
|
|
#include "asterisk/manager.h"
|
2009-04-03 22:41:46 +00:00
|
|
|
#include "asterisk/callerid.h"
|
2005-09-15 20:28:23 +00:00
|
|
|
|
2006-05-22 16:08:23 +00:00
|
|
|
#define PICKUPMARK "PICKUPMARK"
|
|
|
|
|
2008-11-01 21:10:07 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
<application name="Pickup" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Directed extension call pickup.
|
|
|
|
</synopsis>
|
2012-04-25 23:00:26 +00:00
|
|
|
<syntax>
|
|
|
|
<parameter name="targets" argsep="&">
|
2012-04-26 03:12:44 +00:00
|
|
|
<argument name="extension" argsep="@" required="true">
|
|
|
|
<para>Specification of the pickup target.</para>
|
2012-04-25 23:00:26 +00:00
|
|
|
<argument name="extension" required="true"/>
|
|
|
|
<argument name="context" />
|
|
|
|
</argument>
|
2012-04-26 03:12:44 +00:00
|
|
|
<argument name="extension2" argsep="@" multiple="true">
|
|
|
|
<para>Additional specifications of pickup targets.</para>
|
2012-04-25 23:00:26 +00:00
|
|
|
<argument name="extension2" required="true"/>
|
|
|
|
<argument name="context2"/>
|
|
|
|
</argument>
|
2008-11-01 21:10:07 +00:00
|
|
|
</parameter>
|
|
|
|
</syntax>
|
|
|
|
<description>
|
2012-04-26 03:12:44 +00:00
|
|
|
<para>This application can pickup a specified ringing channel. The channel
|
|
|
|
to pickup can be specified in the following ways.</para>
|
|
|
|
<para>1) If no <replaceable>extension</replaceable> targets are specified,
|
|
|
|
the application will pickup a channel matching the pickup group of the
|
|
|
|
requesting channel.</para>
|
|
|
|
<para>2) If the <replaceable>extension</replaceable> is specified with a
|
|
|
|
<replaceable>context</replaceable> of the special string
|
|
|
|
<literal>PICKUPMARK</literal> (for example 10@PICKUPMARK), the application
|
2012-04-26 21:11:25 +00:00
|
|
|
will pickup a channel which has defined the channel variable
|
2012-04-26 03:12:44 +00:00
|
|
|
<variable>PICKUPMARK</variable> with the same value as
|
|
|
|
<replaceable>extension</replaceable> (in this example,
|
|
|
|
<literal>10</literal>).</para>
|
|
|
|
<para>3) If the <replaceable>extension</replaceable> is specified
|
2012-04-26 21:11:25 +00:00
|
|
|
with or without a <replaceable>context</replaceable>, the channel with a
|
|
|
|
matching <replaceable>extension</replaceable> and <replaceable>context</replaceable>
|
|
|
|
will be picked up. If no <replaceable>context</replaceable> is specified,
|
|
|
|
the current context will be used.</para>
|
|
|
|
<note><para>The <replaceable>extension</replaceable> is typically set on
|
|
|
|
matching channels by the dial application that created the channel. The
|
|
|
|
<replaceable>context</replaceable> is set on matching channels by the
|
|
|
|
channel driver for the device.</para></note>
|
2008-11-01 21:10:07 +00:00
|
|
|
</description>
|
|
|
|
</application>
|
|
|
|
<application name="PickupChan" language="en_US">
|
|
|
|
<synopsis>
|
|
|
|
Pickup a ringing channel.
|
|
|
|
</synopsis>
|
2011-07-21 17:33:06 +00:00
|
|
|
<syntax >
|
2013-11-22 16:43:21 +00:00
|
|
|
<parameter name="channel" argsep="&" required="true">
|
|
|
|
<argument name="channel" required="true" />
|
|
|
|
<argument name="channel2" required="false" multiple="true" />
|
|
|
|
<para>List of channel names or channel uniqueids to pickup if ringing.
|
|
|
|
For example, a channel name could be <literal>SIP/bob</literal> or
|
|
|
|
<literal>SIP/bob-00000000</literal> to find
|
|
|
|
<literal>SIP/bob-00000000</literal>.
|
|
|
|
</para>
|
2011-07-21 17:33:06 +00:00
|
|
|
</parameter>
|
2010-03-02 21:58:03 +00:00
|
|
|
<parameter name="options" required="false">
|
|
|
|
<optionlist>
|
|
|
|
<option name="p">
|
2013-11-22 16:43:21 +00:00
|
|
|
<para>Supplied channel names are prefixes. For example,
|
|
|
|
<literal>SIP/bob</literal> will match
|
|
|
|
<literal>SIP/bob-00000000</literal> and
|
|
|
|
<literal>SIP/bobby-00000000</literal>.
|
|
|
|
</para>
|
2010-03-02 21:58:03 +00:00
|
|
|
</option>
|
|
|
|
</optionlist>
|
|
|
|
</parameter>
|
2008-11-01 21:10:07 +00:00
|
|
|
</syntax>
|
|
|
|
<description>
|
2013-11-22 16:43:21 +00:00
|
|
|
<para>Pickup a specified <replaceable>channel</replaceable> if ringing.</para>
|
2008-11-01 21:10:07 +00:00
|
|
|
</description>
|
|
|
|
</application>
|
|
|
|
***/
|
2005-09-15 20:28:23 +00:00
|
|
|
|
2009-06-07 14:55:51 +00:00
|
|
|
static const char app[] = "Pickup";
|
|
|
|
static const char app2[] = "PickupChan";
|
2008-04-25 18:32:22 +00:00
|
|
|
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
struct pickup_by_name_args {
|
2013-11-22 16:43:21 +00:00
|
|
|
/*! Channel attempting to pickup a call. */
|
|
|
|
struct ast_channel *chan;
|
|
|
|
/*! Channel uniqueid or partial channel name to match. */
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
const char *name;
|
2013-11-22 16:43:21 +00:00
|
|
|
/*! Length of partial channel name to match. */
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
size_t len;
|
|
|
|
};
|
|
|
|
|
2013-11-22 16:43:21 +00:00
|
|
|
static int find_by_name(void *obj, void *arg, void *data, int flags)
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
{
|
2011-05-20 16:20:25 +00:00
|
|
|
struct ast_channel *target = obj;/*!< Potential pickup target */
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
struct pickup_by_name_args *args = data;
|
|
|
|
|
2013-11-22 16:43:21 +00:00
|
|
|
if (args->chan == target) {
|
|
|
|
/* The channel attempting to pickup a call cannot pickup itself. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_channel_lock(target);
|
|
|
|
if (!strncasecmp(ast_channel_name(target), args->name, args->len)
|
|
|
|
&& ast_can_pickup(target)) {
|
|
|
|
/* Return with the channel still locked on purpose */
|
|
|
|
return CMP_MATCH | CMP_STOP;
|
|
|
|
}
|
|
|
|
ast_channel_unlock(target);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int find_by_uniqueid(void *obj, void *arg, void *data, int flags)
|
|
|
|
{
|
|
|
|
struct ast_channel *target = obj;/*!< Potential pickup target */
|
|
|
|
struct pickup_by_name_args *args = data;
|
|
|
|
|
|
|
|
if (args->chan == target) {
|
|
|
|
/* The channel attempting to pickup a call cannot pickup itself. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-20 16:20:25 +00:00
|
|
|
ast_channel_lock(target);
|
2013-11-22 16:43:21 +00:00
|
|
|
if (!strcasecmp(ast_channel_uniqueid(target), args->name)
|
|
|
|
&& ast_can_pickup(target)) {
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
/* Return with the channel still locked on purpose */
|
|
|
|
return CMP_MATCH | CMP_STOP;
|
|
|
|
}
|
2011-05-20 16:20:25 +00:00
|
|
|
ast_channel_unlock(target);
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-25 18:32:22 +00:00
|
|
|
/*! \brief Helper Function to walk through ALL channels checking NAME and STATE */
|
2013-11-22 16:43:21 +00:00
|
|
|
static struct ast_channel *find_by_channel(struct ast_channel *chan, const char *channame)
|
2008-04-25 18:32:22 +00:00
|
|
|
{
|
2013-11-22 16:43:21 +00:00
|
|
|
struct ast_channel *target;
|
2008-11-02 02:14:19 +00:00
|
|
|
char *chkchan;
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
struct pickup_by_name_args pickup_args;
|
2008-11-02 02:14:19 +00:00
|
|
|
|
2013-11-22 16:43:21 +00:00
|
|
|
pickup_args.chan = chan;
|
|
|
|
|
2010-10-05 19:57:31 +00:00
|
|
|
if (strchr(channame, '-')) {
|
2013-11-22 16:43:21 +00:00
|
|
|
/*
|
|
|
|
* Use the given channel name string as-is. This allows a full channel
|
|
|
|
* name with a typical sequence number to be used as well as still
|
|
|
|
* allowing the odd partial channel name that has a '-' in it to still
|
|
|
|
* work, i.e. Local/bob@en-phone.
|
|
|
|
*/
|
2010-10-05 19:57:31 +00:00
|
|
|
pickup_args.len = strlen(channame);
|
|
|
|
pickup_args.name = channame;
|
|
|
|
} else {
|
2013-11-22 16:43:21 +00:00
|
|
|
/*
|
|
|
|
* Append a '-' for the comparison so we check the channel name less
|
|
|
|
* a sequence number, i.e Find SIP/bob- and not SIP/bobby.
|
2010-10-05 19:57:31 +00:00
|
|
|
*/
|
|
|
|
pickup_args.len = strlen(channame) + 1;
|
2012-07-31 20:21:43 +00:00
|
|
|
chkchan = ast_alloca(pickup_args.len + 1);
|
2013-11-22 16:43:21 +00:00
|
|
|
strcpy(chkchan, channame);/* Safe */
|
2010-10-05 19:57:31 +00:00
|
|
|
strcat(chkchan, "-");
|
|
|
|
pickup_args.name = chkchan;
|
|
|
|
}
|
2013-11-22 16:43:21 +00:00
|
|
|
target = ast_channel_callback(find_by_name, NULL, &pickup_args, 0);
|
|
|
|
if (target) {
|
|
|
|
return target;
|
|
|
|
}
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
|
2013-11-22 16:43:21 +00:00
|
|
|
/* Now try a search for uniqueid. */
|
|
|
|
pickup_args.name = channame;
|
|
|
|
pickup_args.len = 0;
|
|
|
|
return ast_channel_callback(find_by_uniqueid, NULL, &pickup_args, 0);
|
2008-04-25 18:32:22 +00:00
|
|
|
}
|
|
|
|
|
2013-11-22 16:43:21 +00:00
|
|
|
/*! \brief Attempt to pick up named channel. */
|
|
|
|
static int pickup_by_channel(struct ast_channel *chan, const char *name)
|
2008-04-25 18:32:22 +00:00
|
|
|
{
|
2011-05-20 15:52:20 +00:00
|
|
|
int res = -1;
|
2011-05-20 16:20:25 +00:00
|
|
|
struct ast_channel *target;/*!< Potential pickup target */
|
2008-04-25 18:32:22 +00:00
|
|
|
|
2013-11-22 16:43:21 +00:00
|
|
|
/* The found channel is already locked. */
|
|
|
|
target = find_by_channel(chan, name);
|
2011-05-20 15:52:20 +00:00
|
|
|
if (target) {
|
2013-11-22 16:43:21 +00:00
|
|
|
res = ast_do_pickup(chan, target);
|
2011-05-20 15:52:20 +00:00
|
|
|
ast_channel_unlock(target);
|
|
|
|
target = ast_channel_unref(target);
|
2008-04-25 18:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-10-16 16:26:23 +00:00
|
|
|
/* Attempt to pick up specified extension with context */
|
2007-06-04 17:32:41 +00:00
|
|
|
static int pickup_by_exten(struct ast_channel *chan, const char *exten, const char *context)
|
2006-10-16 16:26:23 +00:00
|
|
|
{
|
2011-05-20 16:20:25 +00:00
|
|
|
struct ast_channel *target = NULL;/*!< Potential pickup target */
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
struct ast_channel_iterator *iter;
|
|
|
|
int res = -1;
|
|
|
|
|
2009-10-21 21:08:47 +00:00
|
|
|
if (!(iter = ast_channel_iterator_by_exten_new(exten, context))) {
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2008-11-05 22:19:22 +00:00
|
|
|
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
while ((target = ast_channel_iterator_next(iter))) {
|
|
|
|
ast_channel_lock(target);
|
2011-06-09 16:47:07 +00:00
|
|
|
if ((chan != target) && ast_can_pickup(target)) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_NOTICE, "%s pickup by %s\n", ast_channel_name(target), ast_channel_name(chan));
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
ast_channel_unlock(target);
|
|
|
|
target = ast_channel_unref(target);
|
|
|
|
}
|
2008-11-05 22:19:22 +00:00
|
|
|
|
2009-10-21 21:08:47 +00:00
|
|
|
ast_channel_iterator_destroy(iter);
|
|
|
|
|
2008-11-05 22:19:22 +00:00
|
|
|
if (target) {
|
Merged revisions 318671 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
........
r318671 | alecdavis | 2011-05-13 10:52:08 +1200 (Fri, 13 May 2011) | 30 lines
Fix directed group pickup feature code *8 with pickupsounds enabled
Since 1.6.2, the new pickupsound and pickupfailsound in features.conf cause many issues.
1). chan_sip:handle_request_invite() shouldn't be playing out the fail/success audio, as it has 'netlock' locked.
2). dialplan applications for directed_pickups shouldn't beep.
3). feature code for directed pickup should beep on success/failure if configured.
Created a sip_pickup() thread to handle the pickup and playout the audio, spawned from handle_request_invite.
Moved app_directed:pickup_do() to features:ast_do_pickup().
Functions below, all now use the new ast_do_pickup()
app_directed_pickup.c:
pickup_by_channel()
pickup_by_exten()
pickup_by_mark()
pickup_by_part()
features.c:
ast_pickup_call()
(closes issue #18654)
Reported by: Docent
Patches:
ast_do_pickup_1.8_trunk.diff.txt uploaded by alecdavis (license 585)
Tested by: lmadsen, francesco_r, amilcar, isis242, alecdavis, irroot, rymkus, loloski, rmudgett
Review: https://reviewboard.asterisk.org/r/1185/
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@318672 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-05-12 22:56:43 +00:00
|
|
|
res = ast_do_pickup(chan, target);
|
2006-10-16 16:26:23 +00:00
|
|
|
ast_channel_unlock(target);
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
target = ast_channel_unref(target);
|
2006-10-16 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
return res;
|
2006-10-16 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
static int find_by_mark(void *obj, void *arg, void *data, int flags)
|
2008-11-09 01:59:59 +00:00
|
|
|
{
|
2011-05-20 16:20:25 +00:00
|
|
|
struct ast_channel *target = obj;/*!< Potential pickup target */
|
2013-11-14 20:53:52 +00:00
|
|
|
struct ast_channel *chan = arg;
|
2008-11-09 01:59:59 +00:00
|
|
|
const char *mark = data;
|
|
|
|
const char *tmp;
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
|
2013-11-14 20:53:52 +00:00
|
|
|
if (chan == target) {
|
|
|
|
/* The channel attempting to pickup a call cannot pickup itself. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-20 16:20:25 +00:00
|
|
|
ast_channel_lock(target);
|
|
|
|
tmp = pbx_builtin_getvar_helper(target, PICKUPMARK);
|
2011-06-09 16:47:07 +00:00
|
|
|
if (tmp && !strcasecmp(tmp, mark) && ast_can_pickup(target)) {
|
2011-05-20 15:52:20 +00:00
|
|
|
/* Return with the channel still locked on purpose */
|
|
|
|
return CMP_MATCH | CMP_STOP;
|
|
|
|
}
|
2011-05-20 16:20:25 +00:00
|
|
|
ast_channel_unlock(target);
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
|
2011-05-20 15:52:20 +00:00
|
|
|
return 0;
|
2008-11-09 01:59:59 +00:00
|
|
|
}
|
|
|
|
|
2006-10-16 16:26:23 +00:00
|
|
|
/* Attempt to pick up specified mark */
|
2007-06-04 17:32:41 +00:00
|
|
|
static int pickup_by_mark(struct ast_channel *chan, const char *mark)
|
2006-10-16 16:26:23 +00:00
|
|
|
{
|
2011-05-20 16:20:25 +00:00
|
|
|
struct ast_channel *target;/*!< Potential pickup target */
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
int res = -1;
|
2008-11-05 22:19:22 +00:00
|
|
|
|
2011-05-20 15:52:20 +00:00
|
|
|
/* The found channel is already locked. */
|
2013-11-14 20:53:52 +00:00
|
|
|
target = ast_channel_callback(find_by_mark, chan, (char *) mark, 0);
|
2011-05-20 15:52:20 +00:00
|
|
|
if (target) {
|
Merged revisions 318671 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
........
r318671 | alecdavis | 2011-05-13 10:52:08 +1200 (Fri, 13 May 2011) | 30 lines
Fix directed group pickup feature code *8 with pickupsounds enabled
Since 1.6.2, the new pickupsound and pickupfailsound in features.conf cause many issues.
1). chan_sip:handle_request_invite() shouldn't be playing out the fail/success audio, as it has 'netlock' locked.
2). dialplan applications for directed_pickups shouldn't beep.
3). feature code for directed pickup should beep on success/failure if configured.
Created a sip_pickup() thread to handle the pickup and playout the audio, spawned from handle_request_invite.
Moved app_directed:pickup_do() to features:ast_do_pickup().
Functions below, all now use the new ast_do_pickup()
app_directed_pickup.c:
pickup_by_channel()
pickup_by_exten()
pickup_by_mark()
pickup_by_part()
features.c:
ast_pickup_call()
(closes issue #18654)
Reported by: Docent
Patches:
ast_do_pickup_1.8_trunk.diff.txt uploaded by alecdavis (license 585)
Tested by: lmadsen, francesco_r, amilcar, isis242, alecdavis, irroot, rymkus, loloski, rmudgett
Review: https://reviewboard.asterisk.org/r/1185/
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@318672 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-05-12 22:56:43 +00:00
|
|
|
res = ast_do_pickup(chan, target);
|
2011-05-20 15:52:20 +00:00
|
|
|
ast_channel_unlock(target);
|
|
|
|
target = ast_channel_unref(target);
|
Merged revisions 318671 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
........
r318671 | alecdavis | 2011-05-13 10:52:08 +1200 (Fri, 13 May 2011) | 30 lines
Fix directed group pickup feature code *8 with pickupsounds enabled
Since 1.6.2, the new pickupsound and pickupfailsound in features.conf cause many issues.
1). chan_sip:handle_request_invite() shouldn't be playing out the fail/success audio, as it has 'netlock' locked.
2). dialplan applications for directed_pickups shouldn't beep.
3). feature code for directed pickup should beep on success/failure if configured.
Created a sip_pickup() thread to handle the pickup and playout the audio, spawned from handle_request_invite.
Moved app_directed:pickup_do() to features:ast_do_pickup().
Functions below, all now use the new ast_do_pickup()
app_directed_pickup.c:
pickup_by_channel()
pickup_by_exten()
pickup_by_mark()
pickup_by_part()
features.c:
ast_pickup_call()
(closes issue #18654)
Reported by: Docent
Patches:
ast_do_pickup_1.8_trunk.diff.txt uploaded by alecdavis (license 585)
Tested by: lmadsen, francesco_r, amilcar, isis242, alecdavis, irroot, rymkus, loloski, rmudgett
Review: https://reviewboard.asterisk.org/r/1185/
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@318672 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-05-12 22:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pickup_by_group(struct ast_channel *chan)
|
|
|
|
{
|
2011-05-20 16:20:25 +00:00
|
|
|
struct ast_channel *target;/*!< Potential pickup target */
|
Merged revisions 318671 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
........
r318671 | alecdavis | 2011-05-13 10:52:08 +1200 (Fri, 13 May 2011) | 30 lines
Fix directed group pickup feature code *8 with pickupsounds enabled
Since 1.6.2, the new pickupsound and pickupfailsound in features.conf cause many issues.
1). chan_sip:handle_request_invite() shouldn't be playing out the fail/success audio, as it has 'netlock' locked.
2). dialplan applications for directed_pickups shouldn't beep.
3). feature code for directed pickup should beep on success/failure if configured.
Created a sip_pickup() thread to handle the pickup and playout the audio, spawned from handle_request_invite.
Moved app_directed:pickup_do() to features:ast_do_pickup().
Functions below, all now use the new ast_do_pickup()
app_directed_pickup.c:
pickup_by_channel()
pickup_by_exten()
pickup_by_mark()
pickup_by_part()
features.c:
ast_pickup_call()
(closes issue #18654)
Reported by: Docent
Patches:
ast_do_pickup_1.8_trunk.diff.txt uploaded by alecdavis (license 585)
Tested by: lmadsen, francesco_r, amilcar, isis242, alecdavis, irroot, rymkus, loloski, rmudgett
Review: https://reviewboard.asterisk.org/r/1185/
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@318672 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-05-12 22:56:43 +00:00
|
|
|
int res = -1;
|
|
|
|
|
2011-05-20 15:52:20 +00:00
|
|
|
/* The found channel is already locked. */
|
2012-09-20 17:22:41 +00:00
|
|
|
target = ast_pickup_find_by_group(chan);
|
2011-05-20 15:52:20 +00:00
|
|
|
if (target) {
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_log(LOG_NOTICE, "pickup %s attempt by %s\n", ast_channel_name(target), ast_channel_name(chan));
|
Merged revisions 318671 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
........
r318671 | alecdavis | 2011-05-13 10:52:08 +1200 (Fri, 13 May 2011) | 30 lines
Fix directed group pickup feature code *8 with pickupsounds enabled
Since 1.6.2, the new pickupsound and pickupfailsound in features.conf cause many issues.
1). chan_sip:handle_request_invite() shouldn't be playing out the fail/success audio, as it has 'netlock' locked.
2). dialplan applications for directed_pickups shouldn't beep.
3). feature code for directed pickup should beep on success/failure if configured.
Created a sip_pickup() thread to handle the pickup and playout the audio, spawned from handle_request_invite.
Moved app_directed:pickup_do() to features:ast_do_pickup().
Functions below, all now use the new ast_do_pickup()
app_directed_pickup.c:
pickup_by_channel()
pickup_by_exten()
pickup_by_mark()
pickup_by_part()
features.c:
ast_pickup_call()
(closes issue #18654)
Reported by: Docent
Patches:
ast_do_pickup_1.8_trunk.diff.txt uploaded by alecdavis (license 585)
Tested by: lmadsen, francesco_r, amilcar, isis242, alecdavis, irroot, rymkus, loloski, rmudgett
Review: https://reviewboard.asterisk.org/r/1185/
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@318672 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-05-12 22:56:43 +00:00
|
|
|
res = ast_do_pickup(chan, target);
|
2011-05-20 15:52:20 +00:00
|
|
|
ast_channel_unlock(target);
|
|
|
|
target = ast_channel_unref(target);
|
Merged revisions 318671 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
........
r318671 | alecdavis | 2011-05-13 10:52:08 +1200 (Fri, 13 May 2011) | 30 lines
Fix directed group pickup feature code *8 with pickupsounds enabled
Since 1.6.2, the new pickupsound and pickupfailsound in features.conf cause many issues.
1). chan_sip:handle_request_invite() shouldn't be playing out the fail/success audio, as it has 'netlock' locked.
2). dialplan applications for directed_pickups shouldn't beep.
3). feature code for directed pickup should beep on success/failure if configured.
Created a sip_pickup() thread to handle the pickup and playout the audio, spawned from handle_request_invite.
Moved app_directed:pickup_do() to features:ast_do_pickup().
Functions below, all now use the new ast_do_pickup()
app_directed_pickup.c:
pickup_by_channel()
pickup_by_exten()
pickup_by_mark()
pickup_by_part()
features.c:
ast_pickup_call()
(closes issue #18654)
Reported by: Docent
Patches:
ast_do_pickup_1.8_trunk.diff.txt uploaded by alecdavis (license 585)
Tested by: lmadsen, francesco_r, amilcar, isis242, alecdavis, irroot, rymkus, loloski, rmudgett
Review: https://reviewboard.asterisk.org/r/1185/
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@318672 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-05-12 22:56:43 +00:00
|
|
|
}
|
|
|
|
|
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: https://origsvn.digium.com/svn/asterisk/trunk@190423 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2009-04-24 14:04:26 +00:00
|
|
|
return res;
|
2006-10-16 16:26:23 +00:00
|
|
|
}
|
|
|
|
|
2008-04-25 18:32:22 +00:00
|
|
|
/* application entry point for Pickup() */
|
2009-05-21 21:13:09 +00:00
|
|
|
static int pickup_exec(struct ast_channel *chan, const char *data)
|
2005-09-15 20:28:23 +00:00
|
|
|
{
|
2013-11-14 21:36:25 +00:00
|
|
|
char *parse;
|
2012-04-26 01:29:09 +00:00
|
|
|
char *exten;
|
|
|
|
char *context;
|
2005-09-15 20:28:23 +00:00
|
|
|
|
2005-10-26 19:48:14 +00:00
|
|
|
if (ast_strlen_zero(data)) {
|
2011-05-20 15:52:20 +00:00
|
|
|
return pickup_by_group(chan) ? 0 : -1;
|
2005-10-19 18:19:02 +00:00
|
|
|
}
|
Merged revisions 318671 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
........
r318671 | alecdavis | 2011-05-13 10:52:08 +1200 (Fri, 13 May 2011) | 30 lines
Fix directed group pickup feature code *8 with pickupsounds enabled
Since 1.6.2, the new pickupsound and pickupfailsound in features.conf cause many issues.
1). chan_sip:handle_request_invite() shouldn't be playing out the fail/success audio, as it has 'netlock' locked.
2). dialplan applications for directed_pickups shouldn't beep.
3). feature code for directed pickup should beep on success/failure if configured.
Created a sip_pickup() thread to handle the pickup and playout the audio, spawned from handle_request_invite.
Moved app_directed:pickup_do() to features:ast_do_pickup().
Functions below, all now use the new ast_do_pickup()
app_directed_pickup.c:
pickup_by_channel()
pickup_by_exten()
pickup_by_mark()
pickup_by_part()
features.c:
ast_pickup_call()
(closes issue #18654)
Reported by: Docent
Patches:
ast_do_pickup_1.8_trunk.diff.txt uploaded by alecdavis (license 585)
Tested by: lmadsen, francesco_r, amilcar, isis242, alecdavis, irroot, rymkus, loloski, rmudgett
Review: https://reviewboard.asterisk.org/r/1185/
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@318672 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2011-05-12 22:56:43 +00:00
|
|
|
|
2006-10-16 16:26:23 +00:00
|
|
|
/* Parse extension (and context if there) */
|
2013-11-14 21:36:25 +00:00
|
|
|
parse = ast_strdupa(data);
|
|
|
|
for (;;) {
|
|
|
|
if (ast_strlen_zero(parse)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
exten = strsep(&parse, "&");
|
|
|
|
if (ast_strlen_zero(exten)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
context = strchr(exten, '@');
|
|
|
|
if (context) {
|
2006-01-13 17:02:15 +00:00
|
|
|
*context++ = '\0';
|
2013-11-14 21:36:25 +00:00
|
|
|
}
|
2007-06-04 17:32:41 +00:00
|
|
|
if (!ast_strlen_zero(context) && !strcasecmp(context, PICKUPMARK)) {
|
2011-05-20 15:52:20 +00:00
|
|
|
if (!pickup_by_mark(chan, exten)) {
|
|
|
|
/* Pickup successful. Stop the dialplan this channel is a zombie. */
|
|
|
|
return -1;
|
|
|
|
}
|
2006-01-13 17:02:15 +00:00
|
|
|
} else {
|
2012-04-26 01:29:09 +00:00
|
|
|
if (ast_strlen_zero(context)) {
|
|
|
|
context = (char *) ast_channel_context(chan);
|
|
|
|
}
|
|
|
|
if (!pickup_by_exten(chan, exten, context)) {
|
2011-05-20 15:52:20 +00:00
|
|
|
/* Pickup successful. Stop the dialplan this channel is a zombie. */
|
|
|
|
return -1;
|
|
|
|
}
|
2005-09-15 20:28:23 +00:00
|
|
|
}
|
2012-04-26 01:29:09 +00:00
|
|
|
ast_log(LOG_NOTICE, "No target channel found for %s@%s.\n", exten, context);
|
2005-09-15 20:28:23 +00:00
|
|
|
}
|
2006-10-16 16:26:23 +00:00
|
|
|
|
2011-05-20 15:52:20 +00:00
|
|
|
/* Pickup failed. Keep going in the dialplan. */
|
|
|
|
return 0;
|
2005-09-15 20:28:23 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 02:32:44 +00:00
|
|
|
/* Find channel for pick up specified by partial channel name */
|
2013-11-22 16:43:21 +00:00
|
|
|
static struct ast_channel *find_by_part(struct ast_channel *chan, const char *part)
|
2010-03-02 21:58:03 +00:00
|
|
|
{
|
2013-11-22 16:43:21 +00:00
|
|
|
struct ast_channel *target;
|
|
|
|
struct pickup_by_name_args pickup_args;
|
2010-03-02 21:58:03 +00:00
|
|
|
|
2013-11-22 16:43:21 +00:00
|
|
|
pickup_args.chan = chan;
|
|
|
|
|
|
|
|
/* Try a partial channel name search. */
|
|
|
|
pickup_args.name = part;
|
|
|
|
pickup_args.len = strlen(part);
|
|
|
|
target = ast_channel_callback(find_by_name, NULL, &pickup_args, 0);
|
|
|
|
if (target) {
|
|
|
|
return target;
|
2010-03-02 21:58:03 +00:00
|
|
|
}
|
|
|
|
|
2013-11-22 16:43:21 +00:00
|
|
|
/* Now try a search for uniqueid. */
|
|
|
|
pickup_args.name = part;
|
|
|
|
pickup_args.len = 0;
|
|
|
|
return ast_channel_callback(find_by_uniqueid, NULL, &pickup_args, 0);
|
2010-03-02 21:58:03 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 02:32:44 +00:00
|
|
|
/* Attempt to pick up specified by partial channel name */
|
2010-03-02 21:58:03 +00:00
|
|
|
static int pickup_by_part(struct ast_channel *chan, const char *part)
|
|
|
|
{
|
2011-05-20 16:20:25 +00:00
|
|
|
struct ast_channel *target;/*!< Potential pickup target */
|
2010-03-02 21:58:03 +00:00
|
|
|
int res = -1;
|
|
|
|
|
2011-05-20 15:52:20 +00:00
|
|
|
/* The found channel is already locked. */
|
2013-11-22 16:43:21 +00:00
|
|
|
target = find_by_part(chan, part);
|
2011-05-20 15:52:20 +00:00
|
|
|
if (target) {
|
|
|
|
res = ast_do_pickup(chan, target);
|
2010-03-02 21:58:03 +00:00
|
|
|
ast_channel_unlock(target);
|
|
|
|
target = ast_channel_unref(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2013-11-14 21:36:25 +00:00
|
|
|
enum OPT_PICKUPCHAN_FLAGS {
|
|
|
|
OPT_PICKUPCHAN_PARTIAL = (1 << 0), /* Channel name is a partial name. */
|
|
|
|
};
|
|
|
|
|
|
|
|
AST_APP_OPTIONS(pickupchan_opts, BEGIN_OPTIONS
|
|
|
|
AST_APP_OPTION('p', OPT_PICKUPCHAN_PARTIAL),
|
|
|
|
END_OPTIONS);
|
|
|
|
|
2008-04-25 18:32:22 +00:00
|
|
|
/* application entry point for PickupChan() */
|
2009-05-21 21:13:09 +00:00
|
|
|
static int pickupchan_exec(struct ast_channel *chan, const char *data)
|
2008-04-25 18:32:22 +00:00
|
|
|
{
|
|
|
|
char *pickup = NULL;
|
2010-03-02 21:58:03 +00:00
|
|
|
char *parse = ast_strdupa(data);
|
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(channel);
|
|
|
|
AST_APP_ARG(options);
|
2013-11-14 21:36:25 +00:00
|
|
|
AST_APP_ARG(other); /* Any remining unused arguments */
|
2010-03-02 21:58:03 +00:00
|
|
|
);
|
2013-11-14 21:36:25 +00:00
|
|
|
struct ast_flags opts;
|
|
|
|
|
2010-03-02 21:58:03 +00:00
|
|
|
AST_STANDARD_APP_ARGS(args, parse);
|
|
|
|
|
|
|
|
if (ast_strlen_zero(args.channel)) {
|
2008-04-25 18:32:22 +00:00
|
|
|
ast_log(LOG_WARNING, "PickupChan requires an argument (channel)!\n");
|
2011-05-20 15:52:20 +00:00
|
|
|
/* Pickup failed. Keep going in the dialplan. */
|
|
|
|
return 0;
|
2010-03-02 21:58:03 +00:00
|
|
|
}
|
2013-11-14 21:36:25 +00:00
|
|
|
if (ast_app_parse_options(pickupchan_opts, &opts, NULL, args.options)) {
|
|
|
|
/*
|
|
|
|
* General invalid option syntax.
|
|
|
|
* Pickup failed. Keep going in the dialplan.
|
|
|
|
*/
|
|
|
|
return 0;
|
2008-04-25 18:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse channel */
|
2013-11-14 21:36:25 +00:00
|
|
|
for (;;) {
|
|
|
|
if (ast_strlen_zero(args.channel)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pickup = strsep(&args.channel, "&");
|
|
|
|
if (ast_strlen_zero(pickup)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_test_flag(&opts, OPT_PICKUPCHAN_PARTIAL)) {
|
|
|
|
if (!pickup_by_part(chan, pickup)) {
|
2011-05-20 15:52:20 +00:00
|
|
|
/* Pickup successful. Stop the dialplan this channel is a zombie. */
|
|
|
|
return -1;
|
2008-04-25 18:32:22 +00:00
|
|
|
}
|
2013-11-14 21:36:25 +00:00
|
|
|
} else if (!pickup_by_channel(chan, pickup)) {
|
|
|
|
/* Pickup successful. Stop the dialplan this channel is a zombie. */
|
|
|
|
return -1;
|
2008-04-25 18:32:22 +00:00
|
|
|
}
|
2013-11-14 21:36:25 +00:00
|
|
|
ast_log(LOG_NOTICE, "No target channel found for %s.\n", pickup);
|
2008-04-25 18:32:22 +00:00
|
|
|
}
|
|
|
|
|
2011-05-20 15:52:20 +00:00
|
|
|
/* Pickup failed. Keep going in the dialplan. */
|
|
|
|
return 0;
|
2008-04-25 18:32:22 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2005-09-15 20:28:23 +00:00
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = ast_unregister_application(app);
|
2008-04-25 18:32:22 +00:00
|
|
|
res |= ast_unregister_application(app2);
|
2008-02-09 11:27:10 +00:00
|
|
|
|
2005-10-18 22:52:21 +00:00
|
|
|
return res;
|
2005-09-15 20:28:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2005-09-15 20:28:23 +00:00
|
|
|
{
|
2008-04-25 18:32:22 +00:00
|
|
|
int res;
|
|
|
|
|
2008-11-01 21:10:07 +00:00
|
|
|
res = ast_register_application_xml(app, pickup_exec);
|
|
|
|
res |= ast_register_application_xml(app2, pickupchan_exec);
|
2008-04-25 18:32:22 +00:00
|
|
|
|
|
|
|
return res;
|
2005-09-15 20:28:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Directed Call Pickup Application");
|