Skip to content
Snippets Groups Projects
Commit 9826fc59 authored by Joshua Colp's avatar Joshua Colp
Browse files

Merged revisions 52049 via svnmerge from

https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r52049 | file | 2007-01-24 13:20:05 -0500 (Wed, 24 Jan 2007) | 2 lines

Merge in dialing API and the app_page that uses it. (issue #BE-118)

........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@52050 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent 2396e24e
No related branches found
No related tags found
No related merge requests found
......@@ -49,6 +49,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/chanvars.h"
#include "asterisk/utils.h"
#include "asterisk/devicestate.h"
#include "asterisk/dial.h"
static const char *app_page= "Page";
......@@ -79,89 +80,18 @@ AST_APP_OPTIONS(page_opts, {
AST_APP_OPTION('s', PAGE_SKIP),
});
struct calloutdata {
char cidnum[64];
char cidname[64];
char tech[64];
char resource[256];
char meetmeopts[64];
struct ast_variable *variables;
};
static void *page_thread(void *data)
{
struct calloutdata *cd = data;
ast_pbx_outgoing_app(cd->tech, AST_FORMAT_SLINEAR, cd->resource, 30000,
"MeetMe", cd->meetmeopts, NULL, 0, cd->cidnum, cd->cidname, cd->variables, NULL, NULL);
free(cd);
return NULL;
}
static void launch_page(struct ast_channel *chan, const char *meetmeopts, const char *tech, const char *resource)
{
struct calloutdata *cd;
const char *varname;
struct ast_variable *lastvar = NULL;
struct ast_var_t *varptr;
pthread_t t;
pthread_attr_t attr;
if (!(cd = ast_calloc(1, sizeof(*cd))))
return;
/* Copy data from our page over */
ast_copy_string(cd->cidnum, chan->cid.cid_num ? chan->cid.cid_num : "", sizeof(cd->cidnum));
ast_copy_string(cd->cidname, chan->cid.cid_name ? chan->cid.cid_name : "", sizeof(cd->cidname));
ast_copy_string(cd->tech, tech, sizeof(cd->tech));
ast_copy_string(cd->resource, resource, sizeof(cd->resource));
ast_copy_string(cd->meetmeopts, meetmeopts, sizeof(cd->meetmeopts));
AST_LIST_TRAVERSE(&chan->varshead, varptr, entries) {
struct ast_variable *newvar = NULL;
if (!(varname = ast_var_full_name(varptr)) || (varname[0] != '_'))
continue;
if (varname[1] == '_')
newvar = ast_variable_new(varname, ast_var_value(varptr));
else
newvar = ast_variable_new(&varname[1], ast_var_value(varptr));
if (newvar) {
if (lastvar)
lastvar->next = newvar;
else
cd->variables = newvar;
lastvar = newvar;
}
}
/* Spawn thread to handle this page */
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
if (ast_pthread_create(&t, &attr, page_thread, cd)) {
ast_log(LOG_WARNING, "Unable to create paging thread: %s\n", strerror(errno));
free(cd);
}
return;
}
#define MAX_DIALS 128
static int page_exec(struct ast_channel *chan, void *data)
{
struct ast_module_user *u;
char *options;
char *tech, *resource;
char meetmeopts[80];
char *options, *tech, *resource, *tmp;
char meetmeopts[88], originator[AST_CHANNEL_NAME];
struct ast_flags flags = { 0 };
unsigned int confid = ast_random();
struct ast_app *app;
char *tmp;
int res=0;
char originator[AST_CHANNEL_NAME];
int res = 0, pos = 0, i = 0;
struct ast_dial *dials[MAX_DIALS];
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "This application requires at least one argument (destination(s) to page)\n");
......@@ -186,16 +116,19 @@ static int page_exec(struct ast_channel *chan, void *data)
if (options)
ast_app_parse_options(page_opts, &flags, NULL, options);
snprintf(meetmeopts, sizeof(meetmeopts), "%ud|%s%sqxdw(5)", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "m"),
snprintf(meetmeopts, sizeof(meetmeopts), "MeetMe|%ud|%s%sqxdw(5)", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "m"),
(ast_test_flag(&flags, PAGE_RECORD) ? "r" : "") );
/* Go through parsing/calling each device */
while ((tech = strsep(&tmp, "&"))) {
int state = 0;
struct ast_dial *dial = NULL;
/* don't call the originating device */
if (!strcasecmp(tech, originator))
continue;
/* If no resource is available, continue on */
if (!(resource = strchr(tech, '/'))) {
ast_log(LOG_WARNING, "Incomplete destination '%s' supplied.\n", tech);
continue;
......@@ -206,9 +139,26 @@ static int page_exec(struct ast_channel *chan, void *data)
ast_log(LOG_WARNING, "Destination '%s' has device state '%s'.\n", tech, devstate2str(state));
continue;
}
*resource++ = '\0';
launch_page(chan, meetmeopts, tech, resource);
/* Create a dialing structure */
if (!(dial = ast_dial_create())) {
ast_log(LOG_WARNING, "Failed to create dialing structure.\n");
continue;
}
/* Append technology and resource */
ast_dial_append(dial, tech, resource);
/* Set ANSWER_EXEC as global option */
ast_dial_option_global_enable(dial, AST_DIAL_OPTION_ANSWER_EXEC, meetmeopts);
/* Run this dial in async mode */
ast_dial_run(dial, chan, 1);
/* Put in our dialing array */
dials[pos++] = dial;
}
if (!ast_test_flag(&flags, PAGE_QUIET)) {
......@@ -223,6 +173,21 @@ static int page_exec(struct ast_channel *chan, void *data)
pbx_exec(chan, app, meetmeopts);
}
/* Go through each dial attempt cancelling, joining, and destroying */
for (i = 0; i < pos; i++) {
struct ast_dial *dial = dials[i];
/* If the dial is already answered, then they will/should get kicked out by Meetme */
if (ast_dial_status(dial) != AST_DIAL_RESULT_ANSWERED)
ast_dial_join(dial);
/* Hangup all channels */
ast_dial_hangup(dial);
/* Destroy dialing structure */
ast_dial_destroy(dial);
}
ast_module_user_remove(u);
return -1;
......
/*
* 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
*/
#ifndef _ASTERISK_DIAL_H
#define _ASTERISK_DIAL_H
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
/*! \brief Main dialing structure. Contains global options, channels being dialed, and more! */
struct ast_dial;
/*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
struct ast_dial_channel;
/*! \brief List of options that are applicable either globally or per dialed channel */
enum ast_dial_option {
AST_DIAL_OPTION_RINGING, /*! Always indicate ringing to caller */
AST_DIAL_OPTION_ANSWER_EXEC, /*! Execute application upon answer in async mode */
AST_DIAL_OPTION_MAX, /*! End terminator -- must always remain last */
};
/*! \brief List of return codes for dial run API calls */
enum ast_dial_result {
AST_DIAL_RESULT_INVALID = 0, /*! Invalid options were passed to run function */
AST_DIAL_RESULT_FAILED, /*! Attempts to dial failed before reaching critical state */
AST_DIAL_RESULT_TRYING, /*! Currently trying to dial */
AST_DIAL_RESULT_RINGING, /*! Dial is presently ringing */
AST_DIAL_RESULT_PROGRESS, /*! Dial is presently progressing */
AST_DIAL_RESULT_PROCEEDING, /*! Dial is presently proceeding */
AST_DIAL_RESULT_ANSWERED, /*! A channel was answered */
AST_DIAL_RESULT_TIMEOUT, /*! Timeout was tripped, nobody answered */
AST_DIAL_RESULT_HANGUP, /*! Caller hung up */
AST_DIAL_RESULT_UNANSWERED, /*! Nobody answered */
};
/*! \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);
/*! \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);
/*! \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);
/*! \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);
/*! \brief Return status of dial
* \note Returns the status of the dial attempt
* \param dial Dialing structure
*/
enum ast_dial_result ast_dial_status(struct ast_dial *dial);
/*! \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);
/*! \brief Hangup channels
* \note Hangup all active channels
* \param dial Dialing structure
*/
void ast_dial_hangup(struct ast_dial *dial);
/*! \brief Destroys a dialing structure
* \note Cancels dialing and 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);
/*! \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);
/*! \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);
/*! \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);
/*! \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);
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
#endif /* _ASTERISK_DIAL_H */
......@@ -26,7 +26,7 @@ OBJS= io.o sched.o logger.o frame.o loader.o config.o channel.o \
utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o \
strcompat.o threadstorage.o
strcompat.o threadstorage.o dial.o
# we need to link in the objects statically, not as a library, because
# otherwise modules will not have them available if none of the static
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment