#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.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/module.h"
#include "asterisk/app.h"
#include "asterisk/devicestate.h"
#include "asterisk/options.h"
Include dependency graph for app_chanisavail.c:
Go to the source code of this file.
Functions | |
static int | chanavail_exec (struct ast_channel *chan, void *data) |
char * | description (void) |
Provides a description of the module. | |
char * | key () |
Returns the ASTERISK_GPL_KEY. | |
int | load_module (void) |
Initialize the module. | |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
int | usecount (void) |
Provides a usecount. | |
Variables | |
static char * | app = "ChanIsAvail" |
static char * | descrip |
LOCAL_USER_DECL | |
STANDARD_LOCAL_USER | |
static char * | synopsis = "Check channel availability" |
static char * | tdesc = "Check channel availability" |
Definition in file app_chanisavail.c.
|
Definition at line 68 of file app_chanisavail.c. References ast_device_state(), ast_goto_if_exists(), ast_hangup(), ast_log(), ast_strdupa, ast_strlen_zero(), ast_channel::context, inuse, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_WARNING, ast_channel::name, ast_channel::nativeformats, option_priority_jumping, pbx_builtin_setvar_helper(), peers, and strsep(). Referenced by load_module(). 00069 { 00070 int res=-1, inuse=-1, option_state=0, priority_jump=0; 00071 int status; 00072 struct localuser *u; 00073 char *info, tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur, *options, *stringp; 00074 struct ast_channel *tempchan; 00075 00076 if (ast_strlen_zero(data)) { 00077 ast_log(LOG_WARNING, "ChanIsAvail requires an argument (Zap/1&Zap/2)\n"); 00078 return -1; 00079 } 00080 00081 LOCAL_USER_ADD(u); 00082 00083 info = ast_strdupa(data); 00084 stringp = info; 00085 strsep(&stringp, "|"); 00086 options = strsep(&stringp, "|"); 00087 if (options) { 00088 if (strchr(options, 's')) 00089 option_state = 1; 00090 if (strchr(options, 'j')) 00091 priority_jump = 1; 00092 } 00093 peers = info; 00094 if (peers) { 00095 cur = peers; 00096 do { 00097 /* remember where to start next time */ 00098 rest = strchr(cur, '&'); 00099 if (rest) { 00100 *rest = 0; 00101 rest++; 00102 } 00103 tech = cur; 00104 number = strchr(tech, '/'); 00105 if (!number) { 00106 ast_log(LOG_WARNING, "ChanIsAvail argument takes format ([technology]/[device])\n"); 00107 LOCAL_USER_REMOVE(u); 00108 return -1; 00109 } 00110 *number = '\0'; 00111 number++; 00112 00113 if (option_state) { 00114 /* If the pbx says in use then don't bother trying further. 00115 This is to permit testing if someone's on a call, even if the 00116 channel can permit more calls (ie callwaiting, sip calls, etc). */ 00117 00118 snprintf(trychan, sizeof(trychan), "%s/%s",cur,number); 00119 status = inuse = ast_device_state(trychan); 00120 } 00121 if ((inuse <= 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) { 00122 pbx_builtin_setvar_helper(chan, "AVAILCHAN", tempchan->name); 00123 /* Store the originally used channel too */ 00124 snprintf(tmp, sizeof(tmp), "%s/%s", tech, number); 00125 pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", tmp); 00126 snprintf(tmp, sizeof(tmp), "%d", status); 00127 pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp); 00128 ast_hangup(tempchan); 00129 tempchan = NULL; 00130 res = 1; 00131 break; 00132 } else { 00133 snprintf(tmp, sizeof(tmp), "%d", status); 00134 pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp); 00135 } 00136 cur = rest; 00137 } while (cur); 00138 } 00139 if (res < 1) { 00140 pbx_builtin_setvar_helper(chan, "AVAILCHAN", ""); 00141 pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", ""); 00142 if (priority_jump || option_priority_jumping) { 00143 if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) { 00144 LOCAL_USER_REMOVE(u); 00145 return -1; 00146 } 00147 } 00148 } 00149 00150 LOCAL_USER_REMOVE(u); 00151 return 0; 00152 }
|
|
Provides a description of the module.
Definition at line 170 of file app_chanisavail.c. References tdesc. 00171 { 00172 return tdesc; 00173 }
|
|
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 182 of file app_chanisavail.c. References ASTERISK_GPL_KEY. 00183 { 00184 return ASTERISK_GPL_KEY; 00185 }
|
|
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 165 of file app_chanisavail.c. References app, ast_register_application(), chanavail_exec(), descrip, and synopsis. 00166 { 00167 return ast_register_application(app, chanavail_exec, synopsis, descrip); 00168 }
|
|
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 154 of file app_chanisavail.c. References app, ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS. 00155 { 00156 int res = 0; 00157 00158 res = ast_unregister_application(app); 00159 00160 STANDARD_HANGUP_LOCALUSERS; 00161 00162 return res; 00163 }
|
|
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 175 of file app_chanisavail.c. References STANDARD_USECOUNT. 00176 { 00177 int res; 00178 STANDARD_USECOUNT(res); 00179 return res; 00180 }
|
|
Definition at line 49 of file app_chanisavail.c. |
|
Definition at line 53 of file app_chanisavail.c. |
|
Definition at line 66 of file app_chanisavail.c. |
|
Definition at line 64 of file app_chanisavail.c. |
|
Definition at line 51 of file app_chanisavail.c. |
|
Definition at line 47 of file app_chanisavail.c. |