Asterisk - The Open Source Telephony Project GIT-master-b023714
Loading...
Searching...
No Matches
Functions | Variables
func_hangupcause.c File Reference

Functions related to retreiving per-channel hangupcause information. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
Include dependency graph for func_hangupcause.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 hangupcause_clear_exec (struct ast_channel *chan, const char *data)
 
static int hangupcause_keys_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
static int hangupcause_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 
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 = "HANGUPCAUSE related functions and applications" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const char app [] = "HangupCauseClear"
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_custom_function hangupcause_function
 
static struct ast_custom_function hangupcause_keys_function
 

Detailed Description

Functions related to retreiving per-channel hangupcause information.

Author
Kinsey Moore kmoor.nosp@m.e@di.nosp@m.gium..nosp@m.com

See Also:

Definition in file func_hangupcause.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 291 of file func_hangupcause.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 291 of file func_hangupcause.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 291 of file func_hangupcause.c.

◆ hangupcause_clear_exec()

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

Definition at line 237 of file func_hangupcause.c.

237 {
238 ast_channel_lock(chan);
240 ast_channel_unlock(chan);
241 return 0;
242}
#define ast_channel_lock(chan)
Definition channel.h:2982
void ast_channel_dialed_causes_clear(const struct ast_channel *chan)
Clear all cause information from the channel.
#define ast_channel_unlock(chan)
Definition channel.h:2983

References ast_channel_dialed_causes_clear(), ast_channel_lock, and ast_channel_unlock.

Referenced by load_module().

◆ hangupcause_keys_read()

static int hangupcause_keys_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

Definition at line 204 of file func_hangupcause.c.

205{
206 struct ast_str *chanlist;
207
208 /* Ensure that the buffer is empty */
209 *buf = 0;
210
211 if (!chan) {
212 return -1;
213 }
214
215 ast_channel_lock(chan);
217 ast_channel_unlock(chan);
218
221 }
222
224 return 0;
225}
#define ast_free(a)
Definition astmm.h:180
struct ast_str * ast_channel_dialed_causes_channels(const struct ast_channel *chan)
Retrieve a comma-separated list of channels for which dialed cause information is available.
char buf[BUFSIZE]
Definition eagi_proxy.c:66
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
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
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425
Support for dynamic strings.
Definition strings.h:623
List of channel drivers.
Definition app_dial.c:804

References ast_channel_dialed_causes_channels(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_free, ast_str_buffer(), ast_str_strlen(), buf, and len().

◆ hangupcause_read()

static int hangupcause_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)
static

< Channel name

< Type of information requested (ast, tech or tech_extended)

Definition at line 118 of file func_hangupcause.c.

