ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/parse.c
Revision: 1243
Committed: Fri Sep 30 10:47:53 2011 UTC (15 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/src/parse.c
File size: 25402 byte(s)
Log Message:
- move content of msg.h, ircd_handler.h and handlers.h into parse.h and
  remove headers accordingly
- killed common.h
- remove m_killhost.c and m_flags.c from contrib/
- sort out unused header includes here and there

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

Properties

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