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