119{
120 char *parms;
121 struct ast_control_pvt_cause_code *cause_code;
122 int res = 0;
123 struct ast_str *causelist;
125 AST_APP_ARG(channel); /*!< Channel name */
126 AST_APP_ARG(type); /*!< Type of information requested (ast, tech or tech_extended) */
127 );
128
129 /* Ensure that the buffer is empty */
130 *buf = 0;
131
132 if (!chan) {
133 return -1;
134 }
135
136 parms = ast_strdupa(data);
138 if (args.argc != 2) {
139 /* Must have two arguments. */
140 ast_log(LOG_WARNING, "The HANGUPCAUSE function must have 2 parameters, not %u\n", args.argc);
141 return -1;
142 }
143
144 causelist = ast_str_create(128);
145 if (!causelist) {
146 ast_log(LOG_ERROR, "Unable to allocate buffer, cause information will be unavailable!\n");
147 return -1;
148 }
149
150 ast_channel_lock(chan);
151 if (!strcmp(args.type, "tech_extended")) {
152 struct ao2_iterator *cause_codes;
153 cause_codes = ast_channel_dialed_causes_find_multiple(chan, args.channel);
154 while ((cause_code = ao2_iterator_next(cause_codes))) {
155 if (!cause_code->cause_extended) {
156 ao2_ref(cause_code, -1);
157 continue;
158 }
159 ast_str_append(&causelist, 0, "%s%s", (ast_str_strlen(causelist) ? "," : ""), cause_code->code);
160 ao2_ref(cause_code, -1);
161 }
162 ao2_iterator_destroy(cause_codes);
163 } else {
164 cause_code = ast_channel_dialed_causes_find(chan, args.channel);
165 if (!cause_code) {
166 ast_log(LOG_WARNING, "Unable to find information for channel '%s'\n", args.channel);
167 ast_channel_unlock(chan);
168 return -1;
169 }
170 }
171 ast_channel_unlock(chan);
172
173 if (!strcmp(args.type, "ast")) {
175 } else if (!strcmp(args.type, "tech")) {
176 ast_copy_string(buf, cause_code->code, len);
177 } else if (!strcmp(args.type, "tech_extended")) {
179 } else {
180 ast_log(LOG_WARNING, "Information type not recognized (%s)\n", args.type);
181 res = -1;
182 }
183
184 if (cause_code) {
185 ao2_cleanup(cause_code);
186 }
187
188 return res;
189}
#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_iterator_next(iter)
Definition astobj2.h:1911
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
static const char type[]
struct ast_control_pvt_cause_code * ast_channel_dialed_causes_find(const struct ast_channel *chan, const char *chan_name)
Retrieve a ref-counted cause code information structure.
const char * ast_cause2str(int cause) attribute_pure
Gives the string form of a given cause code.
Definition channel.c:612
struct ao2_iterator * ast_channel_dialed_causes_find_multiple(const struct ast_channel *chan, const char *chan_name)
Retrieve a ref-counted cause code information structure iterator.
#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_ERROR
#define LOG_WARNING
static struct @519 args
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
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition strings.h:659
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition astobj2.h:1821

References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_next, ao2_ref, args, AST_APP_ARG, ast_control_pvt_cause_code::ast_cause, ast_cause2str(), ast_channel_dialed_causes_find(), ast_channel_dialed_causes_find_multiple(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_strlen(), ast_strdupa, buf, ast_control_pvt_cause_code::cause_extended, ast_control_pvt_cause_code::code, len(), LOG_ERROR, LOG_WARNING, and type.

◆ load_module()

static int load_module ( void  )
static

Definition at line 280 of file func_hangupcause.c.

281{
282 int res;
283
288}
static const char app[]
static int hangupcause_clear_exec(struct ast_channel *chan, const char *data)
static struct ast_custom_function hangupcause_function
static struct ast_custom_function hangupcause_keys_function
@ 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
#define ast_custom_function_register(acf)
Register a custom function.
Definition pbx.h:1562

References app, ast_custom_function_register, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_register_application_xml, hangupcause_clear_exec(), hangupcause_function, and hangupcause_keys_function.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 263 of file func_hangupcause.c.

264{
265 int res;
266
270 return res;
271}
int ast_unregister_application(const char *app)
Unregister an application.
Definition pbx_app.c:392
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.

References app, ast_custom_function_unregister(), ast_unregister_application(), hangupcause_function, and hangupcause_keys_function.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "HANGUPCAUSE related functions and applications" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 291 of file func_hangupcause.c.

◆ app

const char app[] = "HangupCauseClear"
static

Definition at line 254 of file func_hangupcause.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 291 of file func_hangupcause.c.

◆ hangupcause_function

struct ast_custom_function hangupcause_function
static
Initial value:
= {
.name = "HANGUPCAUSE",
}
static int hangupcause_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)

Definition at line 244 of file func_hangupcause.c.

244 {
245 .name = "HANGUPCAUSE",
246 .read = hangupcause_read,
247};

Referenced by load_module(), and unload_module().

◆ hangupcause_keys_function

struct ast_custom_function hangupcause_keys_function
static
Initial value:
= {
.name = "HANGUPCAUSE_KEYS",
}
static int hangupcause_keys_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)

Definition at line 249 of file func_hangupcause.c.

249 {
250 .name = "HANGUPCAUSE_KEYS",
251 .read = hangupcause_keys_read,
252};

Referenced by load_module(), and unload_module().