-int receive_request(connection_t *c)
-{
- int request;
-cp
- if(sscanf(c->buffer, "%d", &request) == 1)
- {
- if((request < 0) || (request >= LAST) || (request_handlers[request] == NULL))
- {
- if(debug_lvl >= DEBUG_META)
- syslog(LOG_DEBUG, _("Unknown request from %s (%s): %s"),
- c->name, c->hostname, c->buffer);
- else
- syslog(LOG_ERR, _("Unknown request from %s (%s)"),
- c->name, c->hostname);
-
- return -1;
- }
- else
- {
- if(debug_lvl >= DEBUG_PROTOCOL)
- {
- if(debug_lvl >= DEBUG_META)
- syslog(LOG_DEBUG, _("Got %s from %s (%s): %s"),
- request_name[request], c->name, c->hostname, c->buffer);
- else
- syslog(LOG_DEBUG, _("Got %s from %s (%s)"),
- request_name[request], c->name, c->hostname);
- }
+void forward_request(connection_t *from, const char *request) {
+ logger(DEBUG_META, LOG_DEBUG, "Forwarding %s from %s (%s): %s", request_name[atoi(request)], from->name, from->hostname, request);
+
+ // Create a temporary newline-terminated copy of the request
+ int len = strlen(request);
+ char tmp[len + 1];
+ memcpy(tmp, request, len);
+ tmp[len] = '\n';
+ broadcast_meta(from, tmp, sizeof(tmp));
+}
+
+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. */
+
+ if(reqno != TERMREQ) {
+ 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;