Thu Jul 9 13:40:47 2009

Asterisk developer's documentation


app_page.c File Reference

page() - Paging application More...

#include "asterisk.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/file.h"
#include "asterisk/app.h"
#include "asterisk/chanvars.h"
#include "asterisk/utils.h"
#include "asterisk/devicestate.h"
#include "asterisk/dial.h"

Go to the source code of this file.

Enumerations

enum  { PAGE_DUPLEX = (1 << 0), PAGE_QUIET = (1 << 1), PAGE_RECORD = (1 << 2), PAGE_SKIP = (1 << 3) }

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int load_module (void)
static int page_exec (struct ast_channel *chan, void *data)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Page Multiple Phones" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, }
static const char * app_page = "Page"
static const struct ast_module_infoast_module_info = &__mod_info
static const char * page_descrip
enum { ... }  page_opt_flags
static struct ast_app_option page_opts [128] = { [ 'd' ] = { .flag = PAGE_DUPLEX }, [ 'q' ] = { .flag = PAGE_QUIET }, [ 'r' ] = { .flag = PAGE_RECORD }, [ 's' ] = { .flag = PAGE_SKIP },}
static const char * page_synopsis = "Pages phones"


Detailed Description

page() - Paging application

Author:
Mark Spencer <markster@digium.com>

Definition in file app_page.c.


Enumeration Type Documentation

anonymous enum

Enumerator:
PAGE_DUPLEX 
PAGE_QUIET 
PAGE_RECORD 
PAGE_SKIP 

Definition at line 62 of file app_page.c.

00062      {
00063    PAGE_DUPLEX = (1 << 0),
00064    PAGE_QUIET = (1 << 1),
00065    PAGE_RECORD = (1 << 2),
00066    PAGE_SKIP = (1 << 3),
00067 } page_opt_flags;


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 212 of file app_page.c.

static void __unreg_module ( void   )  [static]

Definition at line 212 of file app_page.c.

static int load_module ( void   )  [static]

Definition at line 207 of file app_page.c.

References ast_register_application, and page_exec().

static int page_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 77 of file app_page.c.

