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

Comparing:
ircd-hybrid-8/src/parse.c (file contents), Revision 1569 by michael, Tue Oct 16 18:46:53 2012 UTC vs.
ircd-hybrid/trunk/src/parse.c (file contents), Revision 3872 by michael, Fri Jun 6 13:20:05 2014 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  parse.c: The message parser.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2014 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file parse.c
23 > * \brief The message parser.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
# Line 28 | Line 30
30   #include "channel.h"
31   #include "hash.h"
32   #include "irc_string.h"
31 #include "sprintf_irc.h"
33   #include "ircd.h"
34   #include "numeric.h"
35   #include "log.h"
36   #include "send.h"
37   #include "conf.h"
38   #include "memory.h"
39 < #include "s_user.h"
40 < #include "s_serv.h"
39 > #include "user.h"
40 > #include "server.h"
41 >
42  
43   /*
44   * (based on orabidoo's parser code)
# Line 52 | Line 54
54   * 't' points -> [MessageTree *] 'r' -> [MessageTree *] -> 'i'
55   *   -> [MessageTree *] -> [MessageTree *] -> 'e' and matches
56   *
57 < *                               'i' -> [MessageTree *] -> 'e' and matches
57 > *                               'i' -> [MessageTree *] -> 'e' and matches
58   *
59   * BUGS (Limitations!)
60 < *
60 > *
61   * I designed this trie to parse ircd commands. Hence it currently
62   * casefolds. This is trivial to fix by increasing MAXPTRLEN.
63   * This trie also "folds" '{' etc. down. This means, the input to this
# Line 65 | Line 67
67   * MAXPTRLEN 128.
68   *
69   * This is also not a patricia trie. On short ircd tokens, this is
70 < * not likely going to matter.
70 > * not likely going to matter.
71   *
72   * Diane Bruce (Dianora), June 6 2003
73   */
74  
75 < #define MAXPTRLEN       32
75 > #define MAXPTRLEN 32
76                                  /* Must be a power of 2, and
77                                   * larger than 26 [a-z]|[A-Z]
78                                   * its used to allocate the set
# Line 89 | Line 91
91  
92   struct MessageTree
93   {
94 <  int links; /* Count of all pointers (including msg) at this node
95 <              * used as reference count for deletion of _this_ node.
96 <              */
94 >  int links; /* Count of all pointers (including msg) at this node
95 >              * used as reference count for deletion of _this_ node.
96 >              */
97    struct Message *msg;
98    struct MessageTree *pointers[MAXPTRLEN];
99   };
100  
101   static struct MessageTree msg_tree;
102  
103 < /*
102 < * NOTE: parse() should not be called recursively by other functions!
103 < */
104 < static char *sender;
105 < static char *para[MAXPARA + 2]; /* <prefix> + <params> + NULL */
106 < static char buffer[1024];
107 <
108 < static int cancel_clients(struct Client *, struct Client *, char *);
103 > static void cancel_clients(struct Client *, struct Client *, char *);
104   static void remove_unknown(struct Client *, char *, char *);
105 < static void handle_numeric(char[], struct Client *, struct Client *, int, char *[]);
106 < static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char *[]);
105 > static void handle_numeric(unsigned int, struct Client *, int, char *[]);
106 > static void handle_command(struct Message *, struct Client *, unsigned int, char *[]);
107  
108  
109   /*
# Line 121 | Line 116 | parse(struct Client *client_p, char *pbu
116   {
117    struct Client *from = client_p;
118    struct Message *msg_ptr = NULL;
119 +  char *para[MAXPARA + 2];  /* <command> + <parameters> + NULL */
120    char *ch = NULL;
121    char *s = NULL;
122 <  char *numeric = NULL;
122 >  unsigned int numeric = 0;
123    unsigned int parc = 0;
124    unsigned int paramcount;
125  
# Line 131 | Line 127 | parse(struct Client *client_p, char *pbu
127      return;
128  
129    assert(client_p->localClient->fd.flags.open);
130 <  assert((bufend - pbuffer) < 512);
130 >  assert((bufend - pbuffer) < IRCD_BUFSIZE);
131  
132 <  for (ch = pbuffer; *ch == ' '; ++ch) /* skip spaces */
133 <    /* null statement */ ;
132 >  for (ch = pbuffer; *ch == ' '; ++ch)  /* Skip spaces */
133 >    ;
134  
135    if (*ch == ':')
136    {
# Line 142 | Line 138 | parse(struct Client *client_p, char *pbu
138       * Copy the prefix to 'sender' assuming it terminates
139       * with SPACE (or NULL, which is an error, though).
140       */
141 <    sender = ++ch;
141 >    char *sender = ++ch;
142  
143 <    if ((s = strchr(ch, ' ')) != NULL)
143 >    if ((s = strchr(ch, ' ')))
144      {
145        *s = '\0';
146        ch = ++s;
# Line 155 | Line 151 | parse(struct Client *client_p, char *pbu
151        if ((from = find_person(client_p, sender)) == NULL)
152          from = hash_find_server(sender);
153  
154 <      /* Hmm! If the client corresponding to the
155 <       * prefix is not found--what is the correct
156 <       * action??? Now, I will ignore the message
157 <       * (old IRC just let it through as if the
162 <       * prefix just wasn't there...) --msa
154 >      /*
155 >       * Hmm! If the client corresponding to the prefix is not found--what is
156 >       * the correct action??? Now, I will ignore the message (old IRC just
157 >       * let it through as if the prefix just wasn't there...) --msa
158         */
159        if (from == NULL)
160        {
# Line 186 | Line 181 | parse(struct Client *client_p, char *pbu
181      return;
182    }
183  
184 <  /* Extract the command code from the packet.  Point s to the end
184 >  /*
185 >   * Extract the command code from the packet. Point s to the end
186     * of the command code and calculate the length using pointer
187 <   * arithmetic.  Note: only need length for numerics and *all*
187 >   * arithmetic. Note: only need length for numerics and *all*
188     * numerics must have parameters and thus a space after the command
189     * code. -avalon
190     */
191  
192 <  /* EOB is 3 chars long but is not a numeric */
193 <  if (*(ch + 3) == ' ' && /* ok, lets see if its a possible numeric.. */
192 >  /* EOB is 3 characters long but is not a numeric */
193 >  if (*(ch + 3) == ' ' &&  /* Ok, lets see if its a possible numeric.. */
194        IsDigit(*ch) && IsDigit(*(ch + 1)) && IsDigit(*(ch + 2)))
195    {
196 <    numeric = ch;
197 <    paramcount = MAXPARA;
196 >    numeric = (*ch - '0') * 100 + (*(ch + 1) - '0') * 10 + (*(ch + 2) - '0');
197 >    paramcount = 2;  /* Destination, and the rest of it */
198      ++ServerStats.is_num;
199 <    s = ch + 3;  /* I know this is ' ' from above if            */
200 <    *s++ = '\0'; /* blow away the ' ', and point s to next part */
199 >    s = ch + 3;  /* I know this is ' ' from above if */
200 >    *s++ = '\0';  /* Blow away the ' ', and point s to next part */
201    }
202    else
203 <  {
203 >  {
204      unsigned int ii = 0;
205  
206 <    if ((s = strchr(ch, ' ')) != NULL)
206 >    if ((s = strchr(ch, ' ')))
207        *s++ = '\0';
208  
209      if ((msg_ptr = find_command(ch)) == NULL)
210      {
211 <      /* Note: Give error message *only* to recognized
211 >      /*
212 >       * Note: Give error message *only* to recognized
213         * persons. It's a nightmare situation to have
214         * two programs sending "Unknown command"'s or
215         * equivalent to each other at full blast....
# Line 222 | Line 219 | parse(struct Client *client_p, char *pbu
219         * Hm, when is the buffer empty -- if a command
220         * code has been found ?? -Armin
221         */
222 <      if (*pbuffer != '\0')
226 <      {
222 >      if (*pbuffer)
223          if (IsClient(from))
224 <          sendto_one(from, form_str(ERR_UNKNOWNCOMMAND),
229 <                     me.name, from->name, ch);
230 <      }
224 >          sendto_one_numeric(from, &me, ERR_UNKNOWNCOMMAND, ch);
225  
226        ++ServerStats.is_unco;
227        return;
228      }
229  
230 <    assert(msg_ptr->cmd != NULL);
230 >    assert(msg_ptr->cmd);
231  
232      paramcount = msg_ptr->args_max;
233      ii = bufend - ((s) ? s : ch);
# Line 247 | Line 241 | parse(struct Client *client_p, char *pbu
241     * this last parameter (about same effect as ":" has...) --msa
242     */
243  
244 <  /* Note initially true: s==NULL || *(s-1) == '\0' !! */
244 >  /* Note initially true: s == NULL || *(s - 1) == '\0' !! */
245  
246 <  para[parc] = from->name;
246 >  para[parc] = ch;
247  
248    if (s)
249    {
# Line 267 | Line 261 | parse(struct Client *client_p, char *pbu
261         if (*s == ':')
262         {
263           /* The rest is a single parameter */
264 <         para[++parc] = s + 1;
264 >         para[++parc] = s + (!numeric);  /* Keep the colon if it's a numeric */
265           break;
266         }
267  
# Line 283 | Line 277 | parse(struct Client *client_p, char *pbu
277  
278    para[++parc] = NULL;
279  
280 <  if (msg_ptr != NULL)
281 <    handle_command(msg_ptr, client_p, from, parc, para);
280 >  if (msg_ptr)
281 >    handle_command(msg_ptr, from, parc, para);
282    else
283 <    handle_numeric(numeric, client_p, from, parc, para);
283 >    handle_numeric(numeric, from, parc, para);
284   }
285  
286   /* handle_command()
# Line 300 | Line 294 | parse(struct Client *client_p, char *pbu
294   * side effects -
295   */
296   static void
297 < handle_command(struct Message *mptr, struct Client *client_p,
298 <               struct Client *from, unsigned int i, char *hpara[])
297 > handle_command(struct Message *mptr, struct Client *source_p,
298 >               unsigned int i, char *para[])
299   {
300 <  MessageHandler handler = 0;
301 <
308 <  if (IsServer(client_p))
309 <    mptr->rcount++;
310 <
311 <  mptr->count++;
300 >  if (IsServer(source_p->from))
301 >    ++mptr->rcount;
302  
303 <  handler = mptr->handlers[client_p->handler];
303 >  ++mptr->count;
304  
305 <  /* check right amount of params is passed... --is */
305 >  /* Check right amount of parameters is passed... --is */
306    if (i < mptr->args_min)
307 <  {
318 <    if (!IsServer(client_p))
319 <    {
320 <      sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS),
321 <                   me.name, EmptyString(hpara[0]) ? "*" : hpara[0], mptr->cmd);
322 <    }
323 <    else
324 <    {
325 <      sendto_realops_flags(UMODE_ALL, L_ALL,
326 <                           "Dropping server %s due to (invalid) command '%s' "
327 <                           "with only %d arguments (expecting %d).",
328 <                           client_p->name, mptr->cmd, i, mptr->args_min);
329 <      ilog(LOG_TYPE_IRCD, "Insufficient parameters (%d) for command '%s' from %s.",
330 <           i, mptr->cmd, client_p->name);
331 <      exit_client(client_p, client_p,
332 <                  "Not enough arguments to server command.");
333 <    }
334 <  }
307 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, mptr->cmd);
308    else
309 <    (*handler)(client_p, from, i, hpara);
309 >    mptr->handlers[source_p->from->handler](source_p, i, para);
310   }
311  
312   /* add_msg_element()
# Line 357 | Line 330 | handle_command(struct Message *mptr, str
330   * in the parent.
331   */
332   static void
333 < add_msg_element(struct MessageTree *mtree_p,
334 <                struct Message *msg_p, const char *cmd)
333 > add_msg_element(struct MessageTree *mtree_p, struct Message *msg_p,
334 >                const char *cmd)
335   {
336 <  struct MessageTree *ntree_p;
336 >  struct MessageTree *ntree_p = NULL;
337  
338    if (*cmd == '\0')
339    {
340      mtree_p->msg = msg_p;
341 <    mtree_p->links++;           /* Have msg pointer, so up ref count */
341 >    mtree_p->links++;  /* Have msg pointer, so up ref count */
342    }
343    else
344    {
345 <    /* *cmd & (MAXPTRLEN-1)
345 >    /*
346 >     * *cmd & (MAXPTRLEN-1)
347       * convert the char pointed to at *cmd from ASCII to an integer
348       * between 0 and MAXPTRLEN.
349       * Thus 'A' -> 0x1 'B' -> 0x2 'c' -> 0x3 etc.
350       */
377
351      if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]) == NULL)
352      {
353 <      ntree_p = MyMalloc(sizeof(struct MessageTree));
353 >      ntree_p = MyCalloc(sizeof(struct MessageTree));
354        mtree_p->pointers[*cmd & (MAXPTRLEN - 1)] = ntree_p;
355  
356 <      mtree_p->links++;         /* Have new pointer, so up ref count */
356 >      mtree_p->links++;  /* Have new pointer, so up ref count */
357      }
358  
359      add_msg_element(ntree_p, msg_p, cmd + 1);
# Line 413 | Line 386 | add_msg_element(struct MessageTree *mtre
386   static void
387   del_msg_element(struct MessageTree *mtree_p, const char *cmd)
388   {
389 <  struct MessageTree *ntree_p;
389 >  struct MessageTree *ntree_p = NULL;
390  
391    /*
392     * In case this is called for a nonexistent command
393     * check that there is a msg pointer here, else links-- goes -ve
394     * -db
395     */
396 <  if ((*cmd == '\0') && (mtree_p->msg != NULL))
396 >  if (*cmd == '\0' && mtree_p->msg)
397    {
398      mtree_p->msg = NULL;
399      mtree_p->links--;
400    }
401    else
402    {
403 <    if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]) != NULL)
403 >    if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]))
404      {
405        del_msg_element(ntree_p, cmd + 1);
406  
407        if (ntree_p->links == 0)
408        {
409 <        mtree_p->pointers[*cmd & (MAXPTRLEN - 1)] = NULL;
410 <        mtree_p->links--;
411 <        MyFree(ntree_p);
409 >        mtree_p->pointers[*cmd & (MAXPTRLEN - 1)] = NULL;
410 >        mtree_p->links--;
411 >        MyFree(ntree_p);
412        }
413      }
414    }
# Line 452 | Line 425 | static struct Message *
425   msg_tree_parse(const char *cmd)
426   {
427    struct MessageTree *mtree = &msg_tree;
428 +
429    assert(cmd && *cmd);
430  
431    while (IsAlpha(*cmd) && (mtree = mtree->pointers[*cmd & (MAXPTRLEN - 1)]))
# Line 466 | Line 440 | msg_tree_parse(const char *cmd)
440   * inputs       - pointer to struct Message
441   * output       - none
442   * side effects - load this one command name
469 *                msg->count msg->bytes is modified in place, in
470 *                modules address space. Might not want to do that...
443   */
444   void
445   mod_add_cmd(struct Message *msg)
446   {
447    assert(msg && msg->cmd);
448  
449 <  /* command already added? */
449 >  /* Command already added? */
450    if (msg_tree_parse(msg->cmd))
451      return;
452  
453    add_msg_element(&msg_tree, msg, msg->cmd);
482  msg->count = msg->rcount = msg->bytes = 0;
454   }
455  
456   /* mod_del_cmd()
# Line 493 | Line 464 | mod_del_cmd(struct Message *msg)
464   {
465    assert(msg && msg->cmd);
466  
467 +  if (!msg_tree_parse(msg->cmd))
468 +    return;
469 +
470    del_msg_element(&msg_tree, msg->cmd);
471   }
472  
# Line 511 | Line 485 | find_command(const char *cmd)
485   static void
486   recurse_report_messages(struct Client *source_p, const struct MessageTree *mtree)
487   {
488 <  unsigned int i;
488 >  if (mtree->msg)
489 >    sendto_one_numeric(source_p, &me, RPL_STATSCOMMANDS,
490 >                       mtree->msg->cmd,
491 >                       mtree->msg->count, mtree->msg->bytes,
492 >                       mtree->msg->rcount);
493  
494 <  if (mtree->msg != NULL)
495 <    sendto_one(source_p, form_str(RPL_STATSCOMMANDS),
518 <               me.name, source_p->name, mtree->msg->cmd,
519 <               mtree->msg->count, mtree->msg->bytes,
520 <               mtree->msg->rcount);
521 <
522 <  for (i = 0; i < MAXPTRLEN; ++i)
523 <    if (mtree->pointers[i] != NULL)
494 >  for (unsigned int i = 0; i < MAXPTRLEN; ++i)
495 >    if (mtree->pointers[i])
496        recurse_report_messages(source_p, mtree->pointers[i]);
497   }
498  
# Line 534 | Line 506 | void
506   report_messages(struct Client *source_p)
507   {
508    const struct MessageTree *mtree = &msg_tree;
537  unsigned int i;
509  
510 <  for (i = 0; i < MAXPTRLEN; ++i)
511 <    if (mtree->pointers[i] != NULL)
510 >  for (unsigned int i = 0; i < MAXPTRLEN; ++i)
511 >    if (mtree->pointers[i])
512        recurse_report_messages(source_p, mtree->pointers[i]);
513   }
514  
515   /* cancel_clients()
516   *
517 < * inputs       -
518 < * output       -
519 < * side effects -
517 > * inputs       -
518 > * output       -
519 > * side effects -
520   */
521 < static int
521 > static void
522   cancel_clients(struct Client *client_p, struct Client *source_p, char *cmd)
523   {
553  /* kill all possible points that are causing confusion here,
554   * I'm not sure I've got this all right...
555   * - avalon
556   *
557   * knowing avalon, probably not.
558   */
559
560  /* with TS, fake prefixes are a common thing, during the
561   * connect burst when there's a nick collision, and they
562   * must be ignored rather than killed because one of the
563   * two is surviving.. so we don't bother sending them to
564   * all ops everytime, as this could send 'private' stuff
565   * from lagged clients. we do send the ones that cause
566   * servers to be dropped though, as well as the ones from
567   * non-TS servers -orabidoo
568   */
569  /* Incorrect prefix for a server from some connection.  If it is a
570   * client trying to be annoying, just QUIT them, if it is a server
571   * then the same deal.
572   */
524    if (IsServer(source_p) || IsMe(source_p))
525    {
526 <    sendto_realops_flags(UMODE_DEBUG, L_ADMIN, "Message for %s[%s] from %s",
526 >    sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE,
527 >                         "Message for %s[%s] from %s",
528                           source_p->name, source_p->from->name,
529                           get_client_name(client_p, SHOW_IP));
530 <    sendto_realops_flags(UMODE_DEBUG, L_OPER,  "Message for %s[%s] from %s",
530 >    sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE,
531 >                         "Message for %s[%s] from %s",
532                           source_p->name, source_p->from->name,
533                           get_client_name(client_p, MASK_IP));
534 <    sendto_realops_flags(UMODE_DEBUG, L_ALL,
534 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
535                           "Not dropping server %s (%s) for Fake Direction",
536                           client_p->name, source_p->name);
537 <    return -1;
585 <    /* return exit_client(client_p, client_p, &me, "Fake Direction");*/
537 >    return;
538    }
539  
540 <  /* Ok, someone is trying to impose as a client and things are
589 <   * confused.  If we got the wrong prefix from a server, send out a
590 <   * kill, else just exit the lame client.
591 <   */
592 <  /* If the fake prefix is coming from a TS server, discard it
593 <   * silently -orabidoo
594 <   *
595 <   * all servers must be TS these days --is
596 <   */
597 <  sendto_realops_flags(UMODE_DEBUG, L_ADMIN,
540 >  sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE,
541                         "Message for %s[%s@%s!%s] from %s (TS, ignored)",
542                         source_p->name, source_p->username, source_p->host,
543                         source_p->from->name, get_client_name(client_p, SHOW_IP));
544 <  sendto_realops_flags(UMODE_DEBUG, L_OPER,
544 >  sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE,
545                         "Message for %s[%s@%s!%s] from %s (TS, ignored)",
546                         source_p->name, source_p->username, source_p->host,
547                         source_p->from->name, get_client_name(client_p, MASK_IP));
605
606  return 0;
548   }
549  
550   /* remove_unknown()
551   *
552 < * inputs       -
553 < * output       -
554 < * side effects -
552 > * inputs       -
553 > * output       -
554 > * side effects -
555   */
556   static void
557   remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
558   {
559 <  /* Do kill if it came from a server because it means there is a ghost
559 >  /*
560 >   * Do kill if it came from a server because it means there is a ghost
561     * user on the other server which needs to be removed. -avalon
562     * Tell opers about this. -Taner
563     */
564 <  /* '[0-9]something'  is an ID      (KILL/SQUIT depending on its length)
564 >  /*
565 >   * '[0-9]something'  is an ID      (KILL/SQUIT depending on its length)
566     * 'nodots'          is a nickname (KILL)
567     * 'no.dot.at.start' is a server   (SQUIT)
568     */
569 <  if ((IsDigit(*lsender) && strlen(lsender) <= IRC_MAXSID) ||
627 <      strchr(lsender, '.') != NULL)
569 >  if ((IsDigit(*lsender) && strlen(lsender) <= IRC_MAXSID) || strchr(lsender, '.'))
570    {
571 <    sendto_realops_flags(UMODE_DEBUG, L_ADMIN,
571 >    sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE,
572                           "Unknown prefix (%s) from %s, Squitting %s",
573                           lbuffer, get_client_name(client_p, SHOW_IP), lsender);
574 <    sendto_realops_flags(UMODE_DEBUG, L_OPER,
574 >    sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE,
575                           "Unknown prefix (%s) from %s, Squitting %s",
576                           lbuffer, client_p->name, lsender);
577      sendto_one(client_p, ":%s SQUIT %s :(Unknown prefix (%s) from %s)",
578 <               me.name, lsender, lbuffer, client_p->name);
578 >               me.id, lsender, lbuffer, client_p->name);
579    }
580    else
581      sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)",
582 <               me.name, lsender, me.name);
582 >               me.id, lsender, me.name);
583   }
584  
585   /*
# Line 653 | Line 595 | remove_unknown(struct Client *client_p,
595   *      wrong with the message, just *DROP* it! Don't even think of
596   *      sending back a neat error message -- big danger of creating
597   *      a ping pong error message...
598 + *
599 + * Rewritten by Nemesi, Jan 1999, to support numeric nicks in parv[1]
600 + *
601 + * Called when we get a numeric message from a remote _server_ and we are
602 + * supposed to forward it somewhere. Note that we always ignore numerics sent
603 + * to 'me' and simply drop the message if we can't handle with this properly:
604 + * the savvy approach is NEVER generate an error in response to an... error :)
605   */
606   static void
607 < handle_numeric(char numeric[], struct Client *client_p, struct Client *source_p,
659 <               int parc, char *parv[])
607 > handle_numeric(unsigned int numeric, struct Client *source_p, int parc, char *parv[])
608   {
609 <  struct Client *target_p;
610 <  struct Channel *chptr;
663 <  char *t;    /* current position within the buffer */
664 <  int i, tl;  /* current length of presently being built string in t */
609 >  struct Client *target_p = NULL;
610 >  struct Channel *chptr = NULL;
611  
612 +  /*
613 +   * Avoid trash, we need it to come from a server and have a target
614 +   */
615    if (parc < 2 || !IsServer(source_p))
616      return;
617  
618 <  /* Remap low number numerics. */
619 <  if (numeric[0] == '0')
620 <    numeric[0] = '1';
621 <
622 <  /* Prepare the parameter portion of the message into 'buffer'.
623 <   * (Because the buffer is twice as large as the message buffer
675 <   * for the socket, no overflow can occur here... ...on current
676 <   * assumptions--bets are off, if these are changed --msa)
618 >  /*
619 >   * Who should receive this message ? Will we do something with it ?
620 >   * Note that we use findUser functions, so the target can't be neither
621 >   * a server, nor a channel (?) nor a list of targets (?) .. u2.10
622 >   * should never generate numeric replies to non-users anyway
623 >   * Ahem... it can be a channel actually, csc bots use it :\ --Nem
624     */
625 <  t = buffer;
626 <  for (i = 2; i < (parc - 1); i++)
627 <  {
628 <    tl = ircsprintf(t, " %s", parv[i]);
682 <    t += tl;
683 <  }
684 <
685 <  ircsprintf(t, " :%s", parv[parc-1]);
686 <
687 <  if (((target_p = find_person(client_p, parv[1])) != NULL) ||
688 <      ((target_p = hash_find_server(parv[1])) != NULL))
689 <  {
690 <    if (IsMe(target_p))
691 <    {
692 <      int num;
693 <
694 <      /*
695 <       * We shouldn't get numerics sent to us,
696 <       * any numerics we do get indicate a bug somewhere..
697 <       */
698 <      /* ugh.  this is here because of nick collisions.  when two servers
699 <       * relink, they burst each other their nicks, then perform collides.
700 <       * if there is a nick collision, BOTH servers will kill their own
701 <       * nicks, and BOTH will kill the other servers nick, which wont exist,
702 <       * because it will have been already killed by the local server.
703 <       *
704 <       * unfortunately, as we cant guarantee other servers will do the
705 <       * "right thing" on a nick collision, we have to keep both kills.  
706 <       * ergo we need to ignore ERR_NOSUCHNICK. --fl_
707 <       */
708 <      /* quick comment. This _was_ tried. i.e. assume the other servers
709 <       * will do the "right thing" and kill a nick that is colliding.
710 <       * unfortunately, it did not work. --Dianora
711 <       */
712 <
713 <      /* Yes, a good compiler would have optimised this, but
714 <       * this is probably easier to read. -db
715 <       */
716 <      num = atoi(numeric);
625 >  if (IsChanPrefix(*parv[1]))
626 >    chptr = hash_find_channel(parv[1]);
627 >  else
628 >    target_p = find_person(source_p, parv[1]);
629  
630 <      if ((num != ERR_NOSUCHNICK))
631 <        sendto_realops_flags(UMODE_ALL, L_ADMIN,
720 <                             "*** %s(via %s) sent a %s numeric to me: %s",
721 <                             source_p->name, client_p->name, numeric, buffer);
722 <      return;
723 <    }
724 <    else if (target_p->from == client_p)
725 <    {
726 <      /* This message changed direction (nick collision?)
727 <       * ignore it.
728 <       */
729 <      return;
730 <    }
630 >  if (((!target_p) || (target_p->from == source_p->from)) && !chptr)
631 >    return;
632  
633 <    /* csircd will send out unknown umode flag for +a (admin), drop it here. */
634 <    if ((atoi(numeric) == ERR_UMODEUNKNOWNFLAG) && MyClient(target_p))
635 <      return;
636 <    
637 <    /* Fake it for server hiding, if its our client */
638 <    if (ConfigServerHide.hide_servers &&
639 <        MyClient(target_p) && !HasUMode(target_p, UMODE_OPER))
640 <      sendto_one(target_p, ":%s %s %s%s", me.name, numeric, target_p->name, buffer);
633 >  /*
634 >   * Remap low number numerics, not that I understand WHY.. --Nemesi
635 >   */
636 >  /*
637 >   * Numerics below 100 talk about the current 'connection', you're not
638 >   * connected to a remote server so it doesn't make sense to send them
639 >   * remotely - but the information they contain may be useful, so we
640 >   * remap them up. Weird, but true.  -- Isomer
641 >   */
642 >  if (numeric < 100)
643 >    numeric += 100;
644 >
645 >  if (target_p)
646 >  {
647 >    /* Fake it for server hiding, if it's our client */
648 >    if (ConfigServerHide.hide_servers && MyConnect(target_p) &&
649 >        !HasUMode(target_p, UMODE_OPER))
650 >      sendto_one_numeric(target_p, &me, numeric|SND_EXPLICIT, "%s", parv[2]);
651      else
652 <      sendto_one(target_p, ":%s %s %s%s", ID_or_name(source_p, target_p->from),
742 <                 numeric, ID_or_name(target_p, target_p->from), buffer);
743 <    return;
652 >      sendto_one_numeric(target_p, source_p, numeric|SND_EXPLICIT, "%s", parv[2]);
653    }
654 <  else if ((chptr = hash_find_channel(parv[1])) != NULL)
655 <    sendto_channel_local(ALL_MEMBERS, 0, chptr,
656 <                         ":%s %s %s %s",
748 <                         source_p->name,
749 <                         numeric, chptr->chname, buffer);
654 >  else
655 >    sendto_channel_butone(source_p, source_p, chptr, 0, "%u %s %s",
656 >                          numeric, chptr->chname, parv[2]);
657   }
658  
659   /* m_not_oper()
660 < * inputs       -
660 > * inputs       -
661   * output       -
662   * side effects - just returns a nastyogram to given user
663   */
664 < void
665 < m_not_oper(struct Client *client_p, struct Client *source_p,
759 <           int parc, char *parv[])
760 < {
761 <  sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
762 <             me.name, source_p->name);
763 < }
764 <
765 < void
766 < m_unregistered(struct Client *client_p, struct Client *source_p,
767 <               int parc, char *parv[])
664 > int
665 > m_not_oper(struct Client *source_p, int parc, char *parv[])
666   {
667 <  sendto_one(source_p, form_str(ERR_NOTREGISTERED), me.name,
668 <             source_p->name[0] ? source_p->name : "*");
667 >  sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
668 >  return 0;
669   }
670  
671 < void
672 < m_registered(struct Client *client_p, struct Client *source_p,
775 <             int parc, char *parv[])
671 > int
672 > m_unregistered(struct Client *source_p, int parc, char *parv[])
673   {
674 <  sendto_one(source_p, form_str(ERR_ALREADYREGISTRED),  
675 <             me.name, source_p->name);
674 >  sendto_one_numeric(source_p, &me, ERR_NOTREGISTERED);
675 >  return 0;
676   }
677  
678 < void
679 < m_ignore(struct Client *client_p, struct Client *source_p,
783 <         int parc, char *parv[])
678 > int
679 > m_registered(struct Client *source_p, int parc, char *parv[])
680   {
681 <  return;
681 >  sendto_one_numeric(source_p, &me, ERR_ALREADYREGISTRED);
682 >  return 0;
683   }
684  
685 < void
686 < rfc1459_command_send_error(struct Client *client_p, struct Client *source_p,
790 <                           int parc, char *parv[])
685 > int
686 > m_ignore(struct Client *source_p, int parc, char *parv[])
687   {
688 <  const char *in_para;
793 <
794 <  in_para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>";
795 <
796 <  ilog(LOG_TYPE_IRCD, "Received ERROR message from %s: %s",
797 <       source_p->name, in_para);
798 <
799 <  if (client_p == source_p)
800 <  {
801 <    sendto_realops_flags(UMODE_ALL, L_ADMIN, "ERROR :from %s -- %s",
802 <                         get_client_name(client_p, HIDE_IP), in_para);
803 <    sendto_realops_flags(UMODE_ALL, L_OPER,  "ERROR :from %s -- %s",
804 <                         get_client_name(client_p, MASK_IP), in_para);
805 <  }
806 <  else
807 <  {
808 <    sendto_realops_flags(UMODE_ALL, L_OPER, "ERROR :from %s via %s -- %s",
809 <                         source_p->name, get_client_name(client_p, MASK_IP), in_para);
810 <    sendto_realops_flags(UMODE_ALL, L_ADMIN, "ERROR :from %s via %s -- %s",
811 <                         source_p->name, get_client_name(client_p, HIDE_IP), in_para);
812 <  }
813 <
814 <  if (MyClient(source_p))
815 <    exit_client(source_p, source_p, "ERROR");
688 >  return 0;
689   }

Diff Legend

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