summaryrefslogtreecommitdiff
path: root/usr.sbin/httpd/httpd.c
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2014-09-01 09:32:44 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2014-09-01 09:32:44 +0000
commit7ed0b60199efc1671e58463de1c421cf0fd3de86 (patch)
treeaf3501bd350db006b7a4c5496d90848f145eac74 /usr.sbin/httpd/httpd.c
parentb4cc8d615c9e8863f1f95c112753cf60cc0967c9 (diff)
Replace the code to get the FastCGI Status header with a proper way to
parse and write the headers using the http response descriptor. This allows to add other tweaks, like support for chunked encoding, later. OK florian@
Diffstat (limited to 'usr.sbin/httpd/httpd.c')
-rw-r--r--usr.sbin/httpd/httpd.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/usr.sbin/httpd/httpd.c b/usr.sbin/httpd/httpd.c
index 4b631ec7353..720d1880d2b 100644
--- a/usr.sbin/httpd/httpd.c
+++ b/usr.sbin/httpd/httpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: httpd.c,v 1.19 2014/08/13 16:04:28 reyk Exp $ */
+/* $OpenBSD: httpd.c,v 1.20 2014/09/01 09:32:43 reyk Exp $ */
/*
* Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org>
@@ -631,6 +631,40 @@ socket_rlimit(int maxfd)
}
char *
+evbuffer_getline(struct evbuffer *evb)
+{
+ u_int8_t *ptr = EVBUFFER_DATA(evb);
+ size_t len = EVBUFFER_LENGTH(evb);
+ char *str;
+ u_int i;
+
+ /* Safe version of evbuffer_readline() */
+ if ((str = get_string(ptr, len)) == NULL)
+ return (NULL);
+
+ for (i = 0; str[i] != '\0'; i++) {
+ if (str[i] == '\r' || str[i] == '\n')
+ break;
+ }
+
+ if (i == len) {
+ free(str);
+ return (NULL);
+ }
+
+ str[i] = '\0';
+
+ if ((i + 1) < len) {
+ if (ptr[i] == '\r' && ptr[i + 1] == '\n')
+ i++;
+ }
+
+ evbuffer_drain(evb, ++i);
+
+ return (str);
+}
+
+char *
get_string(u_int8_t *ptr, size_t len)
{
size_t i;