Blame


1 9df487d7 2003-11-23 devnull #include <u.h>
2 9df487d7 2003-11-23 devnull #include <libc.h>
3 9df487d7 2003-11-23 devnull #include <bin.h>
4 9df487d7 2003-11-23 devnull #include <httpd.h>
5 9df487d7 2003-11-23 devnull
6 9df487d7 2003-11-23 devnull /*
7 9df487d7 2003-11-23 devnull * read in some header lines, either one or all of them.
8 9df487d7 2003-11-23 devnull * copy results into header log buffer.
9 9df487d7 2003-11-23 devnull */
10 9df487d7 2003-11-23 devnull int
11 9df487d7 2003-11-23 devnull hgethead(HConnect *c, int many)
12 9df487d7 2003-11-23 devnull {
13 9df487d7 2003-11-23 devnull Hio *hin;
14 9df487d7 2003-11-23 devnull char *s, *p, *pp;
15 9df487d7 2003-11-23 devnull int n;
16 9df487d7 2003-11-23 devnull
17 9df487d7 2003-11-23 devnull hin = &c->hin;
18 9df487d7 2003-11-23 devnull for(;;){
19 9df487d7 2003-11-23 devnull s = (char*)hin->pos;
20 9df487d7 2003-11-23 devnull pp = s;
21 9df487d7 2003-11-23 devnull while(p = memchr(pp, '\n', (char*)hin->stop - pp)){
22 2277c5d7 2004-03-21 devnull if(!many || p == pp || (p == pp + 1 && *pp == '\r')){
23 9df487d7 2003-11-23 devnull pp = p + 1;
24 9df487d7 2003-11-23 devnull break;
25 9df487d7 2003-11-23 devnull }
26 9df487d7 2003-11-23 devnull pp = p + 1;
27 9df487d7 2003-11-23 devnull }
28 9df487d7 2003-11-23 devnull hin->pos = (uchar*)pp;
29 9df487d7 2003-11-23 devnull n = pp - s;
30 9df487d7 2003-11-23 devnull if(c->hstop + n > &c->header[HBufSize])
31 2e965b33 2004-05-05 devnull return -1;
32 9df487d7 2003-11-23 devnull memmove(c->hstop, s, n);
33 9df487d7 2003-11-23 devnull c->hstop += n;
34 9df487d7 2003-11-23 devnull *c->hstop = '\0';
35 9df487d7 2003-11-23 devnull if(p != nil)
36 9df487d7 2003-11-23 devnull return 0;
37 2e965b33 2004-05-05 devnull if(hreadbuf(hin, hin->pos) == nil || hin->state == Hend)
38 2e965b33 2004-05-05 devnull return -1;
39 9df487d7 2003-11-23 devnull }
40 9df487d7 2003-11-23 devnull }