ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/src/phandler.C
Revision: 1.4
Committed: Tue Aug 28 17:08:12 2007 UTC (16 years, 9 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +253 -283 lines
Log Message:
- changed name
- updated the example config to the new system
- added more documentation
- enhanced documentation generators
- added a link to the pdf to the website
- added an RSS feed generator
- transitioned hooks to c++ callbacks
- did various merges with upstream along the way
- added const where appropriate
- removed the old block allocator
- fixed most memory leaks
- transitioned some dictionaries to std::map
- transitioned some lists to std::vector
- made some free functions members where appropriate
- renamed string to dynstr and added a static string ststr
- use NOW instead of time (NULL) if possible
- completely reworked database backends, crypto handlers and protocol handlers
  to use an object factory
- removed the old module system. ermyth does not do any dynamic loading anymore
- fixed most of the build system
- reworked how protocol commands work

File Contents

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