Fri Nov 12 11:48:20 2010

Asterisk developer's documentation


app_chanisavail.c File Reference

Check if Channel is Available. More...

#include "asterisk.h"
#include <sys/ioctl.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/devicestate.h"
Include dependency graph for app_chanisavail.c:

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 , .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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, }
static char * app = "ChanIsAvail"
static struct ast_module_infoast_module_info = &__mod_info

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 206 of file app_chanisavail.c.

static void __unreg_module ( void   )  [static]

Definition at line 206 of file app_chanisavail.c.

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

Definition at line 97 of file app_chanisavail.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_hangup(), ast_log(), ast_parse_device_state(), ast_request(), AST_STANDARD_APP_ARGS, ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_strlen(), ast_strlen_zero(), inuse, LOG_WARNING, ast_channel::name, ast_channel::nativeformats, pbx_builtin_setvar_helper(), and status.

Referenced by load_module().

00098 {
00099    int inuse=-1, option_state=0, string_compare=0, option_all_avail=0;
00100    int status;
00101    char *info, tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur;
00102    struct ast_str *tmp_availchan = ast_str_alloca(2048);
00103    struct ast_str *tmp_availorig = ast_str_alloca(2048);
00104    struct ast_str *tmp_availstat = ast_str_alloca(2048);
00105    struct ast_channel *tempchan;
00106    AST_DECLARE_APP_ARGS(args,
00107       AST_APP_ARG(reqchans);
00108       AST_APP_ARG(options);
00109    );
00110 
00111    if (ast_strlen_zero(data)) {
00112       ast_log(LOG_WARNING, "ChanIsAvail requires an argument (DAHDI/1&DAHDI/2)\n");
00113       return -1;
00114    }
00115 
00116    info = ast_strdupa(data);
00117 
00118    AST_STANDARD_APP_ARGS(args, info);
00119 
00120    if (args.options) {
00121       if (strchr(args.options, 'a')) {
00122          option_all_avail = 1;
00123       }
00124       if (strchr(args.options, 's')) {
00125          option_state = 1;
00126       }
00127       if (strchr(args.options, 't')) {
00128          string_compare = 1;
00129       }
00130    }
00131    peers = args.reqchans;
00132    if (peers) {
00133       cur = peers;
00134       do {
00135          /* remember where to start next time */
00136          rest = strchr(cur, '&');
00137          if (rest) {
00138             *rest = 0;
00139             rest++;
00140          }
00141          tech = cur;
00142          number = strchr(tech, '/');
00143          if (!number) {
00144             ast_log(LOG_WARNING, "ChanIsAvail argument takes format ([technology]/[device])\n");
00145             return -1;
00146          }
00147          *number = '\0';
00148          number++;
00149          
00150          if (string_compare) {
00151             /* ast_parse_device_state checks for "SIP/1234" as a channel name.
00152                ast_device_state will ask the SIP driver for the channel state. */
00153 
00154             snprintf(trychan, sizeof(trychan), "%s/%s",cur,number);
00155             status = inuse = ast_parse_device_state(trychan);
00156          } else if (option_state) {
00157             /* If the pbx says in use then don't bother trying further.
00158                This is to permit testing if someone's on a call, even if the
00159                channel can permit more calls (ie callwaiting, sip calls, etc).  */
00160 
00161             snprintf(trychan, sizeof(trychan), "%s/%s",cur,number);
00162             status = inuse = ast_device_state(trychan);
00163          }
00164          if ((inuse <= 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) {
00165                ast_str_append(&tmp_availchan, 0, "%s%s", ast_str_strlen(tmp_availchan) ? "&" : "", tempchan->name);
00166                
00167                snprintf(tmp, sizeof(tmp), "%s/%s", tech, number);
00168                ast_str_append(&tmp_availorig, 0, "%s%s", ast_str_strlen(tmp_availorig) ? "&" : "", tmp);
00169 
00170                snprintf(tmp, sizeof(tmp), "%d", status);
00171                ast_str_append(&tmp_availstat, 0, "%s%s", ast_str_strlen(tmp_availstat) ? "&" : "", tmp);
00172 
00173                ast_hangup(tempchan);
00174                tempchan = NULL;
00175 
00176                if (!option_all_avail) {
00177                   break;
00178                }
00179          } else {
00180             snprintf(tmp, sizeof(tmp), "%d", status);
00181             ast_str_append(&tmp_availstat, 0, "%s%s", ast_str_strlen(tmp_availstat) ? "&" : "", tmp);
00182          }
00183          cur = rest;
00184       } while (cur);
00185    }
00186 
00187    pbx_builtin_setvar_helper(chan, "AVAILCHAN", ast_str_buffer(tmp_availchan));
00188    /* Store the originally used channel too */
00189    pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", ast_str_buffer(tmp_availorig));
00190    pbx_builtin_setvar_helper(chan, "AVAILSTATUS", ast_str_buffer(tmp_availstat));
00191 
00192    return 0;
00193 }

static int load_module ( void   )  [static]
static int unload_module ( void   )  [static]

Definition at line 195 of file app_chanisavail.c.

References ast_unregister_application().

00196 {
00197    return ast_unregister_application(app);
00198 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .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 = "0901e4e500243c855563a2d78b0c03e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 206 of file app_chanisavail.c.

char* app = "ChanIsAvail" [static]

Definition at line 44 of file app_chanisavail.c.

Definition at line 206 of file app_chanisavail.c.


Generated by  doxygen 1.6.2