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-7.2/src/parse.c (file contents), Revision 1013 by michael, Sun Oct 18 14:26:49 2009 UTC vs.
ircd-hybrid-8/src/parse.c (file contents), Revision 1206 by michael, Wed Aug 24 21:41:23 2011 UTC

# Line 111 | Line 111 | static char buffer[1024];
111  
112   static int cancel_clients(struct Client *, struct Client *, char *);
113   static void remove_unknown(struct Client *, char *, char *);
114 < static void do_numeric(char[], struct Client *, struct Client *, int, char **);
115 < static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char **);
114 > static void handle_numeric(char[], struct Client *, struct Client *, int, char *[]);
115 > static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char *[]);
116   static void recurse_report_messages(struct Client *, const struct MessageTree *);
117   static void add_msg_element(struct MessageTree *, struct Message *, const char *);
118   static void del_msg_element(struct MessageTree *, const char *);
119  
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 }
120  
121   /*
122   * parse a buffer.
# Line 180 | Line 127 | void
127   parse(struct Client *client_p, char *pbuffer, char *bufend)
128   {
129    struct Client *from = client_p;
130 +  struct Message *msg_ptr = NULL;
131    char *ch;
132    char *s;
133    char *numeric = 0;
134 <  unsigned int i = 0;
135 <  int paramcount;
134 >  unsigned int parc = 0;
135 >  unsigned int paramcount;
136    int mpara = 0;
189  struct Message *mptr = NULL;
137  
138    if (IsDefunct(client_p))
139      return;
# Line 197 | Line 144 | parse(struct Client *client_p, char *pbu
144    for (ch = pbuffer; *ch == ' '; ch++) /* skip spaces */
145      /* null statement */ ;
146  
200  para[0] = from->name;
201
147    if (*ch == ':')
148    {
149 <    ch++;
150 <
206 <    /* Copy the prefix to 'sender' assuming it terminates
149 >    /*
150 >     * Copy the prefix to 'sender' assuming it terminates
151       * with SPACE (or NULL, which is an error, though).
152       */
153 <    sender = ch;
153 >    sender = ++ch;
154  
155      if ((s = strchr(ch, ' ')) != NULL)
156      {
157        *s = '\0';
158 <      s++;
215 <      ch = s;
158 >      ch = ++s;
159      }
160  
161      if (*sender && IsServer(client_p))
# Line 222 | Line 165 | parse(struct Client *client_p, char *pbu
165         * the ID check should always come first, though, since it is so easy.
166         */
167        if ((from = find_person(client_p, sender)) == NULL)
168 <      {
226 <        from = find_server(sender);
168 >        from = hash_find_server(sender);
169  
228        if (from == NULL && IsCapable(client_p, CAP_TS6) &&
229          client_p->name[0] == '*' && IsDigit(*sender) && strlen(sender) == 3)
230        {
231          /* Dirty hack to allow messages from masked SIDs (i.e. the ones
232           * hidden by fakename="..."). It shouldn't break anything, since
233           * unknown SIDs don't happen during normal ircd work --adx
234           */
235          from = client_p;
236        }
237      }
238      
170        /* Hmm! If the client corresponding to the
171         * prefix is not found--what is the correct
172         * action??? Now, I will ignore the message
# Line 249 | Line 180 | parse(struct Client *client_p, char *pbu
180          return;
181        }
182  
252      para[0] = from->name;
253
183        if (from->from != client_p)
184        {
185          ++ServerStats.is_wrdi;
# Line 260 | Line 189 | parse(struct Client *client_p, char *pbu
189      }
190  
191      while (*ch == ' ')
192 <      ch++;
192 >      ++ch;
193    }
194  
195    if (*ch == '\0')
# Line 280 | Line 209 | parse(struct Client *client_p, char *pbu
209    if (*(ch + 3) == ' ' && /* ok, lets see if its a possible numeric.. */
210        IsDigit(*ch) && IsDigit(*(ch + 1)) && IsDigit(*(ch + 2)))
211    {
283    mptr = NULL;
212      numeric = ch;
213      paramcount = MAXPARA;
214      ++ServerStats.is_num;
# Line 294 | Line 222 | parse(struct Client *client_p, char *pbu
222      if ((s = strchr(ch, ' ')) != NULL)
223        *s++ = '\0';
224  
225 <    if ((mptr = find_command(ch)) == NULL)
225 >    if ((msg_ptr = find_command(ch)) == NULL)
226      {
227        /* Note: Give error message *only* to recognized
228         * persons. It's a nightmare situation to have
# Line 317 | Line 245 | parse(struct Client *client_p, char *pbu
245        return;
246      }
247  
248 <    assert(mptr->cmd != NULL);
248 >    assert(msg_ptr->cmd != NULL);
249  
250 <    paramcount = mptr->parameters;
251 <    mpara      = mptr->maxpara;
250 >    paramcount = msg_ptr->args_max;
251 >    mpara      = msg_ptr->args_min;
252  
253      ii = bufend - ((s) ? s : ch);
254 <    mptr->bytes += ii;
254 >    msg_ptr->bytes += ii;
255    }
256  
257 <  if (s != NULL)
258 <    i = string_to_array(s, para);
259 <  else
257 >  /*
258 >   * Must the following loop really be so devious? On surface it
259 >   * splits the message to parameters from blank spaces. But, if
260 >   * paramcount has been reached, the rest of the message goes into
261 >   * this last parameter (about same effect as ":" has...) --msa
262 >   */
263 >
264 >  /* Note initially true: s==NULL || *(s-1) == '\0' !! */
265 >
266 >  para[parc] = from->name;
267 >
268 >  if (s)
269    {
270 <    i = 0;
271 <    para[1] = NULL;
270 >    if (paramcount > MAXPARA)
271 >      paramcount = MAXPARA;
272 >
273 >    while (1)
274 >    {
275 >       while (*s == ' ')
276 >         *s++ = '\0';
277 >
278 >       if (*s == '\0')
279 >         break;
280 >
281 >       if (*s == ':')
282 >       {
283 >         /* The rest is a single parameter */
284 >         para[++parc] = s + 1;
285 >         break;
286 >       }
287 >
288 >       para[++parc] = s;
289 >
290 >       if (parc >= paramcount)
291 >         break;
292 >
293 >       while (*s && *s != ' ')
294 >         ++s;
295 >    }
296    }
297  
298 <  if (mptr == NULL)
299 <    do_numeric(numeric, client_p, from, i, para);
298 >  para[++parc] = NULL;
299 >
300 >  if (msg_ptr != NULL)
301 >    handle_command(msg_ptr, client_p, from, parc, para);
302    else
303 <    handle_command(mptr, client_p, from, i, para);
303 >    handle_numeric(numeric, client_p, from, parc, para);
304   }
305  
306   /* handle_command()
# Line 376 | Line 339 | handle_command(struct Message *mptr, str
339    handler = mptr->handlers[client_p->handler];
340  
341    /* check right amount of params is passed... --is */
342 <  if (i < mptr->parameters)
342 >  if (i < mptr->args_min)
343    {
344      if (!IsServer(client_p))
345      {
# Line 388 | Line 351 | handle_command(struct Message *mptr, str
351        sendto_realops_flags(UMODE_ALL, L_ALL,
352                             "Dropping server %s due to (invalid) command '%s' "
353                             "with only %d arguments (expecting %d).",
354 <                           client_p->name, mptr->cmd, i, mptr->parameters);
354 >                           client_p->name, mptr->cmd, i, mptr->args_min);
355        ilog(L_CRIT, "Insufficient parameters (%d) for command '%s' from %s.",
356             i, mptr->cmd, client_p->name);
357        exit_client(client_p, client_p,
# Line 740 | Line 703 | remove_unknown(struct Client *client_p,
703   *      a ping pong error message...
704   */
705   static void
706 < do_numeric(char numeric[], struct Client *client_p, struct Client *source_p,
707 <           int parc, char *parv[])
706 > handle_numeric(char numeric[], struct Client *client_p, struct Client *source_p,
707 >               int parc, char *parv[])
708   {
709    struct Client *target_p;
710    struct Channel *chptr;
# Line 770 | Line 733 | do_numeric(char numeric[], struct Client
733    ircsprintf(t," :%s", parv[parc-1]);
734  
735    if (((target_p = find_person(client_p, parv[1])) != NULL) ||
736 <      ((target_p = find_server(parv[1])) != NULL))
736 >      ((target_p = hash_find_server(parv[1])) != NULL))
737    {
738      if (IsMe(target_p))
739      {
# Line 869 | Line 832 | m_registered(struct Client *client_p, st
832               int parc, char *parv[])
833   {
834    sendto_one(client_p, form_str(ERR_ALREADYREGISTRED),  
835 <             me.name, parv[0]);
835 >             me.name, source_p->name);
836   }
837  
838   void

Diff Legend

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