#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 361 of file app_osplookup.c. References tdesc. 00362 { 00363 return tdesc; 00364 }
|
|
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 373 of file app_osplookup.c. References ASTERISK_GPL_KEY. 00374 { 00375 return ASTERISK_GPL_KEY; 00376 }
|
|
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 344 of file app_osplookup.c. References app, app2, app3, ast_register_application(), descrip, descrip2, descrip3, ospfinished_exec(), osplookup_exec(), ospnext_exec(), synopsis, synopsis2, and synopsis3. 00345 { 00346 int res; 00347 00348 res = ast_register_application(app, osplookup_exec, synopsis, descrip); 00349 res |= ast_register_application(app2, ospnext_exec, synopsis2, descrip2); 00350 res |= ast_register_application(app3, ospfinished_exec, synopsis3, descrip3); 00351 00352 return res; 00353 }
|
|
Definition at line 257 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, ast_osp_result::handle, 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(), and str2cause(). Referenced by load_module(). 00258 { 00259 int res=0; 00260 struct localuser *u; 00261 char *temp; 00262 int cause; 00263 time_t start=0, duration=0; 00264 struct ast_osp_result result; 00265 int priority_jump = 0; 00266 AST_DECLARE_APP_ARGS(args, 00267 AST_APP_ARG(status); 00268 AST_APP_ARG(options); 00269 ); 00270 00271 if (ast_strlen_zero(data)) { 00272 ast_log(LOG_WARNING, "OSPFinish should have an argument (status[|options])\n"); 00273 return -1; 00274 } 00275 00276 LOCAL_USER_ADD(u); 00277 00278 temp = ast_strdupa(data); 00279 if (!temp) { 00280 ast_log(LOG_ERROR, "Out of memory!\n"); 00281 LOCAL_USER_REMOVE(u); 00282 return -1; 00283 } 00284 00285 AST_STANDARD_APP_ARGS(args, temp); 00286 00287 if (args.options) { 00288 if (strchr(args.options, 'j')) 00289 priority_jump = 1; 00290 } 00291 00292 if (chan->cdr) { 00293 start = chan->cdr->answer.tv_sec; 00294 if (start) 00295 duration = time(NULL) - start; 00296 else 00297 duration = 0; 00298 } else 00299 ast_log(LOG_WARNING, "OSPFinish called on channel '%s' with no CDR!\n", chan->name); 00300 00301 cause = str2cause(args.status); 00302 temp = pbx_builtin_getvar_helper(chan, "OSPHANDLE"); 00303 result.handle = -1; 00304 if (!ast_strlen_zero(temp) && (sscanf(temp, "%d", &result.handle) == 1) && (result.handle > -1)) { 00305 if (!ast_osp_terminate(result.handle, cause, start, duration)) { 00306 pbx_builtin_setvar_helper(chan, "_OSPHANDLE", ""); 00307 pbx_builtin_setvar_helper(chan, "OSPFINISHSTATUS", "SUCCESS"); 00308 res = 1; 00309 } 00310 } else { 00311 if (!res) { 00312 if (result.handle > -1) 00313 ast_log(LOG_NOTICE, "OSP Finish failed for handle '%d'\n", result.handle); 00314 else 00315 ast_log(LOG_DEBUG, "No OSP handle specified\n"); 00316 pbx_builtin_setvar_helper(chan, "OSPFINISHSTATUS", "FAILED"); 00317 } else 00318 ast_log(LOG_DEBUG, "Got hangup on '%s' while doing OSP Terminate!\n", chan->name); 00319 } 00320 if (!res) { 00321 /* Look for a "busy" place */ 00322 if (priority_jump || option_priority_jumping) 00323 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); 00324 } else if (res > 0) 00325 res = 0; 00326 LOCAL_USER_REMOVE(u); 00327 return res; 00328 }
|
|
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, ast_osp_result::dest, ast_osp_result::handle, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_channel::name, ast_osp_result::numresults, option_priority_jumping, pbx_builtin_setvar_helper(), ast_osp_result::tech, and ast_osp_result::token. 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, ast_osp_result::dest, ast_osp_result::handle, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_channel::name, ast_osp_result::numresults, option_priority_jumping, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), str2cause(), ast_osp_result::tech, and ast_osp_result::token. 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)) { 00220 result.handle = -1; 00221 } 00222 temp = pbx_builtin_getvar_helper(chan, "OSPRESULTS"); 00223 if (ast_strlen_zero(temp) || (sscanf(temp, "%d", &result.numresults) != 1)) { 00224 result.numresults = 0; 00225 } 00226 if ((res = ast_osp_next(&result, cause)) > 0) { 00227 char tmp[80]; 00228 snprintf(tmp, sizeof(tmp), "%d", result.handle); 00229 pbx_builtin_setvar_helper(chan, "_OSPHANDLE", tmp); 00230 pbx_builtin_setvar_helper(chan, "_OSPTECH", result.tech); 00231 pbx_builtin_setvar_helper(chan, "_OSPDEST", result.dest); 00232 pbx_builtin_setvar_helper(chan, "_OSPTOKEN", result.token); 00233 snprintf(tmp, sizeof(tmp), "%d", result.numresults); 00234 pbx_builtin_setvar_helper(chan, "_OSPRESULTS", tmp); 00235 pbx_builtin_setvar_helper(chan, "OSPNEXTSTATUS", "SUCCESS"); 00236 } else { 00237 if (!res) { 00238 if (result.handle < 0) 00239 ast_log(LOG_NOTICE, "OSP Lookup Next failed for handle '%d'\n", result.handle); 00240 else 00241 ast_log(LOG_DEBUG, "No OSP handle specified\n"); 00242 } else 00243 ast_log(LOG_DEBUG, "Got hangup on '%s' while doing OSP Next!\n", chan->name); 00244 00245 pbx_builtin_setvar_helper(chan, "OSPNEXTSTATUS", "FAILED"); 00246 } 00247 if (!res) { 00248 /* Look for a "busy" place */ 00249 if (priority_jump || option_priority_jumping) 00250 ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); 00251 } else if (res > 0) 00252 res = 0; 00253 LOCAL_USER_REMOVE(u); 00254 return res; 00255 }
|
|
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 355 of file app_osplookup.c. 00356 {
00357 return 0;
00358 }
|
|
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 331 of file app_osplookup.c. References app, app2, app3, ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS. 00332 { 00333 int res; 00334 00335 res = ast_unregister_application(app3); 00336 res |= ast_unregister_application(app2); 00337 res |= ast_unregister_application(app); 00338 00339 STANDARD_HANGUP_LOCALUSERS; 00340 00341 return res; 00342 }
|
|
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 366 of file app_osplookup.c. References STANDARD_USECOUNT. 00367 { 00368 int res; 00369 STANDARD_USECOUNT(res); 00370 return res; 00371 }
|
|
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. |