ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/phandler.C
Revision: 1.3
Committed: Sat Jul 21 13:23:22 2007 UTC (19 years, 1 month ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.2: +68 -67 lines
Log Message:
- added rcsid to some files
- more documentation tweaks
- made most protocol commands local to phandler.C
- added ircd metadata (inspircd only for now)
- added inspircd swhois support

File Contents

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