Sat Aug 6 00:39:35 2011

Asterisk developer's documentation


app_page.c File Reference

page() - Paging application More...

#include "asterisk.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "asterisk/options.h"
#include "asterisk/logger.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/dial.h"
#include "asterisk/devicestate.h"

Go to the source code of this file.

Enumerations

enum  {
  PAGE_DUPLEX = (1 << 0), PAGE_QUIET = (1 << 1), PAGE_RECORD = (1 << 2), PAGE_ANNOUNCE = (1 << 3),
  PAGE_NOCALLERANNOUNCE = (1 << 4)
}
enum  { OPT_ARG_ANNOUNCE = 0, OPT_ARG_ARRAY_SIZE = 1 }

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 | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .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 }, [ 'A' ] = { .flag = PAGE_ANNOUNCE , .arg_index = OPT_ARG_ANNOUNCE + 1 }, [ 'n' ] = { .flag = PAGE_NOCALLERANNOUNCE },}
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_ANNOUNCE 
PAGE_NOCALLERANNOUNCE 

Definition at line 73 of file app_page.c.

00073      {
00074    PAGE_DUPLEX = (1 << 0),
00075    PAGE_QUIET = (1 << 1),
00076    PAGE_RECORD = (1 << 2),
00077    PAGE_ANNOUNCE = (1 << 3),
00078    PAGE_NOCALLERANNOUNCE = (1 << 4),
00079 } page_opt_flags;

anonymous enum

Enumerator:
OPT_ARG_ANNOUNCE 
OPT_ARG_ARRAY_SIZE 

Definition at line 81 of file app_page.c.

00081      {
00082    OPT_ARG_ANNOUNCE = 0,
00083    OPT_ARG_ARRAY_SIZE = 1,
00084 };


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 245 of file app_page.c.

static void __unreg_module ( void   )  [static]

Definition at line 245 of file app_page.c.

static int load_module ( void   )  [static]

Definition at line 240 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 95 of file app_page.c.

