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/trunk/src/parse.c (file contents):
Revision 3105 by michael, Thu Mar 6 00:08:26 2014 UTC vs.
Revision 3504 by michael, Sat May 10 19:51:29 2014 UTC

# Line 36 | Line 36
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   /*
# Line 104 | Line 104 | static char *para[MAXPARA + 2]; /* <comm
104  
105   static int cancel_clients(struct Client *, struct Client *, char *);
106   static void remove_unknown(struct Client *, char *, char *);
107 < static void handle_numeric(char[], struct Client *, struct Client *, int, char *[]);
108 < static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char *[]);
107 > static void handle_numeric(char[], struct Client *, int, char *[]);
108 > static void handle_command(struct Message *, struct Client *, unsigned int, char *[]);
109  
110  
111   /*
# Line 141 | Line 141 | parse(struct Client *client_p, char *pbu
141       */
142      char *sender = ++ch;
143  
144 <    if ((s = strchr(ch, ' ')) != NULL)
144 >    if ((s = strchr(ch, ' ')))
145      {
146        *s = '\0';
147        ch = ++s;
# Line 204 | Line 204 | parse(struct Client *client_p, char *pbu
204    {
205      unsigned int ii = 0;
206  
207 <    if ((s = strchr(ch, ' ')) != NULL)
207 >    if ((s = strchr(ch, ' ')))
208        *s++ = '\0';
209  
210      if ((msg_ptr = find_command(ch)) == NULL)
# Line 220 | Line 220 | parse(struct Client *client_p, char *pbu
220         * Hm, when is the buffer empty -- if a command
221         * code has been found ?? -Armin
222         */
223 <      if (*pbuffer != '\0')
224 <      {
223 >      if (*pbuffer)
224          if (IsClient(from))
225 <          sendto_one(from, form_str(ERR_UNKNOWNCOMMAND),
227 <                     me.name, from->name, ch);
228 <      }
225 >          sendto_one_numeric(from, &me, ERR_UNKNOWNCOMMAND, ch);
226  
227        ++ServerStats.is_unco;
228        return;
229      }
230  
231 <    assert(msg_ptr->cmd != NULL);
231 >    assert(msg_ptr->cmd);
232  
233      paramcount = msg_ptr->args_max;
234      ii = bufend - ((s) ? s : ch);
# Line 245 | Line 242 | parse(struct Client *client_p, char *pbu
242     * this last parameter (about same effect as ":" has...) --msa
243     */
244  
245 <  /* Note initially true: s==NULL || *(s-1) == '\0' !! */
245 >  /* Note initially true: s == NULL || *(s - 1) == '\0' !! */
246  
247    para[parc] = ch;
248  
# Line 265 | Line 262 | parse(struct Client *client_p, char *pbu
262         if (*s == ':')
263         {
264           /* The rest is a single parameter */
265 <         para[++parc] = s + (!numeric);  /* keep the colon if it's a numeric */
265 >         para[++parc] = s + (!numeric);  /* Keep the colon if it's a numeric */
266           break;
267         }
268  
# Line 281 | Line 278 | parse(struct Client *client_p, char *pbu
278  
279    para[++parc] = NULL;
280  
281 <  if (msg_ptr != NULL)
282 <    handle_command(msg_ptr, client_p, from, parc, para);
281 >  if (msg_ptr)
282 >    handle_command(msg_ptr, from, parc, para);
283    else
284 <    handle_numeric(numeric, client_p, from, parc, para);
284 >    handle_numeric(numeric, from, parc, para);
285   }
286  
287   /* handle_command()
# Line 298 | Line 295 | parse(struct Client *client_p, char *pbu
295   * side effects -
296   */
297   static void
298 < handle_command(struct Message *mptr, struct Client *client_p,
299 <               struct Client *from, unsigned int i, char *hpara[])
298 > handle_command(struct Message *mptr, struct Client *source_p,
299 >               unsigned int i, char *hpara[])
300   {
301 <  MessageHandler handler = 0;
302 <
306 <  if (IsServer(client_p))
307 <    mptr->rcount++;
308 <
309 <  mptr->count++;
301 >  if (IsServer(source_p->from))
302 >    ++mptr->rcount;
303  
304 <  handler = mptr->handlers[client_p->handler];
304 >  ++mptr->count;
305  
306 <  /* check right amount of params is passed... --is */
306 >  /* Check right amount of params is passed... --is */
307    if (i < mptr->args_min)
308 <  {
316 <    if (!IsServer(client_p))
317 <    {
318 <      sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS), me.name,
319 <                 client_p->name[0] ? client_p->name : "*", mptr->cmd);
320 <    }
321 <    else
322 <    {
323 <      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
324 <                           "Dropping server %s due to (invalid) command '%s' "
325 <                           "with only %d arguments (expecting %d).",
326 <                           client_p->name, mptr->cmd, i, mptr->args_min);
327 <      ilog(LOG_TYPE_IRCD, "Insufficient parameters (%d) for command '%s' from %s.",
328 <           i, mptr->cmd, client_p->name);
329 <      exit_client(client_p, client_p,
330 <                  "Not enough arguments to server command.");
331 <    }
332 <  }
308 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, mptr->cmd);
309    else
310 <    (*handler)(client_p, from, i, hpara);
310 >    mptr->handlers[source_p->from->handler](source_p, i, hpara);
311   }
312  
313   /* add_msg_element()
# Line 375 | Line 351 | add_msg_element(struct MessageTree *mtre
351       */
352      if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]) == NULL)
353      {
354 <      ntree_p = MyMalloc(sizeof(struct MessageTree));
354 >      ntree_p = MyCalloc(sizeof(struct MessageTree));
355        mtree_p->pointers[*cmd & (MAXPTRLEN - 1)] = ntree_p;
356  
357        mtree_p->links++;  /* Have new pointer, so up ref count */
# Line 418 | Line 394 | del_msg_element(struct MessageTree *mtre
394     * check that there is a msg pointer here, else links-- goes -ve
395     * -db
396     */
397 <  if ((*cmd == '\0') && (mtree_p->msg != NULL))
397 >  if (*cmd == '\0' && mtree_p->msg)
398    {
399      mtree_p->msg = NULL;
400      mtree_p->links--;
401    }
402    else
403    {
404 <    if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]) != NULL)
404 >    if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]))
405      {
406        del_msg_element(ntree_p, cmd + 1);
407  
# Line 450 | Line 426 | static struct Message *
426   msg_tree_parse(const char *cmd)
427   {
428    struct MessageTree *mtree = &msg_tree;
429 +
430    assert(cmd && *cmd);
431  
432    while (IsAlpha(*cmd) && (mtree = mtree->pointers[*cmd & (MAXPTRLEN - 1)]))
# Line 472 | Line 449 | mod_add_cmd(struct Message *msg)
449   {
450    assert(msg && msg->cmd);
451  
452 <  /* command already added? */
452 >  /* Command already added? */
453    if (msg_tree_parse(msg->cmd))
454      return;
455  
# Line 509 | Line 486 | find_command(const char *cmd)
486   static void
487   recurse_report_messages(struct Client *source_p, const struct MessageTree *mtree)
488   {
489 <  unsigned int i;
490 <
491 <  if (mtree->msg != NULL)
492 <    sendto_one(source_p, form_str(RPL_STATSCOMMANDS),
493 <               me.name, source_p->name, mtree->msg->cmd,
517 <               mtree->msg->count, mtree->msg->bytes,
518 <               mtree->msg->rcount);
489 >  if (mtree->msg)
490 >    sendto_one_numeric(source_p, &me, RPL_STATSCOMMANDS,
491 >                       mtree->msg->cmd,
492 >                       mtree->msg->count, mtree->msg->bytes,
493 >                       mtree->msg->rcount);
494  
495 <  for (i = 0; i < MAXPTRLEN; ++i)
496 <    if (mtree->pointers[i] != NULL)
495 >  for (unsigned int i = 0; i < MAXPTRLEN; ++i)
496 >    if (mtree->pointers[i])
497        recurse_report_messages(source_p, mtree->pointers[i]);
498   }
499  
# Line 532 | Line 507 | void
507   report_messages(struct Client *source_p)
508   {
509    const struct MessageTree *mtree = &msg_tree;
535  unsigned int i;
510  
511 <  for (i = 0; i < MAXPTRLEN; ++i)
512 <    if (mtree->pointers[i] != NULL)
511 >  for (unsigned int i = 0; i < MAXPTRLEN; ++i)
512 >    if (mtree->pointers[i])
513        recurse_report_messages(source_p, mtree->pointers[i]);
514   }
515  
# Line 607 | Line 581 | cancel_clients(struct Client *client_p,
581                         "Message for %s[%s@%s!%s] from %s (TS, ignored)",
582                         source_p->name, source_p->username, source_p->host,
583                         source_p->from->name, get_client_name(client_p, MASK_IP));
610
584    return 0;
585   }
586  
# Line 630 | Line 603 | remove_unknown(struct Client *client_p,
603     * 'nodots'          is a nickname (KILL)
604     * 'no.dot.at.start' is a server   (SQUIT)
605     */
606 <  if ((IsDigit(*lsender) && strlen(lsender) <= IRC_MAXSID) ||
634 <      strchr(lsender, '.') != NULL)
606 >  if ((IsDigit(*lsender) && strlen(lsender) <= IRC_MAXSID) || strchr(lsender, '.'))
607    {
608      sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE,
609                           "Unknown prefix (%s) from %s, Squitting %s",
# Line 669 | Line 641 | remove_unknown(struct Client *client_p,
641   * the savvy approach is NEVER generate an error in response to an... error :)
642   */
643   static void
644 < handle_numeric(char numeric[], struct Client *client_p, struct Client *source_p,
673 <               int parc, char *parv[])
644 > handle_numeric(char numeric[], struct Client *source_p, int parc, char *parv[])
645   {
646    struct Client *target_p = NULL;
647    struct Channel *chptr = NULL;
# Line 691 | Line 662 | handle_numeric(char numeric[], struct Cl
662    if (IsChanPrefix(*parv[1]))
663      chptr = hash_find_channel(parv[1]);
664    else
665 <    target_p = find_person(client_p, parv[1]);
665 >    target_p = find_person(source_p, parv[1]);
666  
667 <  if (((!target_p) || (target_p->from == client_p)) && !chptr)
667 >  if (((!target_p) || (target_p->from == source_p->from)) && !chptr)
668      return;
669  
670    /*
# Line 719 | Line 690 | handle_numeric(char numeric[], struct Cl
690                   numeric, ID_or_name(target_p, target_p), parv[2]);
691    }
692    else
693 <    sendto_channel_butone(client_p, source_p, chptr, 0, "%s %s %s",
693 >    sendto_channel_butone(source_p, source_p, chptr, 0, "%s %s %s",
694                            numeric, chptr->chname, parv[2]);
695   }
696  
# Line 729 | Line 700 | handle_numeric(char numeric[], struct Cl
700   * side effects - just returns a nastyogram to given user
701   */
702   int
703 < m_not_oper(struct Client *client_p, struct Client *source_p,
733 <           int parc, char *parv[])
703 > m_not_oper(struct Client *source_p, int parc, char *parv[])
704   {
705 <  sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
736 <             me.name, source_p->name);
705 >  sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
706    return 0;
707   }
708  
709   int
710 < m_unregistered(struct Client *client_p, struct Client *source_p,
742 <               int parc, char *parv[])
710 > m_unregistered(struct Client *source_p, int parc, char *parv[])
711   {
712 <  sendto_one(source_p, form_str(ERR_NOTREGISTERED), me.name,
745 <             source_p->name[0] ? source_p->name : "*");
712 >  sendto_one_numeric(source_p, &me, ERR_NOTREGISTERED);
713    return 0;
714   }
715  
716   int
717 < m_registered(struct Client *client_p, struct Client *source_p,
751 <             int parc, char *parv[])
717 > m_registered(struct Client *source_p, int parc, char *parv[])
718   {
719 <  sendto_one(source_p, form_str(ERR_ALREADYREGISTRED),
754 <             me.name, source_p->name);
719 >  sendto_one_numeric(source_p, &me, ERR_ALREADYREGISTRED);
720    return 0;
721   }
722  
723   int
724 < m_ignore(struct Client *client_p, struct Client *source_p,
760 <         int parc, char *parv[])
724 > m_ignore(struct Client *source_p, int parc, char *parv[])
725   {
726    return 0;
727   }

Diff Legend

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