2 * IRC - Internet Relay Chat, common/packet.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.
25 #include "ircd_chattr.h"
33 static void update_bytes_received(struct Client* cptr, unsigned int length)
35 cli_receiveB(&me) += length; /* Update bytes received */
36 cli_receiveB(cptr) += length;
38 if (cli_receiveB(cptr) > 1023) {
39 cli_receiveK(cptr) += (cli_receiveB(cptr) >> 10);
40 cli_receiveB(cptr) &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
42 if (cli_receiveB(&me) > 1023) {
43 cli_receiveK(&me) += (cli_receiveB(&me) >> 10);
44 cli_receiveB(&me) &= 0x03ff;
48 static void update_messages_received(struct Client* cptr)
50 ++(cli_receiveM(&me));
51 ++(cli_receiveM(cptr));
57 * cptr - pointer to client structure for which the buffer data
59 * buffer - pointer to the buffer containing the newly read data
60 * length - number of valid bytes of data in the buffer
63 * It is implicitly assumed that dopacket is called only
64 * with cptr of "local" variation, which contains all the
65 * necessary fields (buffer etc..)
67 int server_dopacket(struct Client* cptr, const char* buffer, int length)
75 update_bytes_received(cptr, length);
77 client_buffer = cli_buffer(cptr);
78 endp = client_buffer + cli_count(cptr);
81 while (length-- > 0) {
84 * Yuck. Stuck. To make sure we stay backward compatible,
85 * we must assume that either CR or LF terminates the message
86 * and not CR-LF. By allowing CR or LF (alone) into the body
87 * of messages, backward compatibility is lost and major
88 * problems will arise. - Avalon
91 if (endp == client_buffer)
92 continue; /* Skip extra LF/CR's */
95 update_messages_received(cptr);
97 if (parse_server(cptr, cli_buffer(cptr), endp) == CPTR_KILLED)
100 * Socket is dead so exit
103 return exit_client(cptr, cptr, &me, cli_info(cptr));
104 endp = client_buffer;
106 else if (endp < client_buffer + BUFSIZE)
107 ++endp; /* There is always room for the null */
109 cli_count(cptr) = endp - cli_buffer(cptr);
114 * client_dopacket - handle client messages
116 int client_dopacket(struct Client *cptr, unsigned int length)
120 update_bytes_received(cptr, length);
121 update_messages_received(cptr);
123 if (CPTR_KILLED == parse_client(cptr, cli_buffer(cptr), cli_buffer(cptr) + length))
125 else if (IsDead(cptr))
126 return exit_client(cptr, cptr, &me, cli_info(cptr));