#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include "asterisk.h"
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/options.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/astosp.h"
#include "asterisk/app.h"
Include dependency graph for app_osplookup.c:
Go to the source code of this file.
Functions | |
char * | description (void) |
Provides a description of the module. | |
char * | key () |
Returns the ASTERISK_GPL_KEY. | |
int | load_module (void) |
Initialize the module. | |
static int | ospfinished_exec (struct ast_channel *chan, void *data) |
static int | osplookup_exec (struct ast_channel *chan, void *data) |
static int | ospnext_exec (struct ast_channel *chan, void *data) |
int | reload (void) |
Reload stuff. | |
static int | str2cause (char *cause) |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
int | usecount (void) |
Provides a usecount. | |
Variables | |
static char * | app = "OSPLookup" |
static char * | app2 = "OSPNext" |
static char * | app3 = "OSPFinish" |
static char * | descrip |
static char * | descrip2 |
static char * | descrip3 |
LOCAL_USER_DECL | |
STANDARD_LOCAL_USER | |
static char * | synopsis = "Lookup number in OSP" |
static char * | synopsis2 = "Lookup next OSP entry" |
static char * | synopsis3 = "Record OSP entry" |
static char * | tdesc = "OSP Lookup" |
Definition in file app_osplookup.c.
|
Provides a description of the module.
Definition at line 359 of file app_osplookup.c. 00360 { 00361 return tdesc; 00362 }
|
|
Returns the ASTERISK_GPL_KEY. This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:
char *key(void) { return ASTERISK_GPL_KEY; }
Definition at line 371 of file app_osplookup.c. References ASTERISK_GPL_KEY. 00372 { 00373 return ASTERISK_GPL_KEY; 00374 }
|
|
Initialize the module. Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.
Definition at line 342 of file app_osplookup.c. References ast_register_application(), ospfinished_exec(), osplookup_exec(), and ospnext_exec(). 00343 { 00344 int res; 00345 00346 res = ast_register_application(app, osplookup_exec, synopsis, descrip); 00347 res |= ast_register_application(app2, ospnext_exec, synopsis2, descrip2); 00348 res |= ast_register_application(app3, ospfinished_exec, synopsis3, descrip3); 00349 00350 return res; 00351 }
|
|
Definition at line 255 of file app_osplookup.c. References ast_cdr::answer, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_goto_if_exists(), ast_log(), ast_osp_terminate(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_channel::cdr, ast_channel::context, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_channel::name, option_priority_jumping, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), result, and str2cause(). Referenced by load_module(). 00256 { 00257 int res=0; 00258 struct localuser *u; 00259 char *temp; 00260 int cause; 00261 time_t start=0, duration=0; 00262 struct ast_osp_result result; 00263 int priority_jump = 0; 00264 AST_DECLARE_APP_ARGS(args, 00265 AST_APP_ARG(status); 00266 AST_APP_ARG(options); 00267 ); 00268 00269 if (ast_strlen_zero(data)) { 00270 ast_log(LOG_WARNING, "OSPFinish should have an argument (status[|options])\n"); 00271 return -1; 00272 } 00273 00274 LOCAL_USER_ADD(u); 00275 00276 temp = ast_strdupa(data); 00277 if (!temp) { 00278 ast_log(LOG_ERROR, "Out of memory!\n"); 00279 LOCAL_USER_REMOVE(u); 00280 return -1; 00281 } 00282 00283 AST_STANDARD_APP_ARGS(args, temp); 00284 00285 if (args.options) { 00286 if (strchr(args.options, 'j')) 00287 priority_jump = 1; 00288 } 00289 00290 if (chan->cdr) { 00291 start = chan->cdr->answer.tv_sec; 00292 if (start) 00293 duration = time(NULL) - start; 00294 else 00295 duration = 0; 00296 } else 00297 ast_log(LOG_WARNING, "OSPFinish called on channel '%s' with no CDR!\n", chan->name); 00298 00299 cause = str2cause(args.status); 00300 temp = pbx_builtin_getvar_helper(chan, "OSPHANDLE"); 00301 result.handle = -1; 00302 if (!ast_strlen_zero(temp) && (sscanf(temp, "%d", &result.handle) == 1) && (result.handle > -1)) { 00303 if (!ast_osp_terminate(result.handle, cause, start, duration)) { 00304 pbx_builtin_setvar_helper(chan, "_OSPHANDLE", ""); 00305 pbx_builtin_setvar_helper(chan, "OSPFINISHSTATUS", "SUCCESS"); 00306 res = 1; 00307 } 00308 } else { 00309 if (!res) { 00310 if (result.handle > -1) 00311 ast_log(LOG_NOTICE, "OSP Finish failed for handle '%d'\n", result.handle); 00312 else 00313 ast_log(LOG_DEBUG, "No OSP handle specified\n"); 00314 pbx_builtin_setvar_helper(chan, "OSPFINISHSTATUS", "FAILED"); 00315 } else 00316 ast_log(LOG_DEBUG, "Got hangup on '%s' while doing OSP Terminate!\n", chan->name); 00317 } 00318 if (!res) { 00319 /* Look for a "busy" place */ 00320 if (priority_jump || option_priority_jumping) 00321 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); 00322 } else if (res > 0) 00323 res = 0; 00324 LOCAL_USER_REMOVE(u); 00325 return res; 00326 }
|
|
Definition at line 119 of file app_osplookup.c. References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_goto_if_exists(), ast_log(), ast_osp_lookup(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_channel::cid, ast_callerid::cid_num, ast_channel::context, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_channel::name, option_priority_jumping, pbx_builtin_setvar_helper(), and result. Referenced by load_module(). 00120 { 00121 int res=0; 00122 struct localuser *u; 00123 char *temp; 00124 struct ast_osp_result result; 00125 int priority_jump = 0; 00126 AST_DECLARE_APP_ARGS(args, 00127 AST_APP_ARG(extension); 00128 AST_APP_ARG(provider); 00129 AST_APP_ARG(options); 00130 ); 00131 00132 if (ast_strlen_zero(data)) { 00133 ast_log(LOG_WARNING, "OSPLookup requires an argument OSPLookup(exten[|provider[|options]])\n"); 00134 return -1; 00135 } 00136 00137 LOCAL_USER_ADD(u); 00138 00139 temp = ast_strdupa(data); 00140 if (!temp) { 00141 ast_log(LOG_ERROR, "Out of memory!\n"); 00142 LOCAL_USER_REMOVE(u); 00143 return -1; 00144 } 00145 00146 AST_STANDARD_APP_ARGS(args, temp); 00147 00148 if (args.options) { 00149 if (strchr(args.options, 'j')) 00150 priority_jump = 1; 00151 } 00152 00153 ast_log(LOG_DEBUG, "Whoo hoo, looking up OSP on '%s' via '%s'\n", args.extension, args.provider ? args.provider : "<default>"); 00154 if ((res = ast_osp_lookup(chan, args.provider, args.extension, chan->cid.cid_num, &result)) > 0) { 00155 char tmp[80]; 00156 snprintf(tmp, sizeof(tmp), "%d", result.handle); 00157 pbx_builtin_setvar_helper(chan, "_OSPHANDLE", tmp); 00158 pbx_builtin_setvar_helper(chan, "_OSPTECH", result.tech); 00159 pbx_builtin_setvar_helper(chan, "_OSPDEST", result.dest); 00160 pbx_builtin_setvar_helper(chan, "_OSPTOKEN", result.token); 00161 snprintf(tmp, sizeof(tmp), "%d", result.numresults); 00162 pbx_builtin_setvar_helper(chan, "_OSPRESULTS", tmp); 00163 pbx_builtin_setvar_helper(chan, "OSPLOOKUPSTATUS", "SUCCESS"); 00164 00165 } else { 00166 if (!res) { 00167 ast_log(LOG_NOTICE, "OSP Lookup failed for '%s' (provider '%s')\n", args.extension, args.provider ? args.provider : "<default>"); 00168 pbx_builtin_setvar_helper(chan, "OSPLOOKUPSTATUS", "FAILED"); 00169 } else 00170 ast_log(LOG_DEBUG, "Got hangup on '%s' while doing OSP Lookup for '%s' (provider '%s')!\n", chan->name, args.extension, args.provider ? args.provider : "<default>" ); 00171 } 00172 if (!res) { 00173 /* Look for a "busy" place */ 00174 if (priority_jump || option_priority_jumping) 00175 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); 00176 } else if (res > 0) 00177 res = 0; 00178 LOCAL_USER_REMOVE(u); 00179 return res; 00180 }
|
|
Definition at line 182 of file app_osplookup.c. References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_goto_if_exists(), ast_log(), ast_osp_next(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_channel::context, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_channel::name, option_priority_jumping, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), result, and str2cause(). Referenced by load_module(). 00183 { 00184 int res=0; 00185 struct localuser *u; 00186 char *temp; 00187 int cause; 00188 struct ast_osp_result result; 00189 int priority_jump = 0; 00190 AST_DECLARE_APP_ARGS(args, 00191 AST_APP_ARG(cause); 00192 AST_APP_ARG(options); 00193 ); 00194 00195 if (ast_strlen_zero(data)) { 00196 ast_log(LOG_WARNING, "OSPNext should have an argument (cause[|options])\n"); 00197 return -1; 00198 } 00199 00200 LOCAL_USER_ADD(u); 00201 00202 temp = ast_strdupa(data); 00203 if (!temp) { 00204 ast_log(LOG_ERROR, "Out of memory!\n"); 00205 LOCAL_USER_REMOVE(u); 00206 return -1; 00207 } 00208 00209 AST_STANDARD_APP_ARGS(args, temp); 00210 00211 if (args.options) { 00212 if (strchr(args.options, 'j')) 00213 priority_jump = 1; 00214 } 00215 00216 cause = str2cause(args.cause); 00217 temp = pbx_builtin_getvar_helper(chan, "OSPHANDLE"); 00218 result.handle = -1; 00219 if (!ast_strlen_zero(temp) && (sscanf(temp, "%d", &result.handle) == 1) && (result.handle > -1)) { 00220 temp = pbx_builtin_getvar_helper(chan, "OSPRESULTS"); 00221 if (ast_strlen_zero(temp) || (sscanf(temp, "%d", &result.numresults) != 1)) { 00222 result.numresults = 0; 00223 } 00224 if ((res = ast_osp_next(&result, cause)) > 0) { 00225 char tmp[80]; 00226 snprintf(tmp, sizeof(tmp), "%d", result.handle); 00227 pbx_builtin_setvar_helper(chan, "_OSPHANDLE", tmp); 00228 pbx_builtin_setvar_helper(chan, "_OSPTECH", result.tech); 00229 pbx_builtin_setvar_helper(chan, "_OSPDEST", result.dest); 00230 pbx_builtin_setvar_helper(chan, "_OSPTOKEN", result.token); 00231 snprintf(tmp, sizeof(tmp), "%d", result.numresults); 00232 pbx_builtin_setvar_helper(chan, "_OSPRESULTS", tmp); 00233 pbx_builtin_setvar_helper(chan, "OSPNEXTSTATUS", "SUCCESS"); 00234 } 00235 } else { 00236 if (!res) { 00237 if (result.handle < 0) 00238 ast_log(LOG_NOTICE, "OSP Lookup Next failed for handle '%d'\n", result.handle); 00239 else 00240 ast_log(LOG_DEBUG, "No OSP handle specified\n"); 00241 pbx_builtin_setvar_helper(chan, "OSPNEXTSTATUS", "FAILED"); 00242 } else 00243 ast_log(LOG_DEBUG, "Got hangup on '%s' while doing OSP Next!\n", chan->name); 00244 } 00245 if (!res) { 00246 /* Look for a "busy" place */ 00247 if (priority_jump || option_priority_jumping) 00248 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); 00249 } else if (res > 0) 00250 res = 0; 00251 LOCAL_USER_REMOVE(u); 00252 return res; 00253 }
|
|
Reload stuff. This function is where any reload routines take place. Re-read config files, change signalling, whatever is appropriate on a reload.
Definition at line 353 of file app_osplookup.c.
|
|
Definition at line 101 of file app_osplookup.c. References AST_CAUSE_BUSY, AST_CAUSE_CONGESTION, AST_CAUSE_NOANSWER, AST_CAUSE_NORMAL, ast_log(), and LOG_WARNING. Referenced by ospfinished_exec(), and ospnext_exec(). 00102 { 00103 if (!strcasecmp(cause, "BUSY")) 00104 return AST_CAUSE_BUSY; 00105 if (!strcasecmp(cause, "CONGESTION")) 00106 return AST_CAUSE_CONGESTION; 00107 if (!strcasecmp(cause, "ANSWER")) 00108 return AST_CAUSE_NORMAL; 00109 if (!strcasecmp(cause, "CANCEL")) 00110 return AST_CAUSE_NORMAL; 00111 if (!strcasecmp(cause, "NOANSWER")) 00112 return AST_CAUSE_NOANSWER; 00113 if (!strcasecmp(cause, "NOCHANAVAIL")) 00114 return AST_CAUSE_CONGESTION; 00115 ast_log(LOG_WARNING, "Unknown cause '%s', using NORMAL\n", cause); 00116 return AST_CAUSE_NORMAL; 00117 }
|
|
Cleanup all module structures, sockets, etc. This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).
Definition at line 329 of file app_osplookup.c. References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS. 00330 { 00331 int res; 00332 00333 res = ast_unregister_application(app3); 00334 res |= ast_unregister_application(app2); 00335 res |= ast_unregister_application(app); 00336 00337 STANDARD_HANGUP_LOCALUSERS; 00338 00339 return res; 00340 }
|
|
Provides a usecount. This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.
Definition at line 364 of file app_osplookup.c. References STANDARD_USECOUNT. 00365 { 00366 int res; 00367 STANDARD_USECOUNT(res); 00368 return res; 00369 }
|
|
Definition at line 52 of file app_osplookup.c. |
|
Definition at line 53 of file app_osplookup.c. |
|
Definition at line 54 of file app_osplookup.c. |
|
Definition at line 60 of file app_osplookup.c. |
|
Definition at line 76 of file app_osplookup.c. |
|
Definition at line 86 of file app_osplookup.c. |
|
Definition at line 99 of file app_osplookup.c. |
|
Definition at line 97 of file app_osplookup.c. |
|
Definition at line 56 of file app_osplookup.c. |
|
Definition at line 57 of file app_osplookup.c. |
|
Definition at line 58 of file app_osplookup.c. |
|
Definition at line 50 of file app_osplookup.c. |