Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "asterisk.h"
00035
00036 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 371516 $")
00037
00038 #include "asterisk/module.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/pbx.h"
00041 #include "asterisk/utils.h"
00042 #include "asterisk/app.h"
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 static int hangupcause_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
00111 {
00112 char *parms;
00113 struct ast_control_pvt_cause_code *cause_code;
00114 int res = 0;
00115 AST_DECLARE_APP_ARGS(args,
00116 AST_APP_ARG(channel);
00117 AST_APP_ARG(type);
00118 );
00119
00120
00121 *buf = 0;
00122
00123 if (!chan) {
00124 return -1;
00125 }
00126
00127 parms = ast_strdupa(data);
00128 AST_STANDARD_APP_ARGS(args, parms);
00129 if (args.argc != 2) {
00130
00131 ast_log(LOG_WARNING, "The HANGUPCAUSE function must have 2 parameters, not %d\n", args.argc);
00132 return -1;
00133 }
00134
00135 ast_channel_lock(chan);
00136 cause_code = ast_channel_dialed_causes_find(chan, args.channel);
00137 ast_channel_unlock(chan);
00138
00139 if (!cause_code) {
00140 ast_log(LOG_WARNING, "Unable to find information for channel %s\n", args.channel);
00141 return -1;
00142 }
00143
00144 if (!strcmp(args.type, "ast")) {
00145 ast_copy_string(buf, ast_cause2str(cause_code->ast_cause), len);
00146 } else if (!strcmp(args.type, "tech")) {
00147 ast_copy_string(buf, cause_code->code, len);
00148 } else {
00149 ast_log(LOG_WARNING, "Information type not recognized (%s)\n", args.type);
00150 res = -1;
00151 }
00152
00153 ao2_ref(cause_code, -1);
00154
00155 return res;
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 static int hangupcause_keys_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
00172 {
00173 struct ast_str *chanlist;
00174
00175
00176 *buf = 0;
00177
00178 if (!chan) {
00179 return -1;
00180 }
00181
00182 ast_channel_lock(chan);
00183 chanlist = ast_channel_dialed_causes_channels(chan);
00184 ast_channel_unlock(chan);
00185
00186 if (chanlist && ast_str_strlen(chanlist)) {
00187 ast_copy_string(buf, ast_str_buffer(chanlist), len);
00188 }
00189
00190 ast_free(chanlist);
00191 return 0;
00192 }
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 static int hangupcause_clear_exec(struct ast_channel *chan, const char *data) {
00205 ast_channel_lock(chan);
00206 ast_channel_dialed_causes_clear(chan);
00207 ast_channel_unlock(chan);
00208 return 0;
00209 }
00210
00211 static struct ast_custom_function hangupcause_function = {
00212 .name = "HANGUPCAUSE",
00213 .read = hangupcause_read,
00214 };
00215
00216 static struct ast_custom_function hangupcause_keys_function = {
00217 .name = "HANGUPCAUSE_KEYS",
00218 .read = hangupcause_keys_read,
00219 };
00220
00221 static const char app[] = "HangupCauseClear";
00222
00223
00224
00225
00226
00227
00228
00229
00230 static int unload_module(void)
00231 {
00232 int res;
00233
00234 res = ast_custom_function_unregister(&hangupcause_function);
00235 res |= ast_custom_function_unregister(&hangupcause_keys_function);
00236 res |= ast_unregister_application(app);
00237 return res;
00238 }
00239
00240
00241
00242
00243
00244
00245
00246
00247 static int load_module(void)
00248 {
00249 int res;
00250
00251 res = ast_custom_function_register(&hangupcause_function);
00252 res |= ast_custom_function_register(&hangupcause_keys_function);
00253 res |= ast_register_application_xml(app, hangupcause_clear_exec);
00254 return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
00255 }
00256
00257
00258 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "HANGUPCAUSE related functions and applications");