various bug fixes
diff --git a/src/libhttpd/gethead.c b/src/libhttpd/gethead.c
index 5983345..0677cc8 100644
--- a/src/libhttpd/gethead.c
+++ b/src/libhttpd/gethead.c
@@ -15,15 +15,11 @@
int n;
hin = &c->hin;
-fprint(2, "hgethead top %p - %p\n", hin->pos, hin->stop);
for(;;){
s = (char*)hin->pos;
pp = s;
-fprint(2, "hgethead %p - %p\n", pp, hin->stop);
while(p = memchr(pp, '\n', (char*)hin->stop - pp)){
-fprint(2, "hgethead %p - %p newline at %p %d\n", pp, hin->stop, p, *pp);
if(!many || p == pp || (p == pp + 1 && *pp == '\r')){
-fprint(2, "breaking\n");
pp = p + 1;
break;
}
@@ -32,14 +28,13 @@
hin->pos = (uchar*)pp;
n = pp - s;
if(c->hstop + n > &c->header[HBufSize])
- return 0;
+ return -1;
memmove(c->hstop, s, n);
c->hstop += n;
*c->hstop = '\0';
-fprint(2, "p %p\n", p);
if(p != nil)
- return 1;
- if(hreadbuf(hin, hin->pos) == nil || hin->state == Hend)
return 0;
+ if(hreadbuf(hin, hin->pos) == nil || hin->state == Hend)
+ return -1;
}
}
diff --git a/src/libhttpd/hio.c b/src/libhttpd/hio.c
index 34d3a3a..3561b68 100644
--- a/src/libhttpd/hio.c
+++ b/src/libhttpd/hio.c
@@ -281,7 +281,7 @@
s = strchr(hstates, buf[0]);
if(s == nil)
- return 0;
+ return -1;
h->state = s - hstates;
s = strchr(hxfers, buf[1]);
@@ -300,13 +300,13 @@
}
*t++ = c;
if(t >= stop)
- return 0;
+ return -1;
}
*t = '\0';
h->pos = h->start;
h->stop = t;
h->seek = 0;
- return 1;
+ return 0;
}
void
diff --git a/src/libhttpd/parse.c b/src/libhttpd/parse.c
index 5fd4092..8e8364b 100644
--- a/src/libhttpd/parse.c
+++ b/src/libhttpd/parse.c
@@ -198,7 +198,7 @@
memset(&h, 0, sizeof(h));
h.c = c;
alarm(timeout);
- if(!hgethead(c, 1))
+ if(hgethead(c, 1) < 0)
return -1;
alarm(0);
h.hstart = c->hpos;
diff --git a/src/libhttpd/parsereq.c b/src/libhttpd/parsereq.c
index 7ef6341..9423798 100644
--- a/src/libhttpd/parsereq.c
+++ b/src/libhttpd/parsereq.c
@@ -41,8 +41,8 @@
* only works for http/1.1 or later.
*/
alarm(timeout);
- if(!hgethead(c, 0))
- return 0;
+ if(hgethead(c, 0) < 0)
+ return -1;
alarm(0);
c->reqtime = time(nil);
c->req.meth = getword(c);