+ }
+
+ oldlen = cl->buflen;
+ cl->buflen += lenin;
+
+ for(;;)
+ {
+ cl->reqlen = 0;
+
+ for(i = oldlen; i < cl->buflen; i++)
+ {
+ if(cl->buffer[i] == '\n')
+ {
+ cl->buffer[i] = 0; /* replace end-of-line by end-of-string so we can use sscanf */
+ cl->reqlen = i + 1;
+ break;
+ }
+ }
+
+ if(cl->reqlen)
+ {
+ if(sscanf(cl->buffer, "%d", &request) == 1)
+ {
+ if((request < 0) || (request > 255) || (request_handlers[request] == NULL))
+ {
+ syslog(LOG_ERR, _("Unknown request: %s"), cl->buffer);
+ return -1;
+ }
+
+ if(debug_lvl > 3)
+ syslog(LOG_DEBUG, _("Got request: %s"), cl->buffer);
+
+ if(request_handlers[request](cl)) /* Something went wrong. Probably scriptkiddies. Terminate. */
+ {
+ syslog(LOG_ERR, _("Error while processing request from " IP_ADDR_S), IP_ADDR_V(cl->real_ip));
+ return -1;
+ }
+ }
+ else
+ {
+ syslog(LOG_ERR, _("Bogus data received."));
+ return -1;
+ }
+
+ cl->buflen -= cl->reqlen;
+ memmove(cl->buffer, cl->buffer + cl->reqlen, cl->buflen);
+ oldlen = 0;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ cl->last_ping_time = time(NULL);
+ cl->want_ping = 0;