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_reply.h"
34 #include "ircd_string.h"
39 #include "querycmds.h"
45 #include "s_numeric.h"
62 struct MessageTree *pointers[26];
66 struct Message msgtab[] = {
70 0, MAXPARA, MFLG_SLOW, 0,
71 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
72 { m_unregistered, m_privmsg, ms_privmsg, mo_privmsg, m_ignore }
77 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
78 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
79 { m_nick, m_nick, ms_nick, m_nick, m_ignore }
84 0, MAXPARA, MFLG_SLOW | MFLG_IGNORE, 0,
85 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
86 { m_ignore, m_notice, ms_notice, mo_notice, m_ignore }
91 0, MAXPARA, MFLG_SLOW, 0,
92 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
93 { m_unregistered, m_wallchops, ms_wallchops, m_wallchops, m_ignore }
98 0, MAXPARA, MFLG_SLOW, 0,
99 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
100 { m_unregistered, m_wallvoices, ms_wallvoices, m_wallvoices, m_ignore }
105 0, MAXPARA, MFLG_SLOW, 0,
106 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
107 { m_unregistered, m_cprivmsg, m_ignore, m_cprivmsg, m_ignore }
112 0, MAXPARA, MFLG_SLOW, 0,
113 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
114 { m_unregistered, m_cnotice, m_ignore, m_cnotice, m_ignore }
119 0, MAXPARA, MFLG_SLOW, 0,
120 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
121 { m_unregistered, m_join, ms_join, m_join, m_ignore }
126 0, MAXPARA, MFLG_SLOW, 0,
127 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
128 { m_unregistered, m_mode, ms_mode, m_mode, m_ignore }
133 0, MAXPARA, MFLG_SLOW, 0,
134 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
135 { m_ignore, m_ignore, ms_burst, m_ignore, m_ignore }
140 0, MAXPARA, MFLG_SLOW, 0,
141 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
142 { m_ignore, m_ignore, ms_create, m_ignore, m_ignore }
147 0, MAXPARA, MFLG_SLOW, 0,
148 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
149 { m_ignore, m_ignore, ms_destruct, m_ignore, m_ignore }
154 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
155 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
156 { m_quit, m_quit, ms_quit, m_quit, m_ignore }
161 0, MAXPARA, MFLG_SLOW, 0,
162 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
163 { m_unregistered, m_part, ms_part, m_part, m_ignore }
168 0, MAXPARA, MFLG_SLOW, 0,
169 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
170 { m_unregistered, m_topic, ms_topic, m_topic, m_ignore }
175 0, MAXPARA, MFLG_SLOW, 0,
176 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
177 { m_unregistered, m_invite, ms_invite, m_invite, m_ignore }
182 0, MAXPARA, MFLG_SLOW, 0,
183 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
184 { m_unregistered, m_kick, ms_kick, m_kick, m_ignore }
189 0, MAXPARA, MFLG_SLOW, 0,
190 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
191 { m_unregistered, m_not_oper, ms_wallops, mo_wallops, m_ignore }
196 0, MAXPARA, MFLG_SLOW, 0,
197 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
198 { m_unregistered, m_not_oper, ms_wallusers, mo_wallusers, m_ignore }
203 0, MAXPARA, MFLG_SLOW, 0,
204 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
205 { m_ignore, m_ignore, ms_desynch, m_ignore, m_ignore }
210 0, MAXPARA, MFLG_SLOW, 0,
211 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
212 { m_unregistered, m_ping, ms_ping, mo_ping, m_ignore }
217 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
218 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
219 { mr_pong, m_pong, ms_pong, m_pong, m_ignore }
224 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
225 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
226 { mr_error, m_ignore, ms_error, m_ignore, m_ignore }
231 0, MAXPARA, MFLG_SLOW, 0,
232 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
233 { m_unregistered, m_not_oper, ms_kill, mo_kill, m_ignore }
238 0, MAXPARA, MFLG_SLOW, 0,
239 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
240 { m_user, m_registered, m_ignore, m_registered, m_ignore }
245 0, MAXPARA, MFLG_SLOW, 0,
246 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
247 { m_unregistered, m_away, ms_away, m_away, m_ignore }
253 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
254 { m_unregistered, m_ison, m_ignore, m_ison, m_ignore }
259 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
260 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
261 { mr_server, m_registered, ms_server, m_registered, m_ignore }
266 0, MAXPARA, MFLG_SLOW, 0,
267 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
268 { m_unregistered, m_not_oper, ms_squit, mo_squit, m_ignore }
273 0, MAXPARA, MFLG_SLOW, 0,
274 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
275 { m_unregistered, m_whois, ms_whois, m_whois, m_ignore }
280 0, MAXPARA, MFLG_SLOW, 0,
281 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
282 { m_unregistered, m_who, m_ignore, m_who, m_ignore }
287 0, MAXPARA, MFLG_SLOW, 0,
288 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
289 { m_unregistered, m_whowas, m_whowas, m_whowas, m_ignore }
294 0, MAXPARA, MFLG_SLOW, 0,
295 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
296 { m_unregistered, m_list, m_ignore, m_list, m_ignore }
301 0, MAXPARA, MFLG_SLOW, 0,
302 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
303 { m_unregistered, m_names, ms_names, m_names, m_ignore }
309 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
310 { m_unregistered, m_userhost, m_ignore, m_userhost, m_ignore }
316 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
317 { m_unregistered, m_userip, m_ignore, m_userip, m_ignore }
322 0, MAXPARA, MFLG_SLOW, 0,
323 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
324 { m_unregistered, m_trace, ms_trace, mo_trace, m_ignore }
329 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
330 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
331 { mr_pass, m_registered, m_ignore, m_registered, m_ignore }
336 0, MAXPARA, MFLG_SLOW, 0,
337 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
338 { m_unregistered, m_lusers, ms_lusers, m_lusers, m_ignore }
343 0, MAXPARA, MFLG_SLOW, 0,
344 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
345 { m_unregistered, m_time, m_time, m_time, m_ignore }
350 0, MAXPARA, MFLG_SLOW, 0,
351 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
352 { m_unregistered, m_ignore, ms_settime, mo_settime, m_ignore }
357 0, MAXPARA, MFLG_SLOW, 0,
358 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
359 { m_unregistered, m_not_oper, ms_rping, mo_rping, m_ignore }
364 0, MAXPARA, MFLG_SLOW, 0,
365 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
366 { m_unregistered, m_ignore, ms_rpong, m_ignore, m_ignore }
371 0, MAXPARA, MFLG_SLOW, 0,
372 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
373 { m_unregistered, m_oper, ms_oper, mo_oper, m_ignore }
378 0, MAXPARA, MFLG_SLOW, 0,
379 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
380 { m_unregistered, m_not_oper, ms_connect, mo_connect, m_ignore }
385 0, MAXPARA, MFLG_SLOW, 0,
386 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
387 { m_unregistered, m_map, m_ignore, m_map, m_ignore }
392 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
393 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
394 { m_version, m_version, ms_version, mo_version, m_ignore }
399 0, MAXPARA, MFLG_SLOW, 0,
400 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
401 { m_unregistered, m_stats, m_stats, m_stats, m_ignore }
406 0, MAXPARA, MFLG_SLOW, 0,
407 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
408 { m_unregistered, m_links, ms_links, m_links, m_ignore }
413 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
414 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
415 { m_admin, m_admin, ms_admin, mo_admin, m_ignore }
420 0, MAXPARA, MFLG_SLOW, 0,
421 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
422 { m_unregistered, m_help, m_ignore, m_help, m_ignore }
427 0, MAXPARA, MFLG_SLOW, 0,
428 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
429 { m_unregistered, m_info, ms_info, mo_info, m_ignore }
434 0, MAXPARA, MFLG_SLOW, 0,
435 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
436 { m_unregistered, m_motd, m_motd, m_motd, m_ignore }
441 0, MAXPARA, MFLG_SLOW, 0,
442 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
443 { m_unregistered, m_not_oper, m_ignore, mo_close, m_ignore }
448 0, MAXPARA, MFLG_SLOW, 0,
449 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
450 { m_unregistered, m_silence, ms_silence, m_silence, m_ignore }
455 0, MAXPARA, MFLG_SLOW, 0,
456 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
457 { m_unregistered, m_gline, ms_gline, mo_gline, m_ignore }
462 0, MAXPARA, MFLG_SLOW, 0,
463 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
464 { m_unregistered, m_jupe, ms_jupe, mo_jupe, m_ignore }
469 0, MAXPARA, MFLG_SLOW, 0,
470 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
471 { m_unregistered, m_not_oper, ms_opmode, mo_opmode, m_ignore }
476 0, MAXPARA, MFLG_SLOW, 0,
477 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
478 { m_unregistered, m_not_oper, ms_clearmode, mo_clearmode, m_ignore }
483 0, MAXPARA, MFLG_SLOW, 0,
484 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
485 { m_unregistered, m_not_oper, ms_uping, mo_uping, m_ignore }
490 0, MAXPARA, MFLG_SLOW, 0,
491 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
492 { m_ignore, m_ignore, ms_end_of_burst, m_ignore, m_ignore }
495 MSG_END_OF_BURST_ACK,
496 TOK_END_OF_BURST_ACK,
498 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
499 { m_ignore, m_ignore, ms_end_of_burst_ack, m_ignore, m_ignore }
504 0, MAXPARA, MFLG_SLOW, 0,
505 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
506 { m_unregistered, m_hash, m_hash, m_hash, m_ignore }
511 0, MAXPARA, MFLG_SLOW, 0,
512 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
513 { m_unregistered, m_dns, m_dns, m_dns, m_ignore }
518 0, MAXPARA, MFLG_SLOW, 0,
519 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
520 { m_unregistered, m_not_oper, m_ignore, mo_rehash, m_ignore }
525 0, MAXPARA, MFLG_SLOW, 0,
526 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
527 { m_unregistered, m_not_oper, m_ignore, mo_restart, m_ignore }
532 0, MAXPARA, MFLG_SLOW, 0,
533 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
534 { m_unregistered, m_not_oper, m_ignore, mo_die, m_ignore }
539 0, MAXPARA, MFLG_SLOW, 0,
540 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
541 { m_proto, m_proto, m_proto, m_proto, m_ignore }
546 0, MAXPARA, MFLG_SLOW, 0,
547 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
548 { m_unregistered, m_not_oper, m_ignore, mo_set, m_ignore }
553 0, MAXPARA, MFLG_SLOW, 0,
554 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
555 { m_unregistered, m_not_oper, m_ignore, mo_reset, m_ignore }
560 0, MAXPARA, MFLG_SLOW, 0,
561 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
562 { m_unregistered, m_not_oper, m_ignore, mo_get, m_ignore }
567 0, MAXPARA, MFLG_SLOW, 0,
568 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
569 { m_unregistered, m_not_oper, m_ignore, mo_privs, m_ignore }
574 0, MAXPARA, MFLG_SLOW, 0,
575 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
576 { m_ignore, m_ignore, ms_account, m_ignore, m_ignore }
581 0, MAXPARA, MFLG_SLOW, 0,
582 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
583 { m_ignore, m_not_oper, ms_asll, mo_asll, m_ignore }
585 /* This command is an alias for QUIT during the unregistered part of
586 * of the server. This is because someone jumping via a broken web
587 * proxy will send a 'POST' as their first command - which we will
588 * obviously disconnect them immediately for, stopping people abusing
594 0, MAXPARA, MFLG_SLOW, 0,
595 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
596 { m_quit, m_ignore, m_ignore, m_ignore, m_ignore }
602 static char *para[MAXPARA + 2]; /* leave room for prefix and null */
605 * Message Tree stuff mostly written by orabidoo, with changes by Dianora.
606 * Adapted to Undernet, adding token support, etc by comstud 10/06/97
609 static struct MessageTree msg_tree_cmd;
610 static struct MessageTree msg_tree_tok;
613 * Guts of making the token tree...
615 static struct Message **do_msg_tree_tok(struct MessageTree *mtree, char *prefix,
616 struct Message **mptr)
618 char newprefix[64]; /* Must be longer than every command name */
620 struct MessageTree *mtree1;
623 if (!lp || !strncmp((*mptr)->tok, prefix, lp))
625 if (!mptr[1] || (lp && strncmp(mptr[1]->tok, prefix, lp)))
627 /* last command in the message struct or last command in this prefix */
628 mtree->final = (*mptr)->tok + lp;
630 for (c = 0; c < 26; ++c)
631 mtree->pointers[c] = NULL;
634 /* command in this prefix */
635 if (0 == ircd_strcmp((*mptr)->tok, prefix))
638 mtree->msg = *mptr++;
643 for (c = 'A'; c <= 'Z'; ++c)
645 if ((*mptr)->tok[lp] == c)
647 mtree1 = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
648 mtree1->final = NULL;
649 mtree->pointers[c - 'A'] = mtree1;
650 strcpy(newprefix, prefix);
652 newprefix[lp + 1] = '\0';
653 mptr = do_msg_tree_tok(mtree1, newprefix, mptr);
654 if (!*mptr || strncmp((*mptr)->tok, prefix, lp))
656 for (c2 = c + 1 - 'A'; c2 < 26; ++c2)
657 mtree->pointers[c2] = NULL;
662 mtree->pointers[c - 'A'] = NULL;
667 * XXX - should never be here, quick hack, this can be done better
674 * Guts of making the command tree...
676 static struct Message *do_msg_tree_cmd(struct MessageTree *mtree, char *prefix,
677 struct Message *mptr)
679 char newprefix[64]; /* Must be longer than every command name */
681 struct MessageTree *mtree1;
684 if (!lp || !strncmp(mptr->cmd, prefix, lp))
686 if (!mptr[1].cmd || (lp && strncmp(mptr[1].cmd, prefix, lp)))
688 /* last command in the message struct or last command in this prefix */
689 mtree->final = mptr->cmd + lp;
691 for (c = 0; c < 26; ++c)
692 mtree->pointers[c] = NULL;
695 /* command in this prefix */
696 if (0 == ircd_strcmp(mptr->cmd, prefix))
704 for (c = 'A'; c <= 'Z'; ++c)
706 if (mptr->cmd[lp] == c)
708 mtree1 = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
709 mtree1->final = NULL;
710 mtree->pointers[c - 'A'] = mtree1;
711 strcpy(newprefix, prefix);
713 newprefix[lp + 1] = '\0';
714 mptr = do_msg_tree_cmd(mtree1, newprefix, mptr);
715 if (!mptr->cmd || strncmp(mptr->cmd, prefix, lp))
717 for (c2 = c + 1 - 'A'; c2 < 26; ++c2)
718 mtree->pointers[c2] = NULL;
723 mtree->pointers[c - 'A'] = NULL;
728 * This should never happen
734 static int mcmdcmp(const struct Message *m1, const struct Message *m2)
736 return strcmp(m1->cmd, m2->cmd);
739 static int mtokcmp(const struct Message **m1, const struct Message **m2)
741 return strcmp((*m1)->tok, (*m2)->tok);
745 * Sort the command names.
746 * Create table of pointers into msgtab for tokens.
747 * Create trees for ->cmd and ->tok and free the token pointers.
749 void initmsgtree(void)
752 struct Message *msg = msgtab;
754 struct Message **msgtab_tok;
755 struct Message **msgtok;
757 for (i = 0; msg->cmd; ++i, ++msg)
759 qsort(msgtab, i, sizeof(struct Message),
760 (int (*)(const void *, const void *))mcmdcmp);
761 msgtab_tok = (struct Message **)MyMalloc((i + 1) * sizeof(struct Message *));
762 for (ii = 0; ii < i; ++ii)
763 msgtab_tok[ii] = msgtab + ii;
764 msgtab_tok[i] = NULL; /* Needed by `do_msg_tree_tok' */
765 qsort(msgtab_tok, i, sizeof(struct Message *),
766 (int (*)(const void *, const void *))mtokcmp);
767 msg = do_msg_tree_cmd(&msg_tree_cmd, "", msgtab);
768 msgtok = do_msg_tree_tok(&msg_tree_tok, "", msgtab_tok);
773 * Generic tree parser which works for both commands and tokens.
776 static struct Message *msg_tree_parse(char *cmd, struct MessageTree *root)
778 struct MessageTree *mtree;
779 unsigned char r = (0xdf & (unsigned char)*cmd) - 'A';
780 if (r > 25 || !(mtree = root->pointers[r]))
784 r = 0xdf & (unsigned char)*++cmd;
785 if (mtree->final && *mtree->final == r)
787 if ((r -= 'A') > 25 || !(mtree = mtree->pointers[r]))
793 * This one is identical to the one above, but it is slower because it
794 * makes sure that `cmd' matches the _full_ command, exactly.
795 * This is to avoid confusion with commands like /quake on clients
796 * that send unknown commands directly to the server.
798 static struct Message *msg_tree_parse_client(char *cmd,
799 struct MessageTree *root)
801 struct MessageTree *mtree;
802 unsigned char q = (0xdf & (unsigned char)*cmd) - 'A';
803 if (q > 25 || !(mtree = root->pointers[q]))
807 q = 0xdf & (unsigned char)*++cmd;
808 if (mtree->final && 0 == ircd_strcmp(mtree->final, cmd))
810 if ((q -= 'A') > 25 || !(mtree = mtree->pointers[q]))
818 * NOTE: parse_*() should not be called recusively by any other fucntions!
820 int parse_client(struct Client *cptr, char *buffer, char *bufend)
822 struct Client* from = cptr;
828 struct Message* mptr;
829 MessageHandler handler = 0;
831 Debug((DEBUG_DEBUG, "Client Parsing: %s", buffer));
836 para[0] = cli_name(from);
837 for (ch = buffer; *ch == ' '; ch++); /* Eat leading spaces */
838 if (*ch == ':') /* Is any client doing this ? */
840 for (++ch; *ch && *ch != ' '; ++ch)
841 ; /* Ignore sender prefix from client */
843 ch++; /* Advance to command */
849 ServerStats->is_empt++;
850 Debug((DEBUG_NOTICE, "Empty message from host %s:%s",
851 cli_name(cptr), cli_name(from)));
855 if ((s = strchr(ch, ' ')))
859 * This is a client/unregistered entity.
860 * Check long command list only.
862 if (!(mptr = msg_tree_parse_client(ch, &msg_tree_cmd)))
865 * Note: Give error message *only* to recognized
866 * persons. It's a nightmare situation to have
867 * two programs sending "Unknown command"'s or
868 * equivalent to each other at full blast....
869 * If it has got to person state, it at least
870 * seems to be well behaving. Perhaps this message
871 * should never be generated, though... --msa
872 * Hm, when is the buffer empty -- if a command
873 * code has been found ?? -Armin
875 if (buffer[0] != '\0')
878 send_reply(from, ERR_UNKNOWNCOMMAND, ch);
879 Debug((DEBUG_ERROR, "Unknown (%s) from %s",
880 ch, get_client_name(cptr, HIDE_IP)));
882 ServerStats->is_unco++;
886 paramcount = mptr->parameters;
887 i = bufend - ((s) ? s : ch);
889 if ((mptr->flags & MFLG_SLOW))
890 cli_since(cptr) += (2 + i / 120);
892 * Allow only 1 msg per 2 seconds
893 * (on average) to prevent dumping.
894 * to keep the response rate up,
895 * bursts of up to 5 msgs are allowed
900 * Must the following loop really be so devious? On
901 * surface it splits the message to parameters from
902 * blank spaces. But, if paramcount has been reached,
903 * the rest of the message goes into this last parameter
904 * (about same effect as ":" has...) --msa
907 /* Note initially true: s==NULL || *(s-1) == '\0' !! */
912 if (paramcount > MAXPARA)
913 paramcount = MAXPARA;
917 * Never "FRANCE " again!! ;-) Clean
918 * out *all* blanks.. --msa
928 * The rest is single parameter--can
929 * include blanks also.
937 for (; *s != ' ' && *s; s++);
943 handler = mptr->handlers[cli_handler(cptr)];
944 assert(0 != handler);
946 if (!feature_bool(FEAT_IDLE_FROM_MSG) && IsUser(cptr) &&
947 handler != m_ping && handler != m_ignore)
948 cli_user(from)->last = CurrentTime;
950 return (*handler) (cptr, from, i, para);
953 int parse_server(struct Client *cptr, char *buffer, char *bufend)
955 struct Client* from = cptr;
962 struct Message* mptr;
964 Debug((DEBUG_DEBUG, "Server Parsing: %s", buffer));
969 para[0] = cli_name(from);
972 * A server ALWAYS sends a prefix. When it starts with a ':' it's the
973 * protocol 9 prefix: a nick or a server name. Otherwise it's a numeric
978 /* Let para[0] point to the name of the sender */
980 if (!(ch = strchr(ch, ' ')))
984 /* And let `from' point to its client structure,
985 opps.. a server is _also_ a client --Nem */
986 from = FindClient(para[0]);
989 * If the client corresponding to the
990 * prefix is not found. We must ignore it,
991 * it is simply a lagged message travelling
992 * upstream a SQUIT that removed the client
997 Debug((DEBUG_NOTICE, "Unknown prefix (%s)(%s) from (%s)",
998 para[0], buffer, cli_name(cptr)));
999 ++ServerStats->is_unpf;
1003 * However, the only thing that MUST be
1004 * allowed to travel upstream against an
1005 * squit, is an SQUIT itself (the timestamp
1006 * protects us from being used wrong)
1010 para[0] = cli_name(cptr);
1016 else if (cli_from(from) != cptr)
1018 ++ServerStats->is_wrdi;
1019 Debug((DEBUG_NOTICE, "Fake direction: Message (%s) coming from (%s)",
1020 buffer, cli_name(cptr)));
1025 char numeric_prefix[6];
1027 for (i = 0; i < 5; ++i) {
1028 if ('\0' == ch[i] || ' ' == (numeric_prefix[i] = ch[i])) {
1032 numeric_prefix[i] = '\0';
1035 * We got a numeric nick as prefix
1036 * 1 or 2 character prefixes are from servers
1037 * 3 or 5 chars are from clients
1040 protocol_violation(cptr,"Missing Prefix");
1043 else if (' ' == ch[1] || ' ' == ch[2])
1044 from = FindNServer(numeric_prefix);
1046 from = findNUser(numeric_prefix);
1052 while (*ch != ' ' && *ch);
1055 * If the client corresponding to the
1056 * prefix is not found. We must ignore it,
1057 * it is simply a lagged message travelling
1058 * upstream a SQUIT that removed the client
1060 * There turned out to be other reasons that
1061 * a prefix is unknown, needing an upstream
1062 * KILL. Also, next to an SQUIT we better
1063 * allow a KILL to pass too.
1068 ServerStats->is_unpf++;
1071 if (*ch == 'N' && (ch[1] == ' ' || ch[1] == 'I'))
1072 /* Only sent a KILL for a nick change */
1074 struct Client *server;
1075 /* Kill the unknown numeric prefix upstream if
1076 * it's server still exists: */
1077 if ((server = FindNServer(numeric_prefix)) && cli_from(server) == cptr)
1078 sendcmdto_one(&me, CMD_KILL, cptr, "%s :%s (Unknown numeric nick)",
1079 numeric_prefix, cli_name(&me));
1082 * Things that must be allowed to travel
1083 * upstream against an squit:
1085 if (ch[1] == 'Q' || (*ch == 'D' && ch[1] == ' ') ||
1086 (*ch == 'K' && ch[2] == 'L'))
1092 /* Let para[0] point to the name of the sender */
1093 para[0] = cli_name(from);
1095 if (cli_from(from) != cptr)
1097 ServerStats->is_wrdi++;
1098 Debug((DEBUG_NOTICE, "Fake direction: Message (%s) coming from (%s)",
1099 buffer, cli_name(cptr)));
1108 ServerStats->is_empt++;
1109 Debug((DEBUG_NOTICE, "Empty message from host %s:%s",
1110 cli_name(cptr), cli_name(from)));
1115 * Extract the command code from the packet. Point s to the end
1116 * of the command code and calculate the length using pointer
1117 * arithmetic. Note: only need length for numerics and *all*
1118 * numerics must have parameters and thus a space after the command
1121 s = strchr(ch, ' '); /* s -> End of the command code */
1122 len = (s) ? (s - ch) : 0;
1123 if (len == 3 && IsDigit(*ch))
1125 numeric = (*ch - '0') * 100 + (*(ch + 1) - '0') * 10 + (*(ch + 2) - '0');
1126 paramcount = 2; /* destination, and the rest of it */
1127 ServerStats->is_num++;
1128 mptr = NULL; /* Init. to avoid stupid compiler warning :/ */
1135 /* Version Receive Send
1137 * 2.10.0 Tkn/Long Long
1138 * 2.10.10 Tkn/Long Tkn
1141 * Clients/unreg servers always receive/
1142 * send long commands -record
1146 * This is a server. Check the token command list.
1147 * -record!jegelhof@cloud9.net
1149 mptr = msg_tree_parse(ch, &msg_tree_tok);
1151 #if 1 /* for 2.10.0/2.10.10 */
1153 * This code supports 2.9 and 2.10.0 sending long commands.
1154 * It makes more calls to ircd_strcmp() than the above
1155 * so it will be somewhat slower.
1158 mptr = msg_tree_parse(ch, &msg_tree_cmd);
1164 * Note: Give error message *only* to recognized
1165 * persons. It's a nightmare situation to have
1166 * two programs sending "Unknown command"'s or
1167 * equivalent to each other at full blast....
1168 * If it has got to person state, it at least
1169 * seems to be well behaving. Perhaps this message
1170 * should never be generated, though... --msa
1171 * Hm, when is the buffer empty -- if a command
1172 * code has been found ?? -Armin
1175 if (buffer[0] != '\0')
1177 Debug((DEBUG_ERROR, "Unknown (%s) from %s",
1178 ch, get_client_name(cptr, HIDE_IP)));
1181 ServerStats->is_unco++;
1185 paramcount = mptr->parameters;
1186 i = bufend - ((s) ? s : ch);
1190 * Must the following loop really be so devious? On
1191 * surface it splits the message to parameters from
1192 * blank spaces. But, if paramcount has been reached,
1193 * the rest of the message goes into this last parameter
1194 * (about same effect as ":" has...) --msa
1197 /* Note initially true: s==NULL || *(s-1) == '\0' !! */
1202 if (paramcount > MAXPARA)
1203 paramcount = MAXPARA;
1207 * Never "FRANCE " again!! ;-) Clean
1208 * out *all* blanks.. --msa
1218 * The rest is single parameter--can
1219 * include blanks also.
1222 para[++i] = s; /* preserve the colon to make do_numeric happy */
1228 if (i >= paramcount)
1230 for (; *s != ' ' && *s; s++);
1235 return (do_numeric(numeric, (*buffer != ':'), cptr, from, i, para));
1238 return (*mptr->handlers[cli_handler(cptr)]) (cptr, from, i, para);