#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"
Include dependency graph for app_page.c:
Go to the source code of this file.
Defines | |
#define | MAX_DIALS 128 |
Enumerations | |
enum | { PAGE_DUPLEX = (1 << 0), PAGE_QUIET = (1 << 1), PAGE_RECORD = (1 << 2) } |
Functions | |
AST_APP_OPTIONS (page_opts,{AST_APP_OPTION('d', PAGE_DUPLEX), AST_APP_OPTION('q', PAGE_QUIET), AST_APP_OPTION('r', PAGE_RECORD),}) | |
AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Page Multiple Phones") | |
static int | load_module (void) |
static int | page_exec (struct ast_channel *chan, void *data) |
static int | unload_module (void) |
Variables | |
static const char * | app_page = "Page" |
static const char * | page_descrip |
enum { ... } | page_opt_flags |
static const char * | page_synopsis = "Pages phones" |
Definition in file app_page.c.
#define MAX_DIALS 128 |
anonymous enum |
Definition at line 68 of file app_page.c.
00068 { 00069 PAGE_DUPLEX = (1 << 0), 00070 PAGE_QUIET = (1 << 1), 00071 PAGE_RECORD = (1 << 2), 00072 } page_opt_flags;
AST_APP_OPTIONS | ( | page_opts | ) |
AST_MODULE_INFO_STANDARD | ( | ASTERISK_GPL_KEY | , | |
"Page Multiple Phones" | ||||
) |
static int load_module | ( | void | ) | [static] |
Definition at line 196 of file app_page.c.
References ast_register_application(), and page_exec().
00197 { 00198 return ast_register_application(app_page, page_exec, page_synopsis, page_descrip); 00199 }
static int page_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 82 of file app_page.c.
References app, ast_app_parse_options(), AST_CHANNEL_NAME, 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_module_user_add, ast_module_user_remove, ast_random(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_test_flag, ast_waitstream(), ast_flags::flags, LOG_WARNING, MAX_DIALS, PAGE_DUPLEX, PAGE_QUIET, PAGE_RECORD, pbx_exec(), pbx_findapp(), and strsep().
Referenced by load_module().
00083 { 00084 struct ast_module_user *u; 00085 char *options, *tech, *resource, *tmp; 00086 char meetmeopts[88], originator[AST_CHANNEL_NAME]; 00087 struct ast_flags flags = { 0 }; 00088 unsigned int confid = ast_random(); 00089 struct ast_app *app; 00090 int res = 0, pos = 0, i = 0; 00091 struct ast_dial *dials[MAX_DIALS]; 00092 00093 if (ast_strlen_zero(data)) { 00094 ast_log(LOG_WARNING, "This application requires at least one argument (destination(s) to page)\n"); 00095 return -1; 00096 } 00097 00098 u = ast_module_user_add(chan); 00099 00100 if (!(app = pbx_findapp("MeetMe"))) { 00101 ast_log(LOG_WARNING, "There is no MeetMe application available!\n"); 00102 ast_module_user_remove(u); 00103 return -1; 00104 }; 00105 00106 options = ast_strdupa(data); 00107 00108 ast_copy_string(originator, chan->name, sizeof(originator)); 00109 if ((tmp = strchr(originator, '-'))) 00110 *tmp = '\0'; 00111 00112 tmp = strsep(&options, "|"); 00113 if (options) 00114 ast_app_parse_options(page_opts, &flags, NULL, options); 00115 00116 snprintf(meetmeopts, sizeof(meetmeopts), "MeetMe|%ud|%s%sqxdw(5)", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "m"), 00117 (ast_test_flag(&flags, PAGE_RECORD) ? "r" : "") ); 00118 00119 /* Go through parsing/calling each device */ 00120 while ((tech = strsep(&tmp, "&"))) { 00121 struct ast_dial *dial = NULL; 00122 00123 /* don't call the originating device */ 00124 if (!strcasecmp(tech, originator)) 00125 continue; 00126 00127 /* If no resource is available, continue on */ 00128 if (!(resource = strchr(tech, '/'))) { 00129 ast_log(LOG_WARNING, "Incomplete destination '%s' supplied.\n", tech); 00130 continue; 00131 } 00132 00133 *resource++ = '\0'; 00134 00135 /* Create a dialing structure */ 00136 if (!(dial = ast_dial_create())) { 00137 ast_log(LOG_WARNING, "Failed to create dialing structure.\n"); 00138 continue; 00139 } 00140 00141 /* Append technology and resource */ 00142 ast_dial_append(dial, tech, resource); 00143 00144 /* Set ANSWER_EXEC as global option */ 00145 ast_dial_option_global_enable(dial, AST_DIAL_OPTION_ANSWER_EXEC, meetmeopts); 00146 00147 /* Run this dial in async mode */ 00148 ast_dial_run(dial, chan, 1); 00149 00150 /* Put in our dialing array */ 00151 dials[pos++] = dial; 00152 } 00153 00154 if (!ast_test_flag(&flags, PAGE_QUIET)) { 00155 res = ast_streamfile(chan, "beep", chan->language); 00156 if (!res) 00157 res = ast_waitstream(chan, ""); 00158 } 00159 00160 if (!res) { 00161 snprintf(meetmeopts, sizeof(meetmeopts), "%ud|A%s%sqxd", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "t"), 00162 (ast_test_flag(&flags, PAGE_RECORD) ? "r" : "") ); 00163 pbx_exec(chan, app, meetmeopts); 00164 } 00165 00166 /* Go through each dial attempt cancelling, joining, and destroying */ 00167 for (i = 0; i < pos; i++) { 00168 struct ast_dial *dial = dials[i]; 00169 00170 /* We have to wait for the async thread to exit as it's possible Meetme won't throw them out immediately */ 00171 ast_dial_join(dial); 00172 00173 /* Hangup all channels */ 00174 ast_dial_hangup(dial); 00175 00176 /* Destroy dialing structure */ 00177 ast_dial_destroy(dial); 00178 } 00179 00180 ast_module_user_remove(u); 00181 00182 return -1; 00183 }
static int unload_module | ( | void | ) | [static] |
Definition at line 185 of file app_page.c.
References ast_module_user_hangup_all, and ast_unregister_application().
00186 { 00187 int res; 00188 00189 res = ast_unregister_application(app_page); 00190 00191 ast_module_user_hangup_all(); 00192 00193 return res; 00194 }
const char* app_page = "Page" [static] |
Definition at line 54 of file app_page.c.
const char* page_descrip [static] |
Definition at line 58 of file app_page.c.
enum { ... } page_opt_flags |
const char* page_synopsis = "Pages phones" [static] |
Definition at line 56 of file app_page.c.