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-8/modules/m_cap.c (file contents):
Revision 1222 by michael, Sun Sep 18 10:57:54 2011 UTC vs.
Revision 1230 by michael, Thu Sep 22 19:41:19 2011 UTC

# Line 44 | Line 44
44   #include "packet.h"
45   #include "irc_string.h"
46  
47 – static void m_cap(struct Client *, struct Client *, int, char *[]);
48 –
49 – struct Message cap_msgtab = {
50 –  "CAP", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
51 –  { m_cap, m_cap, m_ignore, m_ignore, m_cap, m_ignore }
52 – };
53 –
54 – void
55 – _modinit(void)
56 – {
57 –  mod_add_cmd(&cap_msgtab);
58 – }
59 –
60 – void
61 – _moddeinit(void)
62 – {
63 –  mod_del_cmd(&cap_msgtab);
64 – }
65 –
66 – const char *_version = "$Revision$";
47  
48   #define CAPFL_HIDDEN    0x0001  /**< Do not advertize this capability */
49   #define CAPFL_PROHIBIT  0x0002  /**< Client may not set this capability */
# Line 162 | Line 142 | find_cap(const char **caplist_p, int *ne
142    return cap;    /* and return the capability (if any) */
143   }
144  
145 < /** Send a CAP \a subcmd list of capability changes to \a sptr.
145 > /** Send a CAP \a subcmd list of capability changes to \a source_p.
146   * If more than one line is necessary, each line before the last has
147   * an added "*" parameter before that line's capability list.
148 < * @param[in] sptr Client receiving capability list.
148 > * @param[in] source_p Client receiving capability list.
149   * @param[in] set Capabilities to show as set (with ack and sticky modifiers).
150   * @param[in] rem Capabalities to show as removed (with no other modifier).
151   * @param[in] subcmd Name of capability subcommand.
152   */
153   static int
154 < send_caplist(struct Client *sptr, unsigned int set,
154 > send_caplist(struct Client *source_p, unsigned int set,
155               unsigned int rem, const char *subcmd)
156   {
157    char capbuf[IRCD_BUFSIZE] = "", pfx[16];
# Line 180 | Line 160 | send_caplist(struct Client *sptr, unsign
160  
161    /* set up the buffer for the final LS message... */
162    clen = snprintf(cmdbuf, sizeof(capbuf), ":%s CAP %s %s ", me.name,
163 <                  sptr->name[0] ? sptr->name : "*", subcmd);
163 >                  source_p->name[0] ? source_p->name : "*", subcmd);
164  
165    for (i = 0, loc = 0; i < CAPAB_LIST_LEN; ++i)
166    {
# Line 219 | Line 199 | send_caplist(struct Client *sptr, unsign
199      if (sizeof(capbuf) < (clen + loc + len + 15))
200      {
201        /* would add too much; must flush */
202 <      sendto_one(sptr, "%s* :%s", cmdbuf, capbuf);
202 >      sendto_one(source_p, "%s* :%s", cmdbuf, capbuf);
203        capbuf[(loc = 0)] = '\0';    /* re-terminate the buffer... */
204      }
205  
# Line 227 | Line 207 | send_caplist(struct Client *sptr, unsign
207                      "%s%s", pfx, capab_list[i].name);
208    }
209  
210 <  sendto_one(sptr, "%s:%s", cmdbuf, capbuf);
210 >  sendto_one(source_p, "%s:%s", cmdbuf, capbuf);
211  
212    return 0;    /* convenience return */
213   }
214  
215   static int
216 < cap_ls(struct Client *sptr, const char *caplist)
216 > cap_ls(struct Client *source_p, const char *caplist)
217   {
218 <  if (IsUnknown(sptr)) /* registration hasn't completed; suspend it... */
219 <    sptr->localClient->registration |= REG_NEED_CAP;
218 >  if (IsUnknown(source_p)) /* registration hasn't completed; suspend it... */
219 >    source_p->localClient->registration |= REG_NEED_CAP;
220  
221 <  return send_caplist(sptr, 0, 0, "LS"); /* send list of capabilities */
221 >  return send_caplist(source_p, 0, 0, "LS"); /* send list of capabilities */
222   }
223  
224   static int
225 < cap_req(struct Client *sptr, const char *caplist)
225 > cap_req(struct Client *source_p, const char *caplist)
226   {
227    const char *cl = caplist;
228    struct capabilities *cap = NULL;
229    unsigned int set = 0, rem = 0;
230 <  unsigned int cs = sptr->localClient->cap_client; /* capability set */
231 <  unsigned int as = sptr->localClient->cap_active; /* active set */
230 >  unsigned int cs = source_p->localClient->cap_client; /* capability set */
231 >  unsigned int as = source_p->localClient->cap_active; /* active set */
232    int neg = 0;
233  
234 <  if (IsUnknown(sptr)) /* registration hasn't completed; suspend it... */
235 <    sptr->localClient->registration |= REG_NEED_CAP;
234 >  if (IsUnknown(source_p)) /* registration hasn't completed; suspend it... */
235 >    source_p->localClient->registration |= REG_NEED_CAP;
236  
237    while (cl) { /* walk through the capabilities list... */
238      if (!(cap = find_cap(&cl, &neg)) /* look up capability... */
239          || (!neg && (cap->flags & CAPFL_PROHIBIT)) /* is it prohibited? */
240          || (neg && (cap->flags & CAPFL_STICKY))) { /* is it sticky? */
241 <      sendto_one(sptr, ":%s CAP %s NAK :%s", me.name,
242 <                 sptr->name[0] ? sptr->name : "*", caplist);
241 >      sendto_one(source_p, ":%s CAP %s NAK :%s", me.name,
242 >                 source_p->name[0] ? source_p->name : "*", caplist);
243        return 0; /* can't complete requested op... */
244      }
245  
# Line 285 | Line 265 | cap_req(struct Client *sptr, const char
265    }
266  
267    /* Notify client of accepted changes and copy over results. */
268 <  send_caplist(sptr, set, rem, "ACK");
268 >  send_caplist(source_p, set, rem, "ACK");
269  
270 <  sptr->localClient->cap_client = cs;
271 <  sptr->localClient->cap_active = as;
270 >  source_p->localClient->cap_client = cs;
271 >  source_p->localClient->cap_active = as;
272  
273    return 0;
274   }
275  
276   static int
277 < cap_ack(struct Client *sptr, const char *caplist)
277 > cap_ack(struct Client *source_p, const char *caplist)
278   {
279    const char *cl = caplist;
280    struct capabilities *cap = NULL;
# Line 309 | Line 289 | cap_ack(struct Client *sptr, const char
289    {
290      /* walk through the capabilities list... */
291      if (!(cap = find_cap(&cl, &neg)) || /* look up capability... */
292 <        (neg ? (sptr->localClient->cap_active & cap->cap) :
293 <              !(sptr->localClient->cap_active & cap->cap))) /* uh... */
292 >        (neg ? (source_p->localClient->cap_active & cap->cap) :
293 >              !(source_p->localClient->cap_active & cap->cap))) /* uh... */
294        continue;
295  
296      if (neg)    /* set or clear the active capability... */
297 <      sptr->localClient->cap_active &= ~cap->cap;
297 >      source_p->localClient->cap_active &= ~cap->cap;
298      else
299 <      sptr->localClient->cap_active |=  cap->cap;
299 >      source_p->localClient->cap_active |=  cap->cap;
300    }
301  
302    return 0;
303   }
304  
305   static int
306 < cap_clear(struct Client *sptr, const char *caplist)
306 > cap_clear(struct Client *source_p, const char *caplist)
307   {
308    struct capabilities *cap = NULL;
309    unsigned int ii;
# Line 334 | Line 314 | cap_clear(struct Client *sptr, const cha
314      cap = &capab_list[ii];
315  
316      /* Only clear active non-sticky capabilities. */
317 <    if (!(sptr->localClient->cap_active & cap->cap) || (cap->flags & CAPFL_STICKY))
317 >    if (!(source_p->localClient->cap_active & cap->cap) || (cap->flags & CAPFL_STICKY))
318        continue;
319  
320      cleared |= cap->cap;
321 <    sptr->localClient->cap_client &= ~cap->cap;
321 >    source_p->localClient->cap_client &= ~cap->cap;
322  
323      if (!(cap->flags & CAPFL_PROTO))
324 <      sptr->localClient->cap_active &= ~cap->cap;
324 >      source_p->localClient->cap_active &= ~cap->cap;
325    }
326  
327 <  return send_caplist(sptr, 0, cleared, "ACK");
327 >  return send_caplist(source_p, 0, cleared, "ACK");
328   }
329  
330   static int
331 < cap_end(struct Client *sptr, const char *caplist)
331 > cap_end(struct Client *source_p, const char *caplist)
332   {
333 <  if (!IsUnknown(sptr))    /* registration has completed... */
333 >  if (!IsUnknown(source_p))    /* registration has completed... */
334      return 0;    /* so just ignore the message... */
335  
336    /* capability negotiation is now done... */
337 <  sptr->localClient->registration &= ~REG_NEED_CAP;
337 >  source_p->localClient->registration &= ~REG_NEED_CAP;
338  
339    /* if client is now done... */
340 <  if (!sptr->localClient->registration)
340 >  if (!source_p->localClient->registration)
341    {
342 <    register_local_user(sptr);
342 >    register_local_user(source_p);
343      return 0;
344    }
345  
# Line 367 | Line 347 | cap_end(struct Client *sptr, const char
347   }
348  
349   static int
350 < cap_list(struct Client *sptr, const char *caplist)
350 > cap_list(struct Client *source_p, const char *caplist)
351   {
352    /* Send the list of the client's capabilities */
353 <  return send_caplist(sptr, sptr->localClient->cap_client, 0, "LIST");
353 >  return send_caplist(source_p, source_p->localClient->cap_client, 0, "LIST");
354   }
355  
356   static struct subcmd
357   {
358    const char *cmd;
359 <  int (*proc)(struct Client *sptr, const char *caplist);
359 >  int (*proc)(struct Client *, const char *);
360   } cmdlist[] = {
361    { "ACK",   cap_ack   },
362    { "CLEAR", cap_clear },
# Line 394 | Line 374 | subcmd_search(const char *cmd, const str
374   }
375  
376   /** Handle a capability request or response from a client.
377 < * \param cptr Client that sent us the message.
378 < * \param sptr Original source of message.
379 < * \param parc Number of arguments.
380 < * \param parv Argument vector.
377 > * \param client_p Client that sent us the message.
378 > * \param source_p Original source of message.
379 > * \param parc     Number of arguments.
380 > * \param parv     Argument vector.
381   */
382   static void
383 < m_cap(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
383 > m_cap(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
384   {
385    const char *subcmd = NULL, *caplist = NULL;
386    struct subcmd *cmd = NULL;
# Line 418 | Line 398 | m_cap(struct Client *cptr, struct Client
398                        sizeof(cmdlist) / sizeof(struct subcmd),
399                        sizeof(struct subcmd), (bqcmp)subcmd_search)))
400    {
401 <    sendto_one(sptr, form_str(ERR_INVALIDCAPCMD), me.name,
402 <               sptr->name[0] ? sptr->name : "*", subcmd);
401 >    sendto_one(source_p, form_str(ERR_INVALIDCAPCMD), me.name,
402 >               source_p->name[0] ? source_p->name : "*", subcmd);
403      return;
404    }
405  
406    /* then execute it... */
407    if (cmd->proc)
408 <    (cmd->proc)(sptr, caplist);
408 >    (cmd->proc)(source_p, caplist);
409   }
410 +
411 + static struct Message cap_msgtab = {
412 +  "CAP", 0, 0, 2, MAXPARA, MFLG_SLOW, 0,
413 +  { m_cap, m_cap, m_ignore, m_ignore, m_cap, m_ignore }
414 + };
415 +
416 + static void
417 + module_init(void)
418 + {
419 +  mod_add_cmd(&cap_msgtab);
420 + }
421 +
422 + static void
423 + module_exit(void)
424 + {
425 +  mod_del_cmd(&cap_msgtab);
426 + }
427 +
428 + struct module module_entry = {
429 +  .node    = { NULL, NULL, NULL },
430 +  .name    = NULL,
431 +  .version = "$Revision$",
432 +  .handle  = NULL,
433 +  .modinit = module_init,
434 +  .modexit = module_exit,
435 +  .flags   = 0
436 + };

Diff Legend

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