Wed Jan 8 2020 09:49:53

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 = "ac1f6a56484a8820659555499174e588" , .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 marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m
James Golovich james.nosp@m.@gnu.nosp@m.inter.nosp@m..net

Definition in file app_chanisavail.c.

Function Documentation

static void __reg_module ( void  )
static

Definition at line 214 of file app_chanisavail.c.

static void __unreg_module ( void  )
static

Definition at line 214 of file app_chanisavail.c.

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

Definition at line 102 of file app_chanisavail.c.

References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, AST_DEVICE_UNKNOWN, 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(), peers, and status.

Referenced by load_module().

103 {
104  int inuse=-1, option_state=0, string_compare=0, option_all_avail=0;
105  int status;
106  char *info, tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur;
107  struct ast_str *tmp_availchan = ast_str_alloca(2048);
108  struct ast_str *tmp_availorig = ast_str_alloca(2048);
109  struct ast_str *tmp_availstat = ast_str_alloca(2048);
110  struct ast_str *tmp_availcause = ast_str_alloca(2048);
111  struct ast_channel *tempchan;
113  AST_APP_ARG(reqchans);
114  AST_APP_ARG(options);
115  );
116 
117  if (ast_strlen_zero(data)) {
118  ast_log(LOG_WARNING, "ChanIsAvail requires an argument (DAHDI/1&DAHDI/2)\n");
119  return -1;
120  }
121 
122  info = ast_strdupa(data);
123 
125 
126  if (args.options) {
127  if (strchr(args.options, 'a')) {
128  option_all_avail = 1;
129  }
130  if (strchr(args.options, 's')) {
131  option_state = 1;
132  }
133  if (strchr(args.options, 't')) {
134  string_compare = 1;
135  }
136  }
137  peers = args.reqchans;
138  if (peers) {
139  cur = peers;
140  do {
141  /* remember where to start next time */
142  rest = strchr(cur, '&');
143  if (rest) {
144  *rest = 0;
145  rest++;
146  }
147  tech = cur;
148  number = strchr(tech, '/');
149  if (!number) {
150  ast_log(LOG_WARNING, "ChanIsAvail argument takes format ([technology]/[device])\n");
151  return -1;
152  }
153  *number = '\0';
154  number++;
155 
156  status = AST_DEVICE_UNKNOWN;
157 
158  if (string_compare) {
159  /* ast_parse_device_state checks for "SIP/1234" as a channel name.
160  ast_device_state will ask the SIP driver for the channel state. */
161 
162  snprintf(trychan, sizeof(trychan), "%s/%s",cur,number);
163  status = inuse = ast_parse_device_state(trychan);
164  } else if (option_state) {
165  /* If the pbx says in use then don't bother trying further.
166  This is to permit testing if someone's on a call, even if the
167  channel can permit more calls (ie callwaiting, sip calls, etc). */
168 
169  snprintf(trychan, sizeof(trychan), "%s/%s",cur,number);
170  status = inuse = ast_device_state(trychan);
171  }
172  snprintf(tmp, sizeof(tmp), "%d", status);
173  ast_str_append(&tmp_availstat, 0, "%s%s", ast_str_strlen(tmp_availstat) ? "&" : "", tmp);
174  if ((inuse <= 1) && (tempchan = ast_request(tech, chan->nativeformats, chan, number, &status))) {
175  ast_str_append(&tmp_availchan, 0, "%s%s", ast_str_strlen(tmp_availchan) ? "&" : "", tempchan->name);
176 
177  snprintf(tmp, sizeof(tmp), "%s/%s", tech, number);
178  ast_str_append(&tmp_availorig, 0, "%s%s", ast_str_strlen(tmp_availorig) ? "&" : "", tmp);
179 
180  snprintf(tmp, sizeof(tmp), "%d", status);
181  ast_str_append(&tmp_availcause, 0, "%s%s", ast_str_strlen(tmp_availcause) ? "&" : "", tmp);
182 
183  ast_hangup(tempchan);
184  tempchan = NULL;
185 
186  if (!option_all_avail) {
187  break;
188  }
189  }
190  cur = rest;
191  } while (cur);
192  }
193 
194  pbx_builtin_setvar_helper(chan, "AVAILCHAN", ast_str_buffer(tmp_availchan));
195  /* Store the originally used channel too */
196  pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", ast_str_buffer(tmp_availorig));
197  pbx_builtin_setvar_helper(chan, "AVAILSTATUS", ast_str_buffer(tmp_availstat));
198  pbx_builtin_setvar_helper(chan, "AVAILCAUSECODE", ast_str_buffer(tmp_availcause));
199 
200  return 0;
201 }
int ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2804
Main Channel structure associated with a channel.
Definition: channel.h:742
ast_device_state
Device States.
Definition: devicestate.h:51
#define LOG_WARNING
Definition: logger.h:144
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
enum ast_device_state ast_parse_device_state(const char *device)
Search the Channels by Name.
Definition: devicestate.c:271
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:900
format_t nativeformats
Definition: channel.h:852
#define ast_str_alloca(init_len)
Definition: strings.h:608
const char * data
Definition: channel.h:755
Number structure.
Definition: app_followme.c:109
static struct ao2_container * peers
Definition: chan_iax2.c:885
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
static struct @350 args
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
Definition: pbx.c:10546
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:471
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
struct ast_channel * ast_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *status)
Requests a channel.
Definition: channel.c:5695
jack_status_t status
Definition: app_jack.c:143
static int load_module ( void  )
static

Definition at line 208 of file app_chanisavail.c.

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

209 {
212 }
static const char app[]
static int chanavail_exec(struct ast_channel *chan, const char *data)
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
static int unload_module ( void  )
static

Definition at line 203 of file app_chanisavail.c.

References ast_unregister_application().

204 {
206 }
static const char app[]
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 214 of file app_chanisavail.c.

const char app[] = "ChanIsAvail"
static

Definition at line 48 of file app_chanisavail.c.

Definition at line 214 of file app_chanisavail.c.