Asterisk - The Open Source Telephony Project GIT-master-8924258
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
func_hangupcause.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999-2012, Digium, Inc.
5 *
6 * Kinsey Moore <kmoore@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*! \file
20 *
21 * \brief Functions related to retreiving per-channel hangupcause information
22 *
23 * \author Kinsey Moore <kmoore@digium.com>
24 * \ingroup functions
25 *
26 * See Also:
27 * \arg \ref AstCREDITS
28 */
29
30/*** MODULEINFO
31 <support_level>core</support_level>
32 ***/
33
34#include "asterisk.h"
35
36#include "asterisk/module.h"
37#include "asterisk/channel.h"
38#include "asterisk/pbx.h"
39#include "asterisk/utils.h"
40#include "asterisk/app.h"
41
42/*** DOCUMENTATION
43 <function name="HANGUPCAUSE" language="en_US">
44 <since>
45 <version>11.0.0</version>
46 </since>
47 <synopsis>
48 Gets per-channel hangupcause information from the channel.
49 </synopsis>
50 <syntax>
51 <parameter name="channel" required="true">
52 <para>The name of the channel for which to retrieve cause information.</para>
53 </parameter>
54 <parameter name="type" required="true">
55 <para>Parameter describing which type of information is requested. Types are:</para>
56 <enumlist>
57 <enum name="tech"><para>Technology-specific cause information</para></enum>
58 <enum name="ast"><para>Translated Asterisk cause code</para></enum>
59 </enumlist>
60 </parameter>
61 </syntax>
62 <description>
63 <para>Gets technology-specific or translated Asterisk cause code information
64 from the channel for the specified channel that resulted from a dial.</para>
65 </description>
66 <see-also>
67 <ref type="function">HANGUPCAUSE_KEYS</ref>
68 <ref type="application">HangupCauseClear</ref>
69 </see-also>
70 </function>
71 <function name="HANGUPCAUSE_KEYS" language="en_US">
72 <since>
73 <version>11.0.0</version>
74 </since>
75 <synopsis>
76 Gets the list of channels for which hangup causes are available.
77 </synopsis>
78 <description>
79 <para>Returns a comma-separated list of channel names to be used with the HANGUPCAUSE function.</para>
80 </description>
81 <see-also>
82 <ref type="function">HANGUPCAUSE</ref>
83 <ref type="application">HangupCauseClear</ref>
84 </see-also>
85 </function>
86 <application name="HangupCauseClear" language="en_US">
87 <since>
88 <version>11.0.0</version>
89 </since>
90 <synopsis>
91 Clears hangup cause information from the channel that is available through HANGUPCAUSE.
92 </synopsis>
93 <description>
94 <para>Clears all channel-specific hangup cause information from the channel.
95 This is never done automatically (i.e. for new Dial()s).</para>
96 </description>
97 <see-also>
98 <ref type="function">HANGUPCAUSE</ref>
99 <ref type="function">HANGUPCAUSE_KEYS</ref>
100 </see-also>
101 </application>
102 ***/
103
104/*!
105 * \internal
106 * \brief Read values from the hangupcause ao2 container.
107 *
108 * \param chan Asterisk channel to read
109 * \param cmd Not used
110 * \param data HANGUPCAUSE function argument string
111 * \param buf Buffer to fill with read value.
112 * \param len Length of the buffer
113 *
114 * \retval 0 on success.
115 * \retval -1 on error.
116 */
117static int hangupcause_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
118{
119 char *parms;
120 struct ast_control_pvt_cause_code *cause_code;
121 int res = 0;
123 AST_APP_ARG(channel); /*!< Channel name */
124 AST_APP_ARG(type); /*!< Type of information requested (ast or tech) */
125 );
126
127 /* Ensure that the buffer is empty */
128 *buf = 0;
129
130 if (!chan) {
131 return -1;
132 }
133
134 parms = ast_strdupa(data);
136 if (args.argc != 2) {
137 /* Must have two arguments. */
138 ast_log(LOG_WARNING, "The HANGUPCAUSE function must have 2 parameters, not %u\n", args.argc);
139 return -1;
140 }
141
142 ast_channel_lock(chan);
143 cause_code = ast_channel_dialed_causes_find(chan, args.channel);
144 ast_channel_unlock(chan);
145
146 if (!cause_code) {
147 ast_log(LOG_WARNING, "Unable to find information for channel %s\n", args.channel);
148 return -1;
149 }
150
151 if (!strcmp(args.type, "ast")) {
153 } else if (!strcmp(args.type, "tech")) {
154 ast_copy_string(buf, cause_code->code, len);
155 } else {
156 ast_log(LOG_WARNING, "Information type not recognized (%s)\n", args.type);
157 res = -1;
158 }
159
160 ao2_ref(cause_code, -1);
161
162 return res;
163}
164
165/*!
166 * \internal
167 * \brief Read keys from the hangupcause ao2 container.
168 *
169 * \param chan Asterisk channel to read
170 * \param cmd Not used
171 * \param data HANGUPCAUSE_KEYS function argument string
172 * \param buf Buffer to fill with read value.
173 * \param len Length of the buffer
174 *
175 * \retval 0 on success.
176 * \retval -1 on error.
177 */
178static int hangupcause_keys_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
179{
180 struct ast_str *chanlist;
181
182 /* Ensure that the buffer is empty */
183 *buf = 0;
184
185 if (!chan) {
186 return -1;
187 }
188
189 ast_channel_lock(chan);
191 ast_channel_unlock(chan);
192
195 }
196
198 return 0;
199}
200
201/*!
202 * \internal
203 * \brief Remove all keys from the hangupcause ao2 container.
204 *
205 * \param chan Asterisk channel to read
206 * \param data Not used
207 *
208 * \retval 0 on success.
209 * \retval -1 on error.
210 */
211static int hangupcause_clear_exec(struct ast_channel *chan, const char *data) {
212 ast_channel_lock(chan);
214 ast_channel_unlock(chan);
215 return 0;
216}
217
219 .name = "HANGUPCAUSE",
220 .read = hangupcause_read,
221};
222
224 .name = "HANGUPCAUSE_KEYS",
225 .read = hangupcause_keys_read,
226};
227
228static const char app[] = "HangupCauseClear";
229
230/*!
231 * \internal
232 * \brief Unload the function module
233 *
234 * \retval 0 on success.
235 * \retval -1 on error.
236 */
237static int unload_module(void)
238{
239 int res;
240
244 return res;
245}
246
247/*!
248 * \internal
249 * \brief Load and initialize the function module.
250 *
251 * \retval AST_MODULE_LOAD_SUCCESS on success.
252 * \retval AST_MODULE_LOAD_DECLINE on error.
253 */
254static int load_module(void)
255{
256 int res;
257
262}
263
264/* Do not wrap the following line. */
265AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "HANGUPCAUSE related functions and applications");
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition: astmm.h:180
#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_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
static const char type[]
Definition: chan_ooh323.c:109
General Asterisk PBX channel definitions.
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_channel_lock(chan)
Definition: channel.h:2970
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.
const char * ast_cause2str(int cause) attribute_pure
Gives the string form of a given cause code.
Definition: channel.c:612
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:2971
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
static const char app[]
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 load_module(void)
static int unload_module(void)
static struct ast_custom_function hangupcause_function
static struct ast_custom_function hangupcause_keys_function
static int hangupcause_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#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
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:581
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
@ 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
Core PBX routines and definitions.
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1559
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:730
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
Main Channel structure associated with a channel.
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
const char * name
Definition: pbx.h:119
Support for dynamic strings.
Definition: strings.h:623
List of channel drivers.
Definition: app_dial.c:803
const char * args
Utility functions.