Mon Jun 27 16:50:58 2011

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"

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, const char *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_LOAD_ORDER , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static const 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 208 of file app_chanisavail.c.

static void __unreg_module ( void   )  [static]

Definition at line 208 of file app_chanisavail.c.

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

Definition at line 98 of file app_chanisavail.c.

References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_device_state(), 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_strdupa, ast_strlen_zero(), LOG_WARNING, ast_channel::name, ast_channel::nativeformats, pbx_builtin_setvar_helper(), and status.

Referenced by load_module().

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

static int load_module ( void   )  [static]

Definition at line 202 of file app_chanisavail.c.

References AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_application_xml, and chanavail_exec().

static int unload_module ( void   )  [static]

Definition at line 197 of file app_chanisavail.c.

References ast_unregister_application().

00198 {
00199    return ast_unregister_application(app);
00200 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "8586c2a7d357cb591cc3a6607a8f62d1" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, } [static]

Definition at line 208 of file app_chanisavail.c.

const char app[] = "ChanIsAvail" [static]

Definition at line 44 of file app_chanisavail.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 208 of file app_chanisavail.c.


Generated on Mon Jun 27 16:50:58 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7