Blob


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