Asterisk - The Open Source Telephony Project  21.4.1
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"

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 = "da6642af068ee5e6490c5b1d2cc1d238" , .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

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, AST_APP_ARG, ast_control_pvt_cause_code::ast_cause, ast_cause2str(), ast_channel_dialed_causes_find(), ast_copy_string(), AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strdupa, and ast_control_pvt_cause_code::code.

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 }
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
const char * ast_cause2str(int cause) attribute_pure
Gives the string form of a given cause code.
Definition: channel.c:612
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
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's arguments.
#define AST_APP_ARG(name)
Define an application argument.

Variable Documentation

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.

struct ast_custom_function hangupcause_keys_function
static
Initial value:
= {
.name = "HANGUPCAUSE_KEYS",
.read = hangupcause_keys_read,
}

Definition at line 214 of file func_hangupcause.c.