app_softhangup.c
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 #include "asterisk.h"
00033
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00035
00036 #include "asterisk/file.h"
00037 #include "asterisk/channel.h"
00038 #include "asterisk/pbx.h"
00039 #include "asterisk/module.h"
00040 #include "asterisk/lock.h"
00041 #include "asterisk/app.h"
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 static char *app = "SoftHangup";
00067
00068 enum {
00069 OPTION_ALL = (1 << 0),
00070 };
00071
00072 AST_APP_OPTIONS(app_opts,{
00073 AST_APP_OPTION('a', OPTION_ALL),
00074 });
00075
00076 static int softhangup_exec(struct ast_channel *chan, const char *data)
00077 {
00078 struct ast_channel *c = NULL;
00079 char *cut, *opts[0];
00080 char name[AST_CHANNEL_NAME] = "", *parse;
00081 struct ast_flags flags = {0};
00082 int lenmatch;
00083 AST_DECLARE_APP_ARGS(args,
00084 AST_APP_ARG(channel);
00085 AST_APP_ARG(options);
00086 );
00087 struct ast_channel_iterator *iter;
00088
00089 if (ast_strlen_zero(data)) {
00090 ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
00091 return 0;
00092 }
00093
00094 parse = ast_strdupa(data);
00095 AST_STANDARD_APP_ARGS(args, parse);
00096
00097 if (args.argc == 2)
00098 ast_app_parse_options(app_opts, &flags, opts, args.options);
00099 lenmatch = strlen(args.channel);
00100
00101 if (!(iter = ast_channel_iterator_by_name_new(args.channel, lenmatch))) {
00102 return -1;
00103 }
00104
00105 while ((c = ast_channel_iterator_next(iter))) {
00106 ast_channel_lock(c);
00107 ast_copy_string(name, c->name, sizeof(name));
00108 if (ast_test_flag(&flags, OPTION_ALL)) {
00109
00110 if (!strcmp(c->tech->type, "CAPI")) {
00111 cut = strrchr(name, '/');
00112
00113 } else {
00114
00115 cut = strrchr(name,'-');
00116 }
00117
00118 if (cut)
00119 *cut = 0;
00120 }
00121 if (!strcasecmp(name, args.channel)) {
00122 ast_log(LOG_WARNING, "Soft hanging %s up.\n", c->name);
00123 ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
00124 if (!ast_test_flag(&flags, OPTION_ALL)) {
00125 ast_channel_unlock(c);
00126 c = ast_channel_unref(c);
00127 break;
00128 }
00129 }
00130 ast_channel_unlock(c);
00131 c = ast_channel_unref(c);
00132 }
00133
00134 ast_channel_iterator_destroy(iter);
00135
00136 return 0;
00137 }
00138
00139 static int unload_module(void)
00140 {
00141 return ast_unregister_application(app);
00142 }
00143
00144 static int load_module(void)
00145 {
00146 return ast_register_application_xml(app, softhangup_exec);
00147 }
00148
00149 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hangs up the requested channel");