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 4552 by michael, Fri Aug 22 09:13:32 2014 UTC vs.
Revision 8715 by michael, Sun Dec 9 20:17:02 2018 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2014 ircd-hybrid development team
4 > *  Copyright (c) 1997-2018 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 15 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20   */
21  
# Line 29 | Line 29
29   #include "parse.h"
30   #include "channel.h"
31   #include "hash.h"
32 + #include "id.h"
33   #include "irc_string.h"
34   #include "ircd.h"
35   #include "numeric.h"
# Line 38 | Line 39
39   #include "memory.h"
40   #include "user.h"
41   #include "server.h"
42 + #include "packet.h"
43  
44  
45   /*
# Line 82 | Line 84
84   * For a small parser like this, this is a good compromise and does
85   * make it somewhat faster. - Dianora
86   */
87 < #define MAXPTRLEN 32
87 > enum { MAXPTRLEN = 32 };
88  
89  
90   static struct MessageTree
# Line 118 | Line 120 | parse_remove_unknown(struct Client *clie
120    {
121      sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE,
122                           "Unknown prefix (%s) from %s, Squitting %s",
123 <                         lbuffer, get_client_name(client_p, SHOW_IP), lsender);
123 >                         lbuffer, client_get_name(client_p, SHOW_IP), lsender);
124      sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE,
125                           "Unknown prefix (%s) from %s, Squitting %s",
126 <                         lbuffer, client_p->name, lsender);
126 >                         lbuffer, client_get_name(client_p, MASK_IP), lsender);
127      sendto_one(client_p, ":%s SQUIT %s :(Unknown prefix (%s) from %s)",
128                 me.id, lsender, lbuffer, client_p->name);
129    }
# Line 130 | Line 132 | parse_remove_unknown(struct Client *clie
132                 me.id, lsender, me.name);
133   }
134  
133 – /* cancel_clients()
134 – *
135 – * inputs       -
136 – * output       -
137 – * side effects -
138 – */
139 – static void
140 – parse_cancel_clients(struct Client *client_p, struct Client *source_p, char *cmd)
141 – {
142 –  if (IsServer(source_p) || IsMe(source_p))
143 –  {
144 –    sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE,
145 –                         "Message for %s[%s] from %s",
146 –                         source_p->name, source_p->from->name,
147 –                         get_client_name(client_p, SHOW_IP));
148 –    sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE,
149 –                         "Message for %s[%s] from %s",
150 –                         source_p->name, source_p->from->name,
151 –                         get_client_name(client_p, MASK_IP));
152 –    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
153 –                         "Not dropping server %s (%s) for Fake Direction",
154 –                         client_p->name, source_p->name);
155 –    return;
156 –  }
157 –
158 –  sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE,
159 –                       "Message for %s[%s@%s!%s] from %s (TS, ignored)",
160 –                       source_p->name, source_p->username, source_p->host,
161 –                       source_p->from->name, get_client_name(client_p, SHOW_IP));
162 –  sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE,
163 –                       "Message for %s[%s@%s!%s] from %s (TS, ignored)",
164 –                       source_p->name, source_p->username, source_p->host,
165 –                       source_p->from->name, get_client_name(client_p, MASK_IP));
166 – }
167 –
135   /*
136   *
137   *      parc    number of arguments ('sender' counted as one!)
# Line 210 | Line 177 | parse_handle_numeric(unsigned int numeri
177    else
178      target_p = find_person(source_p, parv[1]);
179  
180 <  if (((!target_p) || (target_p->from == source_p->from)) && !chptr)
180 >  if ((target_p == NULL || target_p->from == source_p->from) && chptr == NULL)
181      return;
182  
183    /*
# Line 230 | Line 197 | parse_handle_numeric(unsigned int numeri
197      /* Fake it for server hiding, if it's our client */
198      if ((ConfigServerHide.hide_servers || IsHidden(source_p)) && MyConnect(target_p) &&
199          !HasUMode(target_p, UMODE_OPER))
200 <      sendto_one_numeric(target_p, &me, numeric|SND_EXPLICIT, "%s", parv[2]);
200 >      sendto_one_numeric(target_p, &me, numeric | SND_EXPLICIT, "%s", parv[2]);
201      else
202 <      sendto_one_numeric(target_p, source_p, numeric|SND_EXPLICIT, "%s", parv[2]);
202 >      sendto_one_numeric(target_p, source_p, numeric | SND_EXPLICIT, "%s", parv[2]);
203    }
204    else
205      sendto_channel_butone(source_p, source_p, chptr, 0, "%u %s %s",
206 <                          numeric, chptr->chname, parv[2]);
206 >                          numeric, chptr->name, parv[2]);
207   }
208  
209   /* handle_command()
# Line 250 | Line 217 | parse_handle_numeric(unsigned int numeri
217   * side effects -
218   */
219   static void
220 < parse_handle_command(struct Message *mptr, struct Client *source_p,
220 > parse_handle_command(struct Message *message, struct Client *source_p,
221                       unsigned int i, char *para[])
222   {
223    if (IsServer(source_p->from))
224 <    ++mptr->rcount;
224 >    ++message->rcount;
225 >  ++message->count;
226  
227 <  ++mptr->count;
227 >  if (MyClient(source_p) && (message->flags & MFLG_ENDGRACE))
228 >    flood_endgrace(source_p);
229  
230    /* Check right amount of parameters is passed... --is */
231 <  if (i < mptr->args_min)
232 <    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, mptr->cmd);
231 >  if (i < message->args_min)
232 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, message->cmd);
233    else
234 <    mptr->handlers[source_p->from->handler](source_p, i, para);
234 >    message->handlers[source_p->from->handler](source_p, i, para);
235   }
236  
237   /*
# Line 274 | Line 243 | void
243   parse(struct Client *client_p, char *pbuffer, char *bufend)
244   {
245    struct Client *from = client_p;
246 <  struct Message *msg_ptr = NULL;
246 >  struct Message *message = NULL;
247    char *para[MAXPARA + 2];  /* <command> + <parameters> + NULL */
248    char *ch = NULL;
249    char *s = NULL;
# Line 285 | Line 254 | parse(struct Client *client_p, char *pbu
254    if (IsDefunct(client_p))
255      return;
256  
257 <  assert(client_p->localClient->fd.flags.open);
257 >  assert(client_p->connection);
258 >  assert(client_p->connection->fd);
259 >  assert(client_p->connection->fd->flags.open);
260 >
261 >
262    assert((bufend - pbuffer) < IRCD_BUFSIZE);
263  
264    for (ch = pbuffer; *ch == ' '; ++ch)  /* Skip spaces */
# Line 297 | Line 270 | parse(struct Client *client_p, char *pbu
270       * Copy the prefix to 'sender' assuming it terminates
271       * with SPACE (or NULL, which is an error, though).
272       */
273 <    const char *sender = ++ch;
273 >    const char *const sender = ++ch;
274  
275      if ((s = strchr(ch, ' ')))
276      {
# Line 307 | Line 280 | parse(struct Client *client_p, char *pbu
280  
281      if (*sender && IsServer(client_p))
282      {
283 <      if ((from = find_person(client_p, sender)) == NULL)
284 <        from = hash_find_server(sender);
283 >      if ((from = hash_find_id(sender)) == NULL)
284 >        from = hash_find_client(sender);
285  
286        /*
287         * Hmm! If the client corresponding to the prefix is not found--what is
# Line 325 | Line 298 | parse(struct Client *client_p, char *pbu
298        if (from->from != client_p)
299        {
300          ++ServerStats.is_wrdi;
301 <        parse_cancel_clients(client_p, from, pbuffer);
301 >        sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE,
302 >                             "Fake direction: dropped message from %s[%s] via %s",
303 >                             from->name, from->from->name,
304 >                             client_get_name(client_p, SHOW_IP));
305 >        sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE,
306 >                             "Fake direction: dropped message from %s[%s] via %s",
307 >                             from->name, from->from->name,
308 >                             client_get_name(client_p, MASK_IP));
309          return;
310        }
311      }
# Line 360 | Line 340 | parse(struct Client *client_p, char *pbu
340    }
341    else
342    {
363 –    unsigned int ii = 0;
364 –
343      if ((s = strchr(ch, ' ')))
344        *s++ = '\0';
345  
346 <    if ((msg_ptr = find_command(ch)) == NULL)
346 >    if ((message = find_command(ch)) == NULL)
347      {
348        /*
349         * Note: Give error message *only* to recognized
# Line 386 | Line 364 | parse(struct Client *client_p, char *pbu
364        return;
365      }
366  
367 <    assert(msg_ptr->cmd);
367 >    assert(message->cmd);
368 >
369 >    paramcount = message->args_max;
370  
371 <    paramcount = msg_ptr->args_max;
372 <    ii = bufend - ((s) ? s : ch);
393 <    msg_ptr->bytes += ii;
371 >    size_t length = bufend - ((s) ? s : ch);
372 >    message->bytes += length;
373    }
374  
375    /*
# Line 404 | Line 383 | parse(struct Client *client_p, char *pbu
383  
384    para[parc] = ch;
385  
386 <  if (msg_ptr->flags & MFLG_EXTRA)
386 >  if (message && (message->flags & MFLG_EXTRA))
387    {
388      /*
389       * XXX: This will have to go away after the command handler rewrite
390       */
391 <    para[++parc] = msg_ptr->extra;
391 >    para[++parc] = message->extra;
392    }
393  
394    if (s)
# Line 417 | Line 396 | parse(struct Client *client_p, char *pbu
396      if (paramcount > MAXPARA)
397        paramcount = MAXPARA;
398  
399 <    while (1)
399 >    while (true)
400      {
401         while (*s == ' ')
402           *s++ = '\0';
# Line 427 | Line 406 | parse(struct Client *client_p, char *pbu
406  
407         if (*s == ':')
408         {
409 <         /* The rest is a single parameter */
410 <         para[++parc] = s + (!numeric);  /* Keep the colon if it's a numeric */
409 >         /* The rest is single parameter--can include blanks also. */
410 >         para[++parc] = s + (numeric == 0);  /* Keep the colon if it's a numeric */
411           break;
412         }
413  
# Line 444 | Line 423 | parse(struct Client *client_p, char *pbu
423  
424    para[++parc] = NULL;
425  
426 <  if (msg_ptr)
427 <    parse_handle_command(msg_ptr, from, parc, para);
426 >  if (message)
427 >    parse_handle_command(message, from, parc, para);
428    else
429      parse_handle_numeric(numeric, from, parc, para);
430   }
# Line 491 | Line 470 | add_msg_element(struct MessageTree *mtre
470       */
471      if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]) == NULL)
472      {
473 <      ntree_p = MyCalloc(sizeof(struct MessageTree));
473 >      ntree_p = xcalloc(sizeof(*ntree_p));
474        mtree_p->pointers[*cmd & (MAXPTRLEN - 1)] = ntree_p;
475  
476        mtree_p->links++;  /* Have new pointer, so up ref count */
# Line 549 | Line 528 | del_msg_element(struct MessageTree *mtre
528        {
529          mtree_p->pointers[*cmd & (MAXPTRLEN - 1)] = NULL;
530          mtree_p->links--;
531 <        MyFree(ntree_p);
531 >        xfree(ntree_p);
532        }
533      }
534    }
# Line 567 | Line 546 | msg_tree_parse(const char *cmd)
546   {
547    struct MessageTree *mtree = &msg_tree;
548  
549 <  assert(cmd && *cmd);
549 >  assert(!EmptyString(cmd));
550  
551    while (IsAlpha(*cmd) && (mtree = mtree->pointers[*cmd & (MAXPTRLEN - 1)]))
552      if (*++cmd == '\0')
# Line 585 | Line 564 | msg_tree_parse(const char *cmd)
564   void
565   mod_add_cmd(struct Message *msg)
566   {
567 <  assert(msg && msg->cmd);
567 >  assert(msg);
568 >  assert(msg->cmd);
569  
570    /* Command already added? */
571 <  if (msg_tree_parse(msg->cmd))
572 <    return;
593 <
594 <  add_msg_element(&msg_tree, msg, msg->cmd);
571 >  if (msg_tree_parse(msg->cmd) == NULL)
572 >    add_msg_element(&msg_tree, msg, msg->cmd);
573   }
574  
575   /* mod_del_cmd()
# Line 603 | Line 581 | mod_add_cmd(struct Message *msg)
581   void
582   mod_del_cmd(struct Message *msg)
583   {
584 <  assert(msg && msg->cmd);
584 >  assert(msg);
585 >  assert(msg->cmd);
586  
587 <  if (!msg_tree_parse(msg->cmd))
588 <    return;
610 <
611 <  del_msg_element(&msg_tree, msg->cmd);
587 >  if (msg_tree_parse(msg->cmd))
588 >    del_msg_element(&msg_tree, msg->cmd);
589   }
590  
591   /* find_command()
# Line 646 | Line 623 | recurse_report_messages(struct Client *s
623   void
624   report_messages(struct Client *source_p)
625   {
626 <  const struct MessageTree *mtree = &msg_tree;
626 >  const struct MessageTree *const mtree = &msg_tree;
627  
628    for (unsigned int i = 0; i < MAXPTRLEN; ++i)
629      if (mtree->pointers[i])

Comparing ircd-hybrid/trunk/src/parse.c (property svn:keywords):
Revision 4552 by michael, Fri Aug 22 09:13:32 2014 UTC vs.
Revision 8715 by michael, Sun Dec 9 20:17:02 2018 UTC

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

Diff Legend

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