X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fprotocol.c;h=1c5b6cfd9c1d43dba0c6a2e21defabdb4c431209;hb=19be9cf7150858311f7898fa3fb525d692d02f64;hp=8b62916b523505cebb6c4f10a06c0eef11bbfc8f;hpb=8ac096b5bf9da1b3961a3ac4a03d083629222a63;p=meshlink diff --git a/src/protocol.c b/src/protocol.c index 8b62916b..1c5b6cfd 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -1,7 +1,7 @@ /* protocol.c -- handle the meta-protocol, basic functions Copyright (C) 1999-2005 Ivo Timmermans, - 2000-2009 Guus Sliepen + 2000-2012 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,7 +34,7 @@ bool experimental = false; /* Jumptable for the request handlers */ -static bool (*request_handlers[])(connection_t *, char *) = { +static bool (*request_handlers[])(connection_t *, const char *) = { id_h, metakey_h, challenge_h, chal_reply_h, ack_h, status_h, error_h, termreq_h, ping_h, pong_h, @@ -96,16 +96,32 @@ bool send_request(connection_t *c, const char *format, ...) { return send_meta(c, request, len); } -void forward_request(connection_t *from, char *request) { - /* Note: request is not zero terminated anymore after a call to this function! */ +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); - request[len++] = '\n'; - broadcast_meta(from, request, len); + char tmp[len + 1]; + memcpy(tmp, request, len); + tmp[len] = '\n'; + broadcast_meta(from, tmp, sizeof tmp); } -bool receive_request(connection_t *c, char *request) { +bool receive_request(connection_t *c, const char *request) { + if(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') { @@ -141,14 +157,14 @@ static int past_request_compare(const past_request_t *a, const past_request_t *b static void free_past_request(past_request_t *r) { if(r->request) - free(r->request); + free((char *)r->request); free(r); } static struct event past_request_event; -bool seen_request(char *request) { +bool seen_request(const char *request) { past_request_t *new, p = {NULL}; p.request = request;