References app, ast_app_parse_options(), ast_calloc, AST_CHANNEL_NAME, ast_copy_string(), 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_free, ast_log(), ast_module_user_add, ast_module_user_remove, ast_random(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_test_flag, ast_waitstream(), ast_flags::flags, ast_channel::language, LOG_ERROR, LOG_WARNING, ast_channel::name, OPT_ARG_ANNOUNCE, OPT_ARG_ARRAY_SIZE, PAGE_ANNOUNCE, PAGE_DUPLEX, PAGE_NOCALLERANNOUNCE, page_opts, PAGE_QUIET, PAGE_RECORD, pbx_exec(), and pbx_findapp().

Referenced by load_module().

00096 {
00097    struct ast_module_user *u;
00098    char *options, *tech, *resource, *tmp, *tmp2;
00099    char meetmeopts[128], originator[AST_CHANNEL_NAME];
00100    struct ast_flags flags = { 0 };
00101    char *flag_args[OPT_ARG_ARRAY_SIZE];
00102    unsigned int confid = ast_random();
00103    struct ast_app *app;
00104    int res = 0, pos = 0, i = 0;
00105    struct ast_dial **dial_list;
00106    unsigned int num_dials;
00107 
00108    if (ast_strlen_zero(data)) {
00109       ast_log(LOG_WARNING, "This application requires at least one argument (destination(s) to page)\n");
00110       return -1;
00111    }
00112 
00113    u = ast_module_user_add(chan);
00114 
00115    if (!(app = pbx_findapp("MeetMe"))) {
00116       ast_log(LOG_WARNING, "There is no MeetMe application available!\n");
00117       ast_module_user_remove(u);
00118       return -1;
00119    };
00120 
00121    options = ast_strdupa(data);
00122 
00123    ast_copy_string(originator, chan->name, sizeof(originator));
00124    if ((tmp = strchr(originator, '-')))
00125       *tmp = '\0';
00126 
00127    tmp = strsep(&options, "|");
00128    if (options)
00129        ast_app_parse_options(page_opts, &flags, flag_args, options);
00130   
00131    if (ast_test_flag(&flags, PAGE_ANNOUNCE) && !ast_strlen_zero(flag_args[OPT_ARG_ANNOUNCE])) {
00132        snprintf(meetmeopts, sizeof(meetmeopts), "MeetMe|%ud|%s%sqxdw(5)G(%s)", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "m"),
00133            (ast_test_flag(&flags, PAGE_RECORD) ? "r" : ""), flag_args[OPT_ARG_ANNOUNCE] );
00134  
00135    } else {
00136        snprintf(meetmeopts, sizeof(meetmeopts), "MeetMe|%ud|%s%sqxdw(5)", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "m"),
00137            (ast_test_flag(&flags, PAGE_RECORD) ? "r" : "") );
00138    }
00139 
00140    /* Count number of extensions in list by number of ampersands + 1 */
00141    num_dials = 1;
00142    tmp2 = tmp;
00143    while (*tmp2) {
00144       if (*tmp2 == '&') {
00145          num_dials++;
00146       }
00147       tmp2++;
00148    }
00149 
00150    if (!(dial_list = ast_calloc(num_dials, sizeof(struct ast_dial *)))) {
00151       ast_log(LOG_ERROR, "Can't allocate %ld bytes for dial list\n", (long)(sizeof(struct ast_dial *) * num_dials));
00152       ast_module_user_remove(u);
00153       return -1;
00154    }
00155 
00156    /* Go through parsing/calling each device */
00157    while ((tech = strsep(&tmp, "&"))) {
00158       struct ast_dial *dial = NULL;
00159 
00160       /* don't call the originating device */
00161       if (!strcasecmp(tech, originator))
00162          continue;
00163 
00164       /* If no resource is available, continue on */
00165       if (!(resource = strchr(tech, '/'))) {
00166          ast_log(LOG_WARNING, "Incomplete destination '%s' supplied.\n", tech);
00167          continue;
00168       }
00169 
00170       *resource++ = '\0';
00171 
00172       /* Create a dialing structure */
00173       if (!(dial = ast_dial_create())) {
00174          ast_log(LOG_WARNING, "Failed to create dialing structure.\n");
00175          continue;
00176       }
00177 
00178       /* Append technology and resource */
00179       ast_dial_append(dial, tech, resource);
00180 
00181       /* Set ANSWER_EXEC as global option */
00182       ast_dial_option_global_enable(dial, AST_DIAL_OPTION_ANSWER_EXEC, meetmeopts);
00183 
00184       /* Run this dial in async mode */
00185       ast_dial_run(dial, chan, 1);
00186 
00187       /* Put in our dialing array */
00188       dial_list[pos++] = dial;
00189    }
00190 
00191    if (!ast_test_flag(&flags, PAGE_QUIET)) {
00192       res = ast_streamfile(chan, "beep", chan->language);
00193       if (!res)
00194          res = ast_waitstream(chan, "");
00195    }
00196 
00197    if (!res) {
00198        /* Default behaviour */
00199        snprintf(meetmeopts, sizeof(meetmeopts), "%ud|A%s%sqxd", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "t"), 
00200            (ast_test_flag(&flags, PAGE_RECORD) ? "r" : "") );
00201        if (ast_test_flag(&flags, PAGE_ANNOUNCE) && !ast_strlen_zero(flag_args[OPT_ARG_ANNOUNCE]) &&
00202       !ast_test_flag(&flags, PAGE_NOCALLERANNOUNCE)) {
00203       snprintf(meetmeopts, sizeof(meetmeopts), "%ud|A%s%sqxdG(%s)", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "t"), 
00204           (ast_test_flag(&flags, PAGE_RECORD) ? "r" : ""), flag_args[OPT_ARG_ANNOUNCE] );
00205        }
00206        pbx_exec(chan, app, meetmeopts);
00207    }
00208 
00209    /* Go through each dial attempt cancelling, joining, and destroying */
00210    for (i = 0; i < pos; i++) {
00211       struct ast_dial *dial = dial_list[i];
00212 
00213       /* We have to wait for the async thread to exit as it's possible Meetme won't throw them out immediately */
00214       ast_dial_join(dial);
00215 
00216       /* Hangup all channels */
00217       ast_dial_hangup(dial);
00218 
00219       /* Destroy dialing structure */
00220       ast_dial_destroy(dial);
00221    }
00222 
00223    ast_free(dial_list);
00224    ast_module_user_remove(u);
00225 
00226    return -1;
00227 }

static int unload_module ( void   )  [static]

Definition at line 229 of file app_page.c.

References ast_module_user_hangup_all, and ast_unregister_application().

00230 {
00231    int res;
00232 
00233    res =  ast_unregister_application(app_page);
00234 
00235    ast_module_user_hangup_all();
00236 
00237    return res;
00238 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .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 = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 245 of file app_page.c.

const char* app_page = "Page" [static]

Definition at line 55 of file app_page.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 245 of file app_page.c.

const char* page_descrip [static]

Definition at line 59 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 }, [ 'A' ] = { .flag = PAGE_ANNOUNCE , .arg_index = OPT_ARG_ANNOUNCE + 1 }, [ 'n' ] = { .flag = PAGE_NOCALLERANNOUNCE },} [static]

Definition at line 92 of file app_page.c.

Referenced by page_exec().

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

Definition at line 57 of file app_page.c.


Generated on Sat Aug 6 00:39:35 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7