2007-01-24 18:23:07 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 - 2007, Digium, Inc.
|
|
|
|
*
|
|
|
|
* Joshua Colp <jcolp@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
|
|
|
|
*
|
|
|
|
* \brief Dialing API
|
|
|
|
*
|
2008-01-24 03:25:52 +00:00
|
|
|
* \author Joshua Colp <jcolp@digium.com>
|
2007-01-24 18:23:07 +00:00
|
|
|
*/
|
|
|
|
|
2012-06-15 16:20:16 +00:00
|
|
|
/*** MODULEINFO
|
|
|
|
<support_level>core</support_level>
|
|
|
|
***/
|
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/utils.h"
|
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/linkedlists.h"
|
|
|
|
#include "asterisk/dial.h"
|
|
|
|
#include "asterisk/pbx.h"
|
2007-04-10 19:16:24 +00:00
|
|
|
#include "asterisk/musiconhold.h"
|
2009-06-01 20:57:31 +00:00
|
|
|
#include "asterisk/app.h"
|
2013-04-08 14:26:37 +00:00
|
|
|
#include "asterisk/causes.h"
|
|
|
|
#include "asterisk/stasis_channels.h"
|
2015-04-15 15:38:02 +00:00
|
|
|
#include "asterisk/max_forwards.h"
|
2007-01-24 18:23:07 +00:00
|
|
|
|
|
|
|
/*! \brief Main dialing structure. Contains global options, channels being dialed, and more! */
|
|
|
|
struct ast_dial {
|
2007-04-28 21:01:44 +00:00
|
|
|
int num; /*!< Current number to give to next dialed channel */
|
2007-07-30 20:42:28 +00:00
|
|
|
int timeout; /*!< Maximum time allowed for dial attempts */
|
|
|
|
int actual_timeout; /*!< Actual timeout based on all factors (ie: channels) */
|
2007-04-28 21:01:44 +00:00
|
|
|
enum ast_dial_result state; /*!< Status of dial */
|
|
|
|
void *options[AST_DIAL_OPTION_MAX]; /*!< Global options */
|
|
|
|
ast_dial_state_callback state_callback; /*!< Status callback */
|
2012-03-10 20:06:46 +00:00
|
|
|
void *user_data; /*!< Attached user data */
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_HEAD(, ast_dial_channel) channels; /*!< Channels being dialed */
|
2007-04-28 21:01:44 +00:00
|
|
|
pthread_t thread; /*!< Thread (if running in async) */
|
2015-03-13 01:12:35 +00:00
|
|
|
ast_callid callid; /*!< callid (if running in async) */
|
2008-01-16 15:09:37 +00:00
|
|
|
ast_mutex_t lock; /*! Lock to protect the thread information above */
|
2007-01-24 18:23:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
|
|
|
|
struct ast_dial_channel {
|
2008-10-30 16:49:02 +00:00
|
|
|
int num; /*!< Unique number for dialed channel */
|
|
|
|
int timeout; /*!< Maximum time allowed for attempt */
|
|
|
|
char *tech; /*!< Technology being dialed */
|
|
|
|
char *device; /*!< Device being dialed */
|
|
|
|
void *options[AST_DIAL_OPTION_MAX]; /*!< Channel specific options */
|
|
|
|
int cause; /*!< Cause code in case of failure */
|
|
|
|
unsigned int is_running_app:1; /*!< Is this running an application? */
|
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and
much change was necessary to accomplish it. Channel uniqueids
and linkedids are split into separate string and creation time
components without breaking linkedid propgation. This allowed
the uniqueid to be specified by the user interface - and those
values are now carried through to channel creation, adding the
assignedids value to every function in the chain including the
channel drivers. For local channels, the second channel can be
specified or left to default to a ;2 suffix of first. In ARI,
bridge, playback, and snoop objects can also be created with a
specified uniqueid.
Along the way, the args order to allocating channels was fixed
in chan_mgcp and chan_gtalk, and linkedid is no longer lost as
masquerade occurs.
(closes issue ASTERISK-23120)
Review: https://reviewboard.asterisk.org/r/3191/
........
Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-03-07 15:47:55 +00:00
|
|
|
char *assignedid1; /*!< UniqueID to assign channel */
|
|
|
|
char *assignedid2; /*!< UniqueID to assign 2nd channel */
|
2008-10-30 16:49:02 +00:00
|
|
|
struct ast_channel *owner; /*!< Asterisk channel */
|
|
|
|
AST_LIST_ENTRY(ast_dial_channel) list; /*!< Linked list information */
|
2007-01-24 18:23:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*! \brief Typedef for dial option enable */
|
|
|
|
typedef void *(*ast_dial_option_cb_enable)(void *data);
|
|
|
|
|
|
|
|
/*! \brief Typedef for dial option disable */
|
|
|
|
typedef int (*ast_dial_option_cb_disable)(void *data);
|
|
|
|
|
2007-05-16 07:08:48 +00:00
|
|
|
/*! \brief Structure for 'ANSWER_EXEC' option */
|
2007-01-24 18:23:07 +00:00
|
|
|
struct answer_exec_struct {
|
2007-05-16 07:08:48 +00:00
|
|
|
char app[AST_MAX_APP]; /*!< Application name */
|
|
|
|
char *args; /*!< Application arguments */
|
2007-01-24 18:23:07 +00:00
|
|
|
};
|
|
|
|
|
2007-05-16 07:08:48 +00:00
|
|
|
/*! \brief Enable function for 'ANSWER_EXEC' option */
|
2007-01-24 18:23:07 +00:00
|
|
|
static void *answer_exec_enable(void *data)
|
|
|
|
{
|
|
|
|
struct answer_exec_struct *answer_exec = NULL;
|
|
|
|
char *app = ast_strdupa((char*)data), *args = NULL;
|
|
|
|
|
|
|
|
/* Not giving any data to this option is bad, mmmk? */
|
|
|
|
if (ast_strlen_zero(app))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Create new data structure */
|
|
|
|
if (!(answer_exec = ast_calloc(1, sizeof(*answer_exec))))
|
|
|
|
return NULL;
|
2012-03-22 19:51:16 +00:00
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Parse out application and arguments */
|
2008-06-13 14:15:07 +00:00
|
|
|
if ((args = strchr(app, ','))) {
|
2007-01-24 18:23:07 +00:00
|
|
|
*args++ = '\0';
|
|
|
|
answer_exec->args = ast_strdup(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy application name */
|
|
|
|
ast_copy_string(answer_exec->app, app, sizeof(answer_exec->app));
|
|
|
|
|
|
|
|
return answer_exec;
|
|
|
|
}
|
|
|
|
|
2007-05-16 07:08:48 +00:00
|
|
|
/*! \brief Disable function for 'ANSWER_EXEC' option */
|
2007-01-24 18:23:07 +00:00
|
|
|
static int answer_exec_disable(void *data)
|
|
|
|
{
|
|
|
|
struct answer_exec_struct *answer_exec = data;
|
|
|
|
|
|
|
|
/* Make sure we have a value */
|
|
|
|
if (!answer_exec)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* If arguments are present, free them too */
|
|
|
|
if (answer_exec->args)
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(answer_exec->args);
|
2007-01-24 18:23:07 +00:00
|
|
|
|
|
|
|
/* This is simple - just free the structure */
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(answer_exec);
|
2007-01-24 18:23:07 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-04-10 19:16:24 +00:00
|
|
|
static void *music_enable(void *data)
|
|
|
|
{
|
|
|
|
return ast_strdup(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int music_disable(void *data)
|
|
|
|
{
|
|
|
|
if (!data)
|
|
|
|
return -1;
|
|
|
|
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(data);
|
2007-04-10 19:16:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-09 22:17:14 +00:00
|
|
|
static void *predial_enable(void *data)
|
|
|
|
{
|
|
|
|
return ast_strdup(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int predial_disable(void *data)
|
|
|
|
{
|
|
|
|
if (!data) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_free(data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-05-16 07:08:48 +00:00
|
|
|
/*! \brief Application execution function for 'ANSWER_EXEC' option */
|
2007-11-26 21:14:07 +00:00
|
|
|
static void answer_exec_run(struct ast_dial *dial, struct ast_dial_channel *dial_channel, char *app, char *args)
|
2007-01-24 18:23:07 +00:00
|
|
|
{
|
2007-11-26 21:14:07 +00:00
|
|
|
struct ast_channel *chan = dial_channel->owner;
|
2007-01-24 18:23:07 +00:00
|
|
|
struct ast_app *ast_app = pbx_findapp(app);
|
|
|
|
|
|
|
|
/* If the application was not found, return immediately */
|
|
|
|
if (!ast_app)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* All is well... execute the application */
|
|
|
|
pbx_exec(chan, ast_app, args);
|
|
|
|
|
2007-11-26 21:14:07 +00:00
|
|
|
/* If another thread is not taking over hang up the channel */
|
2008-01-16 15:09:37 +00:00
|
|
|
ast_mutex_lock(&dial->lock);
|
2007-11-26 21:14:07 +00:00
|
|
|
if (dial->thread != AST_PTHREADT_STOP) {
|
|
|
|
ast_hangup(chan);
|
|
|
|
dial_channel->owner = NULL;
|
|
|
|
}
|
2008-01-16 15:09:37 +00:00
|
|
|
ast_mutex_unlock(&dial->lock);
|
2007-11-26 21:14:07 +00:00
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-05 18:13:09 +00:00
|
|
|
struct ast_option_types {
|
2007-01-24 18:23:07 +00:00
|
|
|
enum ast_dial_option option;
|
|
|
|
ast_dial_option_cb_enable enable;
|
|
|
|
ast_dial_option_cb_disable disable;
|
2013-02-05 18:13:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Map options to respective handlers (enable/disable).
|
|
|
|
*
|
|
|
|
* \note This list MUST be perfectly kept in order with enum
|
|
|
|
* ast_dial_option, or else madness will happen.
|
|
|
|
*/
|
|
|
|
static const struct ast_option_types option_types[] = {
|
2007-04-10 19:16:24 +00:00
|
|
|
{ AST_DIAL_OPTION_RINGING, NULL, NULL }, /*!< Always indicate ringing to caller */
|
|
|
|
{ AST_DIAL_OPTION_ANSWER_EXEC, answer_exec_enable, answer_exec_disable }, /*!< Execute application upon answer in async mode */
|
|
|
|
{ AST_DIAL_OPTION_MUSIC, music_enable, music_disable }, /*!< Play music to the caller instead of ringing */
|
2007-07-30 20:42:28 +00:00
|
|
|
{ AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, NULL, NULL }, /*!< Disable call forwarding on channels */
|
2013-12-09 22:17:14 +00:00
|
|
|
{ AST_DIAL_OPTION_PREDIAL, predial_enable, predial_disable }, /*!< Execute a subroutine on the outbound channels prior to dialing */
|
2014-09-05 20:22:12 +00:00
|
|
|
{ AST_DIAL_OPTION_DIAL_REPLACES_SELF, NULL, NULL }, /*!< The dial operation is a replacement for the requester */
|
Dial API: add self destruct option when complete
This patch adds a self-destruction option to the
dial api. The usefulness of this is mostly when
using async mode to spawn a separate thread used
to handle the new call, while the calling thread
is allowed to go on about other business.
The only alternative to this option would be the
calling thread spawning a new thread, or hanging
around itself waiting to destroy the dial struct
after completion.
Example of use (minus error checking):
struct ast_dial *dial = ast_dial_create();
ast_dial_append(dial, "PJSIP", "200", NULL);
ast_dial_option_global_enable(dial, AST_DIAL_OPTION_ANSWER_EXEC, "Echo");
ast_dial_option_global_enable(dial, AST_DIAL_OPTION_SELF_DESTROY, NULL);
ast_dial_run(dial, NULL, 1);
The dial_run call will return almost immediately
after spawning the new thread to run and monitor
the dial. If the call is answered, it is placed
into the echo app. When completed, it will call
ast_dial_destroy() on the dial structure.
Note that any allocations made to pass values to
ast_dial_set_user_data() or dial options must be
free'd in a state callback function on any of:
AST_DIAL_RESULT_UNASWERED,
AST_DIAL_RESULT_ANSWERED,
AST_DIAL_RESULT_HANGUP, or
AST_DIAL_RESULT_TIMEOUT.
Review: https://reviewboard.asterisk.org/r/4443/
........
Merged revisions 432385 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@432386 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-02-26 18:53:36 +00:00
|
|
|
{ AST_DIAL_OPTION_SELF_DESTROY, NULL, NULL}, /*!< Destroy self at end of ast_dial_run */
|
2007-04-10 19:16:24 +00:00
|
|
|
{ AST_DIAL_OPTION_MAX, NULL, NULL }, /*!< Terminator of list */
|
2007-01-24 18:23:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*! \brief Maximum number of channels we can watch at a time */
|
|
|
|
#define AST_MAX_WATCHERS 256
|
|
|
|
|
|
|
|
/*! \brief Macro for finding the option structure to use on a dialed channel */
|
|
|
|
#define FIND_RELATIVE_OPTION(dial, dial_channel, ast_dial_option) (dial_channel->options[ast_dial_option] ? dial_channel->options[ast_dial_option] : dial->options[ast_dial_option])
|
|
|
|
|
|
|
|
/*! \brief Macro that determines whether a channel is the caller or not */
|
|
|
|
#define IS_CALLER(chan, owner) (chan == owner ? 1 : 0)
|
|
|
|
|
|
|
|
/*! \brief New dialing structure
|
|
|
|
* \note Create a dialing structure
|
|
|
|
* \return Returns a calloc'd ast_dial structure, NULL on failure
|
|
|
|
*/
|
|
|
|
struct ast_dial *ast_dial_create(void)
|
|
|
|
{
|
|
|
|
struct ast_dial *dial = NULL;
|
|
|
|
|
|
|
|
/* Allocate new memory for structure */
|
|
|
|
if (!(dial = ast_calloc(1, sizeof(*dial))))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Initialize list of channels */
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_HEAD_INIT(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
|
|
|
|
/* Initialize thread to NULL */
|
|
|
|
dial->thread = AST_PTHREADT_NULL;
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/* No timeout exists... yet */
|
|
|
|
dial->timeout = -1;
|
|
|
|
dial->actual_timeout = -1;
|
|
|
|
|
2008-01-16 15:09:37 +00:00
|
|
|
/* Can't forget about the lock */
|
|
|
|
ast_mutex_init(&dial->lock);
|
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
return dial;
|
|
|
|
}
|
|
|
|
|
2016-03-30 21:47:15 +00:00
|
|
|
static int dial_append_common(struct ast_dial *dial, struct ast_dial_channel *channel,
|
|
|
|
const char *tech, const char *device, const struct ast_assigned_ids *assignedids)
|
2007-01-24 18:23:07 +00:00
|
|
|
{
|
|
|
|
/* Record technology and device for when we actually dial */
|
2007-07-30 20:42:28 +00:00
|
|
|
channel->tech = ast_strdup(tech);
|
|
|
|
channel->device = ast_strdup(device);
|
2007-01-24 18:23:07 +00:00
|
|
|
|
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and
much change was necessary to accomplish it. Channel uniqueids
and linkedids are split into separate string and creation time
components without breaking linkedid propgation. This allowed
the uniqueid to be specified by the user interface - and those
values are now carried through to channel creation, adding the
assignedids value to every function in the chain including the
channel drivers. For local channels, the second channel can be
specified or left to default to a ;2 suffix of first. In ARI,
bridge, playback, and snoop objects can also be created with a
specified uniqueid.
Along the way, the args order to allocating channels was fixed
in chan_mgcp and chan_gtalk, and linkedid is no longer lost as
masquerade occurs.
(closes issue ASTERISK-23120)
Review: https://reviewboard.asterisk.org/r/3191/
........
Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-03-07 15:47:55 +00:00
|
|
|
/* Store the assigned id */
|
2014-03-20 16:35:57 +00:00
|
|
|
if (assignedids && !ast_strlen_zero(assignedids->uniqueid)) {
|
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and
much change was necessary to accomplish it. Channel uniqueids
and linkedids are split into separate string and creation time
components without breaking linkedid propgation. This allowed
the uniqueid to be specified by the user interface - and those
values are now carried through to channel creation, adding the
assignedids value to every function in the chain including the
channel drivers. For local channels, the second channel can be
specified or left to default to a ;2 suffix of first. In ARI,
bridge, playback, and snoop objects can also be created with a
specified uniqueid.
Along the way, the args order to allocating channels was fixed
in chan_mgcp and chan_gtalk, and linkedid is no longer lost as
masquerade occurs.
(closes issue ASTERISK-23120)
Review: https://reviewboard.asterisk.org/r/3191/
........
Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-03-07 15:47:55 +00:00
|
|
|
channel->assignedid1 = ast_strdup(assignedids->uniqueid);
|
|
|
|
|
|
|
|
if (!ast_strlen_zero(assignedids->uniqueid2)) {
|
|
|
|
channel->assignedid2 = ast_strdup(assignedids->uniqueid2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Grab reference number from dial structure */
|
|
|
|
channel->num = ast_atomic_fetchadd_int(&dial->num, +1);
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/* No timeout exists... yet */
|
|
|
|
channel->timeout = -1;
|
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Insert into channels list */
|
|
|
|
AST_LIST_INSERT_TAIL(&dial->channels, channel, list);
|
|
|
|
|
|
|
|
return channel->num;
|
2016-03-30 21:47:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Append a channel
|
|
|
|
* \note Appends a channel to a dialing structure
|
|
|
|
* \return Returns channel reference number on success, -1 on failure
|
|
|
|
*/
|
|
|
|
int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device, const struct ast_assigned_ids *assignedids)
|
|
|
|
{
|
|
|
|
struct ast_dial_channel *channel = NULL;
|
|
|
|
|
|
|
|
/* Make sure we have required arguments */
|
|
|
|
if (!dial || !tech || !device)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Allocate new memory for dialed channel structure */
|
|
|
|
if (!(channel = ast_calloc(1, sizeof(*channel))))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return dial_append_common(dial, channel, tech, device, assignedids);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ast_dial_append_channel(struct ast_dial *dial, struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
struct ast_dial_channel *channel;
|
|
|
|
char *tech;
|
|
|
|
char *device;
|
|
|
|
char *dash;
|
|
|
|
|
|
|
|
if (!dial || !chan) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel = ast_calloc(1, sizeof(*channel));
|
|
|
|
if (!channel) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
channel->owner = chan;
|
|
|
|
|
|
|
|
tech = ast_strdupa(ast_channel_name(chan));
|
|
|
|
|
|
|
|
device = strchr(tech, '/');
|
|
|
|
if (!device) {
|
|
|
|
ast_free(channel);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*device++ = '\0';
|
|
|
|
|
|
|
|
dash = strrchr(device, '-');
|
|
|
|
if (dash) {
|
|
|
|
*dash = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
return dial_append_common(dial, channel, tech, device, NULL);
|
2007-01-24 18:23:07 +00:00
|
|
|
}
|
|
|
|
|
2013-05-18 19:47:24 +00:00
|
|
|
/*! \brief Helper function that requests all channels */
|
2013-12-09 22:17:14 +00:00
|
|
|
static int begin_dial_prerun(struct ast_dial_channel *channel, struct ast_channel *chan, struct ast_format_cap *cap, const char *predial_string)
|
2007-07-30 20:42:28 +00:00
|
|
|
{
|
|
|
|
char numsubst[AST_MAX_EXTENSION];
|
2011-02-03 16:22:10 +00:00
|
|
|
struct ast_format_cap *cap_all_audio = NULL;
|
|
|
|
struct ast_format_cap *cap_request;
|
2015-11-04 20:31:28 +00:00
|
|
|
struct ast_format_cap *requester_cap = NULL;
|
2014-03-20 16:35:57 +00:00
|
|
|
struct ast_assigned_ids assignedids = {
|
|
|
|
.uniqueid = channel->assignedid1,
|
|
|
|
.uniqueid2 = channel->assignedid2,
|
|
|
|
};
|
2007-07-30 20:42:28 +00:00
|
|
|
|
2015-04-15 15:38:02 +00:00
|
|
|
if (chan) {
|
|
|
|
int max_forwards;
|
|
|
|
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
max_forwards = ast_max_forwards_get(chan);
|
2015-11-04 20:31:28 +00:00
|
|
|
requester_cap = ao2_bump(ast_channel_nativeformats(chan));
|
2015-04-15 15:38:02 +00:00
|
|
|
ast_channel_unlock(chan);
|
|
|
|
|
|
|
|
if (max_forwards <= 0) {
|
|
|
|
ast_log(LOG_WARNING, "Cannot dial from channel '%s'. Max forwards exceeded\n",
|
|
|
|
ast_channel_name(chan));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-30 21:47:15 +00:00
|
|
|
if (!channel->owner) {
|
|
|
|
/* Copy device string over */
|
|
|
|
ast_copy_string(numsubst, channel->device, sizeof(numsubst));
|
|
|
|
|
|
|
|
if (cap && ast_format_cap_count(cap)) {
|
|
|
|
cap_request = cap;
|
|
|
|
} else if (requester_cap) {
|
|
|
|
cap_request = requester_cap;
|
|
|
|
} else {
|
|
|
|
cap_all_audio = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
|
|
|
|
ast_format_cap_append_by_type(cap_all_audio, AST_MEDIA_TYPE_AUDIO);
|
|
|
|
cap_request = cap_all_audio;
|
|
|
|
}
|
2011-02-03 16:22:10 +00:00
|
|
|
|
2016-03-30 21:47:15 +00:00
|
|
|
/* If we fail to create our owner channel bail out */
|
|
|
|
if (!(channel->owner = ast_request(channel->tech, cap_request, &assignedids, chan, numsubst, &channel->cause))) {
|
|
|
|
ao2_cleanup(cap_all_audio);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
cap_request = NULL;
|
|
|
|
ao2_cleanup(requester_cap);
|
media formats: re-architect handling of media for performance improvements
In the old times media formats were represented using a bit field. This was
fast but had a few limitations.
1. Asterisk was limited in how many formats it could handle.
2. Formats, being a bit field, could not include any attribute information.
A format was strictly its type, e.g., "this is ulaw".
This was changed in Asterisk 10 (see
https://wiki.asterisk.org/wiki/display/AST/Media+Architecture+Proposal for
notes on that work) which led to the creation of the ast_format structure.
This structure allowed Asterisk to handle attributes and bundle information
with a format.
Additionally, ast_format_cap was created to act as a container for multiple
formats that, together, formed the capability of some entity. Another
mechanism was added to allow logic to be registered which performed format
attribute negotiation. Everywhere throughout the codebase Asterisk was
changed to use this strategy.
Unfortunately, in software, there is no free lunch. These new capabilities
came at a cost.
Performance analysis and profiling showed that we spend an inordinate
amount of time comparing, copying, and generally manipulating formats and
their related structures. Basic prototyping has shown that a reasonably
large performance improvement could be made in this area. This patch is the
result of that project, which overhauled the media format architecture
and its usage in Asterisk to improve performance.
Generally, the new philosophy for handling formats is as follows:
* The ast_format structure is reference counted. This removed a large amount
of the memory allocations and copying that was done in prior versions.
* In order to prevent race conditions while keeping things performant, the
ast_format structure is immutable by convention and lock-free. Violate this
tenet at your peril!
* Because formats are reference counted, codecs are also reference counted.
The Asterisk core generally provides built-in codecs and caches the
ast_format structures created to represent them. Generally, to prevent
inordinate amounts of module reference bumping, codecs and formats can be
added at run-time but cannot be removed.
* All compatibility with the bit field representation of codecs/formats has
been moved to a compatibility API. The primary user of this representation
is chan_iax2, which must continue to maintain its bit-field usage of formats
for interoperability concerns.
* When a format is negotiated with attributes, or when a format cannot be
represented by one of the cached formats, a new format object is created or
cloned from an existing format. That format may have the same codec
underlying it, but is a different format than a version of the format with
different attributes or without attributes.
* While formats are reference counted objects, the reference count maintained
on the format should be manipulated with care. Formats are generally cached
and will persist for the lifetime of Asterisk and do not explicitly need
to have their lifetime modified. An exception to this is when the user of a
format does not know where the format came from *and* the user may outlive
the provider of the format. This occurs, for example, when a format is read
from a channel: the channel may have a format with attributes (hence,
non-cached) and the user of the format may last longer than the channel (if
the reference to the channel is released prior to the format's reference).
For more information on this work, see the API design notes:
https://wiki.asterisk.org/wiki/display/AST/Media+Format+Rewrite
Finally, this work was the culmination of a large number of developer's
efforts. Extra thanks goes to Corey Farrell, who took on a large amount of the
work in the Asterisk core, chan_sip, and was an invaluable resource in peer
reviews throughout this project.
There were a substantial number of patches contributed during this work; the
following issues/patch names simply reflect some of the work (and will cause
the release scripts to give attribution to the individuals who work on them).
Reviews:
https://reviewboard.asterisk.org/r/3814
https://reviewboard.asterisk.org/r/3808
https://reviewboard.asterisk.org/r/3805
https://reviewboard.asterisk.org/r/3803
https://reviewboard.asterisk.org/r/3801
https://reviewboard.asterisk.org/r/3798
https://reviewboard.asterisk.org/r/3800
https://reviewboard.asterisk.org/r/3794
https://reviewboard.asterisk.org/r/3793
https://reviewboard.asterisk.org/r/3792
https://reviewboard.asterisk.org/r/3791
https://reviewboard.asterisk.org/r/3790
https://reviewboard.asterisk.org/r/3789
https://reviewboard.asterisk.org/r/3788
https://reviewboard.asterisk.org/r/3787
https://reviewboard.asterisk.org/r/3786
https://reviewboard.asterisk.org/r/3784
https://reviewboard.asterisk.org/r/3783
https://reviewboard.asterisk.org/r/3778
https://reviewboard.asterisk.org/r/3774
https://reviewboard.asterisk.org/r/3775
https://reviewboard.asterisk.org/r/3772
https://reviewboard.asterisk.org/r/3761
https://reviewboard.asterisk.org/r/3754
https://reviewboard.asterisk.org/r/3753
https://reviewboard.asterisk.org/r/3751
https://reviewboard.asterisk.org/r/3750
https://reviewboard.asterisk.org/r/3748
https://reviewboard.asterisk.org/r/3747
https://reviewboard.asterisk.org/r/3746
https://reviewboard.asterisk.org/r/3742
https://reviewboard.asterisk.org/r/3740
https://reviewboard.asterisk.org/r/3739
https://reviewboard.asterisk.org/r/3738
https://reviewboard.asterisk.org/r/3737
https://reviewboard.asterisk.org/r/3736
https://reviewboard.asterisk.org/r/3734
https://reviewboard.asterisk.org/r/3722
https://reviewboard.asterisk.org/r/3713
https://reviewboard.asterisk.org/r/3703
https://reviewboard.asterisk.org/r/3689
https://reviewboard.asterisk.org/r/3687
https://reviewboard.asterisk.org/r/3674
https://reviewboard.asterisk.org/r/3671
https://reviewboard.asterisk.org/r/3667
https://reviewboard.asterisk.org/r/3665
https://reviewboard.asterisk.org/r/3625
https://reviewboard.asterisk.org/r/3602
https://reviewboard.asterisk.org/r/3519
https://reviewboard.asterisk.org/r/3518
https://reviewboard.asterisk.org/r/3516
https://reviewboard.asterisk.org/r/3515
https://reviewboard.asterisk.org/r/3512
https://reviewboard.asterisk.org/r/3506
https://reviewboard.asterisk.org/r/3413
https://reviewboard.asterisk.org/r/3410
https://reviewboard.asterisk.org/r/3387
https://reviewboard.asterisk.org/r/3388
https://reviewboard.asterisk.org/r/3389
https://reviewboard.asterisk.org/r/3390
https://reviewboard.asterisk.org/r/3321
https://reviewboard.asterisk.org/r/3320
https://reviewboard.asterisk.org/r/3319
https://reviewboard.asterisk.org/r/3318
https://reviewboard.asterisk.org/r/3266
https://reviewboard.asterisk.org/r/3265
https://reviewboard.asterisk.org/r/3234
https://reviewboard.asterisk.org/r/3178
ASTERISK-23114 #close
Reported by: mjordan
media_formats_translation_core.diff uploaded by kharwell (License 6464)
rb3506.diff uploaded by mjordan (License 6283)
media_format_app_file.diff uploaded by kharwell (License 6464)
misc-2.diff uploaded by file (License 5000)
chan_mild-3.diff uploaded by file (License 5000)
chan_obscure.diff uploaded by file (License 5000)
jingle.diff uploaded by file (License 5000)
funcs.diff uploaded by file (License 5000)
formats.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
bridges.diff uploaded by file (License 5000)
mf-codecs-2.diff uploaded by file (License 5000)
mf-app_fax.diff uploaded by file (License 5000)
mf-apps-3.diff uploaded by file (License 5000)
media-formats-3.diff uploaded by file (License 5000)
ASTERISK-23715
rb3713.patch uploaded by coreyfarrell (License 5909)
rb3689.patch uploaded by mjordan (License 6283)
ASTERISK-23957
rb3722.patch uploaded by mjordan (License 6283)
mf-attributes-3.diff uploaded by file (License 5000)
ASTERISK-23958
Tested by: jrose
rb3822.patch uploaded by coreyfarrell (License 5909)
rb3800.patch uploaded by jrose (License 6182)
chan_sip.diff uploaded by mjordan (License 6283)
rb3747.patch uploaded by jrose (License 6182)
ASTERISK-23959 #close
Tested by: sgriepentrog, mjordan, coreyfarrell
sip_cleanup.diff uploaded by opticron (License 6273)
chan_sip_caps.diff uploaded by mjordan (License 6283)
rb3751.patch uploaded by coreyfarrell (License 5909)
chan_sip-3.diff uploaded by file (License 5000)
ASTERISK-23960 #close
Tested by: opticron
direct_media.diff uploaded by opticron (License 6273)
pjsip-direct-media.diff uploaded by file (License 5000)
format_cap_remove.diff uploaded by opticron (License 6273)
media_format_fixes.diff uploaded by opticron (License 6273)
chan_pjsip-2.diff uploaded by file (License 5000)
ASTERISK-23966 #close
Tested by: rmudgett
rb3803.patch uploaded by rmudgetti (License 5621)
chan_dahdi.diff uploaded by file (License 5000)
ASTERISK-24064 #close
Tested by: coreyfarrell, mjordan, opticron, file, rmudgett, sgriepentrog, jrose
rb3814.patch uploaded by rmudgett (License 5621)
moh_cleanup.diff uploaded by opticron (License 6273)
bridge_leak.diff uploaded by opticron (License 6273)
translate.diff uploaded by file (License 5000)
rb3795.patch uploaded by rmudgett (License 5621)
tls_fix.diff uploaded by mjordan (License 6283)
fax-mf-fix-2.diff uploaded by file (License 5000)
rtp_transfer_stuff uploaded by mjordan (License 6283)
rb3787.patch uploaded by rmudgett (License 5621)
media-formats-explicit-translate-format-3.diff uploaded by file (License 5000)
format_cache_case_fix.diff uploaded by opticron (License 6273)
rb3774.patch uploaded by rmudgett (License 5621)
rb3775.patch uploaded by rmudgett (License 5621)
rtp_engine_fix.diff uploaded by opticron (License 6273)
rtp_crash_fix.diff uploaded by opticron (License 6273)
rb3753.patch uploaded by mjordan (License 6283)
rb3750.patch uploaded by mjordan (License 6283)
rb3748.patch uploaded by rmudgett (License 5621)
media_format_fixes.diff uploaded by opticron (License 6273)
rb3740.patch uploaded by mjordan (License 6283)
rb3739.patch uploaded by mjordan (License 6283)
rb3734.patch uploaded by mjordan (License 6283)
rb3689.patch uploaded by mjordan (License 6283)
rb3674.patch uploaded by coreyfarrell (License 5909)
rb3671.patch uploaded by coreyfarrell (License 5909)
rb3667.patch uploaded by coreyfarrell (License 5909)
rb3665.patch uploaded by mjordan (License 6283)
rb3625.patch uploaded by coreyfarrell (License 5909)
rb3602.patch uploaded by coreyfarrell (License 5909)
format_compatibility-2.diff uploaded by file (License 5000)
core.diff uploaded by file (License 5000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419044 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-20 22:06:33 +00:00
|
|
|
ao2_cleanup(cap_all_audio);
|
2011-02-03 16:22:10 +00:00
|
|
|
}
|
2007-07-30 20:42:28 +00:00
|
|
|
|
accountcode: Slightly change accountcode propagation.
The previous behavior was to simply set the accountcode of an outgoing
channel to the accountcode of the channel initiating the call. It was
done this way a long time ago to allow the accountcode set on the SIP/100
channel to be propagated to a local channel so the dialplan execution on
the Local;2 channel would have the SIP/100 accountcode available.
SIP/100 -> Local;1/Local;2 -> SIP/200
Propagating the SIP/100 accountcode to the local channels is very useful.
Without any dialplan manipulation, all channels in this call would have
the same accountcode.
Using dialplan, you can set a different accountcode on the SIP/200 channel
either by setting the accountcode on the Local;2 channel or by the Dial
application's b(pre-dial), M(macro) or U(gosub) options, or by the
FollowMe application's b(pre-dial) option, or by the Queue application's
macro or gosub options. Before Asterisk v12, the altered accountcode on
SIP/200 will remain until the local channels optimize out and the
accountcode would change to the SIP/100 accountcode.
Asterisk v1.8 attempted to add peeraccount support but ultimately had to
punt on the support. The peeraccount support was rendered useless because
of how the CDR code needed to unconditionally force the caller's
accountcode onto the peer channel's accountcode. The CEL events were thus
intentionally made to always use the channel's accountcode as the
peeraccount value.
With the arrival of Asterisk v12, the situation has improved somewhat so
peeraccount support can be made to work. Using the indicated example, the
the accountcode values become as follows when the peeraccount is set on
SIP/100 before calling SIP/200:
SIP/100 ---> Local;1 ---- Local;2 ---> SIP/200
acct: 100 \/ acct: 200 \/ acct: 100 \/ acct: 200
peer: 200 /\ peer: 100 /\ peer: 200 /\ peer: 100
If a channel already has an accountcode it can only change by the
following explicit user actions:
1) A channel originate method that can specify an accountcode to use.
2) The calling channel propagating its non-empty peeraccount or its
non-empty accountcode if the peeraccount was empty to the outgoing
channel's accountcode before initiating the dial. e.g., Dial and
FollowMe. The exception to this propagation method is Queue. Queue will
only propagate peeraccounts this way only if the outgoing channel does not
have an accountcode.
3) Dialplan using CHANNEL(accountcode).
4) Dialplan using CHANNEL(peeraccount) on the other end of a local
channel pair.
If a channel does not have an accountcode it can get one from the
following places:
1) The channel driver's configuration at channel creation.
2) Explicit user action as already indicated.
3) Entering a basic or stasis-mixing bridge from a peer channel's
peeraccount value.
You can specify the accountcode for an outgoing channel by setting the
CHANNEL(peeraccount) before using the Dial, FollowMe, and Queue
applications. Queue adds the wrinkle that it will not overwrite an
existing accountcode on the outgoing channel with the calling channels
values.
Accountcode and peeraccount values propagate to an outgoing channel before
dialing. Accountcodes also propagate when channels enter or leave a basic
or stasis-mixing bridge. The peeraccount value only makes sense for
mixing bridges with two channels; it is meaningless otherwise.
* Made peeraccount functional by changing accountcode propagation as
described above.
* Fixed CEL extracting the wrong ie value for the peeraccount. This was
done intentionally in Asterisk v1.8 when that version had to punt on
peeraccount.
* Fixed a few places dealing with accountcodes that were reading from
channels without the lock held.
AFS-65 #close
Review: https://reviewboard.asterisk.org/r/3601/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419520 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-24 22:48:38 +00:00
|
|
|
if (chan) {
|
|
|
|
ast_channel_lock_both(chan, channel->owner);
|
|
|
|
} else {
|
|
|
|
ast_channel_lock(channel->owner);
|
|
|
|
}
|
|
|
|
|
2013-10-02 16:23:34 +00:00
|
|
|
ast_channel_stage_snapshot(channel->owner);
|
|
|
|
|
2012-02-13 17:27:06 +00:00
|
|
|
ast_channel_appl_set(channel->owner, "AppDial2");
|
|
|
|
ast_channel_data_set(channel->owner, "(Outgoing Line)");
|
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local
channels, we noticed that there's quite a hit in performance during channel
creation and releasing to the dialplan (ARI continue). After investigating
the performance spike that occurs during channel creation, we discovered
that we create a lot of channel snapshots that are technically unnecessary.
This includes creating snapshots during:
* AGI execution
* Returning objects for ARI commands
* During some Local channel operations
* During some dialling operations
* During variable setting
* During some bridging operations
And more.
This patch does the following:
- It removes a number of fields from channel snapshots. These fields were
rarely used, were expensive to have on the snapshot, and hurt performance.
This included formats, translation paths, Log Call ID, callgroup, pickup
group, and all channel variables. As a result, AMI Status,
"core show channel", "core show channelvar", and "pjsip show channel" were
modified to either hit the live channel or not show certain pieces of data.
While this is unfortunate, the performance gain from this patch is worth
the loss in behaviour.
- It adds a mechanism to publish a cached snapshot + blob. A large number of
publications were changed to use this, including:
- During Dial begin
- During Variable assignment (if no AMI variables are emitted - if AMI
variables are set, we have to make snapshots when a variable is changed)
- During channel pickup
- When a channel is put on hold/unhold
- When a DTMF digit is begun/ended
- When creating a bridge snapshot
- When an AOC event is raised
- During Local channel optimization/Local bridging
- When endpoint snapshots are generated
- All AGI events
- All ARI responses that return a channel
- Events in the AgentPool, MeetMe, and some in Queue
- Additionally, some extraneous channel snapshots were being made that were
unnecessary. These were removed.
- The result of ast_hashtab_hash_string is now cached in stasis_cache. This
reduces a large number of calls to ast_hashtab_hash_string, which reduced
the amount of time spent in this function in gprof by around 50%.
#ASTERISK-23811 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/3568/
........
Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-06-13 18:24:49 +00:00
|
|
|
|
2012-02-29 16:52:47 +00:00
|
|
|
memset(ast_channel_whentohangup(channel->owner), 0, sizeof(*ast_channel_whentohangup(channel->owner)));
|
2007-07-30 20:42:28 +00:00
|
|
|
|
|
|
|
/* Inherit everything from he who spawned this dial */
|
|
|
|
if (chan) {
|
|
|
|
ast_channel_inherit_variables(chan, channel->owner);
|
2008-10-03 17:35:37 +00:00
|
|
|
ast_channel_datastore_inherit(chan, channel->owner);
|
2015-04-15 15:38:02 +00:00
|
|
|
ast_max_forwards_decrement(channel->owner);
|
2007-07-30 20:42:28 +00:00
|
|
|
|
|
|
|
/* Copy over callerid information */
|
2012-02-29 16:52:47 +00:00
|
|
|
ast_party_redirecting_copy(ast_channel_redirecting(channel->owner), ast_channel_redirecting(chan));
|
2009-04-03 22:41:46 +00:00
|
|
|
|
2012-02-29 16:52:47 +00:00
|
|
|
ast_channel_dialed(channel->owner)->transit_network_select = ast_channel_dialed(chan)->transit_network_select;
|
2009-04-03 22:41:46 +00:00
|
|
|
|
2012-02-29 16:52:47 +00:00
|
|
|
ast_connected_line_copy_from_caller(ast_channel_connected(channel->owner), ast_channel_caller(chan));
|
2007-07-30 20:42:28 +00:00
|
|
|
|
2012-01-24 20:12:09 +00:00
|
|
|
ast_channel_language_set(channel->owner, ast_channel_language(chan));
|
2014-09-05 20:22:12 +00:00
|
|
|
if (channel->options[AST_DIAL_OPTION_DIAL_REPLACES_SELF]) {
|
|
|
|
ast_channel_req_accountcodes(channel->owner, chan, AST_CHANNEL_REQUESTOR_REPLACEMENT);
|
|
|
|
} else {
|
|
|
|
ast_channel_req_accountcodes(channel->owner, chan, AST_CHANNEL_REQUESTOR_BRIDGE_PEER);
|
|
|
|
}
|
2012-01-24 20:12:09 +00:00
|
|
|
if (ast_strlen_zero(ast_channel_musicclass(channel->owner)))
|
|
|
|
ast_channel_musicclass_set(channel->owner, ast_channel_musicclass(chan));
|
2007-07-30 20:42:28 +00:00
|
|
|
|
2012-02-20 23:43:27 +00:00
|
|
|
ast_channel_adsicpe_set(channel->owner, ast_channel_adsicpe(chan));
|
|
|
|
ast_channel_transfercapability_set(channel->owner, ast_channel_transfercapability(chan));
|
accountcode: Slightly change accountcode propagation.
The previous behavior was to simply set the accountcode of an outgoing
channel to the accountcode of the channel initiating the call. It was
done this way a long time ago to allow the accountcode set on the SIP/100
channel to be propagated to a local channel so the dialplan execution on
the Local;2 channel would have the SIP/100 accountcode available.
SIP/100 -> Local;1/Local;2 -> SIP/200
Propagating the SIP/100 accountcode to the local channels is very useful.
Without any dialplan manipulation, all channels in this call would have
the same accountcode.
Using dialplan, you can set a different accountcode on the SIP/200 channel
either by setting the accountcode on the Local;2 channel or by the Dial
application's b(pre-dial), M(macro) or U(gosub) options, or by the
FollowMe application's b(pre-dial) option, or by the Queue application's
macro or gosub options. Before Asterisk v12, the altered accountcode on
SIP/200 will remain until the local channels optimize out and the
accountcode would change to the SIP/100 accountcode.
Asterisk v1.8 attempted to add peeraccount support but ultimately had to
punt on the support. The peeraccount support was rendered useless because
of how the CDR code needed to unconditionally force the caller's
accountcode onto the peer channel's accountcode. The CEL events were thus
intentionally made to always use the channel's accountcode as the
peeraccount value.
With the arrival of Asterisk v12, the situation has improved somewhat so
peeraccount support can be made to work. Using the indicated example, the
the accountcode values become as follows when the peeraccount is set on
SIP/100 before calling SIP/200:
SIP/100 ---> Local;1 ---- Local;2 ---> SIP/200
acct: 100 \/ acct: 200 \/ acct: 100 \/ acct: 200
peer: 200 /\ peer: 100 /\ peer: 200 /\ peer: 100
If a channel already has an accountcode it can only change by the
following explicit user actions:
1) A channel originate method that can specify an accountcode to use.
2) The calling channel propagating its non-empty peeraccount or its
non-empty accountcode if the peeraccount was empty to the outgoing
channel's accountcode before initiating the dial. e.g., Dial and
FollowMe. The exception to this propagation method is Queue. Queue will
only propagate peeraccounts this way only if the outgoing channel does not
have an accountcode.
3) Dialplan using CHANNEL(accountcode).
4) Dialplan using CHANNEL(peeraccount) on the other end of a local
channel pair.
If a channel does not have an accountcode it can get one from the
following places:
1) The channel driver's configuration at channel creation.
2) Explicit user action as already indicated.
3) Entering a basic or stasis-mixing bridge from a peer channel's
peeraccount value.
You can specify the accountcode for an outgoing channel by setting the
CHANNEL(peeraccount) before using the Dial, FollowMe, and Queue
applications. Queue adds the wrinkle that it will not overwrite an
existing accountcode on the outgoing channel with the calling channels
values.
Accountcode and peeraccount values propagate to an outgoing channel before
dialing. Accountcodes also propagate when channels enter or leave a basic
or stasis-mixing bridge. The peeraccount value only makes sense for
mixing bridges with two channels; it is meaningless otherwise.
* Made peeraccount functional by changing accountcode propagation as
described above.
* Fixed CEL extracting the wrong ie value for the peeraccount. This was
done intentionally in Asterisk v1.8 when that version had to punt on
peeraccount.
* Fixed a few places dealing with accountcodes that were reading from
channels without the lock held.
AFS-65 #close
Review: https://reviewboard.asterisk.org/r/3601/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@419520 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-07-24 22:48:38 +00:00
|
|
|
ast_channel_unlock(chan);
|
2007-07-30 20:42:28 +00:00
|
|
|
}
|
|
|
|
|
2013-10-02 16:23:34 +00:00
|
|
|
ast_channel_stage_snapshot_done(channel->owner);
|
2013-12-18 20:33:37 +00:00
|
|
|
ast_channel_unlock(channel->owner);
|
2013-10-02 16:23:34 +00:00
|
|
|
|
2013-12-09 22:17:14 +00:00
|
|
|
if (!ast_strlen_zero(predial_string)) {
|
2015-09-22 22:08:49 +00:00
|
|
|
if (chan) {
|
|
|
|
ast_autoservice_start(chan);
|
|
|
|
}
|
|
|
|
ast_pre_call(channel->owner, predial_string);
|
|
|
|
if (chan) {
|
|
|
|
ast_autoservice_stop(chan);
|
2013-12-09 22:17:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-18 19:47:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ast_dial_prerun(struct ast_dial *dial, struct ast_channel *chan, struct ast_format_cap *cap)
|
|
|
|
{
|
|
|
|
struct ast_dial_channel *channel;
|
|
|
|
int res = -1;
|
2013-12-09 22:17:14 +00:00
|
|
|
char *predial_string = dial->options[AST_DIAL_OPTION_PREDIAL];
|
|
|
|
|
2013-05-18 19:47:24 +00:00
|
|
|
AST_LIST_LOCK(&dial->channels);
|
|
|
|
AST_LIST_TRAVERSE(&dial->channels, channel, list) {
|
2013-12-09 22:17:14 +00:00
|
|
|
if ((res = begin_dial_prerun(channel, chan, cap, predial_string))) {
|
2013-05-18 19:47:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AST_LIST_UNLOCK(&dial->channels);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Helper function that does the beginning dialing per-appended channel */
|
2016-05-25 15:34:42 +00:00
|
|
|
static int begin_dial_channel(struct ast_dial_channel *channel, struct ast_channel *chan, int async, const char *predial_string, struct ast_channel *forwarder_chan)
|
2013-05-18 19:47:24 +00:00
|
|
|
{
|
|
|
|
char numsubst[AST_MAX_EXTENSION];
|
|
|
|
int res = 1;
|
2016-05-25 15:34:42 +00:00
|
|
|
char forwarder[AST_CHANNEL_NAME];
|
2013-05-18 19:47:24 +00:00
|
|
|
|
|
|
|
/* If no owner channel exists yet execute pre-run */
|
2013-12-09 22:17:14 +00:00
|
|
|
if (!channel->owner && begin_dial_prerun(channel, chan, NULL, predial_string)) {
|
2013-05-18 19:47:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-25 15:34:42 +00:00
|
|
|
if (forwarder_chan) {
|
|
|
|
ast_copy_string(forwarder, ast_channel_name(forwarder_chan), sizeof(forwarder));
|
|
|
|
ast_channel_lock(channel->owner);
|
|
|
|
pbx_builtin_setvar_helper(channel->owner, "FORWARDERNAME", forwarder);
|
|
|
|
ast_channel_unlock(channel->owner);
|
|
|
|
}
|
|
|
|
|
2013-05-18 19:47:24 +00:00
|
|
|
/* Copy device string over */
|
|
|
|
ast_copy_string(numsubst, channel->device, sizeof(numsubst));
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/* Attempt to actually call this device */
|
|
|
|
if ((res = ast_call(channel->owner, numsubst, 0))) {
|
|
|
|
res = 0;
|
|
|
|
ast_hangup(channel->owner);
|
|
|
|
channel->owner = NULL;
|
|
|
|
} else {
|
2013-06-17 03:00:38 +00:00
|
|
|
ast_channel_publish_dial(async ? NULL : chan, channel->owner, channel->device, NULL);
|
2007-07-30 20:42:28 +00:00
|
|
|
res = 1;
|
|
|
|
ast_verb(3, "Called %s\n", numsubst);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Helper function that does the beginning dialing per dial structure */
|
2013-06-17 03:00:38 +00:00
|
|
|
static int begin_dial(struct ast_dial *dial, struct ast_channel *chan, int async)
|
2007-01-24 18:23:07 +00:00
|
|
|
{
|
|
|
|
struct ast_dial_channel *channel = NULL;
|
2007-07-30 20:42:28 +00:00
|
|
|
int success = 0;
|
2013-12-09 22:17:14 +00:00
|
|
|
char *predial_string = dial->options[AST_DIAL_OPTION_PREDIAL];
|
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Iterate through channel list, requesting and calling each one */
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_LOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
AST_LIST_TRAVERSE(&dial->channels, channel, list) {
|
2016-05-25 15:34:42 +00:00
|
|
|
success += begin_dial_channel(channel, chan, async, predial_string, NULL);
|
2007-07-30 20:42:28 +00:00
|
|
|
}
|
2008-03-20 18:01:36 +00:00
|
|
|
AST_LIST_UNLOCK(&dial->channels);
|
2007-07-30 20:42:28 +00:00
|
|
|
|
|
|
|
/* If number of failures matches the number of channels, then this truly failed */
|
|
|
|
return success;
|
|
|
|
}
|
2007-01-24 18:23:07 +00:00
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/*! \brief Helper function to handle channels that have been call forwarded */
|
|
|
|
static int handle_call_forward(struct ast_dial *dial, struct ast_dial_channel *channel, struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
struct ast_channel *original = channel->owner;
|
2012-01-24 20:12:09 +00:00
|
|
|
char *tmp = ast_strdupa(ast_channel_call_forward(channel->owner));
|
2007-07-30 20:42:28 +00:00
|
|
|
char *tech = "Local", *device = tmp, *stuff;
|
2013-12-09 22:17:14 +00:00
|
|
|
char *predial_string = dial->options[AST_DIAL_OPTION_PREDIAL];
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/* If call forwarding is disabled just drop the original channel and don't attempt to dial the new one */
|
|
|
|
if (FIND_RELATIVE_OPTION(dial, channel, AST_DIAL_OPTION_DISABLE_CALL_FORWARDING)) {
|
|
|
|
ast_hangup(original);
|
|
|
|
channel->owner = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-01-24 18:23:07 +00:00
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/* Figure out the new destination */
|
|
|
|
if ((stuff = strchr(tmp, '/'))) {
|
|
|
|
*stuff++ = '\0';
|
|
|
|
tech = tmp;
|
|
|
|
device = stuff;
|
2013-09-20 22:06:07 +00:00
|
|
|
} else {
|
|
|
|
const char *forward_context;
|
|
|
|
char destination[AST_MAX_CONTEXT + AST_MAX_EXTENSION + 1];
|
|
|
|
|
|
|
|
ast_channel_lock(original);
|
|
|
|
forward_context = pbx_builtin_getvar_helper(original, "FORWARD_CONTEXT");
|
|
|
|
snprintf(destination, sizeof(destination), "%s@%s", tmp, S_OR(forward_context, ast_channel_context(original)));
|
|
|
|
ast_channel_unlock(original);
|
|
|
|
device = ast_strdupa(destination);
|
2007-07-30 20:42:28 +00:00
|
|
|
}
|
2007-01-24 18:23:07 +00:00
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/* Drop old destination information */
|
|
|
|
ast_free(channel->tech);
|
|
|
|
ast_free(channel->device);
|
2014-03-20 16:35:57 +00:00
|
|
|
ast_free(channel->assignedid1);
|
|
|
|
channel->assignedid1 = NULL;
|
|
|
|
ast_free(channel->assignedid2);
|
|
|
|
channel->assignedid2 = NULL;
|
2007-02-10 00:40:57 +00:00
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/* Update the dial channel with the new destination information */
|
|
|
|
channel->tech = ast_strdup(tech);
|
|
|
|
channel->device = ast_strdup(device);
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_UNLOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/* Drop the original channel */
|
2013-09-20 22:06:07 +00:00
|
|
|
channel->owner = NULL;
|
|
|
|
|
|
|
|
/* Finally give it a go... send it out into the world */
|
2016-05-25 15:34:42 +00:00
|
|
|
begin_dial_channel(channel, chan, chan ? 0 : 1, predial_string, original);
|
2007-07-30 20:42:28 +00:00
|
|
|
|
2013-12-14 17:19:41 +00:00
|
|
|
ast_channel_publish_dial_forward(chan, original, channel->owner, NULL, "CANCEL",
|
|
|
|
ast_channel_call_forward(original));
|
|
|
|
|
|
|
|
ast_hangup(original);
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
return 0;
|
2007-01-24 18:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Helper function that finds the dialed channel based on owner */
|
|
|
|
static struct ast_dial_channel *find_relative_dial_channel(struct ast_dial *dial, struct ast_channel *owner)
|
|
|
|
{
|
|
|
|
struct ast_dial_channel *channel = NULL;
|
|
|
|
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_LOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
AST_LIST_TRAVERSE(&dial->channels, channel, list) {
|
|
|
|
if (channel->owner == owner)
|
|
|
|
break;
|
|
|
|
}
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_UNLOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
2007-02-12 18:01:15 +00:00
|
|
|
static void set_state(struct ast_dial *dial, enum ast_dial_result state)
|
|
|
|
{
|
|
|
|
dial->state = state;
|
|
|
|
|
|
|
|
if (dial->state_callback)
|
|
|
|
dial->state_callback(dial);
|
|
|
|
}
|
|
|
|
|
2016-04-12 19:55:42 +00:00
|
|
|
/*! \brief Helper function that handles frames */
|
2007-01-24 18:23:07 +00:00
|
|
|
static void handle_frame(struct ast_dial *dial, struct ast_dial_channel *channel, struct ast_frame *fr, struct ast_channel *chan)
|
|
|
|
{
|
|
|
|
if (fr->frametype == AST_FRAME_CONTROL) {
|
2009-11-04 14:05:12 +00:00
|
|
|
switch (fr->subclass.integer) {
|
2007-01-24 18:23:07 +00:00
|
|
|
case AST_CONTROL_ANSWER:
|
2016-04-12 19:55:42 +00:00
|
|
|
if (chan) {
|
|
|
|
ast_verb(3, "%s answered %s\n", ast_channel_name(channel->owner), ast_channel_name(chan));
|
|
|
|
} else {
|
|
|
|
ast_verb(3, "%s answered\n", ast_channel_name(channel->owner));
|
|
|
|
}
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_LOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
AST_LIST_REMOVE(&dial->channels, channel, list);
|
|
|
|
AST_LIST_INSERT_HEAD(&dial->channels, channel, list);
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_UNLOCK(&dial->channels);
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_channel_publish_dial(chan, channel->owner, channel->device, "ANSWER");
|
2007-02-12 18:01:15 +00:00
|
|
|
set_state(dial, AST_DIAL_RESULT_ANSWERED);
|
2007-01-24 18:23:07 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_BUSY:
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verb(3, "%s is busy\n", ast_channel_name(channel->owner));
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_channel_publish_dial(chan, channel->owner, channel->device, "BUSY");
|
2007-01-24 18:23:07 +00:00
|
|
|
ast_hangup(channel->owner);
|
2014-04-18 16:44:48 +00:00
|
|
|
channel->cause = AST_CAUSE_USER_BUSY;
|
2007-01-24 18:23:07 +00:00
|
|
|
channel->owner = NULL;
|
|
|
|
break;
|
|
|
|
case AST_CONTROL_CONGESTION:
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verb(3, "%s is circuit-busy\n", ast_channel_name(channel->owner));
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_channel_publish_dial(chan, channel->owner, channel->device, "CONGESTION");
|
2007-01-24 18:23:07 +00:00
|
|
|
ast_hangup(channel->owner);
|
2014-04-18 16:44:48 +00:00
|
|
|
channel->cause = AST_CAUSE_NORMAL_CIRCUIT_CONGESTION;
|
2007-01-24 18:23:07 +00:00
|
|
|
channel->owner = NULL;
|
|
|
|
break;
|
2011-09-09 16:28:23 +00:00
|
|
|
case AST_CONTROL_INCOMPLETE:
|
2012-02-13 17:27:06 +00:00
|
|
|
ast_verb(3, "%s dialed Incomplete extension %s\n", ast_channel_name(channel->owner), ast_channel_exten(channel->owner));
|
2016-04-12 19:55:42 +00:00
|
|
|
if (chan) {
|
|
|
|
ast_indicate(chan, AST_CONTROL_INCOMPLETE);
|
|
|
|
} else {
|
|
|
|
ast_hangup(channel->owner);
|
|
|
|
channel->cause = AST_CAUSE_UNALLOCATED;
|
|
|
|
channel->owner = NULL;
|
|
|
|
}
|
2011-09-09 16:28:23 +00:00
|
|
|
break;
|
2007-01-24 18:23:07 +00:00
|
|
|
case AST_CONTROL_RINGING:
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verb(3, "%s is ringing\n", ast_channel_name(channel->owner));
|
2016-05-09 20:00:56 +00:00
|
|
|
ast_channel_publish_dial(chan, channel->owner, channel->device, "RINGING");
|
2016-04-12 19:55:42 +00:00
|
|
|
if (chan && !dial->options[AST_DIAL_OPTION_MUSIC])
|
2007-04-10 19:16:24 +00:00
|
|
|
ast_indicate(chan, AST_CONTROL_RINGING);
|
2007-04-24 16:17:36 +00:00
|
|
|
set_state(dial, AST_DIAL_RESULT_RINGING);
|
2007-01-24 18:23:07 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_PROGRESS:
|
2016-05-09 20:00:56 +00:00
|
|
|
ast_channel_publish_dial(chan, channel->owner, channel->device, "PROGRESS");
|
2016-04-12 19:55:42 +00:00
|
|
|
if (chan) {
|
|
|
|
ast_verb(3, "%s is making progress, passing it to %s\n", ast_channel_name(channel->owner), ast_channel_name(chan));
|
|
|
|
ast_indicate(chan, AST_CONTROL_PROGRESS);
|
|
|
|
} else {
|
|
|
|
ast_verb(3, "%s is making progress\n", ast_channel_name(channel->owner));
|
|
|
|
}
|
2007-04-24 16:17:36 +00:00
|
|
|
set_state(dial, AST_DIAL_RESULT_PROGRESS);
|
2007-01-24 18:23:07 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_VIDUPDATE:
|
2016-04-12 19:55:42 +00:00
|
|
|
if (!chan) {
|
|
|
|
break;
|
|
|
|
}
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verb(3, "%s requested a video update, passing it to %s\n", ast_channel_name(channel->owner), ast_channel_name(chan));
|
2007-01-24 18:23:07 +00:00
|
|
|
ast_indicate(chan, AST_CONTROL_VIDUPDATE);
|
|
|
|
break;
|
2008-03-05 22:43:22 +00:00
|
|
|
case AST_CONTROL_SRCUPDATE:
|
2016-04-12 19:55:42 +00:00
|
|
|
if (!chan) {
|
|
|
|
break;
|
|
|
|
}
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verb(3, "%s requested a source update, passing it to %s\n", ast_channel_name(channel->owner), ast_channel_name(chan));
|
2008-03-05 22:43:22 +00:00
|
|
|
ast_indicate(chan, AST_CONTROL_SRCUPDATE);
|
2008-03-16 21:50:58 +00:00
|
|
|
break;
|
2009-04-03 22:41:46 +00:00
|
|
|
case AST_CONTROL_CONNECTED_LINE:
|
2016-04-12 19:55:42 +00:00
|
|
|
if (!chan) {
|
|
|
|
break;
|
|
|
|
}
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verb(3, "%s connected line has changed, passing it to %s\n", ast_channel_name(channel->owner), ast_channel_name(chan));
|
2012-02-27 16:50:19 +00:00
|
|
|
if (ast_channel_connected_line_sub(channel->owner, chan, fr, 1) &&
|
|
|
|
ast_channel_connected_line_macro(channel->owner, chan, fr, 1, 1)) {
|
2009-06-01 20:57:31 +00:00
|
|
|
ast_indicate_data(chan, AST_CONTROL_CONNECTED_LINE, fr->data.ptr, fr->datalen);
|
|
|
|
}
|
2009-04-03 22:41:46 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_REDIRECTING:
|
2016-04-12 19:55:42 +00:00
|
|
|
if (!chan) {
|
|
|
|
break;
|
|
|
|
}
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verb(3, "%s redirecting info has changed, passing it to %s\n", ast_channel_name(channel->owner), ast_channel_name(chan));
|
2012-02-27 16:50:19 +00:00
|
|
|
if (ast_channel_redirecting_sub(channel->owner, chan, fr, 1) &&
|
|
|
|
ast_channel_redirecting_macro(channel->owner, chan, fr, 1, 1)) {
|
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: https://origsvn.digium.com/svn/asterisk/trunk@263541 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-05-17 15:36:31 +00:00
|
|
|
ast_indicate_data(chan, AST_CONTROL_REDIRECTING, fr->data.ptr, fr->datalen);
|
|
|
|
}
|
2009-04-03 22:41:46 +00:00
|
|
|
break;
|
2007-01-24 18:23:07 +00:00
|
|
|
case AST_CONTROL_PROCEEDING:
|
2016-05-09 20:00:56 +00:00
|
|
|
ast_channel_publish_dial(chan, channel->owner, channel->device, "PROCEEDING");
|
2016-04-12 19:55:42 +00:00
|
|
|
if (chan) {
|
|
|
|
ast_verb(3, "%s is proceeding, passing it to %s\n", ast_channel_name(channel->owner), ast_channel_name(chan));
|
|
|
|
ast_indicate(chan, AST_CONTROL_PROCEEDING);
|
|
|
|
} else {
|
|
|
|
ast_verb(3, "%s is proceeding\n", ast_channel_name(channel->owner));
|
|
|
|
}
|
2007-04-24 16:17:36 +00:00
|
|
|
set_state(dial, AST_DIAL_RESULT_PROCEEDING);
|
2007-01-24 18:23:07 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_HOLD:
|
2016-04-12 19:55:42 +00:00
|
|
|
if (!chan) {
|
|
|
|
break;
|
|
|
|
}
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(chan));
|
2014-04-18 16:44:48 +00:00
|
|
|
ast_indicate_data(chan, AST_CONTROL_HOLD, fr->data.ptr, fr->datalen);
|
2007-01-24 18:23:07 +00:00
|
|
|
break;
|
|
|
|
case AST_CONTROL_UNHOLD:
|
2016-04-12 19:55:42 +00:00
|
|
|
if (!chan) {
|
|
|
|
break;
|
|
|
|
}
|
2012-01-09 22:15:50 +00:00
|
|
|
ast_verb(3, "Call on %s left from hold\n", ast_channel_name(chan));
|
2007-01-24 18:23:07 +00:00
|
|
|
ast_indicate(chan, AST_CONTROL_UNHOLD);
|
|
|
|
break;
|
|
|
|
case AST_CONTROL_OFFHOOK:
|
|
|
|
case AST_CONTROL_FLASH:
|
|
|
|
break;
|
2012-05-14 19:44:27 +00:00
|
|
|
case AST_CONTROL_PVT_CAUSE_CODE:
|
2016-04-12 19:55:42 +00:00
|
|
|
if (chan) {
|
|
|
|
ast_indicate_data(chan, AST_CONTROL_PVT_CAUSE_CODE, fr->data.ptr, fr->datalen);
|
|
|
|
}
|
2012-05-14 19:44:27 +00:00
|
|
|
break;
|
2007-01-24 18:23:07 +00:00
|
|
|
case -1:
|
2016-04-12 19:55:42 +00:00
|
|
|
if (chan) {
|
|
|
|
/* Prod the channel */
|
|
|
|
ast_indicate(chan, -1);
|
|
|
|
}
|
2007-01-24 18:23:07 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/*! \brief Helper function to handle when a timeout occurs on dialing attempt */
|
|
|
|
static int handle_timeout_trip(struct ast_dial *dial, struct timeval start)
|
|
|
|
{
|
|
|
|
struct ast_dial_channel *channel = NULL;
|
|
|
|
int diff = ast_tvdiff_ms(ast_tvnow(), start), lowest_timeout = -1, new_timeout = -1;
|
|
|
|
|
2013-05-18 19:47:24 +00:00
|
|
|
/* If there is no difference yet return the dial timeout so we can go again, we were likely interrupted */
|
|
|
|
if (!diff) {
|
|
|
|
return dial->timeout;
|
|
|
|
}
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/* If the global dial timeout tripped switch the state to timeout so our channel loop will drop every channel */
|
|
|
|
if (diff >= dial->timeout) {
|
|
|
|
set_state(dial, AST_DIAL_RESULT_TIMEOUT);
|
|
|
|
new_timeout = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Go through dropping out channels that have met their timeout */
|
|
|
|
AST_LIST_TRAVERSE(&dial->channels, channel, list) {
|
|
|
|
if (dial->state == AST_DIAL_RESULT_TIMEOUT || diff >= channel->timeout) {
|
|
|
|
ast_hangup(channel->owner);
|
2014-04-18 16:44:48 +00:00
|
|
|
channel->cause = AST_CAUSE_NO_ANSWER;
|
2007-07-30 20:42:28 +00:00
|
|
|
channel->owner = NULL;
|
|
|
|
} else if ((lowest_timeout == -1) || (lowest_timeout > channel->timeout)) {
|
|
|
|
lowest_timeout = channel->timeout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate the new timeout using the lowest timeout found */
|
|
|
|
if (lowest_timeout >= 0)
|
|
|
|
new_timeout = lowest_timeout - diff;
|
|
|
|
|
|
|
|
return new_timeout;
|
|
|
|
}
|
|
|
|
|
2013-05-22 18:11:57 +00:00
|
|
|
const char *ast_hangup_cause_to_dial_status(int hangup_cause)
|
2013-04-08 14:26:37 +00:00
|
|
|
{
|
|
|
|
switch(hangup_cause) {
|
|
|
|
case AST_CAUSE_BUSY:
|
|
|
|
return "BUSY";
|
|
|
|
case AST_CAUSE_CONGESTION:
|
|
|
|
return "CONGESTION";
|
|
|
|
case AST_CAUSE_NO_ROUTE_DESTINATION:
|
|
|
|
case AST_CAUSE_UNREGISTERED:
|
|
|
|
return "CHANUNAVAIL";
|
|
|
|
case AST_CAUSE_NO_ANSWER:
|
|
|
|
default:
|
|
|
|
return "NOANSWER";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/*! \brief Helper function that basically keeps tabs on dialing attempts */
|
|
|
|
static enum ast_dial_result monitor_dial(struct ast_dial *dial, struct ast_channel *chan)
|
|
|
|
{
|
2007-07-30 20:42:28 +00:00
|
|
|
int timeout = -1;
|
2007-01-24 18:23:07 +00:00
|
|
|
struct ast_channel *cs[AST_MAX_WATCHERS], *who = NULL;
|
|
|
|
struct ast_dial_channel *channel = NULL;
|
|
|
|
struct answer_exec_struct *answer_exec = NULL;
|
2007-07-30 20:42:28 +00:00
|
|
|
struct timeval start;
|
2007-01-24 18:23:07 +00:00
|
|
|
|
2007-02-12 18:01:15 +00:00
|
|
|
set_state(dial, AST_DIAL_RESULT_TRYING);
|
2007-01-24 18:23:07 +00:00
|
|
|
|
2007-02-12 18:01:15 +00:00
|
|
|
/* If the "always indicate ringing" option is set, change state to ringing and indicate to the owner if present */
|
2007-01-24 18:23:07 +00:00
|
|
|
if (dial->options[AST_DIAL_OPTION_RINGING]) {
|
2007-02-12 18:01:15 +00:00
|
|
|
set_state(dial, AST_DIAL_RESULT_RINGING);
|
2007-01-24 18:23:07 +00:00
|
|
|
if (chan)
|
|
|
|
ast_indicate(chan, AST_CONTROL_RINGING);
|
2012-03-22 19:51:16 +00:00
|
|
|
} else if (chan && dial->options[AST_DIAL_OPTION_MUSIC] &&
|
2007-04-10 19:16:24 +00:00
|
|
|
!ast_strlen_zero(dial->options[AST_DIAL_OPTION_MUSIC])) {
|
2012-01-24 20:12:09 +00:00
|
|
|
char *original_moh = ast_strdupa(ast_channel_musicclass(chan));
|
2007-04-10 19:16:24 +00:00
|
|
|
ast_indicate(chan, -1);
|
2012-01-24 20:12:09 +00:00
|
|
|
ast_channel_musicclass_set(chan, dial->options[AST_DIAL_OPTION_MUSIC]);
|
2007-04-10 19:16:24 +00:00
|
|
|
ast_moh_start(chan, dial->options[AST_DIAL_OPTION_MUSIC], NULL);
|
2012-01-24 20:12:09 +00:00
|
|
|
ast_channel_musicclass_set(chan, original_moh);
|
2007-01-24 18:23:07 +00:00
|
|
|
}
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/* Record start time for timeout purposes */
|
|
|
|
start = ast_tvnow();
|
|
|
|
|
|
|
|
/* We actually figured out the maximum timeout we can do as they were added, so we can directly access the info */
|
|
|
|
timeout = dial->actual_timeout;
|
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Go into an infinite loop while we are trying */
|
2007-02-12 18:01:15 +00:00
|
|
|
while ((dial->state != AST_DIAL_RESULT_UNANSWERED) && (dial->state != AST_DIAL_RESULT_ANSWERED) && (dial->state != AST_DIAL_RESULT_HANGUP) && (dial->state != AST_DIAL_RESULT_TIMEOUT)) {
|
2007-07-30 20:42:28 +00:00
|
|
|
int pos = 0, count = 0;
|
2007-01-24 18:23:07 +00:00
|
|
|
struct ast_frame *fr = NULL;
|
|
|
|
|
|
|
|
/* Set up channel structure array */
|
|
|
|
pos = count = 0;
|
|
|
|
if (chan)
|
|
|
|
cs[pos++] = chan;
|
|
|
|
|
|
|
|
/* Add channels we are attempting to dial */
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_LOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
AST_LIST_TRAVERSE(&dial->channels, channel, list) {
|
|
|
|
if (channel->owner) {
|
|
|
|
cs[pos++] = channel->owner;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_UNLOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
|
2007-02-12 18:01:15 +00:00
|
|
|
/* If we have no outbound channels in progress, switch state to unanswered and stop */
|
2007-01-24 18:23:07 +00:00
|
|
|
if (!count) {
|
2007-02-12 18:01:15 +00:00
|
|
|
set_state(dial, AST_DIAL_RESULT_UNANSWERED);
|
2007-01-24 18:23:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Just to be safe... */
|
|
|
|
if (dial->thread == AST_PTHREADT_STOP)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Wait for frames from channels */
|
|
|
|
who = ast_waitfor_n(cs, pos, &timeout);
|
|
|
|
|
2013-04-08 14:26:37 +00:00
|
|
|
/* Check to see if our thread is being canceled */
|
2007-01-24 18:23:07 +00:00
|
|
|
if (dial->thread == AST_PTHREADT_STOP)
|
|
|
|
break;
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/* If the timeout no longer exists OR if we got no channel it basically means the timeout was tripped, so handle it */
|
|
|
|
if (!timeout || !who) {
|
|
|
|
timeout = handle_timeout_trip(dial, start);
|
2007-01-24 18:23:07 +00:00
|
|
|
continue;
|
2007-07-30 20:42:28 +00:00
|
|
|
}
|
2007-01-24 18:23:07 +00:00
|
|
|
|
|
|
|
/* Find relative dial channel */
|
|
|
|
if (!chan || !IS_CALLER(chan, who))
|
|
|
|
channel = find_relative_dial_channel(dial, who);
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/* See if this channel has been forwarded elsewhere */
|
2012-01-24 20:12:09 +00:00
|
|
|
if (!ast_strlen_zero(ast_channel_call_forward(who))) {
|
2007-07-30 20:42:28 +00:00
|
|
|
handle_call_forward(dial, channel, chan);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Attempt to read in a frame */
|
|
|
|
if (!(fr = ast_read(who))) {
|
2007-02-12 18:01:15 +00:00
|
|
|
/* If this is the caller then we switch state to hangup and stop */
|
2007-01-24 18:23:07 +00:00
|
|
|
if (chan && IS_CALLER(chan, who)) {
|
2007-02-12 18:01:15 +00:00
|
|
|
set_state(dial, AST_DIAL_RESULT_HANGUP);
|
2007-01-24 18:23:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-05-22 18:11:57 +00:00
|
|
|
ast_channel_publish_dial(chan, who, channel->device, ast_hangup_cause_to_dial_status(ast_channel_hangupcause(who)));
|
2007-01-24 18:23:07 +00:00
|
|
|
ast_hangup(who);
|
|
|
|
channel->owner = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process the frame */
|
2016-04-12 19:55:42 +00:00
|
|
|
handle_frame(dial, channel, fr, chan);
|
2007-01-24 18:23:07 +00:00
|
|
|
|
|
|
|
/* Free the received frame and start all over */
|
|
|
|
ast_frfree(fr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do post-processing from loop */
|
2007-02-12 18:01:15 +00:00
|
|
|
if (dial->state == AST_DIAL_RESULT_ANSWERED) {
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Hangup everything except that which answered */
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_LOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
AST_LIST_TRAVERSE(&dial->channels, channel, list) {
|
|
|
|
if (!channel->owner || channel->owner == who)
|
|
|
|
continue;
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_channel_publish_dial(chan, channel->owner, channel->device, "CANCEL");
|
2007-01-24 18:23:07 +00:00
|
|
|
ast_hangup(channel->owner);
|
2014-04-18 16:44:48 +00:00
|
|
|
channel->cause = AST_CAUSE_ANSWERED_ELSEWHERE;
|
2007-01-24 18:23:07 +00:00
|
|
|
channel->owner = NULL;
|
|
|
|
}
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_UNLOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
/* If ANSWER_EXEC is enabled as an option, execute application on answered channel */
|
2007-11-26 21:14:07 +00:00
|
|
|
if ((channel = find_relative_dial_channel(dial, who)) && (answer_exec = FIND_RELATIVE_OPTION(dial, channel, AST_DIAL_OPTION_ANSWER_EXEC))) {
|
|
|
|
channel->is_running_app = 1;
|
|
|
|
answer_exec_run(dial, channel, answer_exec->app, answer_exec->args);
|
|
|
|
channel->is_running_app = 0;
|
|
|
|
}
|
2007-04-10 19:16:24 +00:00
|
|
|
|
2012-03-22 19:51:16 +00:00
|
|
|
if (chan && dial->options[AST_DIAL_OPTION_MUSIC] &&
|
2007-04-10 19:16:24 +00:00
|
|
|
!ast_strlen_zero(dial->options[AST_DIAL_OPTION_MUSIC])) {
|
|
|
|
ast_moh_stop(chan);
|
|
|
|
}
|
2007-02-12 18:01:15 +00:00
|
|
|
} else if (dial->state == AST_DIAL_RESULT_HANGUP) {
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Hangup everything */
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_LOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
AST_LIST_TRAVERSE(&dial->channels, channel, list) {
|
|
|
|
if (!channel->owner)
|
|
|
|
continue;
|
2013-04-08 14:26:37 +00:00
|
|
|
ast_channel_publish_dial(chan, channel->owner, channel->device, "CANCEL");
|
2007-01-24 18:23:07 +00:00
|
|
|
ast_hangup(channel->owner);
|
2014-04-18 16:44:48 +00:00
|
|
|
channel->cause = AST_CAUSE_NORMAL_CLEARING;
|
2007-01-24 18:23:07 +00:00
|
|
|
channel->owner = NULL;
|
|
|
|
}
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_UNLOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
}
|
|
|
|
|
Dial API: add self destruct option when complete
This patch adds a self-destruction option to the
dial api. The usefulness of this is mostly when
using async mode to spawn a separate thread used
to handle the new call, while the calling thread
is allowed to go on about other business.
The only alternative to this option would be the
calling thread spawning a new thread, or hanging
around itself waiting to destroy the dial struct
after completion.
Example of use (minus error checking):
struct ast_dial *dial = ast_dial_create();
ast_dial_append(dial, "PJSIP", "200", NULL);
ast_dial_option_global_enable(dial, AST_DIAL_OPTION_ANSWER_EXEC, "Echo");
ast_dial_option_global_enable(dial, AST_DIAL_OPTION_SELF_DESTROY, NULL);
ast_dial_run(dial, NULL, 1);
The dial_run call will return almost immediately
after spawning the new thread to run and monitor
the dial. If the call is answered, it is placed
into the echo app. When completed, it will call
ast_dial_destroy() on the dial structure.
Note that any allocations made to pass values to
ast_dial_set_user_data() or dial options must be
free'd in a state callback function on any of:
AST_DIAL_RESULT_UNASWERED,
AST_DIAL_RESULT_ANSWERED,
AST_DIAL_RESULT_HANGUP, or
AST_DIAL_RESULT_TIMEOUT.
Review: https://reviewboard.asterisk.org/r/4443/
........
Merged revisions 432385 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@432386 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2015-02-26 18:53:36 +00:00
|
|
|
if (dial->options[AST_DIAL_OPTION_SELF_DESTROY]) {
|
|
|
|
enum ast_dial_result state = dial->state;
|
|
|
|
|
|
|
|
ast_dial_destroy(dial);
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2007-02-12 18:01:15 +00:00
|
|
|
return dial->state;
|
2007-01-24 18:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Dial async thread function */
|
|
|
|
static void *async_dial(void *data)
|
|
|
|
{
|
|
|
|
struct ast_dial *dial = data;
|
2012-03-29 20:01:20 +00:00
|
|
|
if (dial->callid) {
|
|
|
|
ast_callid_threadassoc_add(dial->callid);
|
|
|
|
}
|
2007-01-24 18:23:07 +00:00
|
|
|
|
|
|
|
/* This is really really simple... we basically pass monitor_dial a NULL owner and it changes it's behavior */
|
|
|
|
monitor_dial(dial, NULL);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Execute dialing synchronously or asynchronously
|
|
|
|
* \note Dials channels in a dial structure.
|
|
|
|
* \return Returns dial result code. (TRYING/INVALID/FAILED/ANSWERED/TIMEOUT/UNANSWERED).
|
|
|
|
*/
|
|
|
|
enum ast_dial_result ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, int async)
|
|
|
|
{
|
|
|
|
enum ast_dial_result res = AST_DIAL_RESULT_TRYING;
|
|
|
|
|
|
|
|
/* Ensure required arguments are passed */
|
2013-05-18 19:47:24 +00:00
|
|
|
if (!dial) {
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(1, "invalid #1\n");
|
2007-01-24 18:23:07 +00:00
|
|
|
return AST_DIAL_RESULT_INVALID;
|
2007-02-10 00:40:57 +00:00
|
|
|
}
|
2007-01-24 18:23:07 +00:00
|
|
|
|
|
|
|
/* If there are no channels to dial we can't very well try to dial them */
|
2007-02-10 00:40:57 +00:00
|
|
|
if (AST_LIST_EMPTY(&dial->channels)) {
|
2007-06-14 19:39:12 +00:00
|
|
|
ast_debug(1, "invalid #2\n");
|
2007-01-24 18:23:07 +00:00
|
|
|
return AST_DIAL_RESULT_INVALID;
|
2007-02-10 00:40:57 +00:00
|
|
|
}
|
2007-01-24 18:23:07 +00:00
|
|
|
|
|
|
|
/* Dial each requested channel */
|
2013-06-17 03:00:38 +00:00
|
|
|
if (!begin_dial(dial, chan, async))
|
2007-01-24 18:23:07 +00:00
|
|
|
return AST_DIAL_RESULT_FAILED;
|
|
|
|
|
|
|
|
/* If we are running async spawn a thread and send it away... otherwise block here */
|
|
|
|
if (async) {
|
2012-03-29 20:01:20 +00:00
|
|
|
/* reference be released at dial destruction if it isn't NULL */
|
|
|
|
dial->callid = ast_read_threadstorage_callid();
|
2007-02-22 23:12:26 +00:00
|
|
|
dial->state = AST_DIAL_RESULT_TRYING;
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Try to create a thread */
|
|
|
|
if (ast_pthread_create(&dial->thread, NULL, async_dial, dial)) {
|
|
|
|
/* Failed to create the thread - hangup all dialed channels and return failed */
|
|
|
|
ast_dial_hangup(dial);
|
|
|
|
res = AST_DIAL_RESULT_FAILED;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res = monitor_dial(dial, chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Return channel that answered
|
|
|
|
* \note Returns the Asterisk channel that answered
|
|
|
|
* \param dial Dialing structure
|
|
|
|
*/
|
|
|
|
struct ast_channel *ast_dial_answered(struct ast_dial *dial)
|
|
|
|
{
|
|
|
|
if (!dial)
|
|
|
|
return NULL;
|
|
|
|
|
2007-02-12 18:01:15 +00:00
|
|
|
return ((dial->state == AST_DIAL_RESULT_ANSWERED) ? AST_LIST_FIRST(&dial->channels)->owner : NULL);
|
2007-01-24 18:23:07 +00:00
|
|
|
}
|
|
|
|
|
2008-01-25 02:52:10 +00:00
|
|
|
/*! \brief Steal the channel that answered
|
|
|
|
* \note Returns the Asterisk channel that answered and removes it from the dialing structure
|
|
|
|
* \param dial Dialing structure
|
|
|
|
*/
|
|
|
|
struct ast_channel *ast_dial_answered_steal(struct ast_dial *dial)
|
|
|
|
{
|
|
|
|
struct ast_channel *chan = NULL;
|
|
|
|
|
|
|
|
if (!dial)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (dial->state == AST_DIAL_RESULT_ANSWERED) {
|
|
|
|
chan = AST_LIST_FIRST(&dial->channels)->owner;
|
|
|
|
AST_LIST_FIRST(&dial->channels)->owner = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return chan;
|
|
|
|
}
|
|
|
|
|
2007-02-12 18:01:15 +00:00
|
|
|
/*! \brief Return state of dial
|
|
|
|
* \note Returns the state of the dial attempt
|
2007-01-24 18:23:07 +00:00
|
|
|
* \param dial Dialing structure
|
|
|
|
*/
|
2007-02-12 18:01:15 +00:00
|
|
|
enum ast_dial_result ast_dial_state(struct ast_dial *dial)
|
2007-01-24 18:23:07 +00:00
|
|
|
{
|
2007-02-12 18:01:15 +00:00
|
|
|
return dial->state;
|
2007-01-24 18:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Cancel async thread
|
|
|
|
* \note Cancel a running async thread
|
|
|
|
* \param dial Dialing structure
|
|
|
|
*/
|
|
|
|
enum ast_dial_result ast_dial_join(struct ast_dial *dial)
|
|
|
|
{
|
|
|
|
pthread_t thread;
|
|
|
|
|
|
|
|
/* If the dial structure is not running in async, return failed */
|
|
|
|
if (dial->thread == AST_PTHREADT_NULL)
|
|
|
|
return AST_DIAL_RESULT_FAILED;
|
|
|
|
|
|
|
|
/* Record thread */
|
|
|
|
thread = dial->thread;
|
|
|
|
|
2008-01-16 15:09:37 +00:00
|
|
|
/* Boom, commence locking */
|
|
|
|
ast_mutex_lock(&dial->lock);
|
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Stop the thread */
|
|
|
|
dial->thread = AST_PTHREADT_STOP;
|
|
|
|
|
2007-11-26 21:14:07 +00:00
|
|
|
/* If the answered channel is running an application we have to soft hangup it, can't just poke the thread */
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_LOCK(&dial->channels);
|
2007-11-26 21:14:07 +00:00
|
|
|
if (AST_LIST_FIRST(&dial->channels)->is_running_app) {
|
|
|
|
struct ast_channel *chan = AST_LIST_FIRST(&dial->channels)->owner;
|
2008-02-28 20:14:04 +00:00
|
|
|
if (chan) {
|
|
|
|
ast_channel_lock(chan);
|
|
|
|
ast_softhangup(chan, AST_SOFTHANGUP_EXPLICIT);
|
|
|
|
ast_channel_unlock(chan);
|
|
|
|
}
|
2007-11-26 21:14:07 +00:00
|
|
|
} else {
|
|
|
|
/* Now we signal it with SIGURG so it will break out of it's waitfor */
|
|
|
|
pthread_kill(thread, SIGURG);
|
|
|
|
}
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_UNLOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
|
2008-01-16 15:09:37 +00:00
|
|
|
/* Yay done with it */
|
|
|
|
ast_mutex_unlock(&dial->lock);
|
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Finally wait for the thread to exit */
|
|
|
|
pthread_join(thread, NULL);
|
|
|
|
|
|
|
|
/* Yay thread is all gone */
|
|
|
|
dial->thread = AST_PTHREADT_NULL;
|
|
|
|
|
2007-02-12 18:01:15 +00:00
|
|
|
return dial->state;
|
2007-01-24 18:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Hangup channels
|
|
|
|
* \note Hangup all active channels
|
|
|
|
* \param dial Dialing structure
|
|
|
|
*/
|
|
|
|
void ast_dial_hangup(struct ast_dial *dial)
|
|
|
|
{
|
|
|
|
struct ast_dial_channel *channel = NULL;
|
|
|
|
|
|
|
|
if (!dial)
|
|
|
|
return;
|
2012-03-22 19:51:16 +00:00
|
|
|
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_LOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
AST_LIST_TRAVERSE(&dial->channels, channel, list) {
|
2013-07-17 22:30:28 +00:00
|
|
|
ast_hangup(channel->owner);
|
|
|
|
channel->owner = NULL;
|
2007-01-24 18:23:07 +00:00
|
|
|
}
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_UNLOCK(&dial->channels);
|
2007-01-24 18:23:07 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Destroys a dialing structure
|
|
|
|
* \note Destroys (free's) the given ast_dial structure
|
|
|
|
* \param dial Dialing structure to free
|
|
|
|
* \return Returns 0 on success, -1 on failure
|
|
|
|
*/
|
|
|
|
int ast_dial_destroy(struct ast_dial *dial)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
struct ast_dial_channel *channel = NULL;
|
|
|
|
|
|
|
|
if (!dial)
|
|
|
|
return -1;
|
2012-03-22 19:51:16 +00:00
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Hangup and deallocate all the dialed channels */
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_LOCK(&dial->channels);
|
2007-12-21 16:52:04 +00:00
|
|
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&dial->channels, channel, list) {
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Disable any enabled options */
|
|
|
|
for (i = 0; i < AST_DIAL_OPTION_MAX; i++) {
|
|
|
|
if (!channel->options[i])
|
|
|
|
continue;
|
|
|
|
if (option_types[i].disable)
|
|
|
|
option_types[i].disable(channel->options[i]);
|
|
|
|
channel->options[i] = NULL;
|
|
|
|
}
|
2013-07-17 22:30:28 +00:00
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Hang up channel if need be */
|
2013-07-17 22:30:28 +00:00
|
|
|
ast_hangup(channel->owner);
|
|
|
|
channel->owner = NULL;
|
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Free structure */
|
2007-07-30 20:42:28 +00:00
|
|
|
ast_free(channel->tech);
|
|
|
|
ast_free(channel->device);
|
2014-03-20 16:35:57 +00:00
|
|
|
ast_free(channel->assignedid1);
|
|
|
|
ast_free(channel->assignedid2);
|
uniqueid: channel linkedid, ami, ari object creation with id's
Much needed was a way to assign id to objects on creation, and
much change was necessary to accomplish it. Channel uniqueids
and linkedids are split into separate string and creation time
components without breaking linkedid propgation. This allowed
the uniqueid to be specified by the user interface - and those
values are now carried through to channel creation, adding the
assignedids value to every function in the chain including the
channel drivers. For local channels, the second channel can be
specified or left to default to a ;2 suffix of first. In ARI,
bridge, playback, and snoop objects can also be created with a
specified uniqueid.
Along the way, the args order to allocating channels was fixed
in chan_mgcp and chan_gtalk, and linkedid is no longer lost as
masquerade occurs.
(closes issue ASTERISK-23120)
Review: https://reviewboard.asterisk.org/r/3191/
........
Merged revisions 410157 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@410158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2014-03-07 15:47:55 +00:00
|
|
|
|
2007-12-21 17:40:44 +00:00
|
|
|
AST_LIST_REMOVE_CURRENT(list);
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(channel);
|
2007-01-24 18:23:07 +00:00
|
|
|
}
|
2007-12-21 16:52:04 +00:00
|
|
|
AST_LIST_TRAVERSE_SAFE_END;
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_UNLOCK(&dial->channels);
|
2012-03-22 19:51:16 +00:00
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Disable any enabled options globally */
|
|
|
|
for (i = 0; i < AST_DIAL_OPTION_MAX; i++) {
|
|
|
|
if (!dial->options[i])
|
|
|
|
continue;
|
|
|
|
if (option_types[i].disable)
|
|
|
|
option_types[i].disable(dial->options[i]);
|
|
|
|
dial->options[i] = NULL;
|
|
|
|
}
|
|
|
|
|
2008-01-16 15:09:37 +00:00
|
|
|
/* Lock be gone! */
|
|
|
|
ast_mutex_destroy(&dial->lock);
|
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/* Free structure */
|
2007-06-06 21:20:11 +00:00
|
|
|
ast_free(dial);
|
2007-01-24 18:23:07 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Enables an option globally
|
|
|
|
* \param dial Dial structure to enable option on
|
|
|
|
* \param option Option to enable
|
|
|
|
* \param data Data to pass to this option (not always needed)
|
|
|
|
* \return Returns 0 on success, -1 on failure
|
|
|
|
*/
|
|
|
|
int ast_dial_option_global_enable(struct ast_dial *dial, enum ast_dial_option option, void *data)
|
|
|
|
{
|
|
|
|
/* If the option is already enabled, return failure */
|
|
|
|
if (dial->options[option])
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Execute enable callback if it exists, if not simply make sure the value is set */
|
|
|
|
if (option_types[option].enable)
|
|
|
|
dial->options[option] = option_types[option].enable(data);
|
|
|
|
else
|
|
|
|
dial->options[option] = (void*)1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/*! \brief Helper function for finding a channel in a dial structure based on number
|
|
|
|
*/
|
|
|
|
static struct ast_dial_channel *find_dial_channel(struct ast_dial *dial, int num)
|
|
|
|
{
|
|
|
|
struct ast_dial_channel *channel = AST_LIST_LAST(&dial->channels);
|
|
|
|
|
|
|
|
/* We can try to predict programmer behavior, the last channel they added is probably the one they wanted to modify */
|
|
|
|
if (channel->num == num)
|
|
|
|
return channel;
|
|
|
|
|
|
|
|
/* Hrm not at the end... looking through the list it is! */
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_LOCK(&dial->channels);
|
2007-07-30 20:42:28 +00:00
|
|
|
AST_LIST_TRAVERSE(&dial->channels, channel, list) {
|
|
|
|
if (channel->num == num)
|
|
|
|
break;
|
|
|
|
}
|
2008-02-28 20:14:04 +00:00
|
|
|
AST_LIST_UNLOCK(&dial->channels);
|
2012-03-22 19:51:16 +00:00
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
2007-01-24 18:23:07 +00:00
|
|
|
/*! \brief Enables an option per channel
|
|
|
|
* \param dial Dial structure
|
|
|
|
* \param num Channel number to enable option on
|
|
|
|
* \param option Option to enable
|
|
|
|
* \param data Data to pass to this option (not always needed)
|
|
|
|
* \return Returns 0 on success, -1 on failure
|
|
|
|
*/
|
|
|
|
int ast_dial_option_enable(struct ast_dial *dial, int num, enum ast_dial_option option, void *data)
|
|
|
|
{
|
|
|
|
struct ast_dial_channel *channel = NULL;
|
|
|
|
|
|
|
|
/* Ensure we have required arguments */
|
|
|
|
if (!dial || AST_LIST_EMPTY(&dial->channels))
|
|
|
|
return -1;
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
if (!(channel = find_dial_channel(dial, num)))
|
2007-01-24 18:23:07 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* If the option is already enabled, return failure */
|
|
|
|
if (channel->options[option])
|
|
|
|
return -1;
|
|
|
|
|
2008-03-04 23:04:29 +00:00
|
|
|
/* Execute enable callback if it exists, if not simply make sure the value is set */
|
2007-01-24 18:23:07 +00:00
|
|
|
if (option_types[option].enable)
|
|
|
|
channel->options[option] = option_types[option].enable(data);
|
|
|
|
else
|
|
|
|
channel->options[option] = (void*)1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Disables an option globally
|
|
|
|
* \param dial Dial structure to disable option on
|
|
|
|
* \param option Option to disable
|
|
|
|
* \return Returns 0 on success, -1 on failure
|
|
|
|
*/
|
|
|
|
int ast_dial_option_global_disable(struct ast_dial *dial, enum ast_dial_option option)
|
|
|
|
{
|
2008-03-04 23:04:29 +00:00
|
|
|
/* If the option is not enabled, return failure */
|
|
|
|
if (!dial->options[option]) {
|
|
|
|
return -1;
|
|
|
|
}
|
2007-01-24 18:23:07 +00:00
|
|
|
|
|
|
|
/* Execute callback of option to disable if it exists */
|
|
|
|
if (option_types[option].disable)
|
|
|
|
option_types[option].disable(dial->options[option]);
|
|
|
|
|
|
|
|
/* Finally disable option on the structure */
|
|
|
|
dial->options[option] = NULL;
|
|
|
|
|
2008-03-04 23:04:29 +00:00
|
|
|
return 0;
|
2007-01-24 18:23:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Disables an option per channel
|
|
|
|
* \param dial Dial structure
|
|
|
|
* \param num Channel number to disable option on
|
|
|
|
* \param option Option to disable
|
|
|
|
* \return Returns 0 on success, -1 on failure
|
|
|
|
*/
|
|
|
|
int ast_dial_option_disable(struct ast_dial *dial, int num, enum ast_dial_option option)
|
|
|
|
{
|
|
|
|
struct ast_dial_channel *channel = NULL;
|
|
|
|
|
|
|
|
/* Ensure we have required arguments */
|
|
|
|
if (!dial || AST_LIST_EMPTY(&dial->channels))
|
|
|
|
return -1;
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
if (!(channel = find_dial_channel(dial, num)))
|
2007-01-24 18:23:07 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* If the option is not enabled, return failure */
|
|
|
|
if (!channel->options[option])
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Execute callback of option to disable it if it exists */
|
|
|
|
if (option_types[option].disable)
|
|
|
|
option_types[option].disable(channel->options[option]);
|
|
|
|
|
|
|
|
/* Finally disable the option on the structure */
|
|
|
|
channel->options[option] = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2007-02-12 18:01:15 +00:00
|
|
|
|
2013-05-18 19:47:24 +00:00
|
|
|
int ast_dial_reason(struct ast_dial *dial, int num)
|
|
|
|
{
|
|
|
|
struct ast_dial_channel *channel;
|
|
|
|
|
|
|
|
if (!dial || AST_LIST_EMPTY(&dial->channels) || !(channel = find_dial_channel(dial, num))) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return channel->cause;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ast_channel *ast_dial_get_channel(struct ast_dial *dial, int num)
|
|
|
|
{
|
|
|
|
struct ast_dial_channel *channel;
|
|
|
|
|
|
|
|
if (!dial || AST_LIST_EMPTY(&dial->channels) || !(channel = find_dial_channel(dial, num))) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return channel->owner;
|
|
|
|
}
|
|
|
|
|
2007-02-12 19:18:33 +00:00
|
|
|
void ast_dial_set_state_callback(struct ast_dial *dial, ast_dial_state_callback callback)
|
2007-02-12 18:01:15 +00:00
|
|
|
{
|
|
|
|
dial->state_callback = callback;
|
|
|
|
}
|
2007-07-30 20:42:28 +00:00
|
|
|
|
2012-03-10 20:06:46 +00:00
|
|
|
void ast_dial_set_user_data(struct ast_dial *dial, void *user_data)
|
|
|
|
{
|
|
|
|
dial->user_data = user_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *ast_dial_get_user_data(struct ast_dial *dial)
|
|
|
|
{
|
|
|
|
return dial->user_data;
|
|
|
|
}
|
|
|
|
|
2007-07-30 20:42:28 +00:00
|
|
|
/*! \brief Set the maximum time (globally) allowed for trying to ring phones
|
|
|
|
* \param dial The dial structure to apply the time limit to
|
|
|
|
* \param timeout Maximum time allowed
|
|
|
|
* \return nothing
|
|
|
|
*/
|
|
|
|
void ast_dial_set_global_timeout(struct ast_dial *dial, int timeout)
|
|
|
|
{
|
|
|
|
dial->timeout = timeout;
|
|
|
|
|
2008-10-31 20:05:46 +00:00
|
|
|
if (dial->timeout > 0 && (dial->actual_timeout > dial->timeout || dial->actual_timeout == -1))
|
2007-07-30 20:42:28 +00:00
|
|
|
dial->actual_timeout = dial->timeout;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*! \brief Set the maximum time (per channel) allowed for trying to ring the phone
|
|
|
|
* \param dial The dial structure the channel belongs to
|
|
|
|
* \param num Channel number to set timeout on
|
|
|
|
* \param timeout Maximum time allowed
|
|
|
|
* \return nothing
|
|
|
|
*/
|
|
|
|
void ast_dial_set_timeout(struct ast_dial *dial, int num, int timeout)
|
|
|
|
{
|
|
|
|
struct ast_dial_channel *channel = NULL;
|
|
|
|
|
|
|
|
if (!(channel = find_dial_channel(dial, num)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
channel->timeout = timeout;
|
|
|
|
|
2008-10-31 20:05:46 +00:00
|
|
|
if (channel->timeout > 0 && (dial->actual_timeout > channel->timeout || dial->actual_timeout == -1))
|
2007-07-30 20:42:28 +00:00
|
|
|
dial->actual_timeout = channel->timeout;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|