2 * IRC - Internet Relay Chat, common/parse.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
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
8 * the Free Software Foundation; either version 1, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include "ircd_alloc.h"
29 #include "ircd_chattr.h"
30 #include "ircd_string.h"
36 #include "querycmds.h"
42 #include "s_numeric.h"
59 struct MessageTree *pointers[26];
63 struct Message msgtab[] = {
67 0, MAXPARA, MFLG_SLOW, 0,
68 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
69 { m_unregistered, m_privmsg, ms_privmsg, mo_privmsg, m_ignore }
74 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
75 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
76 { m_nick, m_nick, ms_nick, m_nick, m_ignore }
81 0, MAXPARA, MFLG_SLOW | MFLG_IGNORE, 0,
82 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
83 { m_ignore, m_notice, ms_notice, mo_notice, m_ignore }
88 0, MAXPARA, MFLG_SLOW, 0,
89 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
90 { m_unregistered, m_wallchops, ms_wallchops, m_wallchops, m_ignore }
95 0, MAXPARA, MFLG_SLOW, 0,
96 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
97 { m_unregistered, m_cprivmsg, m_ignore, m_cprivmsg, m_ignore }
102 0, MAXPARA, MFLG_SLOW, 0,
103 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
104 { m_unregistered, m_cnotice, m_ignore, m_cnotice, m_ignore }
109 0, MAXPARA, MFLG_SLOW, 0,
110 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
111 { m_unregistered, m_join, ms_join, m_join, m_ignore }
116 0, MAXPARA, MFLG_SLOW, 0,
117 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
118 { m_unregistered, m_mode, ms_mode, m_mode, m_ignore }
123 0, MAXPARA, MFLG_SLOW, 0,
124 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
125 { m_ignore, m_ignore, ms_burst, m_ignore, m_ignore }
130 0, MAXPARA, MFLG_SLOW, 0,
131 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
132 { m_ignore, m_ignore, ms_create, m_ignore, m_ignore }
137 0, MAXPARA, MFLG_SLOW, 0,
138 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
139 { m_ignore, m_ignore, ms_destruct, m_ignore, m_ignore }
144 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
145 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
146 { m_quit, m_quit, ms_quit, m_quit, m_ignore }
151 0, MAXPARA, MFLG_SLOW, 0,
152 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
153 { m_unregistered, m_part, ms_part, m_part, m_ignore }
158 0, MAXPARA, MFLG_SLOW, 0,
159 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
160 { m_unregistered, m_topic, ms_topic, m_topic, m_ignore }
165 0, MAXPARA, MFLG_SLOW, 0,
166 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
167 { m_unregistered, m_invite, ms_invite, m_invite, m_ignore }
172 0, MAXPARA, MFLG_SLOW, 0,
173 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
174 { m_unregistered, m_kick, ms_kick, m_kick, m_ignore }
179 0, MAXPARA, MFLG_SLOW, 0,
180 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
181 { m_unregistered, m_not_oper, ms_wallops, mo_wallops, m_ignore }
186 0, MAXPARA, MFLG_SLOW, 0,
187 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
188 { m_ignore, m_ignore, ms_desynch, m_ignore, m_ignore }
193 0, MAXPARA, MFLG_SLOW, 0,
194 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
195 { m_unregistered, m_ping, ms_ping, m_ping, m_ignore }
200 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
201 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
202 { mr_pong, m_ignore, ms_pong, m_ignore, m_ignore }
207 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
208 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
209 { mr_error, m_ignore, ms_error, m_ignore, m_ignore }
214 0, MAXPARA, MFLG_SLOW, 0,
215 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
216 { m_unregistered, m_not_oper, ms_kill, mo_kill, m_ignore }
221 0, MAXPARA, MFLG_SLOW, 0,
222 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
223 { m_user, m_registered, m_ignore, m_registered, m_ignore }
228 0, MAXPARA, MFLG_SLOW, 0,
229 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
230 { m_unregistered, m_away, ms_away, m_away, m_ignore }
236 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
237 { m_unregistered, m_ison, m_ignore, m_ison, m_ignore }
242 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
243 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
244 { mr_server, m_registered, ms_server, m_registered, m_ignore }
249 0, MAXPARA, MFLG_SLOW, 0,
250 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
251 { m_unregistered, m_not_oper, ms_squit, mo_squit, m_ignore }
256 0, MAXPARA, MFLG_SLOW, 0,
257 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
258 { m_unregistered, m_whois, m_whois, m_whois, m_ignore }
263 0, MAXPARA, MFLG_SLOW, 0,
264 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
265 { m_unregistered, m_who, m_ignore, m_who, m_ignore }
270 0, MAXPARA, MFLG_SLOW, 0,
271 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
272 { m_unregistered, m_whowas, m_whowas, m_whowas, m_ignore }
277 0, MAXPARA, MFLG_SLOW, 0,
278 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
279 { m_unregistered, m_list, m_ignore, m_list, m_ignore }
284 0, MAXPARA, MFLG_SLOW, 0,
285 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
286 { m_unregistered, m_names, ms_names, m_names, m_ignore }
292 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
293 { m_unregistered, m_userhost, m_ignore, m_userhost, m_ignore }
299 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
300 { m_unregistered, m_userip, m_ignore, m_userip, m_ignore }
305 0, MAXPARA, MFLG_SLOW, 0,
306 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
307 { m_unregistered, m_trace, ms_trace, mo_trace, m_ignore }
312 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
313 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
314 { m_pass, m_registered, m_ignore, m_registered, m_ignore }
319 0, MAXPARA, MFLG_SLOW, 0,
320 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
321 { m_unregistered, m_lusers, ms_lusers, m_lusers, m_ignore }
326 0, MAXPARA, MFLG_SLOW, 0,
327 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
328 { m_unregistered, m_time, m_time, m_time, m_ignore }
333 0, MAXPARA, MFLG_SLOW, 0,
334 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
335 { m_unregistered, m_ignore, ms_settime, mo_settime, m_ignore }
340 0, MAXPARA, MFLG_SLOW, 0,
341 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
342 { m_unregistered, m_not_oper, ms_rping, mo_rping, m_ignore }
347 0, MAXPARA, MFLG_SLOW, 0,
348 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
349 { m_unregistered, m_ignore, ms_rpong, m_ignore, m_ignore }
354 0, MAXPARA, MFLG_SLOW, 0,
355 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
356 { m_unregistered, m_oper, ms_oper, mo_oper, m_ignore }
361 0, MAXPARA, MFLG_SLOW, 0,
362 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
363 { m_unregistered, m_not_oper, ms_connect, mo_connect, m_ignore }
368 0, MAXPARA, MFLG_SLOW, 0,
369 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
370 { m_unregistered, m_map, m_ignore, m_map, m_ignore }
375 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
376 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
377 { m_version, m_version, ms_version, m_version, m_ignore }
382 0, MAXPARA, MFLG_SLOW, 0,
383 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
384 { m_unregistered, m_stats, ms_stats, mo_stats, m_ignore }
389 0, MAXPARA, MFLG_SLOW, 0,
390 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
391 { m_unregistered, m_links, ms_links, m_links, m_ignore }
396 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
397 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
398 { m_admin, m_admin, ms_admin, m_admin, m_ignore }
403 0, MAXPARA, MFLG_SLOW, 0,
404 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
405 { m_unregistered, m_help, m_ignore, m_help, m_ignore }
410 0, MAXPARA, MFLG_SLOW, 0,
411 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
412 { m_unregistered, m_info, ms_info, mo_info, m_ignore }
417 0, MAXPARA, MFLG_SLOW, 0,
418 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
419 { m_unregistered, m_motd, m_motd, m_motd, m_ignore }
424 0, MAXPARA, MFLG_SLOW, 0,
425 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
426 { m_unregistered, m_not_oper, m_ignore, mo_close, m_ignore }
431 0, MAXPARA, MFLG_SLOW, 0,
432 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
433 { m_unregistered, m_silence, ms_silence, m_silence, m_ignore }
438 0, MAXPARA, MFLG_SLOW, 0,
439 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
440 { m_unregistered, m_not_oper, ms_gline, mo_gline, m_ignore }
445 0, MAXPARA, MFLG_SLOW, 0,
446 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
447 { m_unregistered, m_jupe, ms_jupe, mo_jupe, m_ignore }
452 0, MAXPARA, MFLG_SLOW, 0,
453 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
454 { m_ignore, m_ignore, ms_end_of_burst, m_ignore, m_ignore }
457 MSG_END_OF_BURST_ACK,
458 TOK_END_OF_BURST_ACK,
460 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
461 { m_ignore, m_ignore, ms_end_of_burst_ack, m_ignore, m_ignore }
466 0, MAXPARA, MFLG_SLOW, 0,
467 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
468 { m_unregistered, m_hash, m_hash, m_hash, m_ignore }
473 0, MAXPARA, MFLG_SLOW, 0,
474 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
475 { m_unregistered, m_dns, m_dns, m_dns, m_ignore }
480 0, MAXPARA, MFLG_SLOW, 0,
481 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
482 { m_unregistered, m_not_oper, m_ignore, mo_rehash, m_ignore }
487 0, MAXPARA, MFLG_SLOW, 0,
488 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
489 { m_unregistered, m_not_oper, m_ignore, mo_restart, m_ignore }
494 0, MAXPARA, MFLG_SLOW, 0,
495 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
496 { m_unregistered, m_not_oper, m_ignore, mo_die, m_ignore }
501 0, MAXPARA, MFLG_SLOW, 0,
502 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
503 { m_proto, m_proto, m_proto, m_proto, m_ignore }
513 static char *para[MAXPARA + 2]; /* leave room for prefix and null */
516 * Message Tree stuff mostly written by orabidoo, with changes by Dianora.
517 * Adapted to Undernet, adding token support, etc by comstud 10/06/97
520 static struct MessageTree msg_tree_cmd;
521 static struct MessageTree msg_tree_tok;
524 * Guts of making the token tree...
526 static struct Message **do_msg_tree_tok(struct MessageTree *mtree, char *prefix,
527 struct Message **mptr)
529 char newprefix[64]; /* Must be longer than every command name */
531 struct MessageTree *mtree1;
534 if (!lp || !strncmp((*mptr)->tok, prefix, lp))
536 if (!mptr[1] || (lp && strncmp(mptr[1]->tok, prefix, lp)))
538 /* last command in the message struct or last command in this prefix */
539 mtree->final = (*mptr)->tok + lp;
541 for (c = 0; c < 26; ++c)
542 mtree->pointers[c] = NULL;
545 /* command in this prefix */
546 if (0 == ircd_strcmp((*mptr)->tok, prefix))
549 mtree->msg = *mptr++;
554 for (c = 'A'; c <= 'Z'; ++c)
556 if ((*mptr)->tok[lp] == c)
558 mtree1 = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
559 mtree1->final = NULL;
560 mtree->pointers[c - 'A'] = mtree1;
561 strcpy(newprefix, prefix);
563 newprefix[lp + 1] = '\0';
564 mptr = do_msg_tree_tok(mtree1, newprefix, mptr);
565 if (!*mptr || strncmp((*mptr)->tok, prefix, lp))
567 for (c2 = c + 1 - 'A'; c2 < 26; ++c2)
568 mtree->pointers[c2] = NULL;
573 mtree->pointers[c - 'A'] = NULL;
578 * XXX - should never be here, quick hack, this can be done better
585 * Guts of making the command tree...
587 static struct Message *do_msg_tree_cmd(struct MessageTree *mtree, char *prefix,
588 struct Message *mptr)
590 char newprefix[64]; /* Must be longer than every command name */
592 struct MessageTree *mtree1;
595 if (!lp || !strncmp(mptr->cmd, prefix, lp))
597 if (!mptr[1].cmd || (lp && strncmp(mptr[1].cmd, prefix, lp)))
599 /* last command in the message struct or last command in this prefix */
600 mtree->final = mptr->cmd + lp;
602 for (c = 0; c < 26; ++c)
603 mtree->pointers[c] = NULL;
606 /* command in this prefix */
607 if (0 == ircd_strcmp(mptr->cmd, prefix))
615 for (c = 'A'; c <= 'Z'; ++c)
617 if (mptr->cmd[lp] == c)
619 mtree1 = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
620 mtree1->final = NULL;
621 mtree->pointers[c - 'A'] = mtree1;
622 strcpy(newprefix, prefix);
624 newprefix[lp + 1] = '\0';
625 mptr = do_msg_tree_cmd(mtree1, newprefix, mptr);
626 if (!mptr->cmd || strncmp(mptr->cmd, prefix, lp))
628 for (c2 = c + 1 - 'A'; c2 < 26; ++c2)
629 mtree->pointers[c2] = NULL;
634 mtree->pointers[c - 'A'] = NULL;
639 * This should never happen
645 static int mcmdcmp(const struct Message *m1, const struct Message *m2)
647 return strcmp(m1->cmd, m2->cmd);
650 static int mtokcmp(const struct Message **m1, const struct Message **m2)
652 return strcmp((*m1)->tok, (*m2)->tok);
656 * Sort the command names.
657 * Create table of pointers into msgtab for tokens.
658 * Create trees for ->cmd and ->tok and free the token pointers.
660 void initmsgtree(void)
663 struct Message *msg = msgtab;
665 struct Message **msgtab_tok;
666 struct Message **msgtok;
668 for (i = 0; msg->cmd; ++i, ++msg)
670 qsort(msgtab, i, sizeof(struct Message),
671 (int (*)(const void *, const void *))mcmdcmp);
672 msgtab_tok = (struct Message **)MyMalloc((i + 1) * sizeof(struct Message *));
673 for (ii = 0; ii < i; ++ii)
674 msgtab_tok[ii] = msgtab + ii;
675 msgtab_tok[i] = NULL; /* Needed by `do_msg_tree_tok' */
676 qsort(msgtab_tok, i, sizeof(struct Message *),
677 (int (*)(const void *, const void *))mtokcmp);
678 msg = do_msg_tree_cmd(&msg_tree_cmd, "", msgtab);
679 msgtok = do_msg_tree_tok(&msg_tree_tok, "", msgtab_tok);
684 * Generic tree parser which works for both commands and tokens.
687 static struct Message *msg_tree_parse(char *cmd, struct MessageTree *root)
689 struct MessageTree *mtree;
690 unsigned char r = (0xdf & (unsigned char)*cmd) - 'A';
691 if (r > 25 || !(mtree = root->pointers[r]))
695 r = 0xdf & (unsigned char)*++cmd;
696 if (mtree->final && *mtree->final == r)
698 if ((r -= 'A') > 25 || !(mtree = mtree->pointers[r]))
704 * This one is identical to the one above, but it is slower because it
705 * makes sure that `cmd' matches the _full_ command, exactly.
706 * This is to avoid confusion with commands like /quake on clients
707 * that send unknown commands directly to the server.
709 static struct Message *msg_tree_parse_client(char *cmd,
710 struct MessageTree *root)
712 struct MessageTree *mtree;
713 unsigned char q = (0xdf & (unsigned char)*cmd) - 'A';
714 if (q > 25 || !(mtree = root->pointers[q]))
718 q = 0xdf & (unsigned char)*++cmd;
719 if (mtree->final && 0 == ircd_strcmp(mtree->final, cmd))
721 if ((q -= 'A') > 25 || !(mtree = mtree->pointers[q]))
729 * NOTE: parse_*() should not be called recusively by any other fucntions!
731 int parse_client(struct Client *cptr, char *buffer, char *bufend)
733 struct Client* from = cptr;
739 struct Message* mptr;
740 MessageHandler handler = 0;
742 Debug((DEBUG_DEBUG, "Parsing: %s", buffer));
747 para[0] = from->name;
748 for (ch = buffer; *ch == ' '; ch++); /* Eat leading spaces */
749 if (*ch == ':') /* Is any client doing this ? */
751 for (++ch; *ch && *ch != ' '; ++ch)
752 ; /* Ignore sender prefix from client */
754 ch++; /* Advance to command */
760 ServerStats->is_empt++;
761 Debug((DEBUG_NOTICE, "Empty message from host %s:%s",
762 cptr->name, from->name));
766 if ((s = strchr(ch, ' ')))
770 * This is a client/unregistered entity.
771 * Check long command list only.
773 if (!(mptr = msg_tree_parse_client(ch, &msg_tree_cmd)))
776 * Note: Give error message *only* to recognized
777 * persons. It's a nightmare situation to have
778 * two programs sending "Unknown command"'s or
779 * equivalent to each other at full blast....
780 * If it has got to person state, it at least
781 * seems to be well behaving. Perhaps this message
782 * should never be generated, though... --msa
783 * Hm, when is the buffer empty -- if a command
784 * code has been found ?? -Armin
786 if (buffer[0] != '\0')
789 sendto_one(from, ":%s %d %s %s :Unknown command",
790 me.name, ERR_UNKNOWNCOMMAND, from->name, ch);
791 Debug((DEBUG_ERROR, "Unknown (%s) from %s",
792 ch, get_client_name(cptr, HIDE_IP)));
794 ServerStats->is_unco++;
798 paramcount = mptr->parameters;
799 i = bufend - ((s) ? s : ch);
801 if ((mptr->flags & MFLG_SLOW))
802 cptr->since += (2 + i / 120);
804 * Allow only 1 msg per 2 seconds
805 * (on average) to prevent dumping.
806 * to keep the response rate up,
807 * bursts of up to 5 msgs are allowed
812 * Must the following loop really be so devious? On
813 * surface it splits the message to parameters from
814 * blank spaces. But, if paramcount has been reached,
815 * the rest of the message goes into this last parameter
816 * (about same effect as ":" has...) --msa
819 /* Note initially true: s==NULL || *(s-1) == '\0' !! */
824 if (paramcount > MAXPARA)
825 paramcount = MAXPARA;
829 * Never "FRANCE " again!! ;-) Clean
830 * out *all* blanks.. --msa
840 * The rest is single parameter--can
841 * include blanks also.
849 for (; *s != ' ' && *s; s++);
856 * The "unregistered command check" was ugly and mildly inefficient.
857 * I fixed it. :) --Shadow
859 if (!IsUser(cptr) && 0 == (mptr->flags & MFLG_UNREG)) {
860 if (0 == (mptr->flags & MFLG_IGNORE))
861 sendto_one(from, ":%s %d * %s :Register first.",
862 me.name, ERR_NOTREGISTERED, ch);
866 handler = mptr->handlers[cptr->handler];
867 assert(0 != handler);
869 #ifndef IDLE_FROM_MSG
870 if (IsUser(cptr) && handler != m_ping && handler != m_ignore)
871 from->user->last = CurrentTime;
874 return (*handler) (cptr, from, i, para);
877 int parse_server(struct Client *cptr, char *buffer, char *bufend)
879 struct Client* from = cptr;
886 struct Message* mptr;
888 Debug((DEBUG_DEBUG, "Parsing: %s", buffer));
891 len = strlen(buffer);
895 char c = buffer[200];
897 sendto_ops("RCV:%-8.8s(%.4d): \"%s...%s\"",
898 cptr->name, len, buffer, &buffer[len - 200]);
902 sendto_ops("RCV:%-8.8s(%.4d): \"%s\"", cptr->name, len, buffer);
909 para[0] = from->name;
912 * A server ALWAYS sends a prefix. When it starts with a ':' it's the
913 * protocol 9 prefix: a nick or a server name. Otherwise it's a numeric
918 /* Let para[0] point to the name of the sender */
920 if (!(ch = strchr(ch, ' ')))
924 /* And let `from' point to its client structure,
925 opps.. a server is _also_ a client --Nem */
926 from = FindClient(para[0]);
929 * If the client corresponding to the
930 * prefix is not found. We must ignore it,
931 * it is simply a lagged message travelling
932 * upstream a SQUIT that removed the client
937 Debug((DEBUG_NOTICE, "Unknown prefix (%s)(%s) from (%s)",
938 para[0], buffer, cptr->name));
939 ++ServerStats->is_unpf;
943 * However, the only thing that MUST be
944 * allowed to travel upstream against an
945 * squit, is an SQUIT itself (the timestamp
946 * protects us from being used wrong)
950 para[0] = cptr->name;
956 else if (from->from != cptr)
958 ++ServerStats->is_wrdi;
959 Debug((DEBUG_NOTICE, "Fake direction: Message (%s) coming from (%s)",
960 buffer, cptr->name));
964 else if (Protocol(cptr) > 9) /* Well, not ALWAYS, 2.9 can send no prefix */
966 char numeric_prefix[6];
968 for (i = 0; i < 5; ++i) {
969 if ('\0' == ch[i] || ' ' == (numeric_prefix[i] = ch[i])) {
973 numeric_prefix[i] = '\0';
975 * We got a numeric nick as prefix
976 * 1 or 2 character prefixes are from servers
977 * 3 or 5 chars are from clients
979 if (' ' == ch[1] || ' ' == ch[2])
980 from = FindNServer(numeric_prefix);
982 from = findNUser(numeric_prefix);
988 while (*ch != ' ' && *ch);
991 * If the client corresponding to the
992 * prefix is not found. We must ignore it,
993 * it is simply a lagged message travelling
994 * upstream a SQUIT that removed the client
996 * There turned out to be other reasons that
997 * a prefix is unknown, needing an upstream
998 * KILL. Also, next to an SQUIT we better
999 * allow a KILL to pass too.
1004 ServerStats->is_unpf++;
1007 if (*ch == 'N' && (ch[1] == ' ' || ch[1] == 'I'))
1008 /* Only sent a KILL for a nick change */
1010 struct Client *server;
1011 /* Kill the unknown numeric prefix upstream if
1012 * it's server still exists: */
1013 if ((server = FindNServer(numeric_prefix)) && server->from == cptr)
1014 sendto_one(cptr, "%s KILL %s :%s (Unknown numeric nick)",
1015 NumServ(&me), numeric_prefix, me.name);
1018 * Things that must be allowed to travel
1019 * upstream against an squit:
1021 if (ch[1] == 'Q' || (*ch == 'D' && ch[1] == ' ') ||
1022 (*ch == 'K' && ch[2] == 'L'))
1028 /* Let para[0] point to the name of the sender */
1029 para[0] = from->name;
1031 if (from->from != cptr)
1033 ServerStats->is_wrdi++;
1034 Debug((DEBUG_NOTICE, "Fake direction: Message (%s) coming from (%s)",
1035 buffer, cptr->name));
1044 ServerStats->is_empt++;
1045 Debug((DEBUG_NOTICE, "Empty message from host %s:%s",
1046 cptr->name, from->name));
1051 * Extract the command code from the packet. Point s to the end
1052 * of the command code and calculate the length using pointer
1053 * arithmetic. Note: only need length for numerics and *all*
1054 * numerics must have parameters and thus a space after the command
1057 s = strchr(ch, ' '); /* s -> End of the command code */
1058 len = (s) ? (s - ch) : 0;
1059 if (len == 3 && IsDigit(*ch))
1061 numeric = (*ch - '0') * 100 + (*(ch + 1) - '0') * 10 + (*(ch + 2) - '0');
1062 paramcount = MAXPARA;
1063 ServerStats->is_num++;
1064 mptr = NULL; /* Init. to avoid stupid compiler warning :/ */
1071 /* Version Receive Send
1073 * 2.10.0 Tkn/Long Long
1074 * 2.10.10 Tkn/Long Tkn
1077 * Clients/unreg servers always receive/
1078 * send long commands -record
1082 * This is a server. Check the token command list.
1083 * -record!jegelhof@cloud9.net
1085 mptr = msg_tree_parse(ch, &msg_tree_tok);
1087 #if 1 /* for 2.10.0/2.10.10 */
1089 * This code supports 2.9 and 2.10.0 sending long commands.
1090 * It makes more calls to ircd_strcmp() than the above
1091 * so it will be somewhat slower.
1094 mptr = msg_tree_parse(ch, &msg_tree_cmd);
1100 * Note: Give error message *only* to recognized
1101 * persons. It's a nightmare situation to have
1102 * two programs sending "Unknown command"'s or
1103 * equivalent to each other at full blast....
1104 * If it has got to person state, it at least
1105 * seems to be well behaving. Perhaps this message
1106 * should never be generated, though... --msa
1107 * Hm, when is the buffer empty -- if a command
1108 * code has been found ?? -Armin
1111 if (buffer[0] != '\0')
1113 Debug((DEBUG_ERROR, "Unknown (%s) from %s",
1114 ch, get_client_name(cptr, HIDE_IP)));
1117 ServerStats->is_unco++;
1121 paramcount = mptr->parameters;
1122 i = bufend - ((s) ? s : ch);
1126 * Must the following loop really be so devious? On
1127 * surface it splits the message to parameters from
1128 * blank spaces. But, if paramcount has been reached,
1129 * the rest of the message goes into this last parameter
1130 * (about same effect as ":" has...) --msa
1133 /* Note initially true: s==NULL || *(s-1) == '\0' !! */
1138 if (paramcount > MAXPARA)
1139 paramcount = MAXPARA;
1143 * Never "FRANCE " again!! ;-) Clean
1144 * out *all* blanks.. --msa
1154 * The rest is single parameter--can
1155 * include blanks also.
1161 if (i >= paramcount)
1163 for (; *s != ' ' && *s; s++);
1168 return (do_numeric(numeric, (*buffer != ':'), cptr, from, i, para));
1171 return (*mptr->handlers[cptr->handler]) (cptr, from, i, para);