Asterisk - The Open Source Telephony Project  18.5.0
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 = "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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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 256 of file func_hangupcause.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 256 of file func_hangupcause.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 256 of file func_hangupcause.c.

◆ hangupcause_clear_exec()

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

Definition at line 202 of file func_hangupcause.c.

References ast_channel_dialed_causes_clear(), ast_channel_lock, and ast_channel_unlock.

Referenced by load_module().

202  {
203  ast_channel_lock(chan);
205  ast_channel_unlock(chan);
206  return 0;
207 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
#define ast_channel_unlock(chan)
Definition: channel.h:2946
void ast_channel_dialed_causes_clear(const struct ast_channel *chan)
Clear all cause information from the channel.

◆ 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 169 of file func_hangupcause.c.

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

170 {
171  struct ast_str *chanlist;
172 
173  /* Ensure that the buffer is empty */
174  *buf = 0;
175 
176  if (!chan) {
177  return -1;
178  }
179 
180  ast_channel_lock(chan);
181  chanlist = ast_channel_dialed_causes_channels(chan);
182  ast_channel_unlock(chan);
183 
184  if (chanlist && ast_str_strlen(chanlist)) {
185  ast_copy_string(buf, ast_str_buffer(chanlist), len);
186  }
187 
188  ast_free(chanlist);
189  return 0;
190 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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...
List of channel drivers.
Definition: app_dial.c:796
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_channel_unlock(chan)
Definition: channel.h:2946
#define ast_free(a)
Definition: astmm.h:182
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401

◆ 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 or tech)

< Channel name

< Type of information requested (ast or tech)

Definition at line 108 of file func_hangupcause.c.

References ao2_ref, args, AST_APP_ARG, ast_control_pvt_cause_code::ast_cause, ast_cause2str(), ast_channel_dialed_causes_find(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log, AST_STANDARD_APP_ARGS, ast_strdupa, ast_control_pvt_cause_code::code, LOG_WARNING, and type.

109 {
110  char *parms;
111  struct ast_control_pvt_cause_code *cause_code;
112  int res = 0;
114  AST_APP_ARG(channel); /*!< Channel name */
115  AST_APP_ARG(type); /*!< Type of information requested (ast or tech) */
116  );
117 
118  /* Ensure that the buffer is empty */
119  *buf = 0;
120 
121  if (!chan) {
122  return -1;
123  }
124 
125  parms = ast_strdupa(data);
126  AST_STANDARD_APP_ARGS(args, parms);
127  if (args.argc != 2) {
128  /* Must have two arguments. */
129  ast_log(LOG_WARNING, "The HANGUPCAUSE function must have 2 parameters, not %u\n", args.argc);
130  return -1;
131  }
132 
133  ast_channel_lock(chan);
134  cause_code = ast_channel_dialed_causes_find(chan, args.channel);
135  ast_channel_unlock(chan);
136 
137  if (!cause_code) {
138  ast_log(LOG_WARNING, "Unable to find information for channel %s\n", args.channel);
139  return -1;
140  }
141 
142  if (!strcmp(args.type, "ast")) {
143  ast_copy_string(buf, ast_cause2str(cause_code->ast_cause), len);
144  } else if (!strcmp(args.type, "tech")) {
145  ast_copy_string(buf, cause_code->code, len);
146  } else {
147  ast_log(LOG_WARNING, "Information type not recognized (%s)\n", args.type);
148  res = -1;
149  }
150 
151  ao2_ref(cause_code, -1);
152 
153  return res;
154 }
static const char type[]
Definition: chan_ooh323.c:109
#define ast_channel_lock(chan)
Definition: channel.h:2945
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
Definition: muted.c:95
const char * args
#define ast_log
Definition: astobj2.c:42
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_channel_unlock(chan)
Definition: channel.h:2946
const char * ast_cause2str(int state) attribute_pure
Gives the string form of a given cause code.
Definition: channel.c:612
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
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.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ load_module()

static int load_module ( void  )
static

Definition at line 245 of file func_hangupcause.c.

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

246 {
247  int res;
248 
253 }
static struct ast_custom_function hangupcause_function
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static int hangupcause_clear_exec(struct ast_channel *chan, const char *data)
static struct ast_custom_function hangupcause_keys_function
static const char app[]
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1508
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 228 of file func_hangupcause.c.

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

229 {
230  int res;
231 
235  return res;
236 }
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.
static struct ast_custom_function hangupcause_function
static struct ast_custom_function hangupcause_keys_function
static const char app[]

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

Definition at line 256 of file func_hangupcause.c.

◆ app

const char app[] = "HangupCauseClear"
static

Definition at line 219 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 256 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 209 of file func_hangupcause.c.

◆ 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 214 of file func_hangupcause.c.