+ switch(get1()) {
+ case '\n':
+ if(nl)
+ return(off);
+ nl = 1;
+ break;
+ case '\r':
+ break;
+ case -1:
+ return(-1);
+ default:
+ nl = 0;
+ break;
+ }
+ }
+}
+
+#define SKIPNL(ptr) ({ \
+ int __buf__; \
+ if(*(ptr) == '\r') \
+ *((ptr)++) = 0; \
+ if(*(ptr) != '\n') { \
+ __buf__ = 0; \
+ } else { \
+ *((ptr)++) = 0; \
+ __buf__ = 1; \
+ } \
+ __buf__;})
+static struct hthead *parserawreq(char *buf)
+{
+ char *p, *p2, *nl;
+ char *method, *url, *ver;
+ struct hthead *req;
+
+ if((nl = strchr(buf, '\n')) == NULL)
+ return(NULL);
+ if(((p = strchr(buf, ' ')) == NULL) || (p > nl))
+ return(NULL);
+ method = buf;
+ *(p++) = 0;
+ if(((p2 = strchr(p, ' ')) == NULL) || (p2 > nl))
+ return(NULL);
+ url = p;
+ p = p2;
+ *(p++) = 0;
+ if(strncmp(p, "HTTP/", 5))
+ return(NULL);
+ ver = (p += 5);
+ for(; ((*p >= '0') && (*p <= '9')) || (*p == '.'); p++);
+ if(!SKIPNL(p))
+ return(NULL);
+
+ req = mkreq(method, url, ver);
+ while(1) {
+ if(SKIPNL(p)) {
+ if(*p)
+ goto fail;
+ break;
+ }
+ if((nl = strchr(p, '\n')) == NULL)
+ goto fail;
+ if(((p2 = strchr(p, ':')) == NULL) || (p2 > nl))
+ goto fail;
+ *(p2++) = 0;
+ for(; (*p2 == ' ') || (*p2 == '\t'); p2++);
+ for(nl = p2; (*nl != '\r') && (*nl != '\n'); nl++);
+ if(!SKIPNL(nl))
+ goto fail;
+ if(strncasecmp(p, "x-ash-", 6))
+ headappheader(req, p, p2);
+ p = nl;
+ }
+ return(req);
+
+fail:
+ freehthead(req);
+ return(NULL);
+}
+
+static struct hthead *parserawresp(char *buf)
+{
+ char *p, *p2, *nl;
+ char *msg, *ver;
+ int code;
+ struct hthead *resp;
+
+ if((nl = strchr(buf, '\n')) == NULL)
+ return(NULL);
+ p = strchr(buf, '\r');
+ if((p != NULL) && (p < nl))
+ nl = p;
+ if(strncmp(buf, "HTTP/", 5))
+ return(NULL);
+ ver = p = buf + 5;
+ for(; ((*p >= '0') && (*p <= '9')) || (*p == '.'); p++);
+ if(*p != ' ')
+ return(NULL);
+ *(p++) = 0;
+ if(((p2 = strchr(p, ' ')) == NULL) || (p2 > nl))
+ return(NULL);
+ *(p2++) = 0;
+ code = atoi(p);
+ if((code < 100) || (code >= 600))
+ return(NULL);
+ if(p2 >= nl)
+ return(NULL);
+ msg = p2;
+ p = nl;
+ if(!SKIPNL(p))
+ return(NULL);
+
+ resp = mkresp(code, msg, ver);
+ while(1) {
+ if(SKIPNL(p)) {
+ if(*p)
+ goto fail;
+ break;
+ }
+ if((nl = strchr(p, '\n')) == NULL)
+ goto fail;
+ if(((p2 = strchr(p, ':')) == NULL) || (p2 > nl))
+ goto fail;
+ *(p2++) = 0;
+ for(; (*p2 == ' ') || (*p2 == '\t'); p2++);
+ for(nl = p2; (*nl != '\r') && (*nl != '\n'); nl++);
+ if(!SKIPNL(nl))
+ goto fail;
+ headappheader(resp, p, p2);
+ p = nl;