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.
40 * cptr - pointer to client structure for which the buffer data
42 * buffer - pointer to the buffer containing the newly read data
43 * length - number of valid bytes of data in the buffer
46 * It is implicitly assumed that dopacket is called only
47 * with cptr of "local" variation, which contains all the
48 * necessary fields (buffer etc..)
50 int dopacket(aClient *cptr, char *buffer, int length)
54 register char *cptrbuf;
55 aClient *acpt = cptr->acpt;
57 cptrbuf = cptr->buffer;
58 me.receiveB += length; /* Update bytes received */
59 cptr->receiveB += length;
60 if (cptr->receiveB > 1023)
62 cptr->receiveK += (cptr->receiveB >> 10);
63 cptr->receiveB &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
67 acpt->receiveB += length;
68 if (acpt->receiveB > 1023)
70 acpt->receiveK += (acpt->receiveB >> 10);
71 acpt->receiveB &= 0x03ff;
74 else if (me.receiveB > 1023)
76 me.receiveK += (me.receiveB >> 10);
77 me.receiveB &= 0x03ff;
79 ch1 = cptrbuf + cptr->count;
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
92 if (g < '\16' && (g == '\n' || g == '\r'))
95 continue; /* Skip extra LF/CR's */
97 me.receiveM += 1; /* Update messages received */
99 if (cptr->acpt != &me)
100 cptr->acpt->receiveM += 1;
103 if (parse_server(cptr, cptr->buffer, ch1) == CPTR_KILLED)
106 else if (parse_client(cptr, cptr->buffer, ch1) == CPTR_KILLED)
109 * Socket is dead so exit
112 return exit_client(cptr, cptr, &me, LastDeadComment(cptr));
115 else if (ch1 < cptrbuf + (sizeof(cptr->buffer) - 1))
116 ch1++; /* There is always room for the null */
118 cptr->count = ch1 - cptr->buffer;
123 * client_dopacket - handle client messages
125 int client_dopacket(aClient *cptr, size_t length)
129 me.receiveB += length; /* Update bytes received */
130 cptr->receiveB += length;
132 if (cptr->receiveB > 1023)
134 cptr->receiveK += (cptr->receiveB >> 10);
135 cptr->receiveB &= 0x03ff; /* 2^10 = 1024, 3ff = 1023 */
137 if (me.receiveB > 1023)
139 me.receiveK += (me.receiveB >> 10);
140 me.receiveB &= 0x03ff;
144 ++me.receiveM; /* Update messages received */
147 if (CPTR_KILLED == parse_client(cptr, cptr->buffer, cptr->buffer + length))
149 else if (IsDead(cptr))
150 return exit_client(cptr, cptr, &me, LastDeadComment(cptr));