Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Functions | Variables
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)
 
struct ast_moduleAST_MODULE_SELF_SYM (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_DEFAULT , .description = "Check channel availability" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .optional_modules = "func_cdr" }
 
static const char app [] = "ChanIsAvail"
 
static const 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

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 241 of file app_chanisavail.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 241 of file app_chanisavail.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 241 of file app_chanisavail.c.

◆ chanavail_exec()

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

Definition at line 105 of file app_chanisavail.c.

106{
107 int inuse = -1;
108 int option_state = 0;
109 int string_compare = 0;
110 int option_all_avail = 0;
111 int status;
112 char *info;
113 char trychan[512];
114 char *rest;
115 char *tech;
116 char *number;
117 struct ast_str *tmp_availchan = ast_str_alloca(2048);
118 struct ast_str *tmp_availorig = ast_str_alloca(2048);
119 struct ast_str *tmp_availstat = ast_str_alloca(2048);
120 struct ast_str *tmp_availcause = ast_str_alloca(2048);
121 struct ast_channel *tempchan;
122 struct ast_custom_function *cdr_prop_func = ast_custom_function_find("CDR_PROP");
123 struct ast_format_cap *caps = NULL;
125 AST_APP_ARG(reqchans);
127 );
128
129 info = ast_strdupa(data ?: "");
130
132
133 ao2_lock(chan);
135 ao2_unlock(chan);
136
137 if (args.options) {
138 if (strchr(args.options, 'a')) {
139 option_all_avail = 1;
140 }
141 if (strchr(args.options, 's')) {
142 option_state = 1;
143 }
144 if (strchr(args.options, 't')) {
145 string_compare = 1;
146 }
147 }
148
149 rest = args.reqchans;
150 if (!rest) {
151 rest = "";
152 }
153 while ((tech = strsep(&rest, "&"))) {
154 tech = ast_strip(tech);
155
156 number = strchr(tech, '/');
157 if (!number) {
158 if (!ast_strlen_zero(tech)) {
159 ast_log(LOG_WARNING, "Invalid ChanIsAvail technology/resource argument: '%s'\n",
160 tech);
161 }
162
163 ast_str_append(&tmp_availstat, 0, "%s%d",
164 ast_str_strlen(tmp_availstat) ? "&" : "", AST_DEVICE_INVALID);
165 continue;
166 }
167 *number++ = '\0';
168
170
171 if (string_compare) {
172 /* ast_parse_device_state checks for "SIP/1234" as a channel name.
173 ast_device_state will ask the SIP driver for the channel state. */
174
175 snprintf(trychan, sizeof(trychan), "%s/%s", tech, number);
176 status = inuse = ast_parse_device_state(trychan);
177 } else if (option_state) {
178 /* If the pbx says in use then don't bother trying further.
179 This is to permit testing if someone's on a call, even if the
180 channel can permit more calls (ie callwaiting, sip calls, etc). */
181
182 snprintf(trychan, sizeof(trychan), "%s/%s", tech, number);
183 status = inuse = ast_device_state(trychan);
184 }
185 ast_str_append(&tmp_availstat, 0, "%s%d", ast_str_strlen(tmp_availstat) ? "&" : "", status);
186
187 if ((inuse <= (int) AST_DEVICE_NOT_INUSE)
188 && (tempchan = ast_request(tech, caps, NULL, chan, number, &status))) {
189
190 ast_str_append(&tmp_availchan, 0, "%s%s",
191 ast_str_strlen(tmp_availchan) ? "&" : "", ast_channel_name(tempchan));
192
193 ast_str_append(&tmp_availorig, 0, "%s%s/%s",
194 ast_str_strlen(tmp_availorig) ? "&" : "", tech, number);
195
196 ast_str_append(&tmp_availcause, 0, "%s%d",
197 ast_str_strlen(tmp_availcause) ? "&" : "", status);
198
199 /* Disable CDR for this temporary channel. */
200 if (cdr_prop_func) {
201 ast_func_write(tempchan, "CDR_PROP(disable)", "1");
202 }
203
204 ast_hangup(tempchan);
205 tempchan = NULL;
206
207 if (!option_all_avail) {
208 break;
209 }
210 }
211
212 }
213
214 ao2_cleanup(caps);
215
216 pbx_builtin_setvar_helper(chan, "AVAILCHAN", ast_str_buffer(tmp_availchan));
217 /* Store the originally used channel too */
218 pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", ast_str_buffer(tmp_availorig));
219 pbx_builtin_setvar_helper(chan, "AVAILSTATUS", ast_str_buffer(tmp_availstat));
220 pbx_builtin_setvar_helper(chan, "AVAILCAUSECODE", ast_str_buffer(tmp_availcause));
221
222 return 0;
223}
jack_status_t status
Definition app_jack.c:149
char * strsep(char **str, const char *delims)
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
#define ast_log
Definition astobj2.c:42
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define ao2_unlock(a)
Definition astobj2.h:729
#define ao2_lock(a)
Definition astobj2.h:717
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition astobj2.h:480
const char * ast_channel_name(const struct ast_channel *chan)
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition channel.c:2538
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
struct ast_channel * ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
Requests a channel.
Definition channel.c:6349
enum ast_device_state ast_parse_device_state(const char *device)
Search the Channels by Name.
ast_device_state
Device States.
Definition devicestate.h:52
@ AST_DEVICE_UNKNOWN
Definition devicestate.h:53
@ AST_DEVICE_INVALID
Definition devicestate.h:57
@ AST_DEVICE_NOT_INUSE
Definition devicestate.h:54
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define LOG_WARNING
struct ast_custom_function * ast_custom_function_find(const char *name)
Definition ael_main.c:173
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.
int ast_func_write(struct ast_channel *chan, const char *function, const char *value)
executes a write operation on a function
static struct @519 args
#define NULL
Definition resample.c:96
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:1139
size_t attribute_pure ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition strings.h:730
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
#define ast_str_alloca(init_len)
Definition strings.h:848
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition strings.h:223
Main Channel structure associated with a channel.
Data structure associated with a custom dialplan function.
Definition pbx.h:118
Format capabilities structure, holds formats + preference order + etc.
Definition format_cap.c:54
Support for dynamic strings.
Definition strings.h:623
Number structure.
static struct test_options options

References ao2_bump, ao2_cleanup, ao2_lock, ao2_unlock, args, AST_APP_ARG, ast_channel_name(), ast_channel_nativeformats(), ast_custom_function_find(), AST_DECLARE_APP_ARGS, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_UNKNOWN, ast_func_write(), 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_strip(), ast_strlen_zero(), LOG_WARNING, NULL, options, pbx_builtin_setvar_helper(), status, and strsep().

Referenced by load_module().

◆ load_module()

static int load_module ( void  )
static

Definition at line 230 of file app_chanisavail.c.

231{
234}
static const char app[]
static int chanavail_exec(struct ast_channel *chan, const char *data)
@ AST_MODULE_LOAD_SUCCESS
Definition module.h:70
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition module.h:78
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition module.h:640

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

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 225 of file app_chanisavail.c.

226{
228}
int ast_unregister_application(const char *app)
Unregister an application.
Definition pbx_app.c:392

References app, and ast_unregister_application().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Check channel availability" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .optional_modules = "func_cdr" }
static

Definition at line 241 of file app_chanisavail.c.

◆ app

const char app[] = "ChanIsAvail"
static

Definition at line 46 of file app_chanisavail.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 241 of file app_chanisavail.c.