ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_cap.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/modules/m_cap.c (file contents), Revision 872 by michael, Tue Oct 23 10:18:32 2007 UTC vs.
ircd-hybrid/trunk/modules/m_cap.c (file contents), Revision 1592 by michael, Sat Oct 27 21:02:32 2012 UTC

# Line 2 | Line 2
2   *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3   *
4   *  Copyright (C) 2004 Kevin L. Mitchell <klmitch@mit.edu>
5 < *  Copyright (C) 2006 Hybrid Development Team
5 > *  Copyright (C) 2006-2012 Hybrid Development Team
6   *
7   *  This program is free software; you can redistribute it and/or modify
8   *  it under the terms of the GNU General Public License as published by
# Line 28 | Line 28
28   */
29  
30   #include "stdinc.h"
31 #include "handlers.h"
31   #include "client.h"
32   #include "hash.h"
33   #include "ircd.h"
34   #include "numeric.h"
35 < #include "s_conf.h"
35 > #include "conf.h"
36   #include "s_user.h"
37   #include "s_serv.h"
38   #include "send.h"
40 #include "msg.h"
39   #include "parse.h"
40   #include "modules.h"
43 #include "common.h"
41   #include "packet.h"
42   #include "irc_string.h"
43  
47 static void m_cap(struct Client *, struct Client *, int, char *[]);
48
49 struct Message cap_msgtab = {
50  "CAP", 0, 0, 2, 0, MFLG_SLOW, 0,
51  { m_cap, m_cap, m_ignore, m_ignore, m_cap, m_ignore }
52 };
53
54 #ifndef STATIC_MODULES
55 void
56 _modinit(void)
57 {
58  mod_add_cmd(&cap_msgtab);
59 }
60
61 void
62 _moddeinit(void)
63 {
64  mod_del_cmd(&cap_msgtab);
65 }
66
67 const char *_version = "$Revision: 33 $";
68 #endif
44  
45   #define CAPFL_HIDDEN    0x0001  /**< Do not advertize this capability */
46   #define CAPFL_PROHIBIT  0x0002  /**< Client may not set this capability */
# Line 164 | Line 139 | find_cap(const char **caplist_p, int *ne
139    return cap;    /* and return the capability (if any) */
140   }
141  
142 < /** Send a CAP \a subcmd list of capability changes to \a sptr.
142 > /** Send a CAP \a subcmd list of capability changes to \a source_p.
143   * If more than one line is necessary, each line before the last has
144   * an added "*" parameter before that line's capability list.
145 < * @param[in] sptr Client receiving capability list.
145 > * @param[in] source_p Client receiving capability list.
146   * @param[in] set Capabilities to show as set (with ack and sticky modifiers).
147   * @param[in] rem Capabalities to show as removed (with no other modifier).
148   * @param[in] subcmd Name of capability subcommand.
149   */
150   static int
151 < send_caplist(struct Client *sptr, unsigned int set,
151 > send_caplist(struct Client *source_p, unsigned int set,
152               unsigned int rem, const char *subcmd)
153   {
154    char capbuf[IRCD_BUFSIZE] = "", pfx[16];
# Line 182 | Line 157 | send_caplist(struct Client *sptr, unsign
157  
158    /* set up the buffer for the final LS message... */
159    clen = snprintf(cmdbuf, sizeof(capbuf), ":%s CAP %s %s ", me.name,
160 <                  sptr->name[0] ? sptr->name : "*", subcmd);
160 >                  source_p->name[0] ? source_p->name : "*", subcmd);
161  
162    for (i = 0, loc = 0; i < CAPAB_LIST_LEN; ++i)
163    {
# Line 221 | Line 196 | send_caplist(struct Client *sptr, unsign
196      if (sizeof(capbuf) < (clen + loc + len + 15))
197      {
198        /* would add too much; must flush */
199 <      sendto_one(sptr, "%s* :%s", cmdbuf, capbuf);
199 >      sendto_one(source_p, "%s* :%s", cmdbuf, capbuf);
200        capbuf[(loc = 0)] = '\0';    /* re-terminate the buffer... */
201      }
202  
# Line 229 | Line 204 | send_caplist(struct Client *sptr, unsign
204                      "%s%s", pfx, capab_list[i].name);
205    }
206  
207 <  sendto_one(sptr, "%s:%s", cmdbuf, capbuf);
207 >  sendto_one(source_p, "%s:%s", cmdbuf, capbuf);
208  
209    return 0;    /* convenience return */
210   }
211  
212   static int
213 < cap_ls(struct Client *sptr, const char *caplist)
213 > cap_ls(struct Client *source_p, const char *caplist)
214   {
215 <  if (IsUnknown(sptr)) /* registration hasn't completed; suspend it... */
216 <    sptr->localClient->registration |= REG_NEED_CAP;
215 >  if (IsUnknown(source_p)) /* registration hasn't completed; suspend it... */
216 >    source_p->localClient->registration |= REG_NEED_CAP;
217  
218 <  return send_caplist(sptr, 0, 0, "LS"); /* send list of capabilities */
218 >  return send_caplist(source_p, 0, 0, "LS"); /* send list of capabilities */
219   }
220  
221   static int
222 < cap_req(struct Client *sptr, const char *caplist)
222 > cap_req(struct Client *source_p, const char *caplist)
223   {
224    const char *cl = caplist;
225    struct capabilities *cap = NULL;
226    unsigned int set = 0, rem = 0;
227 <  unsigned int cs = sptr->localClient->cap_client; /* capability set */
228 <  unsigned int as = sptr->localClient->cap_active; /* active set */
227 >  unsigned int cs = source_p->localClient->cap_client; /* capability set */
228 >  unsigned int as = source_p->localClient->cap_active; /* active set */
229    int neg = 0;
230  
231 <  if (IsUnknown(sptr)) /* registration hasn't completed; suspend it... */
232 <    sptr->localClient->registration |= REG_NEED_CAP;
231 >  if (IsUnknown(source_p)) /* registration hasn't completed; suspend it... */
232 >    source_p->localClient->registration |= REG_NEED_CAP;
233  
234    while (cl) { /* walk through the capabilities list... */
235      if (!(cap = find_cap(&cl, &neg)) /* look up capability... */
236          || (!neg && (cap->flags & CAPFL_PROHIBIT)) /* is it prohibited? */
237          || (neg && (cap->flags & CAPFL_STICKY))) { /* is it sticky? */
238 <      sendto_one(sptr, ":%s CAP %s NAK :%s", me.name,
239 <                 sptr->name[0] ? sptr->name : "*", caplist);
238 >      sendto_one(source_p, ":%s CAP %s NAK :%s", me.name,
239 >                 source_p->name[0] ? source_p->name : "*", caplist);
240        return 0; /* can't complete requested op... */
241      }
242  
# Line 287 | Line 262 | cap_req(struct Client *sptr, const char
262    }
263  
264    /* Notify client of accepted changes and copy over results. */
265 <  send_caplist(sptr, set, rem, "ACK");
265 >  send_caplist(source_p, set, rem, "ACK");
266  
267 <  sptr->localClient->cap_client = cs;
268 <  sptr->localClient->cap_active = as;
267 >  source_p->localClient->cap_client = cs;
268 >  source_p->localClient->cap_active = as;
269  
270    return 0;
271   }
272  
273   static int
274 < cap_ack(struct Client *sptr, const char *caplist)
274 > cap_ack(struct Client *source_p, const char *caplist)
275   {
276    const char *cl = caplist;
277    struct capabilities *cap = NULL;
# Line 311 | Line 286 | cap_ack(struct Client *sptr, const char
286    {
287      /* walk through the capabilities list... */
288      if (!(cap = find_cap(&cl, &neg)) || /* look up capability... */
289 <        (neg ? (sptr->localClient->cap_active & cap->cap) :
290 <              !(sptr->localClient->cap_active & cap->cap))) /* uh... */
289 >        (neg ? (source_p->localClient->cap_active & cap->cap) :
290 >              !(source_p->localClient->cap_active & cap->cap))) /* uh... */
291        continue;
292  
293      if (neg)    /* set or clear the active capability... */
294 <      sptr->localClient->cap_active &= ~cap->cap;
294 >      source_p->localClient->cap_active &= ~cap->cap;
295      else
296 <      sptr->localClient->cap_active |=  cap->cap;
296 >      source_p->localClient->cap_active |=  cap->cap;
297    }
298  
299    return 0;
300   }
301  
302   static int
303 < cap_clear(struct Client *sptr, const char *caplist)
303 > cap_clear(struct Client *source_p, const char *caplist)
304   {
305    struct capabilities *cap = NULL;
306    unsigned int ii;
# Line 336 | Line 311 | cap_clear(struct Client *sptr, const cha
311      cap = &capab_list[ii];
312  
313      /* Only clear active non-sticky capabilities. */
314 <    if (!(sptr->localClient->cap_active & cap->cap) || (cap->flags & CAPFL_STICKY))
314 >    if (!(source_p->localClient->cap_active & cap->cap) || (cap->flags & CAPFL_STICKY))
315        continue;
316  
317      cleared |= cap->cap;
318 <    sptr->localClient->cap_client &= ~cap->cap;
318 >    source_p->localClient->cap_client &= ~cap->cap;
319  
320      if (!(cap->flags & CAPFL_PROTO))
321 <      sptr->localClient->cap_active &= ~cap->cap;
321 >      source_p->localClient->cap_active &= ~cap->cap;
322    }
323  
324 <  return send_caplist(sptr, 0, cleared, "ACK");
324 >  return send_caplist(source_p, 0, cleared, "ACK");
325   }
326  
327   static int
328 < cap_end(struct Client *sptr, const char *caplist)
328 > cap_end(struct Client *source_p, const char *caplist)
329   {
330 <  if (!IsUnknown(sptr))    /* registration has completed... */
330 >  if (!IsUnknown(source_p))    /* registration has completed... */
331      return 0;    /* so just ignore the message... */
332  
333    /* capability negotiation is now done... */
334 <  sptr->localClient->registration &= ~REG_NEED_CAP;
334 >  source_p->localClient->registration &= ~REG_NEED_CAP;
335  
336    /* if client is now done... */
337 <  if (!sptr->localClient->registration)
337 >  if (!source_p->localClient->registration)
338    {
339 <    char buf[USERLEN + 1];
365 <
366 <    strlcpy(buf, sptr->username, sizeof(buf));
367 <    register_local_user(sptr, sptr, sptr->name, buf);
339 >    register_local_user(source_p);
340      return 0;
341    }
342  
# Line 372 | Line 344 | cap_end(struct Client *sptr, const char
344   }
345  
346   static int
347 < cap_list(struct Client *sptr, const char *caplist)
347 > cap_list(struct Client *source_p, const char *caplist)
348   {
349    /* Send the list of the client's capabilities */
350 <  return send_caplist(sptr, sptr->localClient->cap_client, 0, "LIST");
350 >  return send_caplist(source_p, source_p->localClient->cap_client, 0, "LIST");
351   }
352  
353   static struct subcmd
354   {
355    const char *cmd;
356 <  int (*proc)(struct Client *sptr, const char *caplist);
356 >  int (*proc)(struct Client *, const char *);
357   } cmdlist[] = {
358    { "ACK",   cap_ack   },
359    { "CLEAR", cap_clear },
# Line 399 | Line 371 | subcmd_search(const char *cmd, const str
371   }
372  
373   /** Handle a capability request or response from a client.
374 < * \param cptr Client that sent us the message.
375 < * \param sptr Original source of message.
376 < * \param parc Number of arguments.
377 < * \param parv Argument vector.
374 > * \param client_p Client that sent us the message.
375 > * \param source_p Original source of message.
376 > * \param parc     Number of arguments.
377 > * \param parv     Argument vector.
378   */
379   static void
380 < m_cap(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
380 > m_cap(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
381   {
382 <  char *subcmd = NULL, *caplist = NULL;
382 >  const char *subcmd = NULL, *caplist = NULL;
383    struct subcmd *cmd = NULL;
384  
385 <  if (parc < 2 || EmptyString(parv[1]))    /* a subcommand is required */
385 >  if (EmptyString(parv[1]))    /* a subcommand is required */
386      return;
387  
388    subcmd = parv[1];
# Line 423 | Line 395 | m_cap(struct Client *cptr, struct Client
395                        sizeof(cmdlist) / sizeof(struct subcmd),
396                        sizeof(struct subcmd), (bqcmp)subcmd_search)))
397    {
398 <    sendto_one(sptr, form_str(ERR_INVALIDCAPCMD),
399 <               me.name, sptr->name, subcmd);
398 >    sendto_one(source_p, form_str(ERR_INVALIDCAPCMD), me.name,
399 >               source_p->name[0] ? source_p->name : "*", subcmd);
400      return;
401    }
402  
403    /* then execute it... */
404    if (cmd->proc)
405 <    (cmd->proc)(sptr, caplist);
405 >    (cmd->proc)(source_p, caplist);
406 > }
407 >
408 > static struct Message cap_msgtab = {
409 >  "CAP", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
410 >  { m_cap, m_cap, m_ignore, m_ignore, m_cap, m_ignore }
411 > };
412 >
413 > static void
414 > module_init(void)
415 > {
416 >  mod_add_cmd(&cap_msgtab);
417   }
418 +
419 + static void
420 + module_exit(void)
421 + {
422 +  mod_del_cmd(&cap_msgtab);
423 + }
424 +
425 + struct module module_entry = {
426 +  .node    = { NULL, NULL, NULL },
427 +  .name    = NULL,
428 +  .version = "$Revision$",
429 +  .handle  = NULL,
430 +  .modinit = module_init,
431 +  .modexit = module_exit,
432 +  .flags   = 0
433 + };

Comparing:
ircd-hybrid-7.2/modules/m_cap.c (property svn:executable), Revision 872 by michael, Tue Oct 23 10:18:32 2007 UTC vs.
ircd-hybrid/trunk/modules/m_cap.c (property svn:executable), Revision 1592 by michael, Sat Oct 27 21:02:32 2012 UTC

# Line 1 | Line 0
1 *

Comparing:
ircd-hybrid-7.2/modules/m_cap.c (property svn:keywords), Revision 872 by michael, Tue Oct 23 10:18:32 2007 UTC vs.
ircd-hybrid/trunk/modules/m_cap.c (property svn:keywords), Revision 1592 by michael, Sat Oct 27 21:02:32 2012 UTC

# Line 1 | Line 1
1 < Id
1 > Id Revision

Diff Legend

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