Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <bin.h>
4 #include <httpd.h>
5 #include "escape.h"
7 typedef struct Hlex Hlex;
8 typedef struct MimeHead MimeHead;
10 enum
11 {
12 /*
13 * tokens
14 */
15 Word = 1,
16 QString,
17 };
19 #define UlongMax 4294967295UL
21 struct Hlex
22 {
23 int tok;
24 int eoh;
25 int eol; /* end of header line encountered? */
26 uchar *hstart; /* start of header */
27 jmp_buf jmp; /* jmp here to parse header */
28 char wordval[HMaxWord];
29 HConnect *c;
30 };
32 struct MimeHead
33 {
34 char *name;
35 void (*parse)(Hlex*, char*);
36 uchar seen;
37 uchar ignore;
38 };
40 static void mimeaccept(Hlex*, char*);
41 static void mimeacceptchar(Hlex*, char*);
42 static void mimeacceptenc(Hlex*, char*);
43 static void mimeacceptlang(Hlex*, char*);
44 static void mimeagent(Hlex*, char*);
45 static void mimeauthorization(Hlex*, char*);
46 static void mimeconnection(Hlex*, char*);
47 static void mimecontlen(Hlex*, char*);
48 static void mimeexpect(Hlex*, char*);
49 static void mimefresh(Hlex*, char*);
50 static void mimefrom(Hlex*, char*);
51 static void mimehost(Hlex*, char*);
52 static void mimeifrange(Hlex*, char*);
53 static void mimeignore(Hlex*, char*);
54 static void mimematch(Hlex*, char*);
55 static void mimemodified(Hlex*, char*);
56 static void mimenomatch(Hlex*, char*);
57 static void mimerange(Hlex*, char*);
58 static void mimetransenc(Hlex*, char*);
59 static void mimeunmodified(Hlex*, char*);
61 /*
62 * headers seen also include
63 * allow cache-control chargeto
64 * content-encoding content-language content-location content-md5 content-range content-type
65 * date etag expires forwarded last-modified max-forwards pragma
66 * proxy-agent proxy-authorization proxy-connection
67 * ua-color ua-cpu ua-os ua-pixels
68 * upgrade via x-afs-tokens x-serial-number
69 */
70 static MimeHead mimehead[] =
71 {
72 {"accept", mimeaccept},
73 {"accept-charset", mimeacceptchar},
74 {"accept-encoding", mimeacceptenc},
75 {"accept-language", mimeacceptlang},
76 {"authorization", mimeauthorization},
77 {"connection", mimeconnection},
78 {"content-length", mimecontlen},
79 {"expect", mimeexpect},
80 {"fresh", mimefresh},
81 {"from", mimefrom},
82 {"host", mimehost},
83 {"if-match", mimematch},
84 {"if-modified-since", mimemodified},
85 {"if-none-match", mimenomatch},
86 {"if-range", mimeifrange},
87 {"if-unmodified-since", mimeunmodified},
88 {"range", mimerange},
89 {"transfer-encoding", mimetransenc},
90 {"user-agent", mimeagent},
91 };
93 char* hmydomain;
94 char* hversion = "HTTP/1.1";
96 static void lexhead(Hlex*);
97 static void parsejump(Hlex*, char*);
98 static int getc(Hlex*);
99 static void ungetc(Hlex*);
100 static int wordcr(Hlex*);
101 static int wordnl(Hlex*);
102 static void word(Hlex*, char*);
103 static int lex1(Hlex*, int);
104 static int lex(Hlex*);
105 static int lexbase64(Hlex*);
106 static ulong digtoul(char *s, char **e);
108 /*
109 * flush an clean up junk from a request
110 */
111 void
112 hreqcleanup(HConnect *c)
114 int i;
116 hxferenc(&c->hout, 0);
117 memset(&c->req, 0, sizeof(c->req));
118 memset(&c->head, 0, sizeof(c->head));
119 c->hpos = c->header;
120 c->hstop = c->header;
121 binfree(&c->bin);
122 for(i = 0; i < nelem(mimehead); i++){
123 mimehead[i].seen = 0;
124 mimehead[i].ignore = 0;
128 /*
129 * list of tokens
130 * if the client is HTTP/1.0,
131 * ignore headers which match one of the tokens.
132 * restarts parsing if necessary.
133 */
134 static void
135 mimeconnection(Hlex *h, char *unused)
137 char *u, *p;
138 int reparse, i;
140 reparse = 0;
141 for(;;){
142 while(lex(h) != Word)
143 if(h->tok != ',')
144 goto breakout;
146 if(cistrcmp(h->wordval, "keep-alive") == 0)
147 h->c->head.persist = 1;
148 else if(cistrcmp(h->wordval, "close") == 0)
149 h->c->head.closeit = 1;
150 else if(!http11(h->c)){
151 for(i = 0; i < nelem(mimehead); i++){
152 if(cistrcmp(mimehead[i].name, h->wordval) == 0){
153 reparse = mimehead[i].seen && !mimehead[i].ignore;
154 mimehead[i].ignore = 1;
155 if(cistrcmp(mimehead[i].name, "authorization") == 0){
156 h->c->head.authuser = nil;
157 h->c->head.authpass = nil;
163 if(lex(h) != ',')
164 break;
167 breakout:;
168 /*
169 * if need to ignore headers we've already parsed,
170 * reset & start over. need to save authorization
171 * info because it's written over when parsed.
172 */
173 if(reparse){
174 u = h->c->head.authuser;
175 p = h->c->head.authpass;
176 memset(&h->c->head, 0, sizeof(h->c->head));
177 h->c->head.authuser = u;
178 h->c->head.authpass = p;
180 h->c->hpos = h->hstart;
181 longjmp(h->jmp, 1);
185 int
186 hparseheaders(HConnect *c, int timeout)
188 Hlex h;
190 c->head.fresh_thresh = 0;
191 c->head.fresh_have = 0;
192 c->head.persist = 0;
193 if(c->req.vermaj == 0){
194 c->head.host = hmydomain;
195 return 1;
198 memset(&h, 0, sizeof(h));
199 h.c = c;
200 if(timeout)
201 alarm(timeout);
202 if(hgethead(c, 1) < 0)
203 return -1;
204 if(timeout)
205 alarm(0);
206 h.hstart = c->hpos;
208 if(setjmp(h.jmp) == -1)
209 return -1;
211 h.eol = 0;
212 h.eoh = 0;
213 h.tok = '\n';
214 while(lex(&h) != '\n'){
215 if(h.tok == Word && lex(&h) == ':')
216 parsejump(&h, hstrdup(c, h.wordval));
217 while(h.tok != '\n')
218 lex(&h);
219 h.eol = h.eoh;
222 if(http11(c)){
223 /*
224 * according to the http/1.1 spec,
225 * these rules must be followed
226 */
227 if(c->head.host == nil){
228 hfail(c, HBadReq, nil);
229 return -1;
231 if(c->req.urihost != nil)
232 c->head.host = c->req.urihost;
233 /*
234 * also need to check host is actually this one
235 */
236 }else if(c->head.host == nil)
237 c->head.host = hmydomain;
238 return 1;
241 /*
242 * mimeparams : | mimeparams ";" mimepara
243 * mimeparam : token "=" token | token "=" qstring
244 */
245 static HSPairs*
246 mimeparams(Hlex *h)
248 HSPairs *p;
249 char *s;
251 p = nil;
252 for(;;){
253 if(lex(h) != Word)
254 break;
255 s = hstrdup(h->c, h->wordval);
256 if(lex(h) != Word && h->tok != QString)
257 break;
258 p = hmkspairs(h->c, s, hstrdup(h->c, h->wordval), p);
260 return hrevspairs(p);
263 /*
264 * mimehfields : mimehfield | mimehfields commas mimehfield
265 * mimehfield : token mimeparams
266 * commas : "," | commas ","
267 */
268 static HFields*
269 mimehfields(Hlex *h)
271 HFields *f;
273 f = nil;
274 for(;;){
275 while(lex(h) != Word)
276 if(h->tok != ',')
277 goto breakout;
279 f = hmkhfields(h->c, hstrdup(h->c, h->wordval), nil, f);
281 if(lex(h) == ';')
282 f->params = mimeparams(h);
283 if(h->tok != ',')
284 break;
286 breakout:;
287 return hrevhfields(f);
290 /*
291 * parse a list of acceptable types, encodings, languages, etc.
292 */
293 static HContent*
294 mimeok(Hlex *h, char *name, int multipart, HContent *head)
296 char *generic, *specific, *s;
297 float v;
299 /*
300 * each type is separated by one or more commas
301 */
302 while(lex(h) != Word)
303 if(h->tok != ',')
304 return head;
306 generic = hstrdup(h->c, h->wordval);
307 lex(h);
308 if(h->tok == '/' || multipart){
309 /*
310 * at one time, IE5 improperly said '*' for single types
311 */
312 if(h->tok != '/')
313 return nil;
314 if(lex(h) != Word)
315 return head;
316 specific = hstrdup(h->c, h->wordval);
317 if(!multipart && strcmp(specific, "*") != 0)
318 return head;
319 lex(h);
320 }else
321 specific = nil;
322 head = hmkcontent(h->c, generic, specific, head);
324 for(;;){
325 switch(h->tok){
326 case ';':
327 /*
328 * should make a list of these params
329 * for accept, they fall into two classes:
330 * up to a q=..., they modify the media type.
331 * afterwards, they acceptance criteria
332 */
333 if(lex(h) == Word){
334 s = hstrdup(h->c, h->wordval);
335 if(lex(h) != '=' || lex(h) != Word && h->tok != QString)
336 return head;
337 v = strtod(h->wordval, nil);
338 if(strcmp(s, "q") == 0)
339 head->q = v;
340 else if(strcmp(s, "mxb") == 0)
341 head->mxb = v;
343 break;
344 case ',':
345 return mimeok(h, name, multipart, head);
346 default:
347 return head;
349 lex(h);
351 return head;
354 /*
355 * parse a list of entity tags
356 * 1#entity-tag
357 * entity-tag = [weak] opaque-tag
358 * weak = "W/"
359 * opaque-tag = quoted-string
360 */
361 static HETag*
362 mimeetag(Hlex *h, HETag *head)
364 HETag *e;
365 int weak;
367 for(;;){
368 while(lex(h) != Word && h->tok != QString)
369 if(h->tok != ',')
370 return head;
372 weak = 0;
373 if(h->tok == Word && strcmp(h->wordval, "*") != 0){
374 if(strcmp(h->wordval, "W") != 0)
375 return head;
376 if(lex(h) != '/' || lex(h) != QString)
377 return head;
378 weak = 1;
381 e = halloc(h->c, sizeof(HETag));
382 e->etag = hstrdup(h->c, h->wordval);
383 e->weak = weak;
384 e->next = head;
385 head = e;
387 if(lex(h) != ',')
388 return head;
390 return head;
393 /*
394 * ranges-specifier = byte-ranges-specifier
395 * byte-ranges-specifier = "bytes" "=" byte-range-set
396 * byte-range-set = 1#(byte-range-spec|suffix-byte-range-spec)
397 * byte-range-spec = byte-pos "-" [byte-pos]
398 * byte-pos = 1*DIGIT
399 * suffix-byte-range-spec = "-" suffix-length
400 * suffix-length = 1*DIGIT
402 * syntactically invalid range specifiers cause the
403 * entire header field to be ignored.
404 * it is syntactically incorrect for the second byte pos
405 * to be smaller than the first byte pos
406 */
407 static HRange*
408 mimeranges(Hlex *h, HRange *head)
410 HRange *r, *rh, *tail;
411 char *w;
412 ulong start, stop;
413 int suf;
415 if(lex(h) != Word || strcmp(h->wordval, "bytes") != 0 || lex(h) != '=')
416 return head;
418 rh = nil;
419 tail = nil;
420 for(;;){
421 while(lex(h) != Word){
422 if(h->tok != ','){
423 if(h->tok == '\n')
424 goto breakout;
425 return head;
429 w = h->wordval;
430 start = 0;
431 suf = 1;
432 if(w[0] != '-'){
433 suf = 0;
434 start = digtoul(w, &w);
435 if(w[0] != '-')
436 return head;
438 w++;
439 stop = ~0UL;
440 if(w[0] != '\0'){
441 stop = digtoul(w, &w);
442 if(w[0] != '\0')
443 return head;
444 if(!suf && stop < start)
445 return head;
448 r = halloc(h->c, sizeof(HRange));
449 r->suffix = suf;
450 r->start = start;
451 r->stop = stop;
452 r->next = nil;
453 if(rh == nil)
454 rh = r;
455 else
456 tail->next = r;
457 tail = r;
459 if(lex(h) != ','){
460 if(h->tok == '\n')
461 break;
462 return head;
465 breakout:;
467 if(head == nil)
468 return rh;
470 for(tail = head; tail->next != nil; tail = tail->next)
472 tail->next = rh;
473 return head;
476 static void
477 mimeaccept(Hlex *h, char *name)
479 h->c->head.oktype = mimeok(h, name, 1, h->c->head.oktype);
482 static void
483 mimeacceptchar(Hlex *h, char *name)
485 h->c->head.okchar = mimeok(h, name, 0, h->c->head.okchar);
488 static void
489 mimeacceptenc(Hlex *h, char *name)
491 h->c->head.okencode = mimeok(h, name, 0, h->c->head.okencode);
494 static void
495 mimeacceptlang(Hlex *h, char *name)
497 h->c->head.oklang = mimeok(h, name, 0, h->c->head.oklang);
500 static void
501 mimemodified(Hlex *h, char *unused)
503 lexhead(h);
504 h->c->head.ifmodsince = hdate2sec(h->wordval);
507 static void
508 mimeunmodified(Hlex *h, char *unused)
510 lexhead(h);
511 h->c->head.ifunmodsince = hdate2sec(h->wordval);
514 static void
515 mimematch(Hlex *h, char *unused)
517 h->c->head.ifmatch = mimeetag(h, h->c->head.ifmatch);
520 static void
521 mimenomatch(Hlex *h, char *unused)
523 h->c->head.ifnomatch = mimeetag(h, h->c->head.ifnomatch);
526 /*
527 * argument is either etag or date
528 */
529 static void
530 mimeifrange(Hlex *h, char *unused)
532 int c, d, et;
534 et = 0;
535 c = getc(h);
536 while(c == ' ' || c == '\t')
537 c = getc(h);
538 if(c == '"')
539 et = 1;
540 else if(c == 'W'){
541 d = getc(h);
542 if(d == '/')
543 et = 1;
544 ungetc(h);
546 ungetc(h);
547 if(et){
548 h->c->head.ifrangeetag = mimeetag(h, h->c->head.ifrangeetag);
549 }else{
550 lexhead(h);
551 h->c->head.ifrangedate = hdate2sec(h->wordval);
555 static void
556 mimerange(Hlex *h, char *unused)
558 h->c->head.range = mimeranges(h, h->c->head.range);
561 /*
562 * note: netscape and ie through versions 4.7 and 4
563 * support only basic authorization, so that is all that is supported here
565 * "Authorization" ":" "Basic" base64-user-pass
566 * where base64-user-pass is the base64 encoding of
567 * username ":" password
568 */
569 static void
570 mimeauthorization(Hlex *h, char *unused)
572 char *up, *p;
573 int n;
575 if(lex(h) != Word || cistrcmp(h->wordval, "basic") != 0)
576 return;
578 n = lexbase64(h);
579 if(!n)
580 return;
582 /*
583 * wipe out source for password, so it won't be logged.
584 * it is replaced by a single =,
585 * which is valid base64, but not ok for an auth reponse.
586 * therefore future parses of the header field will not overwrite
587 * authuser and authpass.
588 */
589 memmove(h->c->hpos - (n - 1), h->c->hpos, h->c->hstop - h->c->hpos);
590 h->c->hstop -= n - 1;
591 *h->c->hstop = '\0';
592 h->c->hpos -= n - 1;
593 h->c->hpos[-1] = '=';
595 up = halloc(h->c, n + 1);
596 n = dec64((uchar*)up, n, h->wordval, n);
597 up[n] = '\0';
598 p = strchr(up, ':');
599 if(p != nil){
600 *p++ = '\0';
601 h->c->head.authuser = hstrdup(h->c, up);
602 h->c->head.authpass = hstrdup(h->c, p);
606 static void
607 mimeagent(Hlex *h, char *unused)
609 lexhead(h);
610 h->c->head.client = hstrdup(h->c, h->wordval);
613 static void
614 mimefrom(Hlex *h, char *unused)
616 lexhead(h);
619 static void
620 mimehost(Hlex *h, char *unused)
622 char *hd;
624 lexhead(h);
625 for(hd = h->wordval; *hd == ' ' || *hd == '\t'; hd++)
627 h->c->head.host = hlower(hstrdup(h->c, hd));
630 /*
631 * if present, implies that a message body follows the headers
632 * "content-length" ":" digits
633 */
634 static void
635 mimecontlen(Hlex *h, char *unused)
637 char *e;
638 ulong v;
640 if(lex(h) != Word)
641 return;
642 e = h->wordval;
643 v = digtoul(e, &e);
644 if(v == ~0UL || *e != '\0')
645 return;
646 h->c->head.contlen = v;
649 /*
650 * mimexpect : "expect" ":" expects
651 * expects : | expects "," expect
652 * expect : "100-continue" | token | token "=" token expectparams | token "=" qstring expectparams
653 * expectparams : ";" token | ";" token "=" token | token "=" qstring
654 * for now, we merely parse "100-continue" or anything else.
655 */
656 static void
657 mimeexpect(Hlex *h, char *unused)
659 if(lex(h) != Word || cistrcmp(h->wordval, "100-continue") != 0 || lex(h) != '\n')
660 h->c->head.expectother = 1;
661 h->c->head.expectcont = 1;
664 static void
665 mimetransenc(Hlex *h, char *unused)
667 h->c->head.transenc = mimehfields(h);
670 static void
671 mimefresh(Hlex *h, char *unused)
673 char *s;
675 lexhead(h);
676 for(s = h->wordval; *s && (*s==' ' || *s=='\t'); s++)
678 if(strncmp(s, "pathstat/", 9) == 0)
679 h->c->head.fresh_thresh = atoi(s+9);
680 else if(strncmp(s, "have/", 5) == 0)
681 h->c->head.fresh_have = atoi(s+5);
684 static void
685 mimeignore(Hlex *h, char *unused)
687 lexhead(h);
690 static void
691 parsejump(Hlex *h, char *k)
693 int l, r, m;
695 l = 1;
696 r = nelem(mimehead) - 1;
697 while(l <= r){
698 m = (r + l) >> 1;
699 if(cistrcmp(mimehead[m].name, k) <= 0)
700 l = m + 1;
701 else
702 r = m - 1;
704 m = l - 1;
705 if(cistrcmp(mimehead[m].name, k) == 0 && !mimehead[m].ignore){
706 mimehead[m].seen = 1;
707 (*mimehead[m].parse)(h, k);
708 }else
709 mimeignore(h, k);
712 static int
713 lex(Hlex *h)
715 return h->tok = lex1(h, 0);
718 static int
719 lexbase64(Hlex *h)
721 int c, n;
723 n = 0;
724 lex1(h, 1);
726 while((c = getc(h)) >= 0){
727 if(!(c >= 'A' && c <= 'Z'
728 || c >= 'a' && c <= 'z'
729 || c >= '0' && c <= '9'
730 || c == '+' || c == '/')){
731 ungetc(h);
732 break;
735 if(n < HMaxWord-1)
736 h->wordval[n++] = c;
738 h->wordval[n] = '\0';
739 return n;
742 /*
743 * rfc 822/rfc 1521 lexical analyzer
744 */
745 static int
746 lex1(Hlex *h, int skipwhite)
748 int level, c;
750 if(h->eol)
751 return '\n';
753 top:
754 c = getc(h);
755 switch(c){
756 case '(':
757 level = 1;
758 while((c = getc(h)) >= 0){
759 if(c == '\\'){
760 c = getc(h);
761 if(c < 0)
762 return '\n';
763 continue;
765 if(c == '(')
766 level++;
767 else if(c == ')' && --level == 0)
768 break;
769 else if(c == '\n'){
770 c = getc(h);
771 if(c < 0)
772 return '\n';
773 if(c == ')' && --level == 0)
774 break;
775 if(c != ' ' && c != '\t'){
776 ungetc(h);
777 return '\n';
781 goto top;
783 case ' ': case '\t':
784 goto top;
786 case '\r':
787 c = getc(h);
788 if(c != '\n'){
789 ungetc(h);
790 goto top;
793 case '\n':
794 if(h->tok == '\n'){
795 h->eol = 1;
796 h->eoh = 1;
797 return '\n';
799 c = getc(h);
800 if(c < 0){
801 h->eol = 1;
802 return '\n';
804 if(c != ' ' && c != '\t'){
805 ungetc(h);
806 h->eol = 1;
807 return '\n';
809 goto top;
811 case ')':
812 case '<': case '>':
813 case '[': case ']':
814 case '@': case '/':
815 case ',': case ';': case ':': case '?': case '=':
816 if(skipwhite){
817 ungetc(h);
818 return c;
820 return c;
822 case '"':
823 if(skipwhite){
824 ungetc(h);
825 return c;
827 word(h, "\"");
828 getc(h); /* skip the closing quote */
829 return QString;
831 default:
832 ungetc(h);
833 if(skipwhite)
834 return c;
835 word(h, "\"(){}<>@,;:/[]?=\r\n \t");
836 if(h->wordval[0] == '\0'){
837 h->c->head.closeit = 1;
838 hfail(h->c, HSyntax);
839 longjmp(h->jmp, -1);
841 return Word;
843 goto top;
844 return 0;
847 /*
848 * return the rest of an rfc 822, including \n
849 * do not map to lower case
850 */
851 static void
852 lexhead(Hlex *h)
854 int c, n;
856 n = 0;
857 while((c = getc(h)) >= 0){
858 if(c == '\r')
859 c = wordcr(h);
860 else if(c == '\n')
861 c = wordnl(h);
862 if(c == '\n')
863 break;
864 if(c == '\\'){
865 c = getc(h);
866 if(c < 0)
867 break;
870 if(n < HMaxWord-1)
871 h->wordval[n++] = c;
873 h->tok = '\n';
874 h->eol = 1;
875 h->wordval[n] = '\0';
878 static void
879 word(Hlex *h, char *stop)
881 int c, n;
883 n = 0;
884 while((c = getc(h)) >= 0){
885 if(c == '\r')
886 c = wordcr(h);
887 else if(c == '\n')
888 c = wordnl(h);
889 if(c == '\\'){
890 c = getc(h);
891 if(c < 0)
892 break;
893 }else if(c < 32 || strchr(stop, c) != nil){
894 ungetc(h);
895 break;
898 if(n < HMaxWord-1)
899 h->wordval[n++] = c;
901 h->wordval[n] = '\0';
904 static int
905 wordcr(Hlex *h)
907 int c;
909 c = getc(h);
910 if(c == '\n')
911 return wordnl(h);
912 ungetc(h);
913 return ' ';
916 static int
917 wordnl(Hlex *h)
919 int c;
921 c = getc(h);
922 if(c == ' ' || c == '\t')
923 return c;
924 ungetc(h);
926 return '\n';
929 static int
930 getc(Hlex *h)
932 if(h->eoh)
933 return -1;
934 if(h->c->hpos < h->c->hstop)
935 return *h->c->hpos++;
936 h->eoh = 1;
937 h->eol = 1;
938 return -1;
941 static void
942 ungetc(Hlex *h)
944 if(h->eoh)
945 return;
946 h->c->hpos--;
949 static ulong
950 digtoul(char *s, char **e)
952 ulong v;
953 int c, ovfl;
955 v = 0;
956 ovfl = 0;
957 for(;;){
958 c = *s;
959 if(c < '0' || c > '9')
960 break;
961 s++;
962 c -= '0';
963 if(v > UlongMax/10 || v == UlongMax/10 && c >= UlongMax%10)
964 ovfl = 1;
965 v = v * 10 + c;
968 if(e)
969 *e = s;
970 if(ovfl)
971 return UlongMax;
972 return v;
975 int
976 http11(HConnect *c)
978 return c->req.vermaj > 1 || c->req.vermaj == 1 && c->req.vermin > 0;
981 char*
982 hmkmimeboundary(HConnect *c)
984 char buf[32];
985 int i;
987 srand((time(0)<<16)|getpid());
988 strcpy(buf, "upas-");
989 for(i = 5; i < sizeof(buf)-1; i++)
990 buf[i] = 'a' + nrand(26);
991 buf[i] = 0;
992 return hstrdup(c, buf);
995 HSPairs*
996 hmkspairs(HConnect *c, char *s, char *t, HSPairs *next)
998 HSPairs *sp;
1000 sp = halloc(c, sizeof *sp);
1001 sp->s = s;
1002 sp->t = t;
1003 sp->next = next;
1004 return sp;
1007 HSPairs*
1008 hrevspairs(HSPairs *sp)
1010 HSPairs *last, *next;
1012 last = nil;
1013 for(; sp != nil; sp = next){
1014 next = sp->next;
1015 sp->next = last;
1016 last = sp;
1018 return last;
1021 HFields*
1022 hmkhfields(HConnect *c, char *s, HSPairs *p, HFields *next)
1024 HFields *hf;
1026 hf = halloc(c, sizeof *hf);
1027 hf->s = s;
1028 hf->params = p;
1029 hf->next = next;
1030 return hf;
1033 HFields*
1034 hrevhfields(HFields *hf)
1036 HFields *last, *next;
1038 last = nil;
1039 for(; hf != nil; hf = next){
1040 next = hf->next;
1041 hf->next = last;
1042 last = hf;
1044 return last;
1047 HContent*
1048 hmkcontent(HConnect *c, char *generic, char *specific, HContent *next)
1050 HContent *ct;
1052 ct = halloc(c, sizeof(HContent));
1053 ct->generic = generic;
1054 ct->specific = specific;
1055 ct->next = next;
1056 ct->q = 1;
1057 ct->mxb = 0;
1058 return ct;