ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hybrid-ircservices-1/modules/protocol/invitemask.c
Revision: 1209
Committed: Thu Aug 25 19:05:49 2011 UTC (14 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 5204 byte(s)
Log Message:
- run everything thru indent
  "-bli0 -di1 -npcs -nut -cdw -bls -nbbo -bap"

File Contents

# Content
1 /* Invite mask (+I) related functions.
2 *
3 * IRC Services is copyright (c) 1996-2009 Andrew Church.
4 * E-mail: <achurch@achurch.org>
5 * Parts written by Andrew Kempe and others.
6 * This program is free but copyrighted software; see the file GPL.txt for
7 * details.
8 */
9
10 #include "services.h"
11 #include "modules.h"
12 #include "language.h"
13 #include "modules/chanserv/chanserv.h"
14
15 #include "invitemask.h"
16
17 /*************************************************************************/
18
19 static Module *invitemask_module_chanserv;
20
21 static const char **invitemask_p_s_ChanServ = NULL; /* never used if NULL */
22 #define s_ChanServ (*invitemask_p_s_ChanServ)
23
24 /*************************************************************************/
25 /*************************************************************************/
26
27 /* Callback to handle MODE +/-I. */
28
29 static int
30 invitemask_channel_mode(const char *source, Channel * chan,
31 int modechar, int add, char **av)
32 {
33 if (modechar == 'I')
34 {
35 if (add)
36 {
37 ARRAY_EXTEND(chan->invites);
38 chan->invites[chan->invites_count - 1] = sstrdup(av[0]);
39 }
40 else
41 {
42 int i;
43 ARRAY_SEARCH_PLAIN(chan->invites, av[0], irc_stricmp, i);
44 if (i < chan->invites_count)
45 {
46 free(chan->invites[i]);
47 ARRAY_REMOVE(chan->invites, i);
48 }
49 else
50 {
51 module_log("invitemask: MODE %s -I %s: mask not found",
52 chan->name, *av);
53 }
54 }
55 return 0;
56 }
57 return 0;
58 }
59
60 /*************************************************************************/
61
62 /* Callback to handle clearing invite masks for clear_channel(). */
63
64 static void clear_invites(const char *sender, Channel * chan, const User * u);
65
66 static int
67 invitemask_clear_channel(const char *sender, Channel * chan,
68 int what, const void *param)
69 {
70 if (what & (CLEAR_USERS | CLEAR_INVITES))
71 clear_invites(sender, chan, (what & CLEAR_INVITES) ? param : NULL);
72 return 0;
73 }
74
75
76 static void
77 clear_invites(const char *sender, Channel * chan, const User * u)
78 {
79 int i, count;
80 char **invites;
81
82 if (!chan->invites_count)
83 return;
84 count = chan->invites_count;
85 invites = smalloc(sizeof(char *) * count);
86 memcpy(invites, chan->invites, sizeof(char *) * count);
87 for (i = 0; i < count; i++)
88 {
89 if (!u || match_usermask(invites[i], u))
90 set_cmode(sender, chan, "-I", invites[i]);
91 }
92 free(invites);
93 }
94
95 /*************************************************************************/
96
97 /* Callback to handle ChanServ CLEAR INVITES. */
98
99 static int
100 invitemask_cs_clear(User * u, Channel * c, const char *what)
101 {
102 if (stricmp(what, "INVITES") == 0)
103 {
104 clear_invites(s_ChanServ, c, NULL);
105 set_cmode(NULL, c);
106 notice_lang(s_ChanServ, u, CHAN_CLEARED_INVITES, c->name);
107 return 1;
108 }
109 return 0;
110 }
111
112 /*************************************************************************/
113 /*************************************************************************/
114
115 /* Callback to watch for modules being loaded. */
116
117 static int
118 invitemask_load_module(Module * mod, const char *name)
119 {
120 if (strcmp(name, "chanserv/main") == 0)
121 {
122 invitemask_module_chanserv = mod;
123 invitemask_p_s_ChanServ = get_module_symbol(mod, "s_ChanServ");
124 if (invitemask_p_s_ChanServ)
125 {
126 if (!(add_callback(mod, "CLEAR", invitemask_cs_clear)))
127 module_log("invitemask: Unable to add ChanServ CLEAR" " callback");
128 }
129 else
130 {
131 module_log("invitemask: Symbol `s_ChanServ' not found, CLEAR"
132 " INVITES will not be available");
133 }
134 }
135 return 0;
136 }
137
138 /*************************************************************************/
139
140 /* Callback to watch for modules being unloaded. */
141
142 static int
143 invitemask_unload_module(Module * mod)
144 {
145 if (mod == invitemask_module_chanserv)
146 {
147 invitemask_p_s_ChanServ = NULL;
148 invitemask_module_chanserv = NULL;
149 }
150 return 0;
151 }
152
153 /*************************************************************************/
154 /*************************************************************************/
155
156 int
157 init_invitemask(void)
158 {
159 if (!add_callback(NULL, "channel MODE", invitemask_channel_mode)
160 || !add_callback(NULL, "clear channel", invitemask_clear_channel)
161 || !add_callback(NULL, "load module", invitemask_load_module)
162 || !add_callback(NULL, "unload module", invitemask_unload_module))
163 {
164 module_log("invitemask: Unable to add callbacks");
165 exit_invitemask();
166 return 0;
167 }
168 protocol_features |= PF_INVITEMASK;
169 return 1;
170 }
171
172 /*************************************************************************/
173
174 void
175 exit_invitemask(void)
176 {
177 remove_callback(NULL, "unload module", invitemask_unload_module);
178 remove_callback(NULL, "load module", invitemask_load_module);
179 remove_callback(NULL, "clear channel", invitemask_clear_channel);
180 remove_callback(NULL, "channel MODE", invitemask_channel_mode);
181 }
182
183 /*************************************************************************/
184
185 #undef s_ChanServ
186
187 /*
188 * Local variables:
189 * c-file-style: "stroustrup"
190 * c-file-offsets: ((case-label . *) (statement-case-intro . *))
191 * indent-tabs-mode: nil
192 * End:
193 *
194 * vim: expandtab shiftwidth=4:
195 */