ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/phandler.C
(Generate patch)

Comparing ermyth/src/phandler.C (file contents):
Revision 1.3 by pippijn, Sat Jul 21 13:23:22 2007 UTC vs.
Revision 1.4 by pippijn, Tue Aug 28 17:08:12 2007 UTC

1/* 1/*
2 * phandler.C: Generic protocol handling routines. 2 * phandler.C: Generic protocol handling routines.
3 * Rights to this code are documented in doc/pod/license.pod. 3 * Rights to this code are documented in doc/pod/license.pod.
4 * 4 *
5 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) 5 * Copyright © 2005-2007 Atheme Project (http://www.atheme.org)
6 */ 6 */
7 7
8static char const rcsid[] = "$Id: phandler.C,v 1.3 2007/07/21 13:23:22 pippijn Exp $"; 8static char const rcsid[] = "$Id: phandler.C,v 1.4 2007/08/28 17:08:12 pippijn Exp $";
9 9
10#include "atheme.h" 10#include "atheme.h"
11#include <account/chanacs.h> 11#include <account/chanacs.h>
12#include "uplink.h" 12#include "uplink.h"
13 13
14unsigned int 14namespace protocol
15generic_server_login (void)
16{ 15{
16 unsigned int
17 handler::server_login (void)
18 {
17 /* Nothing to do here. */ 19 /* Nothing to do here. */
18 return 0; 20 return 0;
19} 21 }
20 22
21static void 23 void
22generic_introduce_nick (user_t *u) 24 handler::introduce_nick (user_t *u)
23{ 25 {
24 /* Nothing to do here. */ 26 /* Nothing to do here. */
25} 27 }
26 28
27static void 29 void
28generic_wallops_sts (const char *text) 30 handler::wallops_sts (char const * const text)
29{ 31 {
30 slog (LG_INFO, "Don't know how to send wallops: %s", text); 32 slog (LG_INFO, "Don't know how to send wallops: %s", text);
31} 33 }
32 34
33static void 35 void
34generic_join_sts (channel_t *c, user_t *u, bool isnew, char *modes) 36 handler::join_sts (channel_t *c, user_t *u, bool isnew, char const * const modes)
35{ 37 {
36 /* We can't do anything here. Bail. */ 38 /* We can't do anything here. Bail. */
37} 39 }
38 40
39static void 41 void
40generic_chan_lowerts (channel_t *c, user_t *u) 42 handler::chan_lowerts (channel_t *c, user_t *u)
41{ 43 {
42 slog (LG_ERROR, "chan_lowerts() called but not supported!"); 44 slog (LG_ERROR, "chan_lowerts() called but not supported!");
43 join_sts (c, u, true, channel_modes (c, true)); 45 join_sts (c, u, true, channel_modes (c, true));
44} 46 }
45 47
46static void 48 void
47generic_kick (char *from, char *channel, char *to, char *reason) 49 handler::kick (char const * const from, char const * const channel, char const * const to, char const * const reason)
48{ 50 {
49 /* We can't do anything here. Bail. */ 51 /* We can't do anything here. Bail. */
50} 52 }
51 53
52static void 54 void
53generic_mdchange (char const *target, char const *key, char const *value) 55 handler::mdchange (char const *target, char const *key, char const *value)
54{ 56 {
55 /* We can't do anything here. Bail. */ 57 /* We can't do anything here. Bail. */
56} 58 }
57 59
58static void 60 void
59generic_msg (const char *from, const char *target, const char *fmt, ...) 61 handler::privmsg (char const * const from, char const * const target, char const * const fmt, ...)
60{ 62 {
61 va_list ap; 63 va_list ap;
62 char *buf; 64 char *buf;
63 65
64 va_start (ap, fmt); 66 va_start (ap, fmt);
65 vasprintf (&buf, fmt, ap); 67 vasprintf (&buf, fmt, ap);
66 va_end (ap); 68 va_end (ap);
67 69
68 slog (LG_INFO, "Cannot send message to %s (%s): don't know how. Load a protocol module perhaps?", target, buf); 70 slog (LG_INFO, "Cannot send message to %s (%s): don't know how. Load a protocol module perhaps?", target, buf);
69 free (buf); 71 sfree (buf);
70} 72 }
71 73
72static void 74 void
73generic_notice_user_sts (user_t *from, user_t *target, const char *text) 75 handler::notice_user_sts (user_t *from, user_t *target, char const * const text)
74{ 76 {
75 slog (LG_INFO, "Cannot send notice to %s (%s): don't know how. Load a protocol module perhaps?", target->nick, text); 77 slog (LG_INFO, "Cannot send notice to %s (%s): don't know how. Load a protocol module perhaps?", target->nick, text);
76} 78 }
77 79
78static void 80 void
79generic_notice_global_sts (user_t *from, const char *mask, const char *text) 81 handler::notice_global_sts (user_t *from, char const * const mask, char const * const text)
80{ 82 {
81 slog (LG_INFO, "Cannot send global notice to %s (%s): don't know how. Load a protocol module perhaps?", mask, text); 83 slog (LG_INFO, "Cannot send global notice to %s (%s): don't know how. Load a protocol module perhaps?", mask, text);
82} 84 }
83 85
84static void 86 void
85generic_notice_channel_sts (user_t *from, channel_t *target, const char *text) 87 handler::notice_channel_sts (user_t *from, channel_t *target, char const * const text)
86{ 88 {
87 slog (LG_INFO, "Cannot send notice to %s (%s): don't know how. Load a protocol module perhaps?", target->name, text); 89 slog (LG_INFO, "Cannot send notice to %s (%s): don't know how. Load a protocol module perhaps?", target->name, text);
88} 90 }
89 91
90extern void // XXX: extern 92 void
91generic_wallchops (user_t *sender, channel_t *channel, const char *message) 93 handler::wallchops (user_t *sender, channel_t *channel, char const * const message)
92{ 94 {
93 /* ugly, but always works -- jilles */ 95 /* ugly, but always works -- jilles */
94 node_t *n; 96 node_t *n;
95 chanuser_t *cu; 97 chanuser_t *cu;
96 98
97 LIST_FOREACH (n, channel->members.head) 99 LIST_FOREACH (n, channel->members.head)
98 { 100 {
99 cu = (chanuser_t *) n->data; 101 cu = (chanuser_t *) n->data;
100 if (cu->user->server != me.me && cu->modes & CMODE_OP) 102 if (cu->user->server != me.me && cu->modes & CMODE_OP)
101 notice (sender->nick, cu->user->nick, "[@%s] %s", channel->name, message); 103 notice (sender->nick, cu->user->nick, "[@%s] %s", channel->name, message);
104 }
105 }
102 } 106
103} 107 void
104 108 handler::numeric_sts (char const * const from, int numeric, char const * const target, char const * const fmt, ...)
105static void 109 {
106generic_numeric_sts (char *from, int numeric, char *target, char *fmt, ...)
107{
108 va_list va; 110 va_list va;
109 char *buf; 111 char *buf;
110 112
111 va_start (va, fmt); 113 va_start (va, fmt);
112 vasprintf (&buf, fmt, va); 114 vasprintf (&buf, fmt, va);
113 va_end (va); 115 va_end (va);
114 116
115 sts (":%s %d %s %s", from, numeric, target, buf); 117 sts (":%s %d %s %s", from, numeric, target, buf);
116 free (buf); 118 sfree (buf);
117} 119 }
118 120
119static void 121 void
120generic_skill (char *from, char *nick, char *fmt, ...) 122 handler::skill (char const * const from, char const * const nick, char const * const fmt, ...)
121{ 123 {
122 /* cant do anything here. bail. */ 124 /* cant do anything here. bail. */
123} 125 }
124 126
125static void 127 void
126generic_part_sts (channel_t *c, user_t *u) 128 handler::part_sts (channel_t *c, user_t *u)
127{ 129 {
128 /* cant do anything here. bail. */ 130 /* cant do anything here. bail. */
129} 131 }
130 132
131static void 133 void
132generic_kline_sts (char *server, char *user, char *host, long duration, char *reason) 134 handler::kline_sts (char const * const server, char const * const user, char const * const host, long duration, char const * const reason)
133{ 135 {
134 /* cant do anything here. bail. */ 136 /* cant do anything here. bail. */
135} 137 }
136 138
137static void 139 void
138generic_unkline_sts (char *server, char *user, char *host) 140 handler::unkline_sts (char const * const server, char const * const user, char const * const host)
139{ 141 {
140 /* cant do anything here. bail. */ 142 /* cant do anything here. bail. */
141} 143 }
142 144
143static void 145 void
144generic_topic_sts (channel_t *c, const char *setter, time_t ts, time_t prevts, const char *topic) 146 handler::topic_sts (channel_t *c, char const * const setter, time_t ts, time_t prevts, char const * const topic)
145{ 147 {
146 /* cant do anything here. bail. */ 148 /* cant do anything here. bail. */
147} 149 }
148 150
149static void 151 void
150generic_mode_sts (char *sender, channel_t *target, char *modes) 152 handler::mode_sts (char const * const sender, channel_t *target, char const * const modes)
151{ 153 {
152 /* cant do anything here. bail. */ 154 /* cant do anything here. bail. */
153} 155 }
154 156
155static void 157 void
156generic_ping_sts (void) 158 handler::ping_sts (void)
157{ 159 {
158 /* cant do anything here. bail. */ 160 /* cant do anything here. bail. */
159} 161 }
160 162
161static void 163 void
162generic_quit_sts (user_t *u, const char *reason) 164 handler::quit_sts (user_t *u, char const * const reason)
163{ 165 {
164 /* cant do anything here. bail. */ 166 /* cant do anything here. bail. */
165} 167 }
166 168
167static void 169 void
168generic_on_login (char *origin, char *user, char *wantedhost) 170 handler::ircd_on_login (char const * const origin, char const * const user, char const * const wantedhost)
169{ 171 {
170 /* nothing to do here. */ 172 /* nothing to do here. */
171} 173 }
172 174
173bool 175 bool
174generic_on_logout (char *origin, char *user, char *wantedhost) 176 handler::ircd_on_logout (char const * const origin, char const * const user, char const * const wantedhost)
175{ 177 {
176 /* nothing to do here. */ 178 /* nothing to do here. */
177 return false; 179 return false;
178} 180 }
179 181
180static void 182 void
181generic_jupe (const char *server, const char *reason) 183 handler::jupe (char const * const server, char const * const reason)
182{ 184 {
183 /* nothing to do here. */ 185 /* nothing to do here. */
184} 186 }
185 187
186static void 188 void
187generic_sethost_sts (char *source, char *target, char *host) 189 handler::sethost_sts (char const * const source, char const * const target, char const * const host)
188{ 190 {
189 /* nothing to do here. */ 191 /* nothing to do here. */
190} 192 }
191 193
192extern void // XXX extern? 194 void
193generic_fnc_sts (user_t *source, user_t *u, char *newnick, int type) 195 handler::fnc_sts (user_t *source, user_t *u, char const * const newnick, int type)
194{ 196 {
195 if (type == FNC_FORCE) 197 if (type == FNC_FORCE)
196 skill (source->nick, u->nick, "Nickname enforcement (%s)", u->nick); 198 skill (source->nick, u->nick, "Nickname enforcement (%s)", u->nick);
197} 199 }
198 200
199static void 201 void
200generic_holdnick_sts (user_t *source, int duration, const char *nick, myuser_t *account) 202 handler::holdnick_sts (user_t *source, int duration, char const * const nick, myuser_t *account)
201{ 203 {
202 /* nothing to do here. */ 204 /* nothing to do here. */
203} 205 }
204 206
205static void 207 void
206generic_invite_sts (user_t *source, user_t *target, channel_t *channel) 208 handler::invite_sts (user_t *source, user_t *target, channel_t *channel)
207{ 209 {
208 /* nothing to do here. */ 210 /* nothing to do here. */
209} 211 }
210 212
211static void 213 void
212generic_svslogin_sts (char *target, char *nick, char *user, char *host, char *login) 214 handler::svslogin_sts (char const * const target, char const * const nick, char const * const user, char const * const host, char const * const login)
213{ 215 {
214 /* nothing to do here. */ 216 /* nothing to do here. */
215} 217 }
216 218
217static void 219 void
218generic_sasl_sts (char *target, char mode, char *data) 220 handler::sasl_sts (char const * const target, char const mode, char const * const data)
219{ 221 {
220 /* nothing to do here. */ 222 /* nothing to do here. */
221} 223 }
222 224
223static node_t * 225 node_t *
224generic_next_matching_ban (channel_t *c, user_t *u, int type, node_t *first) 226 handler::next_matching_ban (channel_t *c, user_t *u, int type, node_t *first)
225{ 227 {
226 chanban_t *cb; 228 chanban_t *cb;
227 node_t *n; 229 node_t *n;
228 char hostbuf[NICKLEN + USERLEN + HOSTLEN]; 230 char hostbuf[NICKLEN + USERLEN + HOSTLEN];
229 char realbuf[NICKLEN + USERLEN + HOSTLEN]; 231 char realbuf[NICKLEN + USERLEN + HOSTLEN];
230 char ipbuf[NICKLEN + USERLEN + HOSTLEN]; 232 char ipbuf[NICKLEN + USERLEN + HOSTLEN];
231 233
232 snprintf (hostbuf, sizeof hostbuf, "%s!%s@%s", u->nick, u->user, u->vhost); 234 snprintf (hostbuf, sizeof hostbuf, "%s!%s@%s", u->nick, u->user, u->vhost);
233 snprintf (realbuf, sizeof realbuf, "%s!%s@%s", u->nick, u->user, u->host); 235 snprintf (realbuf, sizeof realbuf, "%s!%s@%s", u->nick, u->user, u->host);
234 /* will be nick!user@ if ip unknown, doesn't matter */ 236 /* will be nick!user@ if ip unknown, doesn't matter */
235 snprintf (ipbuf, sizeof ipbuf, "%s!%s@%s", u->nick, u->user, u->ip); 237 snprintf (ipbuf, sizeof ipbuf, "%s!%s@%s", u->nick, u->user, u->ip);
236 LIST_FOREACH (n, first) 238 LIST_FOREACH (n, first)
237 { 239 {
238 cb = static_cast<chanban_t *> (n->data); 240 cb = static_cast<chanban_t *> (n->data);
239 241
240 if (cb->type == type && (!match (cb->mask, hostbuf) || !match (cb->mask, realbuf) || !match (cb->mask, ipbuf) || (ircd->flags & IRCD_CIDR_BANS && !match_cidr (cb->mask, ipbuf)))) 242 if (cb->type == type && (!match (cb->mask, hostbuf) || !match (cb->mask, realbuf) || !match (cb->mask, ipbuf) || (ircd->flags & IRCD_CIDR_BANS && !match_cidr (cb->mask, ipbuf))))
241 return n; 243 return n;
242 } 244 }
243 return NULL; 245 return NULL;
244} 246 }
245 247
246static node_t * 248 node_t *
247generic_next_matching_host_chanacs (mychan_t *mc, user_t *u, node_t *first) 249 handler::next_matching_host_chanacs (mychan_t *mc, user_t *u, node_t *first)
248{ 250 {
249 chanacs_t *ca; 251 chanacs_t *ca;
250 node_t *n; 252 node_t *n;
251 char hostbuf[NICKLEN + USERLEN + HOSTLEN]; 253 char hostbuf[NICKLEN + USERLEN + HOSTLEN];
252 char ipbuf[NICKLEN + USERLEN + HOSTLEN]; 254 char ipbuf[NICKLEN + USERLEN + HOSTLEN];
253 255
254 snprintf (hostbuf, sizeof hostbuf, "%s!%s@%s", u->nick, u->user, u->vhost); 256 snprintf (hostbuf, sizeof hostbuf, "%s!%s@%s", u->nick, u->user, u->vhost);
255 /* will be nick!user@ if ip unknown, doesn't matter */ 257 /* will be nick!user@ if ip unknown, doesn't matter */
256 snprintf (ipbuf, sizeof ipbuf, "%s!%s@%s", u->nick, u->user, u->ip); 258 snprintf (ipbuf, sizeof ipbuf, "%s!%s@%s", u->nick, u->user, u->ip);
257 259
258 LIST_FOREACH (n, first) 260 LIST_FOREACH (n, first)
259 { 261 {
260 ca = static_cast<chanacs_t *> (n->data); 262 ca = static_cast<chanacs_t *> (n->data);
261 263
262 if (ca->myuser != NULL) 264 if (ca->myuser != NULL)
263 continue; 265 continue;
264 if (!match (ca->host, hostbuf) || !match (ca->host, ipbuf) || (ircd->flags & IRCD_CIDR_BANS && !match_cidr (ca->host, ipbuf))) 266 if (!match (ca->host, hostbuf) || !match (ca->host, ipbuf) || (ircd->flags & IRCD_CIDR_BANS && !match_cidr (ca->host, ipbuf)))
265 return n; 267 return n;
266 } 268 }
267 return NULL; 269 return NULL;
268} 270 }
269 271} // namespace protocol
270unsigned int (*server_login) (void) = generic_server_login;
271void (*introduce_nick) (user_t *u) = generic_introduce_nick;
272void (*wallops_sts) (const char *text) = generic_wallops_sts;
273void (*join_sts) (channel_t *c, user_t *u, bool isnew, char *modes) = generic_join_sts;
274void (*chan_lowerts) (channel_t *c, user_t *u) = generic_chan_lowerts;
275void (*kick) (char *from, char *channel, char *to, char *reason) = generic_kick;
276void (*mdchange) (const char *target, const char *key, const char *value) = generic_mdchange;
277void (*msg) (const char *from, const char *target, const char *fmt, ...) = generic_msg;
278void (*notice_user_sts) (user_t *from, user_t *target, const char *text) = generic_notice_user_sts;
279void (*notice_global_sts) (user_t *from, const char *mask, const char *text) = generic_notice_global_sts;
280void (*notice_channel_sts) (user_t *from, channel_t *target, const char *text) = generic_notice_channel_sts;
281void (*wallchops) (user_t *source, channel_t *target, const char *message) = generic_wallchops;
282void (*numeric_sts) (char *from, int numeric, char *target, char *fmt, ...) = generic_numeric_sts;
283void (*skill) (char *from, char *nick, char *fmt, ...) = generic_skill;
284void (*part_sts) (channel_t *c, user_t *u) = generic_part_sts;
285void (*kline_sts) (char *server, char *user, char *host, long duration, char *reason) = generic_kline_sts;
286void (*unkline_sts) (char *server, char *user, char *host) = generic_unkline_sts;
287void (*topic_sts) (channel_t *c, const char *setter, time_t ts, time_t prevts, const char *topic) = generic_topic_sts;
288void (*mode_sts) (char *sender, channel_t *target, char *modes) = generic_mode_sts;
289void (*ping_sts) (void) = generic_ping_sts;
290void (*quit_sts) (user_t *u, const char *reason) = generic_quit_sts;
291void (*ircd_on_login) (char *origin, char *user, char *wantedhost) = generic_on_login;
292bool (*ircd_on_logout) (char *origin, char *user, char *wantedhost) = generic_on_logout;
293void (*jupe) (const char *server, const char *reason) = generic_jupe;
294void (*sethost_sts) (char *source, char *target, char *host) = generic_sethost_sts;
295void (*fnc_sts) (user_t *source, user_t *u, char *newnick, int type) = generic_fnc_sts;
296void (*holdnick_sts) (user_t *source, int duration, const char *nick, myuser_t *account) = generic_holdnick_sts;
297void (*invite_sts) (user_t *source, user_t *target, channel_t *channel) = generic_invite_sts;
298void (*svslogin_sts) (char *target, char *nick, char *user, char *host, char *login) = generic_svslogin_sts;
299void (*sasl_sts) (char *target, char mode, char *data) = generic_sasl_sts;
300node_t *(*next_matching_ban) (channel_t *c, user_t *u, int type, node_t *first) = generic_next_matching_ban;
301node_t *(*next_matching_host_chanacs) (mychan_t *mc, user_t *u, node_t *first) = generic_next_matching_host_chanacs;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines