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.
30 #include "ircd_alloc.h"
31 #include "ircd_chattr.h"
32 #include "ircd_features.h"
33 #include "ircd_policy.h"
34 #include "ircd_reply.h"
35 #include "ircd_string.h"
40 #include "querycmds.h"
46 #include "s_numeric.h"
63 struct MessageTree *pointers[26];
67 struct Message msgtab[] = {
71 0, MAXPARA, MFLG_SLOW, 0,
72 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
73 { m_unregistered, m_privmsg, ms_privmsg, mo_privmsg, m_ignore }
78 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
79 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
80 { m_nick, m_nick, ms_nick, m_nick, m_ignore }
85 0, MAXPARA, MFLG_SLOW | MFLG_IGNORE, 0,
86 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
87 { m_ignore, m_notice, ms_notice, mo_notice, m_ignore }
92 0, MAXPARA, MFLG_SLOW, 0,
93 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
94 { m_unregistered, m_wallchops, ms_wallchops, m_wallchops, m_ignore }
99 0, MAXPARA, MFLG_SLOW, 0,
100 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
101 { m_unregistered, m_cprivmsg, m_ignore, m_cprivmsg, m_ignore }
106 0, MAXPARA, MFLG_SLOW, 0,
107 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
108 { m_unregistered, m_cnotice, m_ignore, m_cnotice, m_ignore }
113 0, MAXPARA, MFLG_SLOW, 0,
114 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
115 { m_unregistered, m_join, ms_join, m_join, m_ignore }
120 0, MAXPARA, MFLG_SLOW, 0,
121 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
122 { m_unregistered, m_mode, ms_mode, m_mode, m_ignore }
127 0, MAXPARA, MFLG_SLOW, 0,
128 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
129 { m_ignore, m_ignore, ms_burst, m_ignore, m_ignore }
134 0, MAXPARA, MFLG_SLOW, 0,
135 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
136 { m_ignore, m_ignore, ms_create, m_ignore, m_ignore }
141 0, MAXPARA, MFLG_SLOW, 0,
142 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
143 { m_ignore, m_ignore, ms_destruct, m_ignore, m_ignore }
148 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
149 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
150 { m_quit, m_quit, ms_quit, m_quit, m_ignore }
155 0, MAXPARA, MFLG_SLOW, 0,
156 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
157 { m_unregistered, m_part, ms_part, m_part, m_ignore }
162 0, MAXPARA, MFLG_SLOW, 0,
163 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
164 { m_unregistered, m_topic, ms_topic, m_topic, m_ignore }
169 0, MAXPARA, MFLG_SLOW, 0,
170 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
171 { m_unregistered, m_invite, ms_invite, m_invite, m_ignore }
176 0, MAXPARA, MFLG_SLOW, 0,
177 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
178 { m_unregistered, m_kick, ms_kick, m_kick, m_ignore }
183 0, MAXPARA, MFLG_SLOW, 0,
184 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
185 { m_unregistered, m_not_oper, ms_wallops, mo_wallops, m_ignore }
190 0, MAXPARA, MFLG_SLOW, 0,
191 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
192 { m_unregistered, m_not_oper, ms_wallusers, mo_wallusers, m_ignore }
197 0, MAXPARA, MFLG_SLOW, 0,
198 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
199 { m_ignore, m_ignore, ms_desynch, m_ignore, m_ignore }
204 0, MAXPARA, MFLG_SLOW, 0,
205 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
206 { m_unregistered, m_ping, ms_ping, mo_ping, m_ignore }
211 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
212 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
213 { mr_pong, m_pong, ms_pong, m_pong, m_ignore }
218 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
219 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
220 { mr_error, m_ignore, ms_error, m_ignore, m_ignore }
225 0, MAXPARA, MFLG_SLOW, 0,
226 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
227 { m_unregistered, m_not_oper, ms_kill, mo_kill, m_ignore }
232 0, MAXPARA, MFLG_SLOW, 0,
233 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
234 { m_user, m_registered, m_ignore, m_registered, m_ignore }
239 0, MAXPARA, MFLG_SLOW, 0,
240 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
241 { m_unregistered, m_away, ms_away, m_away, m_ignore }
247 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
248 { m_unregistered, m_ison, m_ignore, m_ison, m_ignore }
253 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
254 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
255 { mr_server, m_registered, ms_server, m_registered, m_ignore }
260 0, MAXPARA, MFLG_SLOW, 0,
261 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
262 { m_unregistered, m_not_oper, ms_squit, mo_squit, m_ignore }
267 0, MAXPARA, MFLG_SLOW, 0,
268 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
269 { m_unregistered, m_whois, m_whois, m_whois, m_ignore }
274 0, MAXPARA, MFLG_SLOW, 0,
275 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
276 { m_unregistered, m_who, m_ignore, m_who, m_ignore }
281 0, MAXPARA, MFLG_SLOW, 0,
282 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
283 { m_unregistered, m_whowas, m_whowas, m_whowas, m_ignore }
288 0, MAXPARA, MFLG_SLOW, 0,
289 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
290 { m_unregistered, m_list, m_ignore, m_list, m_ignore }
295 0, MAXPARA, MFLG_SLOW, 0,
296 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
297 { m_unregistered, m_names, ms_names, m_names, m_ignore }
303 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
304 { m_unregistered, m_userhost, m_ignore, m_userhost, m_ignore }
310 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
311 { m_unregistered, m_userip, m_ignore, m_userip, m_ignore }
316 0, MAXPARA, MFLG_SLOW, 0,
317 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
318 #ifdef HEAD_IN_SAND_TRACE
319 { m_unregistered, m_not_oper, ms_trace, mo_trace, m_ignore }
321 { m_unregistered, m_trace, ms_trace, mo_trace, m_ignore }
327 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
328 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
329 { mr_pass, m_registered, m_ignore, m_registered, m_ignore }
334 0, MAXPARA, MFLG_SLOW, 0,
335 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
336 { m_unregistered, m_lusers, ms_lusers, m_lusers, m_ignore }
341 0, MAXPARA, MFLG_SLOW, 0,
342 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
343 { m_unregistered, m_time, m_time, m_time, m_ignore }
348 0, MAXPARA, MFLG_SLOW, 0,
349 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
350 { m_unregistered, m_ignore, ms_settime, mo_settime, m_ignore }
355 0, MAXPARA, MFLG_SLOW, 0,
356 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
357 { m_unregistered, m_not_oper, ms_rping, mo_rping, m_ignore }
362 0, MAXPARA, MFLG_SLOW, 0,
363 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
364 { m_unregistered, m_ignore, ms_rpong, m_ignore, m_ignore }
369 0, MAXPARA, MFLG_SLOW, 0,
370 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
371 { m_unregistered, m_oper, ms_oper, mo_oper, m_ignore }
376 0, MAXPARA, MFLG_SLOW, 0,
377 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
378 { m_unregistered, m_not_oper, ms_connect, mo_connect, m_ignore }
383 0, MAXPARA, MFLG_SLOW, 0,
384 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
385 #ifdef HEAD_IN_SAND_MAP
386 { m_unregistered, m_map_redirect, m_ignore, m_map, m_ignore }
388 { m_unregistered, m_map, m_ignore, m_map, m_ignore }
394 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
395 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
396 { m_version, m_version, ms_version, m_version, m_ignore }
401 0, MAXPARA, MFLG_SLOW, 0,
402 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
403 { m_unregistered, m_stats, ms_stats, mo_stats, m_ignore }
408 0, MAXPARA, MFLG_SLOW, 0,
409 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
410 #ifdef HEAD_IN_SAND_LINKS
411 { m_unregistered, m_links_redirect, ms_links, m_links, m_ignore }
413 { m_unregistered, m_links, ms_links, m_links, m_ignore }
419 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
420 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
421 { m_admin, m_admin, ms_admin, m_admin, m_ignore }
426 0, MAXPARA, MFLG_SLOW, 0,
427 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
428 { m_unregistered, m_help, m_ignore, m_help, m_ignore }
433 0, MAXPARA, MFLG_SLOW, 0,
434 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
435 { m_unregistered, m_info, ms_info, mo_info, m_ignore }
440 0, MAXPARA, MFLG_SLOW, 0,
441 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
442 { m_unregistered, m_motd, m_motd, m_motd, m_ignore }
447 0, MAXPARA, MFLG_SLOW, 0,
448 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
449 { m_unregistered, m_not_oper, m_ignore, mo_close, m_ignore }
454 0, MAXPARA, MFLG_SLOW, 0,
455 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
456 { m_unregistered, m_silence, ms_silence, m_silence, m_ignore }
461 0, MAXPARA, MFLG_SLOW, 0,
462 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
463 { m_unregistered, m_gline, ms_gline, mo_gline, m_ignore }
468 0, MAXPARA, MFLG_SLOW, 0,
469 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
470 { m_unregistered, m_jupe, ms_jupe, mo_jupe, m_ignore }
475 0, MAXPARA, MFLG_SLOW, 0,
476 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
477 { m_unregistered, m_not_oper, ms_opmode, mo_opmode, m_ignore }
482 0, MAXPARA, MFLG_SLOW, 0,
483 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
484 { m_unregistered, m_not_oper, ms_clearmode, mo_clearmode, m_ignore }
489 0, MAXPARA, MFLG_SLOW, 0,
490 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
491 { m_unregistered, m_not_oper, ms_uping, mo_uping, m_ignore }
496 0, MAXPARA, MFLG_SLOW, 0,
497 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
498 { m_ignore, m_ignore, ms_end_of_burst, m_ignore, m_ignore }
501 MSG_END_OF_BURST_ACK,
502 TOK_END_OF_BURST_ACK,
504 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
505 { m_ignore, m_ignore, ms_end_of_burst_ack, m_ignore, m_ignore }
510 0, MAXPARA, MFLG_SLOW, 0,
511 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
512 { m_unregistered, m_hash, m_hash, m_hash, m_ignore }
517 0, MAXPARA, MFLG_SLOW, 0,
518 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
519 { m_unregistered, m_dns, m_dns, m_dns, m_ignore }
524 0, MAXPARA, MFLG_SLOW, 0,
525 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
526 { m_unregistered, m_not_oper, m_ignore, mo_rehash, m_ignore }
531 0, MAXPARA, MFLG_SLOW, 0,
532 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
533 { m_unregistered, m_not_oper, m_ignore, mo_restart, m_ignore }
538 0, MAXPARA, MFLG_SLOW, 0,
539 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
540 { m_unregistered, m_not_oper, m_ignore, mo_die, m_ignore }
545 0, MAXPARA, MFLG_SLOW, 0,
546 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
547 { m_proto, m_proto, m_proto, m_proto, m_ignore }
552 0, MAXPARA, MFLG_SLOW, 0,
553 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
554 { m_unregistered, m_not_oper, m_ignore, mo_set, m_ignore }
559 0, MAXPARA, MFLG_SLOW, 0,
560 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
561 { m_unregistered, m_not_oper, m_ignore, mo_reset, m_ignore }
566 0, MAXPARA, MFLG_SLOW, 0,
567 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
568 { m_unregistered, m_not_oper, m_ignore, mo_get, m_ignore }
573 0, MAXPARA, MFLG_SLOW, 0,
574 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
575 { m_unregistered, m_not_oper, m_ignore, mo_privs, m_ignore }
577 /* This command is an alias for QUIT during the unregistered part of
578 * of the server. This is because someone jumping via a broken web
579 * proxy will send a 'POST' as their first command - which we will
580 * obviously disconnect them immediately for, stopping people abusing
586 0, MAXPARA, MFLG_SLOW, 0,
587 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
588 { m_quit, m_ignore, m_ignore, m_ignore, m_ignore }
594 static char *para[MAXPARA + 2]; /* leave room for prefix and null */
597 * Message Tree stuff mostly written by orabidoo, with changes by Dianora.
598 * Adapted to Undernet, adding token support, etc by comstud 10/06/97
601 static struct MessageTree msg_tree_cmd;
602 static struct MessageTree msg_tree_tok;
605 * Guts of making the token tree...
607 static struct Message **do_msg_tree_tok(struct MessageTree *mtree, char *prefix,
608 struct Message **mptr)
610 char newprefix[64]; /* Must be longer than every command name */
612 struct MessageTree *mtree1;
615 if (!lp || !strncmp((*mptr)->tok, prefix, lp))
617 if (!mptr[1] || (lp && strncmp(mptr[1]->tok, prefix, lp)))
619 /* last command in the message struct or last command in this prefix */
620 mtree->final = (*mptr)->tok + lp;
622 for (c = 0; c < 26; ++c)
623 mtree->pointers[c] = NULL;
626 /* command in this prefix */
627 if (0 == ircd_strcmp((*mptr)->tok, prefix))
630 mtree->msg = *mptr++;
635 for (c = 'A'; c <= 'Z'; ++c)
637 if ((*mptr)->tok[lp] == c)
639 mtree1 = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
640 mtree1->final = NULL;
641 mtree->pointers[c - 'A'] = mtree1;
642 strcpy(newprefix, prefix);
644 newprefix[lp + 1] = '\0';
645 mptr = do_msg_tree_tok(mtree1, newprefix, mptr);
646 if (!*mptr || strncmp((*mptr)->tok, prefix, lp))
648 for (c2 = c + 1 - 'A'; c2 < 26; ++c2)
649 mtree->pointers[c2] = NULL;
654 mtree->pointers[c - 'A'] = NULL;
659 * XXX - should never be here, quick hack, this can be done better
666 * Guts of making the command tree...
668 static struct Message *do_msg_tree_cmd(struct MessageTree *mtree, char *prefix,
669 struct Message *mptr)
671 char newprefix[64]; /* Must be longer than every command name */
673 struct MessageTree *mtree1;
676 if (!lp || !strncmp(mptr->cmd, prefix, lp))
678 if (!mptr[1].cmd || (lp && strncmp(mptr[1].cmd, prefix, lp)))
680 /* last command in the message struct or last command in this prefix */
681 mtree->final = mptr->cmd + lp;
683 for (c = 0; c < 26; ++c)
684 mtree->pointers[c] = NULL;
687 /* command in this prefix */
688 if (0 == ircd_strcmp(mptr->cmd, prefix))
696 for (c = 'A'; c <= 'Z'; ++c)
698 if (mptr->cmd[lp] == c)
700 mtree1 = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
701 mtree1->final = NULL;
702 mtree->pointers[c - 'A'] = mtree1;
703 strcpy(newprefix, prefix);
705 newprefix[lp + 1] = '\0';
706 mptr = do_msg_tree_cmd(mtree1, newprefix, mptr);
707 if (!mptr->cmd || strncmp(mptr->cmd, prefix, lp))
709 for (c2 = c + 1 - 'A'; c2 < 26; ++c2)
710 mtree->pointers[c2] = NULL;
715 mtree->pointers[c - 'A'] = NULL;
720 * This should never happen
726 static int mcmdcmp(const struct Message *m1, const struct Message *m2)
728 return strcmp(m1->cmd, m2->cmd);
731 static int mtokcmp(const struct Message **m1, const struct Message **m2)
733 return strcmp((*m1)->tok, (*m2)->tok);
737 * Sort the command names.
738 * Create table of pointers into msgtab for tokens.
739 * Create trees for ->cmd and ->tok and free the token pointers.
741 void initmsgtree(void)
744 struct Message *msg = msgtab;
746 struct Message **msgtab_tok;
747 struct Message **msgtok;
749 for (i = 0; msg->cmd; ++i, ++msg)
751 qsort(msgtab, i, sizeof(struct Message),
752 (int (*)(const void *, const void *))mcmdcmp);
753 msgtab_tok = (struct Message **)MyMalloc((i + 1) * sizeof(struct Message *));
754 for (ii = 0; ii < i; ++ii)
755 msgtab_tok[ii] = msgtab + ii;
756 msgtab_tok[i] = NULL; /* Needed by `do_msg_tree_tok' */
757 qsort(msgtab_tok, i, sizeof(struct Message *),
758 (int (*)(const void *, const void *))mtokcmp);
759 msg = do_msg_tree_cmd(&msg_tree_cmd, "", msgtab);
760 msgtok = do_msg_tree_tok(&msg_tree_tok, "", msgtab_tok);
765 * Generic tree parser which works for both commands and tokens.
768 static struct Message *msg_tree_parse(char *cmd, struct MessageTree *root)
770 struct MessageTree *mtree;
771 unsigned char r = (0xdf & (unsigned char)*cmd) - 'A';
772 if (r > 25 || !(mtree = root->pointers[r]))
776 r = 0xdf & (unsigned char)*++cmd;
777 if (mtree->final && *mtree->final == r)
779 if ((r -= 'A') > 25 || !(mtree = mtree->pointers[r]))
785 * This one is identical to the one above, but it is slower because it
786 * makes sure that `cmd' matches the _full_ command, exactly.
787 * This is to avoid confusion with commands like /quake on clients
788 * that send unknown commands directly to the server.
790 static struct Message *msg_tree_parse_client(char *cmd,
791 struct MessageTree *root)
793 struct MessageTree *mtree;
794 unsigned char q = (0xdf & (unsigned char)*cmd) - 'A';
795 if (q > 25 || !(mtree = root->pointers[q]))
799 q = 0xdf & (unsigned char)*++cmd;
800 if (mtree->final && 0 == ircd_strcmp(mtree->final, cmd))
802 if ((q -= 'A') > 25 || !(mtree = mtree->pointers[q]))
810 * NOTE: parse_*() should not be called recusively by any other fucntions!
812 int parse_client(struct Client *cptr, char *buffer, char *bufend)
814 struct Client* from = cptr;
820 struct Message* mptr;
821 MessageHandler handler = 0;
823 Debug((DEBUG_DEBUG, "Client Parsing: %s", buffer));
828 para[0] = cli_name(from);
829 for (ch = buffer; *ch == ' '; ch++); /* Eat leading spaces */
830 if (*ch == ':') /* Is any client doing this ? */
832 for (++ch; *ch && *ch != ' '; ++ch)
833 ; /* Ignore sender prefix from client */
835 ch++; /* Advance to command */
841 ServerStats->is_empt++;
842 Debug((DEBUG_NOTICE, "Empty message from host %s:%s",
843 cli_name(cptr), cli_name(from)));
847 if ((s = strchr(ch, ' ')))
851 * This is a client/unregistered entity.
852 * Check long command list only.
854 if (!(mptr = msg_tree_parse_client(ch, &msg_tree_cmd)))
857 * Note: Give error message *only* to recognized
858 * persons. It's a nightmare situation to have
859 * two programs sending "Unknown command"'s or
860 * equivalent to each other at full blast....
861 * If it has got to person state, it at least
862 * seems to be well behaving. Perhaps this message
863 * should never be generated, though... --msa
864 * Hm, when is the buffer empty -- if a command
865 * code has been found ?? -Armin
867 if (buffer[0] != '\0')
870 send_reply(from, ERR_UNKNOWNCOMMAND, ch);
871 Debug((DEBUG_ERROR, "Unknown (%s) from %s",
872 ch, get_client_name(cptr, HIDE_IP)));
874 ServerStats->is_unco++;
878 paramcount = mptr->parameters;
879 i = bufend - ((s) ? s : ch);
881 if ((mptr->flags & MFLG_SLOW))
882 cli_since(cptr) += (2 + i / 120);
884 * Allow only 1 msg per 2 seconds
885 * (on average) to prevent dumping.
886 * to keep the response rate up,
887 * bursts of up to 5 msgs are allowed
892 * Must the following loop really be so devious? On
893 * surface it splits the message to parameters from
894 * blank spaces. But, if paramcount has been reached,
895 * the rest of the message goes into this last parameter
896 * (about same effect as ":" has...) --msa
899 /* Note initially true: s==NULL || *(s-1) == '\0' !! */
904 if (paramcount > MAXPARA)
905 paramcount = MAXPARA;
909 * Never "FRANCE " again!! ;-) Clean
910 * out *all* blanks.. --msa
920 * The rest is single parameter--can
921 * include blanks also.
929 for (; *s != ' ' && *s; s++);
935 handler = mptr->handlers[cli_handler(cptr)];
936 assert(0 != handler);
938 if (!feature_bool(FEAT_IDLE_FROM_MSG) && IsUser(cptr) &&
939 handler != m_ping && handler != m_ignore)
940 cli_user(from)->last = CurrentTime;
942 return (*handler) (cptr, from, i, para);
945 int parse_server(struct Client *cptr, char *buffer, char *bufend)
947 struct Client* from = cptr;
954 struct Message* mptr;
956 Debug((DEBUG_DEBUG, "Server Parsing: %s", buffer));
961 para[0] = cli_name(from);
964 * A server ALWAYS sends a prefix. When it starts with a ':' it's the
965 * protocol 9 prefix: a nick or a server name. Otherwise it's a numeric
970 /* Let para[0] point to the name of the sender */
972 if (!(ch = strchr(ch, ' ')))
976 /* And let `from' point to its client structure,
977 opps.. a server is _also_ a client --Nem */
978 from = FindClient(para[0]);
981 * If the client corresponding to the
982 * prefix is not found. We must ignore it,
983 * it is simply a lagged message travelling
984 * upstream a SQUIT that removed the client
989 Debug((DEBUG_NOTICE, "Unknown prefix (%s)(%s) from (%s)",
990 para[0], buffer, cli_name(cptr)));
991 ++ServerStats->is_unpf;
995 * However, the only thing that MUST be
996 * allowed to travel upstream against an
997 * squit, is an SQUIT itself (the timestamp
998 * protects us from being used wrong)
1002 para[0] = cli_name(cptr);
1008 else if (cli_from(from) != cptr)
1010 ++ServerStats->is_wrdi;
1011 Debug((DEBUG_NOTICE, "Fake direction: Message (%s) coming from (%s)",
1012 buffer, cli_name(cptr)));
1017 char numeric_prefix[6];
1019 for (i = 0; i < 5; ++i) {
1020 if ('\0' == ch[i] || ' ' == (numeric_prefix[i] = ch[i])) {
1024 numeric_prefix[i] = '\0';
1027 * We got a numeric nick as prefix
1028 * 1 or 2 character prefixes are from servers
1029 * 3 or 5 chars are from clients
1032 protocol_violation(cptr,"Missing Prefix");
1035 else if (' ' == ch[1] || ' ' == ch[2])
1036 from = FindNServer(numeric_prefix);
1038 from = findNUser(numeric_prefix);
1044 while (*ch != ' ' && *ch);
1047 * If the client corresponding to the
1048 * prefix is not found. We must ignore it,
1049 * it is simply a lagged message travelling
1050 * upstream a SQUIT that removed the client
1052 * There turned out to be other reasons that
1053 * a prefix is unknown, needing an upstream
1054 * KILL. Also, next to an SQUIT we better
1055 * allow a KILL to pass too.
1060 ServerStats->is_unpf++;
1063 if (*ch == 'N' && (ch[1] == ' ' || ch[1] == 'I'))
1064 /* Only sent a KILL for a nick change */
1066 struct Client *server;
1067 /* Kill the unknown numeric prefix upstream if
1068 * it's server still exists: */
1069 if ((server = FindNServer(numeric_prefix)) && cli_from(server) == cptr)
1070 sendcmdto_one(&me, CMD_KILL, cptr, "%s :%s (Unknown numeric nick)",
1071 numeric_prefix, cli_name(&me));
1074 * Things that must be allowed to travel
1075 * upstream against an squit:
1077 if (ch[1] == 'Q' || (*ch == 'D' && ch[1] == ' ') ||
1078 (*ch == 'K' && ch[2] == 'L'))
1084 /* Let para[0] point to the name of the sender */
1085 para[0] = cli_name(from);
1087 if (cli_from(from) != cptr)
1089 ServerStats->is_wrdi++;
1090 Debug((DEBUG_NOTICE, "Fake direction: Message (%s) coming from (%s)",
1091 buffer, cli_name(cptr)));
1100 ServerStats->is_empt++;
1101 Debug((DEBUG_NOTICE, "Empty message from host %s:%s",
1102 cli_name(cptr), cli_name(from)));
1107 * Extract the command code from the packet. Point s to the end
1108 * of the command code and calculate the length using pointer
1109 * arithmetic. Note: only need length for numerics and *all*
1110 * numerics must have parameters and thus a space after the command
1113 s = strchr(ch, ' '); /* s -> End of the command code */
1114 len = (s) ? (s - ch) : 0;
1115 if (len == 3 && IsDigit(*ch))
1117 numeric = (*ch - '0') * 100 + (*(ch + 1) - '0') * 10 + (*(ch + 2) - '0');
1118 paramcount = 2; /* destination, and the rest of it */
1119 ServerStats->is_num++;
1120 mptr = NULL; /* Init. to avoid stupid compiler warning :/ */
1127 /* Version Receive Send
1129 * 2.10.0 Tkn/Long Long
1130 * 2.10.10 Tkn/Long Tkn
1133 * Clients/unreg servers always receive/
1134 * send long commands -record
1138 * This is a server. Check the token command list.
1139 * -record!jegelhof@cloud9.net
1141 mptr = msg_tree_parse(ch, &msg_tree_tok);
1143 #if 1 /* for 2.10.0/2.10.10 */
1145 * This code supports 2.9 and 2.10.0 sending long commands.
1146 * It makes more calls to ircd_strcmp() than the above
1147 * so it will be somewhat slower.
1150 mptr = msg_tree_parse(ch, &msg_tree_cmd);
1156 * Note: Give error message *only* to recognized
1157 * persons. It's a nightmare situation to have
1158 * two programs sending "Unknown command"'s or
1159 * equivalent to each other at full blast....
1160 * If it has got to person state, it at least
1161 * seems to be well behaving. Perhaps this message
1162 * should never be generated, though... --msa
1163 * Hm, when is the buffer empty -- if a command
1164 * code has been found ?? -Armin
1167 if (buffer[0] != '\0')
1169 Debug((DEBUG_ERROR, "Unknown (%s) from %s",
1170 ch, get_client_name(cptr, HIDE_IP)));
1173 ServerStats->is_unco++;
1177 paramcount = mptr->parameters;
1178 i = bufend - ((s) ? s : ch);
1182 * Must the following loop really be so devious? On
1183 * surface it splits the message to parameters from
1184 * blank spaces. But, if paramcount has been reached,
1185 * the rest of the message goes into this last parameter
1186 * (about same effect as ":" has...) --msa
1189 /* Note initially true: s==NULL || *(s-1) == '\0' !! */
1194 if (paramcount > MAXPARA)
1195 paramcount = MAXPARA;
1199 * Never "FRANCE " again!! ;-) Clean
1200 * out *all* blanks.. --msa
1210 * The rest is single parameter--can
1211 * include blanks also.
1214 para[++i] = s; /* preserve the colon to make do_numeric happy */
1220 if (i >= paramcount)
1222 for (; *s != ' ' && *s; s++);
1227 return (do_numeric(numeric, (*buffer != ':'), cptr, from, i, para));
1230 return (*mptr->handlers[cli_handler(cptr)]) (cptr, from, i, para);