return 1;
}
+int connect_dopacket(struct Client *cptr, const char *buffer, int length)
+{
+ const char* src;
+ char* endp;
+ char* client_buffer;
+
+ assert(0 != cptr);
+
+ update_bytes_received(cptr, length);
+
+ client_buffer = cli_buffer(cptr);
+ endp = client_buffer + cli_count(cptr);
+ src = buffer;
+
+ while (length-- > 0)
+ {
+ *endp = *src++;
+ /*
+ * Yuck. Stuck. To make sure we stay backward compatible,
+ * we must assume that either CR or LF terminates the message
+ * and not CR-LF. By allowing CR or LF (alone) into the body
+ * of messages, backward compatibility is lost and major
+ * problems will arise. - Avalon
+ */
+ if (IsEol(*endp))
+ {
+ /* Skip extra LF/CR's */
+ if (endp == client_buffer)
+ continue;
+ *endp = '\0';
+
+ update_messages_received(cptr);
+
+ if (parse_client(cptr, cli_buffer(cptr), endp) == CPTR_KILLED)
+ return CPTR_KILLED;
+ /* Socket is dead so exit */
+ if (IsDead(cptr))
+ return exit_client(cptr, cptr, &me, cli_info(cptr));
+ endp = client_buffer;
+ }
+ else if (endp < client_buffer + BUFSIZE)
+ /* There is always room for the null */
+ ++endp;
+ }
+ cli_count(cptr) = endp - cli_buffer(cptr);
+ return 1;
+}
+
/*
* client_dopacket - handle client messages
*/
* For server connections, we process as many as we can without
* worrying about the time of day or anything :)
*/
- if (length > 0 &&
- (IsServer(cptr) || IsHandshake(cptr) || IsConnecting(cptr))) {
+ if (length <= 0)
+ ;
+ else if (IsServer(cptr))
+ {
return server_dopacket(cptr, readbuf, length);
}
- else {
+ else if (IsHandshake(cptr) || IsConnecting(cptr))
+ return connect_dopacket(cptr, readbuf, length);
+ else
+ {
/*
* Before we even think of parsing what we just read, stick
* it on the end of the receive queue and do it when its
* turn comes around.
*/
- if (length > 0 && 0 == dbuf_put(&(cli_recvQ(cptr)), readbuf, length)) {
+ if (dbuf_put(&(cli_recvQ(cptr)), readbuf, length) == 0)
return exit_client(cptr, cptr, &me, "dbuf_put fail");
- }
-
- if (DBufLength(&(cli_recvQ(cptr))) > feature_int(FEAT_CLIENT_FLOOD))
+ else if (DBufLength(&(cli_recvQ(cptr))) > feature_int(FEAT_CLIENT_FLOOD))
return exit_client(cptr, cptr, &me, "Excess Flood");
while (DBufLength(&(cli_recvQ(cptr))) && !NoNewLine(cptr) &&
* If it has become registered as a Server
* then skip the per-message parsing below.
*/
- if (IsServer(cptr)) {
- dolen = dbuf_get(&(cli_recvQ(cptr)), readbuf, sizeof(readbuf));
- return (dolen) ? server_dopacket(cptr, readbuf, dolen) : 1;
+ if (IsHandshake(cptr) || IsServer(cptr))
+ {
+ int ret;
+ while (-1)
+ {
+ dolen = dbuf_get(&(cli_recvQ(cptr)), readbuf, sizeof(readbuf));
+ if (dolen <= 0)
+ return 1;
+ ret = IsServer(cptr) ? server_dopacket(cptr, readbuf, dolen) :
+ connect_dopacket(cptr, readbuf, dolen);
+ if (ret != 1)
+ return ret;
+ }
}
dolen = dbuf_getmsg(&(cli_recvQ(cptr)), cli_buffer(cptr), BUFSIZE);
/*
* deletes the rest of the buffer contents.
* -avalon
*/
- if (0 == dolen) {
+ if (dolen = 0)
+ {
if (DBufLength(&(cli_recvQ(cptr))) < 510)
cli_flags(cptr) |= FLAGS_NONL;
else
DBufClear(&(cli_recvQ(cptr)));
}
- else if (CPTR_KILLED == client_dopacket(cptr, dolen))
+ else if (client_dopacket(cptr, dolen) == CPTR_KILLED)
return CPTR_KILLED;
}
/* If there's still data to process, wait 2 seconds first */
if (DBufLength(&(cli_recvQ(cptr))) && !NoNewLine(cptr) &&
- !t_onqueue(&(cli_proc(cptr)))) {
+ !t_onqueue(&(cli_proc(cptr))))
+ {
Debug((DEBUG_LIST, "Adding client process timer for %C", cptr));
cli_freeflag(cptr) |= FREEFLAG_TIMER;
timer_add(&(cli_proc(cptr)), client_timer_callback, cli_connect(cptr),