mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-31 18:55:19 +00:00
Merge "Dial: Add function to append already-created channel."
This commit is contained in:
@@ -76,6 +76,18 @@ struct ast_dial *ast_dial_create(void);
|
|||||||
*/
|
*/
|
||||||
int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device, const struct ast_assigned_ids *assignedids);
|
int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device, const struct ast_assigned_ids *assignedids);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Append a channel using an actual channel object
|
||||||
|
*
|
||||||
|
* \param dial The ast_dial to add the channel to
|
||||||
|
* \param chan The channel to add to the dial
|
||||||
|
* \retval -1 Failure
|
||||||
|
* \retval non-zero The position of the channel in the list of dialed channels
|
||||||
|
*
|
||||||
|
* \note The chan ref is stolen with a successful return.
|
||||||
|
*/
|
||||||
|
int ast_dial_append_channel(struct ast_dial *dial, struct ast_channel *chan);
|
||||||
|
|
||||||
/*! \brief Request all appended channels, but do not dial
|
/*! \brief Request all appended channels, but do not dial
|
||||||
* \param dial Dialing structure
|
* \param dial Dialing structure
|
||||||
* \param chan Optional dialing channel
|
* \param chan Optional dialing channel
|
||||||
|
|||||||
73
main/dial.c
73
main/dial.c
@@ -248,22 +248,9 @@ struct ast_dial *ast_dial_create(void)
|
|||||||
return dial;
|
return dial;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief Append a channel
|
static int dial_append_common(struct ast_dial *dial, struct ast_dial_channel *channel,
|
||||||
* \note Appends a channel to a dialing structure
|
const char *tech, const char *device, const struct ast_assigned_ids *assignedids)
|
||||||
* \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;
|
|
||||||
|
|
||||||
/* Record technology and device for when we actually dial */
|
/* Record technology and device for when we actually dial */
|
||||||
channel->tech = ast_strdup(tech);
|
channel->tech = ast_strdup(tech);
|
||||||
channel->device = ast_strdup(device);
|
channel->device = ast_strdup(device);
|
||||||
@@ -287,6 +274,60 @@ int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device,
|
|||||||
AST_LIST_INSERT_TAIL(&dial->channels, channel, list);
|
AST_LIST_INSERT_TAIL(&dial->channels, channel, list);
|
||||||
|
|
||||||
return channel->num;
|
return channel->num;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief Helper function that requests all channels */
|
/*! \brief Helper function that requests all channels */
|
||||||
@@ -315,6 +356,7 @@ static int begin_dial_prerun(struct ast_dial_channel *channel, struct ast_channe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!channel->owner) {
|
||||||
/* Copy device string over */
|
/* Copy device string over */
|
||||||
ast_copy_string(numsubst, channel->device, sizeof(numsubst));
|
ast_copy_string(numsubst, channel->device, sizeof(numsubst));
|
||||||
|
|
||||||
@@ -336,6 +378,7 @@ static int begin_dial_prerun(struct ast_dial_channel *channel, struct ast_channe
|
|||||||
cap_request = NULL;
|
cap_request = NULL;
|
||||||
ao2_cleanup(requester_cap);
|
ao2_cleanup(requester_cap);
|
||||||
ao2_cleanup(cap_all_audio);
|
ao2_cleanup(cap_all_audio);
|
||||||
|
}
|
||||||
|
|
||||||
if (chan) {
|
if (chan) {
|
||||||
ast_channel_lock_both(chan, channel->owner);
|
ast_channel_lock_both(chan, channel->owner);
|
||||||
|
|||||||
Reference in New Issue
Block a user