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 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 229491 $")
00031
00032 #include "asterisk/file.h"
00033 #include "asterisk/channel.h"
00034 #include "asterisk/pbx.h"
00035 #include "asterisk/module.h"
00036 #include "asterisk/lock.h"
00037 #include "asterisk/app.h"
00038
00039 static char *synopsis = "Soft Hangup Application";
00040
00041 static char *desc = " SoftHangup(Technology/resource[,options]):\n"
00042 "Hangs up the requested channel. If there are no channels to hangup,\n"
00043 "the application will report it.\n"
00044 " Options:\n"
00045 " 'a' - hang up all channels on a specified device instead of a single resource\n";
00046
00047 static char *app = "SoftHangup";
00048
00049 enum {
00050 OPTION_ALL = (1 << 0),
00051 };
00052
00053 AST_APP_OPTIONS(app_opts,{
00054 AST_APP_OPTION('a', OPTION_ALL),
00055 });
00056
00057 static int softhangup_exec(struct ast_channel *chan, void *data)
00058 {
00059 struct ast_channel *c = NULL;
00060 char *cut, *opts[0];
00061 char name[AST_CHANNEL_NAME] = "", *parse;
00062 struct ast_flags flags = {0};
00063 int lenmatch;
00064 AST_DECLARE_APP_ARGS(args,
00065 AST_APP_ARG(channel);
00066 AST_APP_ARG(options);
00067 );
00068
00069 if (ast_strlen_zero(data)) {
00070 ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
00071 return 0;
00072 }
00073
00074 parse = ast_strdupa(data);
00075 AST_STANDARD_APP_ARGS(args, parse);
00076
00077 if (args.argc == 2)
00078 ast_app_parse_options(app_opts, &flags, opts, args.options);
00079 lenmatch = strlen(args.channel);
00080
00081 for (c = ast_walk_channel_by_name_prefix_locked(NULL, args.channel, lenmatch);
00082 c;
00083 c = ast_walk_channel_by_name_prefix_locked(c, args.channel, lenmatch)) {
00084 ast_copy_string(name, c->name, sizeof(name));
00085 if (ast_test_flag(&flags, OPTION_ALL)) {
00086
00087 if (!strcmp(c->tech->type, "CAPI")) {
00088 cut = strrchr(name, '/');
00089
00090 } else {
00091
00092 cut = strrchr(name,'-');
00093 }
00094
00095 if (cut)
00096 *cut = 0;
00097 }
00098 if (!strcasecmp(name, args.channel)) {
00099 ast_log(LOG_WARNING, "Soft hanging %s up.\n", c->name);
00100 ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
00101 if (!ast_test_flag(&flags, OPTION_ALL)) {
00102 ast_channel_unlock(c);
00103 break;
00104 }
00105 }
00106 ast_channel_unlock(c);
00107 }
00108
00109 return 0;
00110 }
00111
00112 static int unload_module(void)
00113 {
00114 return ast_unregister_application(app);
00115 }
00116
00117 static int load_module(void)
00118 {
00119 return ast_register_application(app, softhangup_exec, synopsis, desc);
00120 }
00121
00122 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hangs up the requested channel");