Sat Aug 6 00:39:34 2011

Asterisk developer's documentation


app_chanisavail.c File Reference

Check if Channel is Available. More...

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/ioctl.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"

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int chanavail_exec (struct ast_channel *chan, void *data)
static int load_module (void)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Check channel availability" , .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 char * app = "ChanIsAvail"
static const struct ast_module_infoast_module_info = &__mod_info
static char * descrip
static char * synopsis = "Check channel availability"


Detailed Description

Check if Channel is Available.

Author:
Mark Spencer <markster@digium.com>

James Golovich <james@gnuinter.net>

Definition in file app_chanisavail.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 178 of file app_chanisavail.c.

static void __unreg_module ( void   )  [static]

Definition at line 178 of file app_chanisavail.c.

static int chanavail_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 72 of file app_chanisavail.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_device_state(), ast_goto_if_exists(), ast_hangup(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_opt_priority_jumping, ast_request(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_channel::context, inuse, LOG_WARNING, ast_channel::name, ast_channel::nativeformats, and pbx_builtin_setvar_helper().

Referenced by load_module().

00073 {
00074    int res=-1, inuse=-1, option_state=0, priority_jump=0;
00075    int status;
00076    struct ast_module_user *u;
00077    char *info, tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur;
00078    struct ast_channel *tempchan;
00079    AST_DECLARE_APP_ARGS(args,
00080       AST_APP_ARG(reqchans);
00081       AST_APP_ARG(options);
00082    );
00083 
00084    if (ast_strlen_zero(data)) {
00085       ast_log(LOG_WARNING, "ChanIsAvail requires an argument (Zap/1&Zap/2)\n");
00086       return -1;
00087    }
00088 
00089    u = ast_module_user_add(chan);
00090 
00091    info = ast_strdupa(data); 
00092 
00093    AST_STANDARD_APP_ARGS(args, info);
00094 
00095    if (args.options) {
00096       if (strchr(args.options, 's'))
00097          option_state = 1;
00098       if (strchr(args.options, 'j'))
00099          priority_jump = 1;
00100    }
00101    peers = args.reqchans;
00102    if (peers) {
00103       cur = peers;
00104       do {
00105          /* remember where to start next time */
00106          rest = strchr(cur, '&');
00107          if (rest) {
00108             *rest = 0;
00109             rest++;
00110          }
00111          tech = cur;
00112          number = strchr(tech, '/');
00113          if (!number) {
00114             ast_log(LOG_WARNING, "ChanIsAvail argument takes format ([technology]/[device])\n");
00115             ast_module_user_remove(u);
00116             return -1;
00117          }
00118          *number = '\0';
00119          number++;
00120          
00121          if (option_state) {
00122             /* If the pbx says in use then don't bother trying further.
00123                This is to permit testing if someone's on a call, even if the 
00124                channel can permit more calls (ie callwaiting, sip calls, etc).  */
00125                                
00126             snprintf(trychan, sizeof(trychan), "%s/%s",cur,number);
00127             status = inuse = ast_device_state(trychan);
00128          }
00129          if ((inuse <= 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) {
00130                pbx_builtin_setvar_helper(chan, "AVAILCHAN", tempchan->name);
00131                /* Store the originally used channel too */
00132                snprintf(tmp, sizeof(tmp), "%s/%s", tech, number);
00133                pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", tmp);
00134                snprintf(tmp, sizeof(tmp), "%d", status);
00135                pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp);
00136                ast_hangup(tempchan);
00137                tempchan = NULL;
00138                res = 1;
00139                break;
00140          } else {
00141             snprintf(tmp, sizeof(tmp), "%d", status);
00142             pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp);
00143          }
00144          cur = rest;
00145       } while (cur);
00146    }
00147    if (res < 1) {
00148       pbx_builtin_setvar_helper(chan, "AVAILCHAN", "");
00149       pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", "");
00150       if (priority_jump || ast_opt_priority_jumping) {
00151          if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
00152             ast_module_user_remove(u);
00153             return -1;
00154          }
00155       }
00156    }
00157 
00158    ast_module_user_remove(u);
00159    return 0;
00160 }

static int load_module ( void   )  [static]

Definition at line 173 of file app_chanisavail.c.

References ast_register_application(), and chanavail_exec().

00174 {
00175    return ast_register_application(app, chanavail_exec, synopsis, descrip);
00176 }

static int unload_module ( void   )  [static]

Definition at line 162 of file app_chanisavail.c.

References ast_module_user_hangup_all, and ast_unregister_application().

00163 {
00164    int res = 0;
00165 
00166    res = ast_unregister_application(app);
00167 
00168    ast_module_user_hangup_all();
00169    
00170    return res;
00171 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Check channel availability" , .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 178 of file app_chanisavail.c.

char* app = "ChanIsAvail" [static]

Definition at line 51 of file app_chanisavail.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 178 of file app_chanisavail.c.

char* descrip [static]

Definition at line 55 of file app_chanisavail.c.

char* synopsis = "Check channel availability" [static]

Definition at line 53 of file app_chanisavail.c.


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