+bool receive_request(connection_t *c, const char *request) {
+ if(c->outgoing && proxytype == PROXY_HTTP && c->allow_request == ID) {
+ if(!request[0] || request[0] == '\r')
+ return true;
+ if(!strncasecmp(request, "HTTP/1.1 ", 9)) {
+ if(!strncmp(request + 9, "200", 3)) {
+ logger(DEBUG_CONNECTIONS, LOG_DEBUG, "Proxy request granted");
+ return true;
+ } else {
+ logger(DEBUG_ALWAYS, LOG_DEBUG, "Proxy request rejected: %s", request + 9);
+ return false;
+ }
+ }
+ }
+
+ int reqno = atoi(request);
+
+ if(reqno || *request == '0') {
+ if((reqno < 0) || (reqno >= LAST) || !request_handlers[reqno]) {
+ logger(DEBUG_META, LOG_DEBUG, "Unknown request from %s (%s): %s", c->name, c->hostname, request);
+ return false;
+ } else {
+ logger(DEBUG_META, LOG_DEBUG, "Got %s from %s (%s): %s", request_name[reqno], c->name, c->hostname, request);
+ }
+
+ if((c->allow_request != ALL) && (c->allow_request != reqno)) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Unauthorized request from %s (%s)", c->name, c->hostname);
+ return false;
+ }
+
+ if(!request_handlers[reqno](c, request)) {
+ /* Something went wrong. Probably scriptkiddies. Terminate. */
+
+ logger(DEBUG_ALWAYS, LOG_ERR, "Error while processing %s from %s (%s)", request_name[reqno], c->name, c->hostname);
+ return false;
+ }
+ } else {
+ logger(DEBUG_ALWAYS, LOG_ERR, "Bogus data received from %s (%s)", c->name, c->hostname);
+ return false;
+ }
+
+ return true;