aboutsummaryrefslogtreecommitdiff
path: root/src/or/buffers.c
diff options
context:
space:
mode:
authorRavi Chandra Padmala <neenaoffline@gmail.com>2012-02-21 08:52:03 +0530
committerNick Mathewson <nickm@torproject.org>2017-06-21 10:34:26 -0400
commit417d778652770a8f4b0b6f8e5d8e139e193b8b1e (patch)
tree18b468cfcda2991224a463850becf2de6f0447a9 /src/or/buffers.c
parent884c0ffe3b4266e66adbd6bb914c3b3b00401acb (diff)
downloadtor-417d778652770a8f4b0b6f8e5d8e139e193b8b1e.tar.gz
tor-417d778652770a8f4b0b6f8e5d8e139e193b8b1e.zip
Respond meaningfully to HTTP requests on the control port. Fix #1667
(Squashed with bufferevents portions removed, by nickm)
Diffstat (limited to 'src/or/buffers.c')
-rw-r--r--src/or/buffers.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/or/buffers.c b/src/or/buffers.c
index 3692ed4d08..af1b67e091 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -2022,6 +2022,31 @@ parse_socks_client(const uint8_t *data, size_t datalen,
return -1;
}
+/** Return true if <b>cmd</b> looks like a HTTP (proxy) request. */
+int
+peek_buf_has_http_command(buf_t *buf)
+{
+ if (peek_buf_startswith(buf, "CONNECT ") ||
+ peek_buf_startswith(buf, "DELETE ") ||
+ peek_buf_startswith(buf, "GET ") ||
+ peek_buf_startswith(buf, "POST ") ||
+ peek_buf_startswith(buf, "PUT " ))
+ return 1;
+ return 0;
+}
+
+/** Return 1 iff <b>buf</b> starts with <b>cmd</b>. <b>cmd</b> must be a null
+ * terminated string */
+int
+peek_buf_startswith(buf_t *buf, const char *cmd)
+{
+ int clen = strlen(cmd);
+ if (buf->datalen >= clen)
+ if (!strncasecmp((buf->head)->data, cmd, (size_t) clen))
+ return 1;
+ return 0;
+}
+
/** Return 1 iff buf looks more like it has an (obsolete) v0 controller
* command on it than any valid v1 controller command. */
int