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.
27 #include "ircd_chattr.h"
35 static void update_bytes_received(struct Client* cptr, unsigned int length)
37 cli_receiveB(&me) += length; /* Update bytes received */
38 cli_receiveB(cptr) += length;
40 if (cli_receiveB(cptr) > 1023) {
41 cli_receiveK(cptr) += (cli_receiveB(cptr) >> 10);
42 cli_receiveB(cptr) &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
44 if (cli_receiveB(&me) > 1023) {
45 cli_receiveK(&me) += (cli_receiveB(&me) >> 10);
46 cli_receiveB(&me) &= 0x03ff;
50 static void update_messages_received(struct Client* cptr)
52 ++(cli_receiveM(&me));
53 ++(cli_receiveM(cptr));
59 * cptr - pointer to client structure for which the buffer data
61 * buffer - pointer to the buffer containing the newly read data
62 * length - number of valid bytes of data in the buffer
65 * It is implicitly assumed that dopacket is called only
66 * with cptr of "local" variation, which contains all the
67 * necessary fields (buffer etc..)
69 int server_dopacket(struct Client* cptr, const char* buffer, int length)
77 update_bytes_received(cptr, length);
79 client_buffer = cli_buffer(cptr);
80 endp = client_buffer + cli_count(cptr);
83 while (length-- > 0) {
86 * Yuck. Stuck. To make sure we stay backward compatible,
87 * we must assume that either CR or LF terminates the message
88 * and not CR-LF. By allowing CR or LF (alone) into the body
89 * of messages, backward compatibility is lost and major
90 * problems will arise. - Avalon
93 if (endp == client_buffer)
94 continue; /* Skip extra LF/CR's */
97 update_messages_received(cptr);
99 if (parse_server(cptr, cli_buffer(cptr), endp) == CPTR_KILLED)
102 * Socket is dead so exit
105 return exit_client(cptr, cptr, &me, cli_info(cptr));
106 endp = client_buffer;
108 else if (endp < client_buffer + BUFSIZE)
109 ++endp; /* There is always room for the null */
111 cli_count(cptr) = endp - cli_buffer(cptr);
116 * client_dopacket - handle client messages
118 int client_dopacket(struct Client *cptr, unsigned int length)
122 update_bytes_received(cptr, length);
123 update_messages_received(cptr);
125 if (CPTR_KILLED == parse_client(cptr, cli_buffer(cptr), cli_buffer(cptr) + length))
127 else if (IsDead(cptr))
128 return exit_client(cptr, cptr, &me, cli_info(cptr));