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.
29 #include "ircd_alloc.h"
30 #include "ircd_chattr.h"
31 #include "ircd_features.h"
32 #include "ircd_policy.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_cprivmsg, m_ignore, m_cprivmsg, m_ignore }
105 0, MAXPARA, MFLG_SLOW, 0,
106 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
107 { m_unregistered, m_cnotice, m_ignore, m_cnotice, m_ignore }
112 0, MAXPARA, MFLG_SLOW, 0,
113 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
114 { m_unregistered, m_join, ms_join, m_join, m_ignore }
119 0, MAXPARA, MFLG_SLOW, 0,
120 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
121 { m_unregistered, m_mode, ms_mode, m_mode, m_ignore }
126 0, MAXPARA, MFLG_SLOW, 0,
127 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
128 { m_ignore, m_ignore, ms_burst, m_ignore, m_ignore }
133 0, MAXPARA, MFLG_SLOW, 0,
134 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
135 { m_ignore, m_ignore, ms_create, m_ignore, m_ignore }
140 0, MAXPARA, MFLG_SLOW, 0,
141 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
142 { m_ignore, m_ignore, ms_destruct, m_ignore, m_ignore }
147 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
148 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
149 { m_quit, m_quit, ms_quit, m_quit, m_ignore }
154 0, MAXPARA, MFLG_SLOW, 0,
155 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
156 { m_unregistered, m_part, ms_part, m_part, m_ignore }
161 0, MAXPARA, MFLG_SLOW, 0,
162 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
163 { m_unregistered, m_topic, ms_topic, m_topic, m_ignore }
168 0, MAXPARA, MFLG_SLOW, 0,
169 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
170 { m_unregistered, m_invite, ms_invite, m_invite, m_ignore }
175 0, MAXPARA, MFLG_SLOW, 0,
176 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
177 { m_unregistered, m_kick, ms_kick, m_kick, m_ignore }
182 0, MAXPARA, MFLG_SLOW, 0,
183 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
184 { m_unregistered, m_not_oper, ms_wallops, mo_wallops, m_ignore }
189 0, MAXPARA, MFLG_SLOW, 0,
190 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
191 { m_unregistered, m_not_oper, ms_wallusers, mo_wallusers, m_ignore }
196 0, MAXPARA, MFLG_SLOW, 0,
197 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
198 { m_ignore, m_ignore, ms_desynch, m_ignore, m_ignore }
203 0, MAXPARA, MFLG_SLOW, 0,
204 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
205 { m_unregistered, m_ping, ms_ping, m_ping, m_ignore }
210 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
211 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
212 { mr_pong, m_pong, ms_pong, m_pong, m_ignore }
217 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
218 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
219 { m_ignore, m_ignore, ms_error, m_ignore, m_ignore }
224 0, MAXPARA, MFLG_SLOW, 0,
225 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
226 { m_unregistered, m_not_oper, ms_kill, mo_kill, m_ignore }
231 0, MAXPARA, MFLG_SLOW, 0,
232 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
233 { m_user, m_registered, m_ignore, m_registered, m_ignore }
238 0, MAXPARA, MFLG_SLOW, 0,
239 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
240 { m_unregistered, m_away, ms_away, m_away, m_ignore }
246 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
247 { m_unregistered, m_ison, m_ignore, m_ison, m_ignore }
252 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
253 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
254 { mr_server, m_registered, ms_server, m_registered, m_ignore }
259 0, MAXPARA, MFLG_SLOW, 0,
260 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
261 { m_unregistered, m_not_oper, ms_squit, mo_squit, m_ignore }
266 0, MAXPARA, MFLG_SLOW, 0,
267 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
268 { m_unregistered, m_whois, m_whois, m_whois, m_ignore }
273 0, MAXPARA, MFLG_SLOW, 0,
274 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
275 { m_unregistered, m_who, m_ignore, m_who, m_ignore }
280 0, MAXPARA, MFLG_SLOW, 0,
281 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
282 { m_unregistered, m_whowas, m_whowas, m_whowas, m_ignore }
287 0, MAXPARA, MFLG_SLOW, 0,
288 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
289 { m_unregistered, m_list, m_ignore, m_list, m_ignore }
294 0, MAXPARA, MFLG_SLOW, 0,
295 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
296 { m_unregistered, m_names, ms_names, m_names, m_ignore }
302 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
303 { m_unregistered, m_userhost, m_ignore, m_userhost, m_ignore }
309 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
310 { m_unregistered, m_userip, m_ignore, m_userip, m_ignore }
315 0, MAXPARA, MFLG_SLOW, 0,
316 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
317 #ifdef HEAD_IN_SAND_TRACE
318 { m_unregistered, m_not_oper, ms_trace, mo_trace, m_ignore }
320 { m_unregistered, m_trace, ms_trace, mo_trace, m_ignore }
326 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
327 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
328 { mr_pass, m_registered, m_ignore, m_registered, m_ignore }
333 0, MAXPARA, MFLG_SLOW, 0,
334 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
335 { m_unregistered, m_lusers, ms_lusers, m_lusers, m_ignore }
340 0, MAXPARA, MFLG_SLOW, 0,
341 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
342 { m_unregistered, m_time, m_time, m_time, m_ignore }
347 0, MAXPARA, MFLG_SLOW, 0,
348 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
349 { m_unregistered, m_ignore, ms_settime, mo_settime, m_ignore }
354 0, MAXPARA, MFLG_SLOW, 0,
355 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
356 { m_unregistered, m_not_oper, ms_rping, mo_rping, m_ignore }
361 0, MAXPARA, MFLG_SLOW, 0,
362 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
363 { m_unregistered, m_ignore, ms_rpong, m_ignore, m_ignore }
368 0, MAXPARA, MFLG_SLOW, 0,
369 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
370 { m_unregistered, m_oper, ms_oper, mo_oper, m_ignore }
375 0, MAXPARA, MFLG_SLOW, 0,
376 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
377 { m_unregistered, m_not_oper, ms_connect, mo_connect, m_ignore }
382 0, MAXPARA, MFLG_SLOW, 0,
383 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
384 #ifdef HEAD_IN_SAND_MAP
385 { m_unregistered, m_map_redirect, m_ignore, m_map, m_ignore }
387 { m_unregistered, m_map, m_ignore, m_map, m_ignore }
393 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
394 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
395 { m_version, m_version, ms_version, m_version, m_ignore }
400 0, MAXPARA, MFLG_SLOW, 0,
401 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
402 { m_unregistered, m_stats, ms_stats, mo_stats, m_ignore }
407 0, MAXPARA, MFLG_SLOW, 0,
408 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
409 #ifdef HEAD_IN_SAND_LINKS
410 { m_unregistered, m_links_redirect, ms_links, m_links, m_ignore }
412 { m_unregistered, m_links, ms_links, m_links, m_ignore }
418 0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
419 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
420 { m_admin, m_admin, ms_admin, m_admin, m_ignore }
425 0, MAXPARA, MFLG_SLOW, 0,
426 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
427 { m_unregistered, m_help, m_ignore, m_help, m_ignore }
432 0, MAXPARA, MFLG_SLOW, 0,
433 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
434 { m_unregistered, m_info, ms_info, mo_info, m_ignore }
439 0, MAXPARA, MFLG_SLOW, 0,
440 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
441 { m_unregistered, m_motd, m_motd, m_motd, m_ignore }
446 0, MAXPARA, MFLG_SLOW, 0,
447 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
448 { m_unregistered, m_not_oper, m_ignore, mo_close, m_ignore }
453 0, MAXPARA, MFLG_SLOW, 0,
454 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
455 { m_unregistered, m_silence, ms_silence, m_silence, m_ignore }
460 0, MAXPARA, MFLG_SLOW, 0,
461 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
462 { m_unregistered, m_gline, ms_gline, mo_gline, m_ignore }
467 0, MAXPARA, MFLG_SLOW, 0,
468 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
469 { m_unregistered, m_jupe, ms_jupe, mo_jupe, m_ignore }
474 0, MAXPARA, MFLG_SLOW, 0,
475 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
476 { m_unregistered, m_not_oper, ms_opmode, mo_opmode, m_ignore }
481 0, MAXPARA, MFLG_SLOW, 0,
482 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
483 { m_unregistered, m_not_oper, ms_clearmode, mo_clearmode, m_ignore }
488 0, MAXPARA, MFLG_SLOW, 0,
489 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
490 { m_unregistered, m_not_oper, ms_uping, mo_uping, m_ignore }
495 0, MAXPARA, MFLG_SLOW, 0,
496 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
497 { m_ignore, m_ignore, ms_end_of_burst, m_ignore, m_ignore }
500 MSG_END_OF_BURST_ACK,
501 TOK_END_OF_BURST_ACK,
503 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
504 { m_ignore, m_ignore, ms_end_of_burst_ack, m_ignore, m_ignore }
509 0, MAXPARA, MFLG_SLOW, 0,
510 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
511 { m_unregistered, m_hash, m_hash, m_hash, m_ignore }
516 0, MAXPARA, MFLG_SLOW, 0,
517 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
518 { m_unregistered, m_dns, m_dns, m_dns, m_ignore }
523 0, MAXPARA, MFLG_SLOW, 0,
524 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
525 { m_unregistered, m_not_oper, m_ignore, mo_rehash, m_ignore }
530 0, MAXPARA, MFLG_SLOW, 0,
531 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
532 { m_unregistered, m_not_oper, m_ignore, mo_restart, m_ignore }
537 0, MAXPARA, MFLG_SLOW, 0,
538 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
539 { m_unregistered, m_not_oper, m_ignore, mo_die, m_ignore }
544 0, MAXPARA, MFLG_SLOW, 0,
545 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
546 { m_proto, m_proto, m_proto, m_proto, m_ignore }
551 0, MAXPARA, MFLG_SLOW, 0,
552 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
553 { m_unregistered, m_not_oper, m_ignore, mo_set, m_ignore }
558 0, MAXPARA, MFLG_SLOW, 0,
559 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
560 { m_unregistered, m_not_oper, m_ignore, mo_reset, m_ignore }
565 0, MAXPARA, MFLG_SLOW, 0,
566 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
567 { m_unregistered, m_not_oper, m_ignore, mo_get, m_ignore }
572 0, MAXPARA, MFLG_SLOW, 0,
573 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
574 { m_unregistered, m_not_oper, m_ignore, mo_privs, m_ignore }
576 /* This command is an alias for QUIT during the unregistered part of
577 * of the server. This is because someone jumping via a broken web
578 * proxy will send a 'POST' as their first command - which we will
579 * obviously disconnect them immediately for, stopping people abusing
585 0, MAXPARA, MFLG_SLOW, 0,
586 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
587 { m_quit, m_ignore, m_ignore, m_ignore, m_ignore }
593 static char *para[MAXPARA + 2]; /* leave room for prefix and null */
596 * Message Tree stuff mostly written by orabidoo, with changes by Dianora.
597 * Adapted to Undernet, adding token support, etc by comstud 10/06/97
600 static struct MessageTree msg_tree_cmd;
601 static struct MessageTree msg_tree_tok;
604 * Guts of making the token tree...
606 static struct Message **do_msg_tree_tok(struct MessageTree *mtree, char *prefix,
607 struct Message **mptr)
609 char newprefix[64]; /* Must be longer than every command name */
611 struct MessageTree *mtree1;
614 if (!lp || !strncmp((*mptr)->tok, prefix, lp))
616 if (!mptr[1] || (lp && strncmp(mptr[1]->tok, prefix, lp)))
618 /* last command in the message struct or last command in this prefix */
619 mtree->final = (*mptr)->tok + lp;
621 for (c = 0; c < 26; ++c)
622 mtree->pointers[c] = NULL;
625 /* command in this prefix */
626 if (0 == ircd_strcmp((*mptr)->tok, prefix))
629 mtree->msg = *mptr++;
634 for (c = 'A'; c <= 'Z'; ++c)
636 if ((*mptr)->tok[lp] == c)
638 mtree1 = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
639 mtree1->final = NULL;
640 mtree->pointers[c - 'A'] = mtree1;
641 strcpy(newprefix, prefix);
643 newprefix[lp + 1] = '\0';
644 mptr = do_msg_tree_tok(mtree1, newprefix, mptr);
645 if (!*mptr || strncmp((*mptr)->tok, prefix, lp))
647 for (c2 = c + 1 - 'A'; c2 < 26; ++c2)
648 mtree->pointers[c2] = NULL;
653 mtree->pointers[c - 'A'] = NULL;
658 * XXX - should never be here, quick hack, this can be done better
665 * Guts of making the command tree...
667 static struct Message *do_msg_tree_cmd(struct MessageTree *mtree, char *prefix,
668 struct Message *mptr)
670 char newprefix[64]; /* Must be longer than every command name */
672 struct MessageTree *mtree1;
675 if (!lp || !strncmp(mptr->cmd, prefix, lp))
677 if (!mptr[1].cmd || (lp && strncmp(mptr[1].cmd, prefix, lp)))
679 /* last command in the message struct or last command in this prefix */
680 mtree->final = mptr->cmd + lp;
682 for (c = 0; c < 26; ++c)
683 mtree->pointers[c] = NULL;
686 /* command in this prefix */
687 if (0 == ircd_strcmp(mptr->cmd, prefix))
695 for (c = 'A'; c <= 'Z'; ++c)
697 if (mptr->cmd[lp] == c)
699 mtree1 = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
700 mtree1->final = NULL;
701 mtree->pointers[c - 'A'] = mtree1;
702 strcpy(newprefix, prefix);
704 newprefix[lp + 1] = '\0';
705 mptr = do_msg_tree_cmd(mtree1, newprefix, mptr);
706 if (!mptr->cmd || strncmp(mptr->cmd, prefix, lp))
708 for (c2 = c + 1 - 'A'; c2 < 26; ++c2)
709 mtree->pointers[c2] = NULL;
714 mtree->pointers[c - 'A'] = NULL;
719 * This should never happen
725 static int mcmdcmp(const struct Message *m1, const struct Message *m2)
727 return strcmp(m1->cmd, m2->cmd);
730 static int mtokcmp(const struct Message **m1, const struct Message **m2)
732 return strcmp((*m1)->tok, (*m2)->tok);
736 * Sort the command names.
737 * Create table of pointers into msgtab for tokens.
738 * Create trees for ->cmd and ->tok and free the token pointers.
740 void initmsgtree(void)
743 struct Message *msg = msgtab;
745 struct Message **msgtab_tok;
746 struct Message **msgtok;
748 for (i = 0; msg->cmd; ++i, ++msg)
750 qsort(msgtab, i, sizeof(struct Message),
751 (int (*)(const void *, const void *))mcmdcmp);
752 msgtab_tok = (struct Message **)MyMalloc((i + 1) * sizeof(struct Message *));
753 for (ii = 0; ii < i; ++ii)
754 msgtab_tok[ii] = msgtab + ii;
755 msgtab_tok[i] = NULL; /* Needed by `do_msg_tree_tok' */
756 qsort(msgtab_tok, i, sizeof(struct Message *),
757 (int (*)(const void *, const void *))mtokcmp);
758 msg = do_msg_tree_cmd(&msg_tree_cmd, "", msgtab);
759 msgtok = do_msg_tree_tok(&msg_tree_tok, "", msgtab_tok);
764 * Generic tree parser which works for both commands and tokens.
767 static struct Message *msg_tree_parse(char *cmd, struct MessageTree *root)
769 struct MessageTree *mtree;
770 unsigned char r = (0xdf & (unsigned char)*cmd) - 'A';
771 if (r > 25 || !(mtree = root->pointers[r]))
775 r = 0xdf & (unsigned char)*++cmd;
776 if (mtree->final && *mtree->final == r)
778 if ((r -= 'A') > 25 || !(mtree = mtree->pointers[r]))
784 * This one is identical to the one above, but it is slower because it
785 * makes sure that `cmd' matches the _full_ command, exactly.
786 * This is to avoid confusion with commands like /quake on clients
787 * that send unknown commands directly to the server.
789 static struct Message *msg_tree_parse_client(char *cmd,
790 struct MessageTree *root)
792 struct MessageTree *mtree;
793 unsigned char q = (0xdf & (unsigned char)*cmd) - 'A';
794 if (q > 25 || !(mtree = root->pointers[q]))
798 q = 0xdf & (unsigned char)*++cmd;
799 if (mtree->final && 0 == ircd_strcmp(mtree->final, cmd))
801 if ((q -= 'A') > 25 || !(mtree = mtree->pointers[q]))
809 * NOTE: parse_*() should not be called recusively by any other fucntions!
811 int parse_client(struct Client *cptr, char *buffer, char *bufend)
813 struct Client* from = cptr;
819 struct Message* mptr;
820 MessageHandler handler = 0;
822 Debug((DEBUG_DEBUG, "Client Parsing: %s", buffer));
827 para[0] = cli_name(from);
828 for (ch = buffer; *ch == ' '; ch++); /* Eat leading spaces */
829 if (*ch == ':') /* Is any client doing this ? */
831 for (++ch; *ch && *ch != ' '; ++ch)
832 ; /* Ignore sender prefix from client */
834 ch++; /* Advance to command */
840 ServerStats->is_empt++;
841 Debug((DEBUG_NOTICE, "Empty message from host %s:%s",
842 cli_name(cptr), cli_name(from)));
846 if ((s = strchr(ch, ' ')))
850 * This is a client/unregistered entity.
851 * Check long command list only.
853 if (!(mptr = msg_tree_parse_client(ch, &msg_tree_cmd)))
856 * Note: Give error message *only* to recognized
857 * persons. It's a nightmare situation to have
858 * two programs sending "Unknown command"'s or
859 * equivalent to each other at full blast....
860 * If it has got to person state, it at least
861 * seems to be well behaving. Perhaps this message
862 * should never be generated, though... --msa
863 * Hm, when is the buffer empty -- if a command
864 * code has been found ?? -Armin
866 if (buffer[0] != '\0')
869 send_reply(from, ERR_UNKNOWNCOMMAND, ch);
870 Debug((DEBUG_ERROR, "Unknown (%s) from %s",
871 ch, get_client_name(cptr, HIDE_IP)));
873 ServerStats->is_unco++;
877 paramcount = mptr->parameters;
878 i = bufend - ((s) ? s : ch);
880 if ((mptr->flags & MFLG_SLOW))
881 cli_since(cptr) += (2 + i / 120);
883 * Allow only 1 msg per 2 seconds
884 * (on average) to prevent dumping.
885 * to keep the response rate up,
886 * bursts of up to 5 msgs are allowed
891 * Must the following loop really be so devious? On
892 * surface it splits the message to parameters from
893 * blank spaces. But, if paramcount has been reached,
894 * the rest of the message goes into this last parameter
895 * (about same effect as ":" has...) --msa
898 /* Note initially true: s==NULL || *(s-1) == '\0' !! */
903 if (paramcount > MAXPARA)
904 paramcount = MAXPARA;
908 * Never "FRANCE " again!! ;-) Clean
909 * out *all* blanks.. --msa
919 * The rest is single parameter--can
920 * include blanks also.
928 for (; *s != ' ' && *s; s++);
934 handler = mptr->handlers[cli_handler(cptr)];
935 assert(0 != handler);
937 if (!feature_bool(FEAT_IDLE_FROM_MSG) && IsUser(cptr) &&
938 handler != m_ping && handler != m_ignore)
939 cli_user(from)->last = CurrentTime;
941 return (*handler) (cptr, from, i, para);
944 int parse_server(struct Client *cptr, char *buffer, char *bufend)
946 struct Client* from = cptr;
953 struct Message* mptr;
955 Debug((DEBUG_DEBUG, "Server Parsing: %s", buffer));
960 para[0] = cli_name(from);
963 * A server ALWAYS sends a prefix. When it starts with a ':' it's the
964 * protocol 9 prefix: a nick or a server name. Otherwise it's a numeric
969 /* Let para[0] point to the name of the sender */
971 if (!(ch = strchr(ch, ' ')))
975 /* And let `from' point to its client structure,
976 opps.. a server is _also_ a client --Nem */
977 from = FindClient(para[0]);
980 * If the client corresponding to the
981 * prefix is not found. We must ignore it,
982 * it is simply a lagged message travelling
983 * upstream a SQUIT that removed the client
988 Debug((DEBUG_NOTICE, "Unknown prefix (%s)(%s) from (%s)",
989 para[0], buffer, cli_name(cptr)));
990 ++ServerStats->is_unpf;
994 * However, the only thing that MUST be
995 * allowed to travel upstream against an
996 * squit, is an SQUIT itself (the timestamp
997 * protects us from being used wrong)
1001 para[0] = cli_name(cptr);
1007 else if (cli_from(from) != cptr)
1009 ++ServerStats->is_wrdi;
1010 Debug((DEBUG_NOTICE, "Fake direction: Message (%s) coming from (%s)",
1011 buffer, cli_name(cptr)));
1016 char numeric_prefix[6];
1018 for (i = 0; i < 5; ++i) {
1019 if ('\0' == ch[i] || ' ' == (numeric_prefix[i] = ch[i])) {
1023 numeric_prefix[i] = '\0';
1026 * We got a numeric nick as prefix
1027 * 1 or 2 character prefixes are from servers
1028 * 3 or 5 chars are from clients
1031 protocol_violation(cptr,"Missing Prefix");
1034 else if (' ' == ch[1] || ' ' == ch[2])
1035 from = FindNServer(numeric_prefix);
1037 from = findNUser(numeric_prefix);
1043 while (*ch != ' ' && *ch);
1046 * If the client corresponding to the
1047 * prefix is not found. We must ignore it,
1048 * it is simply a lagged message travelling
1049 * upstream a SQUIT that removed the client
1051 * There turned out to be other reasons that
1052 * a prefix is unknown, needing an upstream
1053 * KILL. Also, next to an SQUIT we better
1054 * allow a KILL to pass too.
1059 ServerStats->is_unpf++;
1062 if (*ch == 'N' && (ch[1] == ' ' || ch[1] == 'I'))
1063 /* Only sent a KILL for a nick change */
1065 struct Client *server;
1066 /* Kill the unknown numeric prefix upstream if
1067 * it's server still exists: */
1068 if ((server = FindNServer(numeric_prefix)) && cli_from(server) == cptr)
1069 sendcmdto_one(&me, CMD_KILL, cptr, "%s :%s (Unknown numeric nick)",
1070 numeric_prefix, cli_name(&me));
1073 * Things that must be allowed to travel
1074 * upstream against an squit:
1076 if (ch[1] == 'Q' || (*ch == 'D' && ch[1] == ' ') ||
1077 (*ch == 'K' && ch[2] == 'L'))
1083 /* Let para[0] point to the name of the sender */
1084 para[0] = cli_name(from);
1086 if (cli_from(from) != cptr)
1088 ServerStats->is_wrdi++;
1089 Debug((DEBUG_NOTICE, "Fake direction: Message (%s) coming from (%s)",
1090 buffer, cli_name(cptr)));
1099 ServerStats->is_empt++;
1100 Debug((DEBUG_NOTICE, "Empty message from host %s:%s",
1101 cli_name(cptr), cli_name(from)));
1106 * Extract the command code from the packet. Point s to the end
1107 * of the command code and calculate the length using pointer
1108 * arithmetic. Note: only need length for numerics and *all*
1109 * numerics must have parameters and thus a space after the command
1112 s = strchr(ch, ' '); /* s -> End of the command code */
1113 len = (s) ? (s - ch) : 0;
1114 if (len == 3 && IsDigit(*ch))
1116 numeric = (*ch - '0') * 100 + (*(ch + 1) - '0') * 10 + (*(ch + 2) - '0');
1117 paramcount = 2; /* destination, and the rest of it */
1118 ServerStats->is_num++;
1119 mptr = NULL; /* Init. to avoid stupid compiler warning :/ */
1126 /* Version Receive Send
1128 * 2.10.0 Tkn/Long Long
1129 * 2.10.10 Tkn/Long Tkn
1132 * Clients/unreg servers always receive/
1133 * send long commands -record
1137 * This is a server. Check the token command list.
1138 * -record!jegelhof@cloud9.net
1140 mptr = msg_tree_parse(ch, &msg_tree_tok);
1142 #if 1 /* for 2.10.0/2.10.10 */
1144 * This code supports 2.9 and 2.10.0 sending long commands.
1145 * It makes more calls to ircd_strcmp() than the above
1146 * so it will be somewhat slower.
1149 mptr = msg_tree_parse(ch, &msg_tree_cmd);
1155 * Note: Give error message *only* to recognized
1156 * persons. It's a nightmare situation to have
1157 * two programs sending "Unknown command"'s or
1158 * equivalent to each other at full blast....
1159 * If it has got to person state, it at least
1160 * seems to be well behaving. Perhaps this message
1161 * should never be generated, though... --msa
1162 * Hm, when is the buffer empty -- if a command
1163 * code has been found ?? -Armin
1166 if (buffer[0] != '\0')
1168 Debug((DEBUG_ERROR, "Unknown (%s) from %s",
1169 ch, get_client_name(cptr, HIDE_IP)));
1172 ServerStats->is_unco++;
1176 paramcount = mptr->parameters;
1177 i = bufend - ((s) ? s : ch);
1181 * Must the following loop really be so devious? On
1182 * surface it splits the message to parameters from
1183 * blank spaces. But, if paramcount has been reached,
1184 * the rest of the message goes into this last parameter
1185 * (about same effect as ":" has...) --msa
1188 /* Note initially true: s==NULL || *(s-1) == '\0' !! */
1193 if (paramcount > MAXPARA)
1194 paramcount = MAXPARA;
1198 * Never "FRANCE " again!! ;-) Clean
1199 * out *all* blanks.. --msa
1209 * The rest is single parameter--can
1210 * include blanks also.
1213 para[++i] = s; /* preserve the colon to make do_numeric happy */
1219 if (i >= paramcount)
1221 for (; *s != ' ' && *s; s++);
1226 return (do_numeric(numeric, (*buffer != ':'), cptr, from, i, para));
1229 return (*mptr->handlers[cli_handler(cptr)]) (cptr, from, i, para);