ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/parse.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 25550 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * parse.c: The message parser.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "parse.h"
27     #include "client.h"
28     #include "channel.h"
29     #include "handlers.h"
30     #include "common.h"
31     #include "hash.h"
32     #include "ircd.h"
33     #include "numeric.h"
34     #include "s_stats.h"
35     #include "send.h"
36     #include "ircd_handler.h"
37     #include "msg.h"
38     #include "s_conf.h"
39     #include "s_user.h"
40     #include "s_serv.h"
41    
42     /*
43     * (based on orabidoo's parser code)
44     *
45     * This has always just been a trie. Look at volume III of Knuth ACP
46     *
47     *
48     * ok, you start out with an array of pointers, each one corresponds
49     * to a letter at the current position in the command being examined.
50     *
51     * so roughly you have this for matching 'trie' or 'tie'
52     *
53     * 't' points -> [MessageTree *] 'r' -> [MessageTree *] -> 'i'
54     * -> [MessageTree *] -> [MessageTree *] -> 'e' and matches
55     *
56     * 'i' -> [MessageTree *] -> 'e' and matches
57     *
58     * BUGS (Limitations!)
59     *
60     * I designed this trie to parse ircd commands. Hence it currently
61     * casefolds. This is trivial to fix by increasing MAXPTRLEN.
62     * This trie also "folds" '{' etc. down. This means, the input to this
63     * trie must be alpha tokens only. This again, is a limitation that
64     * can be overcome by increasing MAXPTRLEN to include upper/lower case
65     * at the expense of more memory. At the extreme end, you could make
66     * MAXPTRLEN 128.
67     *
68     * This is also not a patricia trie. On short ircd tokens, this is
69     * not likely going to matter.
70     *
71     * Diane Bruce (Dianora), June 6 2003
72     */
73    
74     #define MAXPTRLEN 32
75     /* Must be a power of 2, and
76     * larger than 26 [a-z]|[A-Z]
77     * its used to allocate the set
78     * of pointers at each node of the tree
79     * There are MAXPTRLEN pointers at each node.
80     * Obviously, there have to be more pointers
81     * Than ASCII letters. 32 is a nice number
82     * since there is then no need to shift
83     * 'A'/'a' to base 0 index, at the expense
84     * of a few never used pointers. For a small
85     * parser like this, this is a good compromise
86     * and does make it somewhat faster.
87     *
88     * - Dianora
89     */
90    
91     struct MessageTree
92     {
93     int links; /* Count of all pointers (including msg) at this node
94     * used as reference count for deletion of _this_ node.
95     */
96     struct Message *msg;
97     struct MessageTree *pointers[MAXPTRLEN];
98     };
99    
100     static struct MessageTree msg_tree;
101    
102     /*
103     * NOTE: parse() should not be called recursively by other functions!
104     */
105     static char *sender;
106     static char *para[MAXPARA + 1];
107     static char buffer[1024];
108    
109     static int cancel_clients(struct Client *, struct Client *, char *);
110     static void remove_unknown(struct Client *, char *, char *);
111     static void do_numeric(char[], struct Client *, struct Client *, int, char **);
112     static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char **);
113     static void recurse_report_messages(struct Client *source_p, struct MessageTree *mtree);
114     static void add_msg_element(struct MessageTree *mtree_p, struct Message *msg_p, const char *cmd);
115     static void del_msg_element(struct MessageTree *mtree_p, const char *cmd);
116    
117     /* turn a string into a parc/parv pair */
118     static inline int
119     string_to_array(char *string, char *parv[MAXPARA])
120     {
121     char *p;
122     char *buf = string;
123     int x = 1;
124    
125     parv[x] = NULL;
126    
127     while (*buf == ' ') /* skip leading spaces */
128     buf++;
129    
130     if (*buf == '\0') /* ignore all-space args */
131     return(x);
132    
133     do
134     {
135     if (*buf == ':') /* Last parameter */
136     {
137     buf++;
138     parv[x++] = buf;
139     parv[x] = NULL;
140     return(x);
141     }
142     else
143     {
144     parv[x++] = buf;
145     parv[x] = NULL;
146    
147     if ((p = strchr(buf, ' ')) != NULL)
148     {
149     *p++ = '\0';
150     buf = p;
151     }
152     else
153     return(x);
154     }
155    
156     while (*buf == ' ')
157     buf++;
158    
159     if (*buf == '\0')
160     return(x);
161     } while (x < MAXPARA - 1);
162    
163     if (*p == ':')
164     p++;
165    
166     parv[x++] = p;
167     parv[x] = NULL;
168     return(x);
169     }
170    
171     /*
172     * parse a buffer.
173     *
174     * NOTE: parse() should not be called recusively by any other functions!
175     */
176     void
177     parse(struct Client *client_p, char *pbuffer, char *bufend)
178     {
179     struct Client *from = client_p;
180     char *ch;
181     char *s;
182     char *numeric = 0;
183     unsigned int i = 0;
184     int paramcount;
185     int mpara = 0;
186     struct Message *mptr = NULL;
187    
188     if (IsDefunct(client_p))
189     return;
190    
191     assert(client_p->localClient->fd.flags.open);
192     assert((bufend - pbuffer) < 512);
193    
194     for (ch = pbuffer; *ch == ' '; ch++) /* skip spaces */
195     /* null statement */ ;
196    
197     para[0] = from->name;
198    
199     if (*ch == ':')
200     {
201     ch++;
202    
203     /* Copy the prefix to 'sender' assuming it terminates
204     * with SPACE (or NULL, which is an error, though).
205     */
206     sender = ch;
207    
208     if ((s = strchr(ch, ' ')) != NULL)
209     {
210     *s = '\0';
211     s++;
212     ch = s;
213     }
214    
215     if (*sender && IsServer(client_p))
216     {
217     /*
218     * XXX it could be useful to know which of these occurs most frequently.
219     * the ID check should always come first, though, since it is so easy.
220     */
221     if ((from = find_person(client_p, sender)) == NULL)
222     {
223     from = find_server(sender);
224    
225     if (from == NULL && IsCapable(client_p, CAP_TS6) &&
226     client_p->name[0] == '*' && IsDigit(*sender) && strlen(sender) == 3)
227     {
228     /* Dirty hack to allow messages from masked SIDs (i.e. the ones
229     * hidden by fakename="..."). It shouldn't break anything, since
230     * unknown SIDs don't happen during normal ircd work --adx
231     */
232     from = client_p;
233     }
234     }
235    
236     /* Hmm! If the client corresponding to the
237     * prefix is not found--what is the correct
238     * action??? Now, I will ignore the message
239     * (old IRC just let it through as if the
240     * prefix just wasn't there...) --msa
241     */
242     if (from == NULL)
243     {
244     ServerStats->is_unpf++;
245     remove_unknown(client_p, sender, pbuffer);
246     return;
247     }
248    
249     para[0] = from->name;
250    
251     if (from->from != client_p)
252     {
253     ServerStats->is_wrdi++;
254     cancel_clients(client_p, from, pbuffer);
255     return;
256     }
257     }
258    
259     while (*ch == ' ')
260     ch++;
261     }
262    
263     if (*ch == '\0')
264     {
265     ServerStats->is_empt++;
266     return;
267     }
268    
269     /* Extract the command code from the packet. Point s to the end
270     * of the command code and calculate the length using pointer
271     * arithmetic. Note: only need length for numerics and *all*
272     * numerics must have parameters and thus a space after the command
273     * code. -avalon
274     */
275    
276     /* EOB is 3 chars long but is not a numeric */
277     if (*(ch + 3) == ' ' && /* ok, lets see if its a possible numeric.. */
278     IsDigit(*ch) && IsDigit(*(ch + 1)) && IsDigit(*(ch + 2)))
279     {
280     mptr = NULL;
281     numeric = ch;
282     paramcount = MAXPARA;
283     ServerStats->is_num++;
284     s = ch + 3; /* I know this is ' ' from above if */
285     *s++ = '\0'; /* blow away the ' ', and point s to next part */
286     }
287     else
288     {
289     int ii = 0;
290    
291     if ((s = strchr(ch, ' ')) != NULL)
292     *s++ = '\0';
293    
294     if ((mptr = find_command(ch)) == NULL)
295     {
296     /* Note: Give error message *only* to recognized
297     * persons. It's a nightmare situation to have
298     * two programs sending "Unknown command"'s or
299     * equivalent to each other at full blast....
300     * If it has got to person state, it at least
301     * seems to be well behaving. Perhaps this message
302     * should never be generated, though... --msa
303     * Hm, when is the buffer empty -- if a command
304     * code has been found ?? -Armin
305     */
306     if (pbuffer[0] != '\0')
307     {
308     if (IsClient(from))
309     sendto_one(from, form_str(ERR_UNKNOWNCOMMAND),
310     me.name, from->name, ch);
311     }
312    
313     ServerStats->is_unco++;
314     return;
315     }
316    
317     assert(mptr->cmd != NULL);
318    
319     paramcount = mptr->parameters;
320     mpara = mptr->maxpara;
321    
322     ii = bufend - ((s) ? s : ch);
323     mptr->bytes += ii;
324     }
325    
326     if (s != NULL)
327     i = string_to_array(s, para);
328     else
329     {
330     i = 0;
331     para[1] = NULL;
332     }
333    
334     if (mptr == NULL)
335     do_numeric(numeric, client_p, from, i, para);
336     else
337     handle_command(mptr, client_p, from, i, para);
338     }
339    
340     /* handle_command()
341     *
342     * inputs - pointer to message block
343     * - pointer to client
344     * - pointer to client message is from
345     * - count of number of args
346     * - pointer to argv[] array
347     * output - -1 if error from server
348     * side effects -
349     */
350     static void
351     handle_command(struct Message *mptr, struct Client *client_p,
352     struct Client *from, unsigned int i, char *hpara[MAXPARA])
353     {
354     MessageHandler handler = 0;
355    
356     if (IsServer(client_p))
357     mptr->rcount++;
358    
359     mptr->count++;
360    
361     /* New patch to avoid server flooding from unregistered connects
362     * - Pie-Man 07/27/2000 */
363     if (!IsRegistered(client_p))
364     {
365     /* if its from a possible server connection
366     * ignore it.. more than likely its a header thats sneaked through
367     */
368     if ((IsHandshake(client_p) || IsConnecting(client_p) ||
369     IsServer(client_p)) && !(mptr->flags & MFLG_UNREG))
370     return;
371     }
372    
373     handler = mptr->handlers[client_p->handler];
374    
375     /* check right amount of params is passed... --is */
376     if (i < mptr->parameters)
377     {
378     if (!IsServer(client_p))
379     {
380     sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS),
381     me.name, EmptyString(hpara[0]) ? "*" : hpara[0], mptr->cmd);
382     }
383     else
384     {
385     sendto_realops_flags(UMODE_ALL, L_ALL,
386     "Dropping server %s due to (invalid) command '%s' "
387     "with only %d arguments (expecting %d).",
388     client_p->name, mptr->cmd, i, mptr->parameters);
389     ilog(L_CRIT, "Insufficient parameters (%d) for command '%s' from %s.",
390     i, mptr->cmd, client_p->name);
391     exit_client(client_p, client_p,
392     "Not enough arguments to server command.");
393     }
394     }
395     else
396     (*handler)(client_p, from, i, hpara);
397     }
398    
399     /* clear_tree_parse()
400     *
401     * inputs - NONE
402     * output - NONE
403     * side effects - MUST MUST be called at startup ONCE before
404     * any other keyword routine is used.
405     */
406     void
407     clear_tree_parse(void)
408     {
409     memset(&msg_tree, 0, sizeof(msg_tree));
410     }
411    
412     /* add_msg_element()
413     *
414     * inputs - pointer to MessageTree
415     * - pointer to Message to add for given command
416     * - pointer to current portion of command being added
417     * output - NONE
418     * side effects - recursively build the Message Tree ;-)
419     */
420     /*
421     * How this works.
422     *
423     * The code first checks to see if its reached the end of the command
424     * If so, that struct MessageTree has a msg pointer updated and the links
425     * count incremented, since a msg pointer is a reference.
426     * Then the code descends recursively, building the trie.
427     * If a pointer index inside the struct MessageTree is NULL a new
428     * child struct MessageTree has to be allocated.
429     * The links (reference count) is incremented as they are created
430     * in the parent.
431     */
432     static void
433     add_msg_element(struct MessageTree *mtree_p,
434     struct Message *msg_p, const char *cmd)
435     {
436     struct MessageTree *ntree_p;
437    
438     if (*cmd == '\0')
439     {
440     mtree_p->msg = msg_p;
441     mtree_p->links++; /* Have msg pointer, so up ref count */
442     }
443     else
444     {
445     /* *cmd & (MAXPTRLEN-1)
446     * convert the char pointed to at *cmd from ASCII to an integer
447     * between 0 and MAXPTRLEN.
448     * Thus 'A' -> 0x1 'B' -> 0x2 'c' -> 0x3 etc.
449     */
450    
451     if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN-1)]) == NULL)
452     {
453     ntree_p = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
454     mtree_p->pointers[*cmd & (MAXPTRLEN-1)] = ntree_p;
455    
456     mtree_p->links++; /* Have new pointer, so up ref count */
457     }
458     add_msg_element(ntree_p, msg_p, cmd+1);
459     }
460     }
461    
462     /* del_msg_element()
463     *
464     * inputs - Pointer to MessageTree to delete from
465     * - pointer to command name to delete
466     * output - NONE
467     * side effects - recursively deletes a token from the Message Tree ;-)
468     */
469     /*
470     * How this works.
471     *
472     * Well, first off, the code recursively descends into the trie
473     * until it finds the terminating letter of the command being removed.
474     * Once it has done that, it marks the msg pointer as NULL then
475     * reduces the reference count on that allocated struct MessageTree
476     * since a command counts as a reference.
477     *
478     * Then it pops up the recurse stack. As it comes back up the recurse
479     * The code checks to see if the child now has no pointers or msg
480     * i.e. the links count has gone to zero. If its no longer used, the
481     * child struct MessageTree can be deleted. The parent reference
482     * to this child is then removed and the parents link count goes down.
483     * Thus, we continue to go back up removing all unused MessageTree(s)
484     */
485     static void
486     del_msg_element(struct MessageTree *mtree_p, const char *cmd)
487     {
488     struct MessageTree *ntree_p;
489    
490     /* In case this is called for a nonexistent command
491     * check that there is a msg pointer here, else links-- goes -ve
492     * -db
493     */
494    
495     if ((*cmd == '\0') && (mtree_p->msg != NULL))
496     {
497     mtree_p->msg = NULL;
498     mtree_p->links--;
499     }
500     else
501     {
502     if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN-1)]) != NULL)
503     {
504     del_msg_element(ntree_p, cmd+1);
505     if (ntree_p->links == 0)
506     {
507     mtree_p->pointers[*cmd & (MAXPTRLEN-1)] = NULL;
508     mtree_p->links--;
509     MyFree(ntree_p);
510     }
511     }
512     }
513     }
514    
515     /* msg_tree_parse()
516     *
517     * inputs - Pointer to command to find
518     * - Pointer to MessageTree root
519     * output - Find given command returning Message * if found NULL if not
520     * side effects - none
521     */
522     static struct Message *
523     msg_tree_parse(const char *cmd, struct MessageTree *root)
524     {
525     struct MessageTree *mtree;
526     assert(cmd && *cmd);
527     for (mtree = root->pointers[(*cmd) & (MAXPTRLEN-1)]; mtree != NULL;
528     mtree = mtree->pointers[(*++cmd) & (MAXPTRLEN-1)])
529     {
530     if (!IsAlpha(*cmd))
531     return(NULL);
532     if (*(cmd + 1) == '\0')
533     return(mtree->msg); /* NULL if parsed invalid/unknown command */
534    
535     }
536    
537     return(NULL);
538     }
539    
540     /* mod_add_cmd()
541     *
542     * inputs - pointer to struct Message
543     * output - none
544     * side effects - load this one command name
545     * msg->count msg->bytes is modified in place, in
546     * modules address space. Might not want to do that...
547     */
548     void
549     mod_add_cmd(struct Message *msg)
550     {
551     struct Message *found_msg;
552    
553     if (msg == NULL)
554     return;
555    
556     /* someone loaded a module with a bad messagetab */
557     assert(msg->cmd != NULL);
558    
559     /* command already added? */
560     if ((found_msg = msg_tree_parse(msg->cmd, &msg_tree)) != NULL)
561     return;
562    
563     add_msg_element(&msg_tree, msg, msg->cmd);
564     msg->count = msg->rcount = msg->bytes = 0;
565     }
566    
567     /* mod_del_cmd()
568     *
569     * inputs - pointer to struct Message
570     * output - none
571     * side effects - unload this one command name
572     */
573     void
574     mod_del_cmd(struct Message *msg)
575     {
576     assert(msg != NULL);
577    
578     if (msg == NULL)
579     return;
580    
581     del_msg_element(&msg_tree, msg->cmd);
582     }
583    
584     /* find_command()
585     *
586     * inputs - command name
587     * output - pointer to struct Message
588     * side effects - none
589     */
590     struct Message *
591     find_command(const char *cmd)
592     {
593     return(msg_tree_parse(cmd, &msg_tree));
594     }
595    
596     /* report_messages()
597     *
598     * inputs - pointer to client to report to
599     * output - NONE
600     * side effects - client is shown list of commands
601     */
602     void
603     report_messages(struct Client *source_p)
604     {
605     struct MessageTree *mtree = &msg_tree;
606     int i;
607    
608     for (i = 0; i < MAXPTRLEN; i++)
609     {
610     if (mtree->pointers[i] != NULL)
611     recurse_report_messages(source_p, mtree->pointers[i]);
612     }
613     }
614    
615     static void
616     recurse_report_messages(struct Client *source_p, struct MessageTree *mtree)
617     {
618     int i;
619    
620     if (mtree->msg != NULL)
621     {
622     sendto_one(source_p, form_str(RPL_STATSCOMMANDS),
623     me.name, source_p->name, mtree->msg->cmd,
624     mtree->msg->count, mtree->msg->bytes,
625     mtree->msg->rcount);
626     }
627    
628     for (i = 0; i < MAXPTRLEN; i++)
629     {
630     if (mtree->pointers[i] != NULL)
631     recurse_report_messages(source_p, mtree->pointers[i]);
632     }
633     }
634    
635     /* cancel_clients()
636     *
637     * inputs -
638     * output -
639     * side effects -
640     */
641     static int
642     cancel_clients(struct Client *client_p, struct Client *source_p, char *cmd)
643     {
644     /* kill all possible points that are causing confusion here,
645     * I'm not sure I've got this all right...
646     * - avalon
647     *
648     * knowing avalon, probably not.
649     */
650    
651     /* with TS, fake prefixes are a common thing, during the
652     * connect burst when there's a nick collision, and they
653     * must be ignored rather than killed because one of the
654     * two is surviving.. so we don't bother sending them to
655     * all ops everytime, as this could send 'private' stuff
656     * from lagged clients. we do send the ones that cause
657     * servers to be dropped though, as well as the ones from
658     * non-TS servers -orabidoo
659     */
660     /* Incorrect prefix for a server from some connection. If it is a
661     * client trying to be annoying, just QUIT them, if it is a server
662     * then the same deal.
663     */
664     if (IsServer(source_p) || IsMe(source_p))
665     {
666     sendto_realops_flags(UMODE_DEBUG, L_ADMIN, "Message for %s[%s] from %s",
667     source_p->name, source_p->from->name,
668     get_client_name(client_p, SHOW_IP));
669     sendto_realops_flags(UMODE_DEBUG, L_OPER, "Message for %s[%s] from %s",
670     source_p->name, source_p->from->name,
671     get_client_name(client_p, MASK_IP));
672     sendto_realops_flags(UMODE_DEBUG, L_ALL,
673     "Not dropping server %s (%s) for Fake Direction",
674     client_p->name, source_p->name);
675     return(-1);
676     /* return exit_client(client_p, client_p, &me, "Fake Direction");*/
677     }
678    
679     /* Ok, someone is trying to impose as a client and things are
680     * confused. If we got the wrong prefix from a server, send out a
681     * kill, else just exit the lame client.
682     */
683     /* If the fake prefix is coming from a TS server, discard it
684     * silently -orabidoo
685     *
686     * all servers must be TS these days --is
687     */
688     sendto_realops_flags(UMODE_DEBUG, L_ADMIN,
689     "Message for %s[%s@%s!%s] from %s (TS, ignored)",
690     source_p->name, source_p->username, source_p->host,
691     source_p->from->name, get_client_name(client_p, SHOW_IP));
692     sendto_realops_flags(UMODE_DEBUG, L_OPER,
693     "Message for %s[%s@%s!%s] from %s (TS, ignored)",
694     source_p->name, source_p->username, source_p->host,
695     source_p->from->name, get_client_name(client_p, MASK_IP));
696    
697     return(0);
698     }
699    
700     /* remove_unknown()
701     *
702     * inputs -
703     * output -
704     * side effects -
705     */
706     static void
707     remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
708     {
709     /* Do kill if it came from a server because it means there is a ghost
710     * user on the other server which needs to be removed. -avalon
711     * Tell opers about this. -Taner
712     */
713     /* '[0-9]something' is an ID (KILL/SQUIT depending on its length)
714     * 'nodots' is a nickname (KILL)
715     * 'no.dot.at.start' is a server (SQUIT)
716     */
717     if ((IsDigit(*lsender) && strlen(lsender) <= IRC_MAXSID) ||
718     strchr(lsender, '.') != NULL)
719     {
720     sendto_realops_flags(UMODE_DEBUG, L_ADMIN,
721     "Unknown prefix (%s) from %s, Squitting %s",
722     lbuffer, get_client_name(client_p, SHOW_IP), lsender);
723     sendto_realops_flags(UMODE_DEBUG, L_OPER,
724     "Unknown prefix (%s) from %s, Squitting %s",
725     lbuffer, client_p->name, lsender);
726     sendto_one(client_p, ":%s SQUIT %s :(Unknown prefix (%s) from %s)",
727     me.name, lsender, lbuffer, client_p->name);
728     }
729     else
730     sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)",
731     me.name, lsender, me.name);
732     }
733    
734     /*
735     *
736     * parc number of arguments ('sender' counted as one!)
737     * parv[0] pointer to 'sender' (may point to empty string) (not used)
738     * parv[1]..parv[parc-1]
739     * pointers to additional parameters, this is a NULL
740     * terminated list (parv[parc] == NULL).
741     *
742     * *WARNING*
743     * Numerics are mostly error reports. If there is something
744     * wrong with the message, just *DROP* it! Don't even think of
745     * sending back a neat error message -- big danger of creating
746     * a ping pong error message...
747     */
748     static void
749     do_numeric(char numeric[], struct Client *client_p, struct Client *source_p,
750     int parc, char *parv[])
751     {
752     struct Client *target_p;
753     struct Channel *chptr;
754     char *t; /* current position within the buffer */
755     int i, tl; /* current length of presently being built string in t */
756    
757     if (parc < 2 || !IsServer(source_p))
758     return;
759    
760     /* Remap low number numerics. */
761     if (numeric[0] == '0')
762     numeric[0] = '1';
763    
764     /* Prepare the parameter portion of the message into 'buffer'.
765     * (Because the buffer is twice as large as the message buffer
766     * for the socket, no overflow can occur here... ...on current
767     * assumptions--bets are off, if these are changed --msa)
768     */
769     t = buffer;
770     for (i = 2; i < (parc - 1); i++)
771     {
772     tl = ircsprintf(t, " %s", parv[i]);
773     t += tl;
774     }
775    
776     ircsprintf(t," :%s", parv[parc-1]);
777    
778     if (((target_p = find_person(client_p, parv[1])) != NULL) ||
779     ((target_p = find_server(parv[1])) != NULL))
780     {
781     if (IsMe(target_p))
782     {
783     int num;
784    
785     /*
786     * We shouldn't get numerics sent to us,
787     * any numerics we do get indicate a bug somewhere..
788     */
789     /* ugh. this is here because of nick collisions. when two servers
790     * relink, they burst each other their nicks, then perform collides.
791     * if there is a nick collision, BOTH servers will kill their own
792     * nicks, and BOTH will kill the other servers nick, which wont exist,
793     * because it will have been already killed by the local server.
794     *
795     * unfortunately, as we cant guarantee other servers will do the
796     * "right thing" on a nick collision, we have to keep both kills.
797     * ergo we need to ignore ERR_NOSUCHNICK. --fl_
798     */
799     /* quick comment. This _was_ tried. i.e. assume the other servers
800     * will do the "right thing" and kill a nick that is colliding.
801     * unfortunately, it did not work. --Dianora
802     */
803    
804     /* Yes, a good compiler would have optimised this, but
805     * this is probably easier to read. -db
806     */
807     num = atoi(numeric);
808    
809     if ((num != ERR_NOSUCHNICK))
810     sendto_realops_flags(UMODE_ALL, L_ADMIN,
811     "*** %s(via %s) sent a %s numeric to me: %s",
812     source_p->name, client_p->name, numeric, buffer);
813     return;
814     }
815     else if (target_p->from == client_p)
816     {
817     /* This message changed direction (nick collision?)
818     * ignore it.
819     */
820     return;
821     }
822    
823     /* csircd will send out unknown umode flag for +a (admin), drop it here. */
824     if ((atoi(numeric) == ERR_UMODEUNKNOWNFLAG) && MyClient(target_p))
825     return;
826    
827     /* Fake it for server hiding, if its our client */
828     if (ConfigServerHide.hide_servers &&
829     MyClient(target_p) && !IsOper(target_p))
830     sendto_one(target_p, ":%s %s %s%s", me.name, numeric, target_p->name, buffer);
831     else if (!MyClient(target_p) && IsCapable(target_p->from, CAP_TS6) && HasID(source_p))
832     sendto_one(target_p, ":%s %s %s%s", source_p->id, numeric, target_p->id, buffer);
833     else /* either it is our client, or a client linked throuh a non-ts6 server. must use names! */
834     sendto_one(target_p, ":%s %s %s%s", source_p->name, numeric, target_p->name, buffer);
835     return;
836     }
837     else if ((chptr = hash_find_channel(parv[1])) != NULL)
838     sendto_channel_local(ALL_MEMBERS, NO, chptr,
839     ":%s %s %s %s",
840     source_p->name,
841     numeric, chptr->chname, buffer);
842     }
843    
844     /* m_not_oper()
845     * inputs -
846     * output -
847     * side effects - just returns a nastyogram to given user
848     */
849     void
850     m_not_oper(struct Client *client_p, struct Client *source_p,
851     int parc, char *parv[])
852     {
853     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
854     me.name, parv[0]);
855     }
856    
857     void
858     m_unregistered(struct Client *client_p, struct Client *source_p,
859     int parc, char *parv[])
860     {
861     /* bit of a hack.
862     * I don't =really= want to waste a bit in a flag
863     * number_of_nick_changes is only really valid after the client
864     * is fully registered..
865     */
866     if (client_p->localClient->number_of_nick_changes == 0)
867     {
868     sendto_one(client_p, ":%s %d * %s :Register first.",
869     me.name, ERR_NOTREGISTERED, parv[0]);
870     client_p->localClient->number_of_nick_changes++;
871     }
872     }
873    
874     void
875     m_registered(struct Client *client_p, struct Client *source_p,
876     int parc, char *parv[])
877     {
878     sendto_one(client_p, form_str(ERR_ALREADYREGISTRED),
879     me.name, parv[0]);
880     }
881    
882     void
883     m_ignore(struct Client *client_p, struct Client *source_p,
884     int parc, char *parv[])
885     {
886     return;
887     }
888    

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision