Use find_user for existsmailbox
[asterisk/asterisk.git] / apps / app_softhangup.c
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * SoftHangup application
5  * 
6  * Copyright (C) 1999, Mark Spencer
7  *
8  * Mark Spencer <markster@linux-support.net>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #include <sys/types.h>
15 #include <asterisk/file.h>
16 #include <asterisk/logger.h>
17 #include <asterisk/channel.h>
18 #include <asterisk/pbx.h>
19 #include <asterisk/module.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <stdlib.h>
24
25 #include <pthread.h>
26
27
28 static char *synopsis = "Soft Hangup Application";
29
30 static char *tdesc = "Hangs up the requested channel";
31
32 static char *desc = "  SoftHangup(Technology/resource)\n"
33 "Hangs up the requested channel.  Always returns 0\n";
34
35 static char *app = "SoftHangup";
36
37 STANDARD_LOCAL_USER;
38
39 LOCAL_USER_DECL;
40
41 static int softhangup_exec(struct ast_channel *chan, void *data)
42 {
43         struct localuser *u;
44         struct ast_channel *c=NULL;
45         if (!data) {
46                 ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
47                 return 0;
48         }
49         LOCAL_USER_ADD(u);
50         c = ast_channel_walk_locked(NULL);
51         while (c) {
52                 if (!strcasecmp(c->name, data)) {
53                         ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
54                         ast_mutex_unlock(&c->lock);
55                         break;
56                 }
57                 ast_mutex_unlock(&c->lock);
58                 c = ast_channel_walk_locked(c);
59         }
60         LOCAL_USER_REMOVE(u);
61
62         return 0;
63 }
64
65 int unload_module(void)
66 {
67         STANDARD_HANGUP_LOCALUSERS;
68         return ast_unregister_application(app);
69 }
70
71 int load_module(void)
72 {
73         return ast_register_application(app, softhangup_exec, synopsis, desc);
74 }
75
76 char *description(void)
77 {
78         return tdesc;
79 }
80
81 int usecount(void)
82 {
83         int res;
84         STANDARD_USECOUNT(res);
85         return res;
86 }
87
88 char *key()
89 {
90         return ASTERISK_GPL_KEY;
91 }