ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hybrid-ircservices-1/send.c
(Generate patch)

Comparing:
extended-ircservices-1/send.c (file contents), Revision 1194 by michael, Sat Aug 20 18:25:54 2011 UTC vs.
hybrid-ircservices-1/send.c (file contents), Revision 1347 by michael, Wed Apr 11 14:31:21 2012 UTC

# Line 14 | Line 14
14  
15   /*************************************************************************/
16  
17 < time_t last_send;       /* Time last data was sent to server */
17 > time_t last_send;               /* Time last data was sent to server */
18  
19  
20   /* Modes to send for Services users. */
# Line 32 | Line 32 | static void unimplemented(void);
32   FUNCPTR(void, send_nick, (const char *nick, const char *user,
33                            const char *host, const char *server,
34                            const char *name, const char *modes))
35 <     = (void *)unimplemented;
35 >  = (void *) unimplemented;
36   FUNCPTR(void, send_nickchange, (const char *nick, const char *newnick))
37 <     = (void *)unimplemented;
37 >  = (void *) unimplemented;
38   FUNCPTR(void, send_namechange, (const char *nick, const char *newname))
39 <     = (void *)unimplemented;
40 < FUNCPTR(void, send_server, (void))
41 <     = (void *)unimplemented;
39 >  = (void *) unimplemented;
40 > FUNCPTR(void, send_server, (void)) = (void *) unimplemented;
41   FUNCPTR(void, send_server_remote, (const char *server, const char *desc))
42 <     = (void *)unimplemented;
42 >  = (void *) unimplemented;
43   FUNCPTR(void, wallops, (const char *source, const char *fmt, ...)
44 <                        FORMAT(printf,2,3))
46 <     = (void *)unimplemented;
44 >        FORMAT(printf, 2, 3)) = (void *) unimplemented;
45   FUNCPTR(void, notice_all, (const char *source, const char *fmt, ...)
46 <                          FORMAT(printf,2,3))
49 <     = (void *)unimplemented;
46 >        FORMAT(printf, 2, 3)) = (void *) unimplemented;
47   FUNCPTR(void, send_channel_cmd, (const char *source, const char *fmt, ...)
48 <                                FORMAT(printf,2,3))
52 <     = (void *)unimplemented;
48 >        FORMAT(printf, 2, 3)) = (void *) unimplemented;
49   FUNCPTR(void, send_nickchange_remote, (const char *nick, const char *newnick))
50 <     = (void *)unimplemented;
50 >  = (void *) unimplemented;
51  
52   /*************************************************************************/
53  
# Line 59 | Line 55 | FUNCPTR(void, send_nickchange_remote, (c
55   * protocol module set everything up correctly.
56   */
57  
58 < const char *protocol_name    = NULL;
58 > const char *protocol_name = NULL;
59   const char *protocol_version = NULL;
60 < uint32 protocol_features     = PF_UNSET;
61 < int protocol_nickmax         = 0;
60 > uint32 protocol_features = PF_UNSET;
61 > int protocol_nickmax = 0;
62  
63   #define PROTOCHK(var) \
64      if (!var) \
# Line 71 | Line 67 | int protocol_nickmax         = 0;
67      if ((void *)var == (void *)unimplemented) \
68          fatal("Function `" #var "' not set by protocol module `%s'", name);
69  
70 < static int do_load_module(Module *mod, const char *name)
70 > static int
71 > do_load_module(Module * mod, const char *name)
72   {
73 <    /* Assume the first module loaded is a protocol module */
73 >  /* Assume the first module loaded is a protocol module */
74  
75 <    PROTOCHK(protocol_name);
76 <    if (protocol_features & PF_UNSET)
77 <        fatal("Variable `protocol_features' not set by protocol module `%s'",
78 <              name);
79 <    PROTOCHK(protocol_nickmax);
80 <
81 <    FUNCCHK(send_nick);
82 <    FUNCCHK(send_nickchange);
83 <    FUNCCHK(send_namechange);
84 <    FUNCCHK(send_server);
85 <    FUNCCHK(send_server_remote);
86 <    FUNCCHK(wallops);
87 <    FUNCCHK(notice_all);
88 <    FUNCCHK(send_channel_cmd);
89 <    if (protocol_features & PF_CHANGENICK)
90 <        FUNCCHK(send_nickchange_remote);
91 <
92 <    /* Make sure NICKMAX is large enough to hold the largest nickname
93 <     * supported by the protocol plus a trailing NULL. */
94 <    if (protocol_nickmax+1 > NICKMAX)
95 <        fatal("NICKMAX is too small (%d)--increase to at least %d and"
96 <              " recompile", NICKMAX, protocol_nickmax+1);
75 >  PROTOCHK(protocol_name);
76 >  if (protocol_features & PF_UNSET)
77 >    fatal("Variable `protocol_features' not set by protocol module `%s'",
78 >          name);
79 >  PROTOCHK(protocol_nickmax);
80 >
81 >  FUNCCHK(send_nick);
82 >  FUNCCHK(send_nickchange);
83 >  FUNCCHK(send_namechange);
84 >  FUNCCHK(send_server);
85 >  FUNCCHK(send_server_remote);
86 >  FUNCCHK(wallops);
87 >  FUNCCHK(notice_all);
88 >  FUNCCHK(send_channel_cmd);
89 >  if (protocol_features & PF_CHANGENICK)
90 >    FUNCCHK(send_nickchange_remote);
91 >
92 >  /* Make sure NICKMAX is large enough to hold the largest nickname
93 >   * supported by the protocol plus a trailing NULL. */
94 >  if (protocol_nickmax + 1 > NICKMAX)
95 >    fatal("NICKMAX is too small (%d)--increase to at least %d and"
96 >          " recompile", NICKMAX, protocol_nickmax + 1);
97  
98 <    /* Remove the callback now that everything's checked. */
99 <    remove_callback(NULL, "load module", do_load_module);
98 >  /* Remove the callback now that everything's checked. */
99 >  remove_callback(NULL, "load module", do_load_module);
100  
101 <    return 0;
101 >  return 0;
102   }
103  
104   #undef FUNCCHK
105   #undef PROTOCHK
106  
107  
108 < int send_init(int ac, char **av)
108 > int
109 > send_init(int ac, char **av)
110   {
111 <    if (!add_callback(NULL, "load module", do_load_module)) {
112 <        log("send.c: Unable to add load module callback");
113 <        return 0;
114 <    }
115 <    return 1;
111 >  if (!add_callback(NULL, "load module", do_load_module))
112 >  {
113 >    log("send.c: Unable to add load module callback");
114 >    return 0;
115 >  }
116 >  return 1;
117   }
118  
119   /*************************************************************************/
120  
121   /* Cleanup. */
122  
123 < void send_cleanup(void)
123 > void
124 > send_cleanup(void)
125   {
126 <    remove_callback(NULL, "load module", do_load_module);
126 >  remove_callback(NULL, "load module", do_load_module);
127   }
128  
129   /*************************************************************************/
# Line 134 | Line 134 | void send_cleanup(void)
134   * these functions do nothing.
135   */
136  
137 < void send_cmd(const char *source, const char *fmt, ...)
137 > void
138 > send_cmd(const char *source, const char *fmt, ...)
139   {
140 <    va_list args;
140 >  va_list args;
141  
142 <    va_start(args, fmt);
143 <    vsend_cmd(source, fmt, args);
144 <    va_end(args);
145 < }
146 <
147 < void vsend_cmd(const char *source, const char *fmt, va_list args)
148 < {
149 <    char buf[BUFSIZE];
150 <
151 <    if (!servsock)
152 <        return;
153 <    vsnprintf(buf, sizeof(buf), fmt, args);
154 <    if (source) {
155 <        if (servsock)
156 <            sockprintf(servsock, ":%s %s\r\n", source, buf);
157 <        log_debug(1, "Sent: :%s %s", source, buf);
158 <    } else {
159 <        if (servsock)
160 <            sockprintf(servsock, "%s\r\n", buf);
161 <        log_debug(1, "Sent: %s", buf);
162 <    }
163 <    last_send = time(NULL);
142 >  va_start(args, fmt);
143 >  vsend_cmd(source, fmt, args);
144 >  va_end(args);
145 > }
146 >
147 > void
148 > vsend_cmd(const char *source, const char *fmt, va_list args)
149 > {
150 >  char buf[BUFSIZE];
151 >
152 >  if (!servsock)
153 >    return;
154 >  vsnprintf(buf, sizeof(buf), fmt, args);
155 >  if (source)
156 >  {
157 >    if (servsock)
158 >      sockprintf(servsock, ":%s %s\r\n", source, buf);
159 >    log_debug(1, "Sent: :%s %s", source, buf);
160 >  }
161 >  else
162 >  {
163 >    if (servsock)
164 >      sockprintf(servsock, "%s\r\n", buf);
165 >    log_debug(1, "Sent: %s", buf);
166 >  }
167 >  last_send = time(NULL);
168   }
169  
170   /*************************************************************************/
# Line 167 | Line 172 | void vsend_cmd(const char *source, const
172  
173   /* Send an ERROR message and close the connection to the server. */
174  
175 < void send_error(const char *fmt, ...)
175 > void
176 > send_error(const char *fmt, ...)
177   {
178 <    va_list args;
179 <    char buf[BUFSIZE];
178 >  va_list args;
179 >  char buf[BUFSIZE];
180  
181 <    snprintf(buf, sizeof(buf), "ERROR :%s", fmt);
182 <    va_start(args, fmt);
183 <    vsend_cmd(NULL, buf, args);
184 <    va_end(args);
185 <    disconn(servsock);
181 >  snprintf(buf, sizeof(buf), "ERROR :%s", fmt);
182 >  va_start(args, fmt);
183 >  vsend_cmd(NULL, buf, args);
184 >  va_end(args);
185 >  disconn(servsock);
186   }
187  
188   /*************************************************************************/
# Line 186 | Line 192 | void send_error(const char *fmt, ...)
192   * zero to force our modes through.)
193   */
194  
195 < void send_cmode_cmd(const char *source, const char *channel,
196 <                    const char *fmt, ...)
195 > void
196 > send_cmode_cmd(const char *source, const char *channel, const char *fmt, ...)
197   {
198 <    va_list args;
199 <    char buf[BUFSIZE];
198 >  va_list args;
199 >  char buf[BUFSIZE];
200  
201 <    va_start(args, fmt);
202 <    vsnprintf(buf, sizeof(buf), fmt, args);
203 <    va_end(args);
204 <    if (protocol_features & PF_MODETS_FIRST)
205 <        send_channel_cmd(source, "MODE %s 0 %s", channel, buf);
206 <    else
207 <        send_channel_cmd(source, "MODE %s %s", channel, buf);
201 >  va_start(args, fmt);
202 >  vsnprintf(buf, sizeof(buf), fmt, args);
203 >  va_end(args);
204 >  if (protocol_features & PF_MODETS_FIRST)
205 >    send_channel_cmd(source, "MODE %s 0 %s", channel, buf);
206 >  else
207 >    send_channel_cmd(source, "MODE %s %s", channel, buf);
208   }
209  
210   /*************************************************************************/
# Line 209 | Line 215 | void send_cmode_cmd(const char *source,
215   * if the pseudoclient should be invisible (+i).
216   */
217  
218 < void send_pseudo_nick(const char *nick, const char *realname, int flags)
218 > void
219 > send_pseudo_nick(const char *nick, const char *realname, int flags)
220   {
221 <    char modebuf[BUFSIZE];
221 >  char modebuf[BUFSIZE];
222  
223 <    snprintf(modebuf, sizeof(modebuf), "%s%s%s",
224 <             pseudoclient_modes,
225 <             (flags & PSEUDO_OPER) && pseudoclient_oper ? "o" : "",
226 <             (flags & PSEUDO_INVIS) ? "i" : "");
227 <    send_nick(nick, ServiceUser, ServiceHost, ServerName, realname, modebuf);
223 >  snprintf(modebuf, sizeof(modebuf), "%s%s%s",
224 >           pseudoclient_modes,
225 >           (flags & PSEUDO_OPER) && pseudoclient_oper ? "o" : "",
226 >           (flags & PSEUDO_INVIS) ? "i" : "");
227 >  send_nick(nick, ServiceUser, ServiceHost, ServerName, realname, modebuf);
228   }
229  
230   /*************************************************************************/
231  
232   /* Send a NOTICE from the given source to the given nick. */
233  
234 < void notice(const char *source, const char *dest, const char *fmt, ...)
234 > void
235 > notice(const char *source, const char *dest, const char *fmt, ...)
236   {
237 <    va_list args;
238 <    char buf[BUFSIZE];
237 >  va_list args;
238 >  char buf[BUFSIZE];
239  
240 <    va_start(args, fmt);
241 <    vsnprintf(buf, sizeof(buf), fmt, args);
242 <    va_end(args);
243 <    send_cmd(source, "NOTICE %s :%s", dest, buf);
240 >  va_start(args, fmt);
241 >  vsnprintf(buf, sizeof(buf), fmt, args);
242 >  va_end(args);
243 >  send_cmd(source, "NOTICE %s :%s", dest, buf);
244   }
245  
246  
247   /* Send a NULL-terminated array of text as NOTICEs. */
248  
249 < void notice_list(const char *source, const char *dest, const char **text)
249 > void
250 > notice_list(const char *source, const char *dest, const char **text)
251   {
252 <    while (*text) {
253 <        /* Have to kludge around client/server silliness here: if a notice
254 <         * includes no text, it is ignored, so we replace blank lines by
255 <         * lines with a single space. */
256 <        if (**text)
257 <            notice(source, dest, *text);
258 <        else
259 <            notice(source, dest, " ");
260 <        text++;
261 <    }
252 >  while (*text)
253 >  {
254 >    /* Have to kludge around client/server silliness here: if a notice
255 >     * includes no text, it is ignored, so we replace blank lines by
256 >     * lines with a single space. */
257 >    if (**text)
258 >      notice(source, dest, "%s", *text);
259 >    else
260 >      notice(source, dest, " ");
261 >    text++;
262 >  }
263   }
264  
265  
266   /* Send a message in the user's selected language to the user using NOTICE. */
267  
268 < void notice_lang(const char *source, const User *dest, int message, ...)
268 > void
269 > notice_lang(const char *source, const User * dest, int message, ...)
270   {
271 <    va_list args;
272 <    char buf[4096];     /* because messages can be really big */
273 <    char *s, *t;
274 <    const char *fmt;
275 <
276 <    if (!dest)
277 <        return;
278 <    fmt = getstring(dest->ngi, message);
279 <    if (!fmt)
280 <        return;
281 <    va_start(args, message);
282 <    vsnprintf(buf, sizeof(buf), fmt, args);
283 <    va_end(args);
284 <    s = buf;
285 <    while (*s) {
286 <        char c;
287 <        t = s;
288 <        s += strcspn(s, "\n");
289 <        c = *s;
290 <        *s = 0;
291 <        send_cmd(source, "NOTICE %s :%s", dest->nick, *t ? t : " ");
292 <        *s = c;
293 <        if (c)
294 <            s++;
295 <    }
271 >  va_list args;
272 >  char buf[4096];               /* because messages can be really big */
273 >  char *s, *t;
274 >  const char *fmt;
275 >
276 >  if (!dest)
277 >    return;
278 >  fmt = getstring(dest->ngi, message);
279 >  if (!fmt)
280 >    return;
281 >  va_start(args, message);
282 >  vsnprintf(buf, sizeof(buf), fmt, args);
283 >  va_end(args);
284 >  s = buf;
285 >  while (*s)
286 >  {
287 >    char c;
288 >    t = s;
289 >    s += strcspn(s, "\n");
290 >    c = *s;
291 >    *s = 0;
292 >    send_cmd(source, "NOTICE %s :%s", dest->nick, *t ? t : " ");
293 >    *s = c;
294 >    if (c)
295 >      s++;
296 >  }
297   }
298  
299  
# Line 289 | Line 301 | void notice_lang(const char *source, con
301   * to simplify letting help messages display the name of the pseudoclient
302   * that's sending them.
303   */
304 < void notice_help(const char *source, const User *dest, int message, ...)
304 > void
305 > notice_help(const char *source, const User * dest, int message, ...)
306   {
307 <    va_list args;
308 <    char buf[4096], buf2[4096], outbuf[BUFSIZE];
309 <    char *s, *t;
310 <    const char *fmt;
311 <
312 <    if (!dest)
313 <        return;
314 <    fmt = getstring(dest->ngi, message);
315 <    if (!fmt)
316 <        return;
317 <    /* Some sprintf()'s eat %S or turn it into just S, so change all %S's
318 <     * into \1\1... we assume this doesn't occur anywhere else in the
319 <     * string. */
320 <    strbcpy(buf2, fmt);
321 <    strnrepl(buf2, sizeof(buf2), "%S", "\1\1");
322 <    va_start(args, message);
323 <    vsnprintf(buf, sizeof(buf), buf2, args);
324 <    va_end(args);
325 <    s = buf;
326 <    while (*s) {
327 <        char c;
328 <        t = s;
329 <        s += strcspn(s, "\n");
330 <        c = *s;
331 <        *s = 0;
332 <        strbcpy(outbuf, t);
333 <        *s = c;
334 <        if (c)
335 <            s++;
336 <        strnrepl(outbuf, sizeof(outbuf), "\1\1", source);
337 <        send_cmd(source, "NOTICE %s :%s", dest->nick, *outbuf ? outbuf : " ");
338 <    }
307 >  va_list args;
308 >  char buf[4096], buf2[4096], outbuf[BUFSIZE];
309 >  char *s, *t;
310 >  const char *fmt;
311 >
312 >  if (!dest)
313 >    return;
314 >  fmt = getstring(dest->ngi, message);
315 >  if (!fmt)
316 >    return;
317 >  /* Some sprintf()'s eat %S or turn it into just S, so change all %S's
318 >   * into \1\1... we assume this doesn't occur anywhere else in the
319 >   * string. */
320 >  strbcpy(buf2, fmt);
321 >  strnrepl(buf2, sizeof(buf2), "%S", "\1\1");
322 >  va_start(args, message);
323 >  vsnprintf(buf, sizeof(buf), buf2, args);
324 >  va_end(args);
325 >  s = buf;
326 >  while (*s)
327 >  {
328 >    char c;
329 >    t = s;
330 >    s += strcspn(s, "\n");
331 >    c = *s;
332 >    *s = 0;
333 >    strbcpy(outbuf, t);
334 >    *s = c;
335 >    if (c)
336 >      s++;
337 >    strnrepl(outbuf, sizeof(outbuf), "\1\1", source);
338 >    send_cmd(source, "NOTICE %s :%s", dest->nick, *outbuf ? outbuf : " ");
339 >  }
340   }
341  
342   /*************************************************************************/
343  
344   /* Send a PRIVMSG from the given source to the given nick. */
345  
346 < void privmsg(const char *source, const char *dest, const char *fmt, ...)
346 > void
347 > privmsg(const char *source, const char *dest, const char *fmt, ...)
348   {
349 <    va_list args;
350 <    char buf[BUFSIZE];
349 >  va_list args;
350 >  char buf[BUFSIZE];
351  
352 <    va_start(args, fmt);
353 <    vsnprintf(buf, sizeof(buf), fmt, args);
354 <    va_end(args);
355 <    send_cmd(source, "PRIVMSG %s :%s", dest, buf);
352 >  va_start(args, fmt);
353 >  vsnprintf(buf, sizeof(buf), fmt, args);
354 >  va_end(args);
355 >  send_cmd(source, "PRIVMSG %s :%s", dest, buf);
356   }
357  
358   /*************************************************************************/
# Line 345 | Line 360 | void privmsg(const char *source, const c
360  
361   /* Handler for unimplemented functions. */
362  
363 < static void unimplemented(void)
363 > static void
364 > unimplemented(void)
365   {
366 <    fatal("send.c: No (or bad) protocol module loaded.");
366 >  fatal("send.c: No (or bad) protocol module loaded.");
367   }
368  
369   /*************************************************************************/

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)