References app, ast_app_parse_options(), ast_calloc, AST_CHANNEL_NAME, ast_copy_string(), AST_DEVICE_NOT_INUSE, ast_device_state(), AST_DEVICE_UNKNOWN, ast_dial_append(), ast_dial_create(), ast_dial_destroy(), ast_dial_hangup(), ast_dial_join(), AST_DIAL_OPTION_ANSWER_EXEC, ast_dial_option_global_enable(), ast_dial_run(), ast_log(), ast_random(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_test_flag, ast_waitstream(), chan, devstate2str(), ast_flags::flags, ast_channel::language, LOG_ERROR, LOG_WARNING, ast_channel::name, PAGE_DUPLEX, page_opts, PAGE_QUIET, PAGE_RECORD, PAGE_SKIP, pbx_exec(), pbx_findapp(), and strsep().

Referenced by load_module().

00078 {
00079    char *options, *tech, *resource, *tmp, *tmp2;
00080    char meetmeopts[88], originator[AST_CHANNEL_NAME], *opts[0];
00081    struct ast_flags flags = { 0 };
00082    unsigned int confid = ast_random();
00083    struct ast_app *app;
00084    int res = 0, pos = 0, i = 0;
00085    struct ast_dial **dial_list;
00086    unsigned int num_dials;
00087 
00088    if (ast_strlen_zero(data)) {
00089       ast_log(LOG_WARNING, "This application requires at least one argument (destination(s) to page)\n");
00090       return -1;
00091    }
00092 
00093    if (!(app = pbx_findapp("MeetMe"))) {
00094       ast_log(LOG_WARNING, "There is no MeetMe application available!\n");
00095       return -1;
00096    };
00097 
00098    options = ast_strdupa(data);
00099 
00100    ast_copy_string(originator, chan->name, sizeof(originator));
00101    if ((tmp = strchr(originator, '-')))
00102       *tmp = '\0';
00103 
00104    tmp = strsep(&options, ",");
00105    if (options)
00106       ast_app_parse_options(page_opts, &flags, opts, options);
00107 
00108    snprintf(meetmeopts, sizeof(meetmeopts), "MeetMe,%ud,%s%sqxdw(5)", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "m"),
00109       (ast_test_flag(&flags, PAGE_RECORD) ? "r" : "") );
00110 
00111    /* Count number of extensions in list by number of ampersands + 1 */
00112    num_dials = 1;
00113    tmp2 = tmp;
00114    while (*tmp2) {
00115       if (*tmp2 == '&') {
00116          num_dials++;
00117       }
00118       tmp2++;
00119    }
00120 
00121    if (!(dial_list = ast_calloc(num_dials, sizeof(struct ast_dial *)))) {
00122       ast_log(LOG_ERROR, "Can't allocate %ld bytes for dial list\n", (long)(sizeof(struct ast_dial *) * num_dials));
00123       return -1;
00124    }
00125 
00126    /* Go through parsing/calling each device */
00127    while ((tech = strsep(&tmp, "&"))) {
00128       int state = 0;
00129       struct ast_dial *dial = NULL;
00130 
00131       /* don't call the originating device */
00132       if (!strcasecmp(tech, originator))
00133          continue;
00134 
00135       /* If no resource is available, continue on */
00136       if (!(resource = strchr(tech, '/'))) {
00137          ast_log(LOG_WARNING, "Incomplete destination '%s' supplied.\n", tech);
00138          continue;
00139       }
00140 
00141       /* Ensure device is not in use if skip option is enabled */
00142       if (ast_test_flag(&flags, PAGE_SKIP)) {
00143          state = ast_device_state(tech);
00144          if (state == AST_DEVICE_UNKNOWN) {
00145             ast_log(LOG_WARNING, "Destination '%s' has device state '%s'. Paging anyway.\n", tech, devstate2str(state));
00146          } else if (state != AST_DEVICE_NOT_INUSE) {
00147             ast_log(LOG_WARNING, "Destination '%s' has device state '%s'.\n", tech, devstate2str(state));
00148             continue;
00149          }
00150       }
00151 
00152       *resource++ = '\0';
00153 
00154       /* Create a dialing structure */
00155       if (!(dial = ast_dial_create())) {
00156          ast_log(LOG_WARNING, "Failed to create dialing structure.\n");
00157          continue;
00158       }
00159 
00160       /* Append technology and resource */
00161       ast_dial_append(dial, tech, resource);
00162 
00163       /* Set ANSWER_EXEC as global option */
00164       ast_dial_option_global_enable(dial, AST_DIAL_OPTION_ANSWER_EXEC, meetmeopts);
00165 
00166       /* Run this dial in async mode */
00167       ast_dial_run(dial, chan, 1);
00168 
00169       /* Put in our dialing array */
00170       dial_list[pos++] = dial;
00171    }
00172 
00173    if (!ast_test_flag(&flags, PAGE_QUIET)) {
00174       res = ast_streamfile(chan, "beep", chan->language);
00175       if (!res)
00176          res = ast_waitstream(chan, "");
00177    }
00178 
00179    if (!res) {
00180       snprintf(meetmeopts, sizeof(meetmeopts), "%ud,A%s%sqxd", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "t"), 
00181          (ast_test_flag(&flags, PAGE_RECORD) ? "r" : "") );
00182       pbx_exec(chan, app, meetmeopts);
00183    }
00184 
00185    /* Go through each dial attempt cancelling, joining, and destroying */
00186    for (i = 0; i < pos; i++) {
00187       struct ast_dial *dial = dial_list[i];
00188 
00189       /* We have to wait for the async thread to exit as it's possible Meetme won't throw them out immediately */
00190       ast_dial_join(dial);
00191 
00192       /* Hangup all channels */
00193       ast_dial_hangup(dial);
00194 
00195       /* Destroy dialing structure */
00196       ast_dial_destroy(dial);
00197    }
00198 
00199    return -1;
00200 }

static int unload_module ( void   )  [static]

Definition at line 202 of file app_page.c.

References ast_unregister_application().

00203 {
00204    return ast_unregister_application(app_page);
00205 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Page Multiple Phones" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } [static]

Definition at line 212 of file app_page.c.

const char* app_page = "Page" [static]

Definition at line 47 of file app_page.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 212 of file app_page.c.

const char* page_descrip [static]

Definition at line 51 of file app_page.c.

enum { ... } page_opt_flags

struct ast_app_option page_opts[128] = { [ 'd' ] = { .flag = PAGE_DUPLEX }, [ 'q' ] = { .flag = PAGE_QUIET }, [ 'r' ] = { .flag = PAGE_RECORD }, [ 's' ] = { .flag = PAGE_SKIP },} [static]

Definition at line 74 of file app_page.c.

Referenced by page_exec().

const char* page_synopsis = "Pages phones" [static]

Definition at line 49 of file app_page.c.


Generated on Thu Jul 9 13:40:47 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7