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

Comparing:
ircd-hybrid/src/parse.c (file contents), Revision 1155 by michael, Tue Aug 9 20:27:45 2011 UTC vs.
ircd-hybrid-8/src/parse.c (file contents), Revision 1322 by michael, Fri Mar 30 11:37:32 2012 UTC

# Line 23 | Line 23
23   */
24  
25   #include "stdinc.h"
26 #include "parse.h"
26   #include "client.h"
27 + #include "parse.h"
28   #include "channel.h"
29 #include "handlers.h"
30 #include "common.h"
29   #include "hash.h"
30   #include "irc_string.h"
31   #include "sprintf_irc.h"
32   #include "ircd.h"
33   #include "numeric.h"
34 < #include "s_log.h"
34 > #include "log.h"
35   #include "send.h"
36 < #include "ircd_handler.h"
39 < #include "msg.h"
40 < #include "s_conf.h"
36 > #include "conf.h"
37   #include "memory.h"
38   #include "s_user.h"
39   #include "s_serv.h"
# Line 106 | Line 102 | static struct MessageTree msg_tree;
102   * NOTE: parse() should not be called recursively by other functions!
103   */
104   static char *sender;
105 < static char *para[MAXPARA + 1];
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 *);
109   static void remove_unknown(struct Client *, char *, char *);
110 < static void do_numeric(char[], struct Client *, struct Client *, int, char **);
111 < static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char **);
116 < static void recurse_report_messages(struct Client *, const struct MessageTree *);
110 > static void handle_numeric(char[], struct Client *, struct Client *, int, char *[]);
111 > static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char *[]);
112   static void add_msg_element(struct MessageTree *, struct Message *, const char *);
113   static void del_msg_element(struct MessageTree *, const char *);
114  
120 /* turn a string into a parc/parv pair */
121 static inline int
122 string_to_array(char *string, char *parv[MAXPARA])
123 {
124  char *p;
125  char *buf = string;
126  int x = 1;
127
128  parv[x] = NULL;
129
130  while (*buf == ' ') /* skip leading spaces */
131    buf++;
132
133  if (*buf == '\0') /* ignore all-space args */
134    return(x);
135
136  do
137  {
138    if (*buf == ':') /* Last parameter */
139    {
140      buf++;
141      parv[x++] = buf;
142      parv[x]   = NULL;
143      return(x);
144    }
145    else
146    {
147      parv[x++] = buf;
148      parv[x]   = NULL;
149
150      if ((p = strchr(buf, ' ')) != NULL)
151      {
152        *p++ = '\0';
153        buf  = p;
154      }
155      else
156        return(x);
157    }      
158
159    while (*buf == ' ')
160      buf++;
161
162    if (*buf == '\0')
163      return(x);
164  } while (x < MAXPARA - 1);
165
166  if (*p == ':')
167    p++;
168
169  parv[x++] = p;
170  parv[x]   = NULL;
171  return(x);
172 }
115  
116   /*
117   * parse a buffer.
# Line 180 | Line 122 | void
122   parse(struct Client *client_p, char *pbuffer, char *bufend)
123   {
124    struct Client *from = client_p;
125 <  char *ch;
126 <  char *s;
127 <  char *numeric = 0;
128 <  unsigned int i = 0;
129 <  int paramcount;
130 <  int mpara = 0;
189 <  struct Message *mptr = NULL;
125 >  struct Message *msg_ptr = NULL;
126 >  char *ch = NULL;
127 >  char *s = NULL;
128 >  char *numeric = NULL;
129 >  unsigned int parc = 0;
130 >  unsigned int paramcount;
131  
132    if (IsDefunct(client_p))
133      return;
# Line 194 | Line 135 | parse(struct Client *client_p, char *pbu
135    assert(client_p->localClient->fd.flags.open);
136    assert((bufend - pbuffer) < 512);
137  
138 <  for (ch = pbuffer; *ch == ' '; ch++) /* skip spaces */
138 >  for (ch = pbuffer; *ch == ' '; ++ch) /* skip spaces */
139      /* null statement */ ;
140  
200  para[0] = from->name;
201
141    if (*ch == ':')
142    {
143 <    ch++;
144 <
206 <    /* Copy the prefix to 'sender' assuming it terminates
143 >    /*
144 >     * Copy the prefix to 'sender' assuming it terminates
145       * with SPACE (or NULL, which is an error, though).
146       */
147 <    sender = ch;
147 >    sender = ++ch;
148  
149      if ((s = strchr(ch, ' ')) != NULL)
150      {
151        *s = '\0';
152 <      s++;
215 <      ch = s;
152 >      ch = ++s;
153      }
154  
155      if (*sender && IsServer(client_p))
156      {
220      /*
221       * XXX it could be useful to know which of these occurs most frequently.
222       * the ID check should always come first, though, since it is so easy.
223       */
157        if ((from = find_person(client_p, sender)) == NULL)
158 <        from = find_server(sender);
158 >        from = hash_find_server(sender);
159  
160        /* Hmm! If the client corresponding to the
161         * prefix is not found--what is the correct
# Line 237 | Line 170 | parse(struct Client *client_p, char *pbu
170          return;
171        }
172  
240      para[0] = from->name;
241
173        if (from->from != client_p)
174        {
175          ++ServerStats.is_wrdi;
# Line 248 | Line 179 | parse(struct Client *client_p, char *pbu
179      }
180  
181      while (*ch == ' ')
182 <      ch++;
182 >      ++ch;
183    }
184  
185    if (*ch == '\0')
# Line 268 | Line 199 | parse(struct Client *client_p, char *pbu
199    if (*(ch + 3) == ' ' && /* ok, lets see if its a possible numeric.. */
200        IsDigit(*ch) && IsDigit(*(ch + 1)) && IsDigit(*(ch + 2)))
201    {
271    mptr = NULL;
202      numeric = ch;
203      paramcount = MAXPARA;
204      ++ServerStats.is_num;
# Line 282 | Line 212 | parse(struct Client *client_p, char *pbu
212      if ((s = strchr(ch, ' ')) != NULL)
213        *s++ = '\0';
214  
215 <    if ((mptr = find_command(ch)) == NULL)
215 >    if ((msg_ptr = find_command(ch)) == NULL)
216      {
217        /* Note: Give error message *only* to recognized
218         * persons. It's a nightmare situation to have
# Line 294 | Line 224 | parse(struct Client *client_p, char *pbu
224         * Hm, when is the buffer empty -- if a command
225         * code has been found ?? -Armin
226         */
227 <      if (pbuffer[0] != '\0')
227 >      if (*pbuffer != '\0')
228        {
229          if (IsClient(from))
230            sendto_one(from, form_str(ERR_UNKNOWNCOMMAND),
# Line 305 | Line 235 | parse(struct Client *client_p, char *pbu
235        return;
236      }
237  
238 <    assert(mptr->cmd != NULL);
309 <
310 <    paramcount = mptr->parameters;
311 <    mpara      = mptr->maxpara;
238 >    assert(msg_ptr->cmd != NULL);
239  
240 +    paramcount = msg_ptr->args_max;
241      ii = bufend - ((s) ? s : ch);
242 <    mptr->bytes += ii;
242 >    msg_ptr->bytes += ii;
243    }
244  
245 <  if (s != NULL)
246 <    i = string_to_array(s, para);
247 <  else
245 >  /*
246 >   * Must the following loop really be so devious? On surface it
247 >   * splits the message to parameters from blank spaces. But, if
248 >   * paramcount has been reached, the rest of the message goes into
249 >   * this last parameter (about same effect as ":" has...) --msa
250 >   */
251 >
252 >  /* Note initially true: s==NULL || *(s-1) == '\0' !! */
253 >
254 >  para[parc] = from->name;
255 >
256 >  if (s)
257    {
258 <    i = 0;
259 <    para[1] = NULL;
258 >    if (paramcount > MAXPARA)
259 >      paramcount = MAXPARA;
260 >
261 >    while (1)
262 >    {
263 >       while (*s == ' ')
264 >         *s++ = '\0';
265 >
266 >       if (*s == '\0')
267 >         break;
268 >
269 >       if (*s == ':')
270 >       {
271 >         /* The rest is a single parameter */
272 >         para[++parc] = s + 1;
273 >         break;
274 >       }
275 >
276 >       para[++parc] = s;
277 >
278 >       if (parc >= paramcount)
279 >         break;
280 >
281 >       while (*s && *s != ' ')
282 >         ++s;
283 >    }
284    }
285  
286 <  if (mptr == NULL)
287 <    do_numeric(numeric, client_p, from, i, para);
286 >  para[++parc] = NULL;
287 >
288 >  if (msg_ptr != NULL)
289 >    handle_command(msg_ptr, client_p, from, parc, para);
290    else
291 <    handle_command(mptr, client_p, from, i, para);
291 >    handle_numeric(numeric, client_p, from, parc, para);
292   }
293  
294   /* handle_command()
# Line 364 | Line 327 | handle_command(struct Message *mptr, str
327    handler = mptr->handlers[client_p->handler];
328  
329    /* check right amount of params is passed... --is */
330 <  if (i < mptr->parameters)
330 >  if (i < mptr->args_min)
331    {
332      if (!IsServer(client_p))
333      {
# Line 376 | Line 339 | handle_command(struct Message *mptr, str
339        sendto_realops_flags(UMODE_ALL, L_ALL,
340                             "Dropping server %s due to (invalid) command '%s' "
341                             "with only %d arguments (expecting %d).",
342 <                           client_p->name, mptr->cmd, i, mptr->parameters);
343 <      ilog(L_CRIT, "Insufficient parameters (%d) for command '%s' from %s.",
342 >                           client_p->name, mptr->cmd, i, mptr->args_min);
343 >      ilog(LOG_TYPE_IRCD, "Insufficient parameters (%d) for command '%s' from %s.",
344             i, mptr->cmd, client_p->name);
345        exit_client(client_p, client_p,
346                    "Not enough arguments to server command.");
# Line 479 | Line 442 | del_msg_element(struct MessageTree *mtre
442   {
443    struct MessageTree *ntree_p;
444  
445 <  /* In case this is called for a nonexistent command
445 >  /*
446 >   * In case this is called for a nonexistent command
447     * check that there is a msg pointer here, else links-- goes -ve
448     * -db
449     */
486
450    if ((*cmd == '\0') && (mtree_p->msg != NULL))
451    {
452      mtree_p->msg = NULL;
# Line 536 | Line 499 | msg_tree_parse(const char *cmd, struct M
499   void
500   mod_add_cmd(struct Message *msg)
501   {
502 <  struct Message *found_msg;
540 <
541 <  if (msg == NULL)
542 <    return;
543 <
544 <  /* someone loaded a module with a bad messagetab */
545 <  assert(msg->cmd != NULL);
502 >  assert(msg && msg->cmd);
503  
504    /* command already added? */
505 <  if ((found_msg = msg_tree_parse(msg->cmd, &msg_tree)) != NULL)
505 >  if (msg_tree_parse(msg->cmd, &msg_tree))
506      return;
507  
508    add_msg_element(&msg_tree, msg, msg->cmd);
# Line 561 | Line 518 | mod_add_cmd(struct Message *msg)
518   void
519   mod_del_cmd(struct Message *msg)
520   {
521 <  assert(msg != NULL);
565 <
566 <  if (msg == NULL)
567 <    return;
521 >  assert(msg && msg->cmd);
522  
523    del_msg_element(&msg_tree, msg->cmd);
524   }
# Line 581 | Line 535 | find_command(const char *cmd)
535    return msg_tree_parse(cmd, &msg_tree);
536   }
537  
538 + static void
539 + recurse_report_messages(struct Client *source_p, const struct MessageTree *mtree)
540 + {
541 +  unsigned int i;
542 +
543 +  if (mtree->msg != NULL)
544 +    sendto_one(source_p, form_str(RPL_STATSCOMMANDS),
545 +               me.name, source_p->name, mtree->msg->cmd,
546 +               mtree->msg->count, mtree->msg->bytes,
547 +               mtree->msg->rcount);
548 +
549 +  for (i = 0; i < MAXPTRLEN; ++i)
550 +    if (mtree->pointers[i] != NULL)
551 +      recurse_report_messages(source_p, mtree->pointers[i]);
552 + }
553 +
554   /* report_messages()
555   *
556   * inputs       - pointer to client to report to
# Line 593 | Line 563 | report_messages(struct Client *source_p)
563    const struct MessageTree *mtree = &msg_tree;
564    unsigned int i;
565  
566 <  for (i = 0; i < MAXPTRLEN; i++)
597 <    if (mtree->pointers[i] != NULL)
598 <      recurse_report_messages(source_p, mtree->pointers[i]);
599 < }
600 <
601 < static void
602 < recurse_report_messages(struct Client *source_p, const struct MessageTree *mtree)
603 < {
604 <  unsigned int i;
605 <
606 <  if (mtree->msg != NULL)
607 <    sendto_one(source_p, form_str(RPL_STATSCOMMANDS),
608 <               me.name, source_p->name, mtree->msg->cmd,
609 <               mtree->msg->count, mtree->msg->bytes,
610 <               mtree->msg->rcount);
611 <
612 <  for (i = 0; i < MAXPTRLEN; i++)
566 >  for (i = 0; i < MAXPTRLEN; ++i)
567      if (mtree->pointers[i] != NULL)
568        recurse_report_messages(source_p, mtree->pointers[i]);
569   }
# Line 728 | Line 682 | remove_unknown(struct Client *client_p,
682   *      a ping pong error message...
683   */
684   static void
685 < do_numeric(char numeric[], struct Client *client_p, struct Client *source_p,
686 <           int parc, char *parv[])
685 > handle_numeric(char numeric[], struct Client *client_p, struct Client *source_p,
686 >               int parc, char *parv[])
687   {
688    struct Client *target_p;
689    struct Channel *chptr;
# Line 755 | Line 709 | do_numeric(char numeric[], struct Client
709      t += tl;
710    }
711  
712 <  ircsprintf(t," :%s", parv[parc-1]);
712 >  ircsprintf(t, " :%s", parv[parc-1]);
713  
714    if (((target_p = find_person(client_p, parv[1])) != NULL) ||
715 <      ((target_p = find_server(parv[1])) != NULL))
715 >      ((target_p = hash_find_server(parv[1])) != NULL))
716    {
717      if (IsMe(target_p))
718      {
# Line 808 | Line 762 | do_numeric(char numeric[], struct Client
762      
763      /* Fake it for server hiding, if its our client */
764      if (ConfigServerHide.hide_servers &&
765 <        MyClient(target_p) && !IsOper(target_p))
765 >        MyClient(target_p) && !HasUMode(target_p, UMODE_OPER))
766        sendto_one(target_p, ":%s %s %s%s", me.name, numeric, target_p->name, buffer);
767      else
768        sendto_one(target_p, ":%s %s %s%s", ID_or_name(source_p, target_p->from),
# Line 816 | Line 770 | do_numeric(char numeric[], struct Client
770      return;
771    }
772    else if ((chptr = hash_find_channel(parv[1])) != NULL)
773 <    sendto_channel_local(ALL_MEMBERS, NO, chptr,
773 >    sendto_channel_local(ALL_MEMBERS, 0, chptr,
774                           ":%s %s %s %s",
775                           source_p->name,
776                           numeric, chptr->chname, buffer);
# Line 839 | Line 793 | void
793   m_unregistered(struct Client *client_p, struct Client *source_p,
794                 int parc, char *parv[])
795   {
796 <  /* bit of a hack.
797 <   * I don't =really= want to waste a bit in a flag
844 <   * number_of_nick_changes is only really valid after the client
845 <   * is fully registered..
846 <   */
847 <  if (client_p->localClient->number_of_nick_changes == 0)
848 <  {
849 <    sendto_one(client_p, ":%s %d * %s :Register first.",
850 <               me.name, ERR_NOTREGISTERED, parv[0]);
851 <    client_p->localClient->number_of_nick_changes++;
852 <  }
796 >  sendto_one(source_p, form_str(ERR_NOTREGISTERED), me.name,
797 >             source_p->name[0] ? source_p->name : "*");
798   }
799  
800   void
801   m_registered(struct Client *client_p, struct Client *source_p,
802               int parc, char *parv[])
803   {
804 <  sendto_one(client_p, form_str(ERR_ALREADYREGISTRED),  
804 >  sendto_one(source_p, form_str(ERR_ALREADYREGISTRED),  
805               me.name, source_p->name);
806   }
807  
# Line 875 | Line 820 | rfc1459_command_send_error(struct Client
820  
821    in_para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>";
822  
823 <  ilog(L_ERROR, "Received ERROR message from %s: %s",
823 >  ilog(LOG_TYPE_IRCD, "Received ERROR message from %s: %s",
824         source_p->name, in_para);
825  
826    if (client_p == source_p)

Diff Legend

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