diff -N -c -r -X exclude_files squid-1.0.beta8/src/ftp.c squid-1.0.beta8.henrik/src/ftp.c *** squid-1.0.beta8/src/ftp.c Thu May 23 19:07:18 1996 --- squid-1.0.beta8.henrik/src/ftp.c Thu May 23 19:07:47 1996 *************** *** 134,145 **** char *buf; /* chunk just read by ftpReadReply() */ int size; { - char *s = NULL; char *t = NULL; - char *t1 = NULL; - char *t2 = NULL; StoreEntry *entry = data->entry; - char *headers = NULL; int room; int hdr_len; struct _http_reply *reply = NULL; --- 134,141 ---- *************** *** 160,177 **** data->reply_hdr_state += 2; return; } ! /* need to take the lowest, non-zero pointer to the end of the headers. ! * some objects have \n\n separating header and body, but \r\n\r\n in ! * body text. */ ! t1 = strstr(data->reply_hdr, "\r\n\r\n"); ! t2 = strstr(data->reply_hdr, "\n\n"); ! if (t1 && t2) ! t = t2 < t1 ? t2 : t1; ! else ! t = t2 ? t2 : t1; if (!t) return; /* headers not complete */ ! t += (t == t1 ? 4 : 2); *t = '\0'; reply = entry->mem_obj->reply; reply->hdr_sz = t - data->reply_hdr; --- 156,166 ---- data->reply_hdr_state += 2; return; } ! /* Find the end of the headers */ ! t = mime_headers_end(data->reply_hdr); if (!t) return; /* headers not complete */ ! /* Cut after end of headers */ *t = '\0'; reply = entry->mem_obj->reply; reply->hdr_sz = t - data->reply_hdr; *************** *** 179,228 **** data->reply_hdr_state++; } if (data->reply_hdr_state == 1) { - headers = xstrdup(data->reply_hdr); data->reply_hdr_state++; debug(11, 9, "GOT HTTP REPLY HDR:\n---------\n%s\n----------\n", data->reply_hdr); ! t = strtok(headers, "\n"); ! while (t) { ! s = t + strlen(t); ! while (*s == '\r') ! *s-- = '\0'; ! if (!strncasecmp(t, "HTTP", 4)) { ! sscanf(t + 1, "%lf", &reply->version); ! if ((t = strchr(t, ' '))) { ! t++; ! reply->code = atoi(t); ! } ! } else if (!strncasecmp(t, "Content-type:", 13)) { ! if ((t = strchr(t, ' '))) { ! t++; ! strncpy(reply->content_type, t, HTTP_REPLY_FIELD_SZ - 1); ! } ! } else if (!strncasecmp(t, "Content-length:", 15)) { ! if ((t = strchr(t, ' '))) { ! t++; ! reply->content_length = atoi(t); ! } ! } else if (!strncasecmp(t, "Date:", 5)) { ! if ((t = strchr(t, ' '))) { ! t++; ! strncpy(reply->date, t, HTTP_REPLY_FIELD_SZ - 1); ! } ! } else if (!strncasecmp(t, "Expires:", 8)) { ! if ((t = strchr(t, ' '))) { ! t++; ! strncpy(reply->expires, t, HTTP_REPLY_FIELD_SZ - 1); ! } ! } else if (!strncasecmp(t, "Last-Modified:", 14)) { ! if ((t = strchr(t, ' '))) { ! t++; ! strncpy(reply->last_modified, t, HTTP_REPLY_FIELD_SZ - 1); ! } ! } ! t = strtok(NULL, "\n"); ! } ! safe_free(headers); if (reply->code) debug(11, 3, "ftpProcessReplyHeader: HTTP CODE: %d\n", reply->code); switch (reply->code) { --- 168,179 ---- data->reply_hdr_state++; } if (data->reply_hdr_state == 1) { data->reply_hdr_state++; debug(11, 9, "GOT HTTP REPLY HDR:\n---------\n%s\n----------\n", data->reply_hdr); ! /* Parse headers into reply structure */ ! httpParseHeaders(data->reply_hdr,reply); ! /* Check if object is cacheable or not based on reply code */ if (reply->code) debug(11, 3, "ftpProcessReplyHeader: HTTP CODE: %d\n", reply->code); switch (reply->code) { diff -N -c -r -X exclude_files squid-1.0.beta8/src/http.c squid-1.0.beta8.henrik/src/http.c *** squid-1.0.beta8/src/http.c Thu May 23 19:07:18 1996 --- squid-1.0.beta8.henrik/src/http.c Thu May 23 19:07:47 1996 *************** *** 110,126 **** } void httpProcessReplyHeader(httpState, buf, size) HttpStateData *httpState; char *buf; /* chunk just read by httpReadReply() */ int size; { - char *s = NULL; char *t = NULL; - char *t1 = NULL; - char *t2 = NULL; StoreEntry *entry = httpState->entry; - char *headers = NULL; int room; int hdr_len; struct _http_reply *reply = NULL; --- 110,173 ---- } + /* Build a reply structure from HTTP mime headers */ + void httpParseHeaders(mime, reply) + char *mime; + struct _http_reply *reply; + { + char *headers, *t, *s; + + headers = xstrdup(mime); + t = strtok(headers, "\n"); + while (t) { + s = t + strlen(t); + while (*s == '\r') + *s-- = '\0'; + if (!strncasecmp(t, "HTTP", 4)) { + sscanf(t + 1, "%lf", &reply->version); + if ((t = strchr(t, ' '))) { + t++; + reply->code = atoi(t); + } + } else if (!strncasecmp(t, "Content-type:", 13)) { + if ((t = strchr(t, ' '))) { + t++; + strncpy(reply->content_type, t, HTTP_REPLY_FIELD_SZ - 1); + } + } else if (!strncasecmp(t, "Content-length:", 15)) { + if ((t = strchr(t, ' '))) { + t++; + reply->content_length = atoi(t); + } + } else if (!strncasecmp(t, "Date:", 5)) { + if ((t = strchr(t, ' '))) { + t++; + strncpy(reply->date, t, HTTP_REPLY_FIELD_SZ - 1); + } + } else if (!strncasecmp(t, "Expires:", 8)) { + if ((t = strchr(t, ' '))) { + t++; + strncpy(reply->expires, t, HTTP_REPLY_FIELD_SZ - 1); + } + } else if (!strncasecmp(t, "Last-Modified:", 14)) { + if ((t = strchr(t, ' '))) { + t++; + strncpy(reply->last_modified, t, HTTP_REPLY_FIELD_SZ - 1); + } + } + t = strtok(NULL, "\n"); + } + safe_free(headers); + } + + void httpProcessReplyHeader(httpState, buf, size) HttpStateData *httpState; char *buf; /* chunk just read by httpReadReply() */ int size; { char *t = NULL; StoreEntry *entry = httpState->entry; int room; int hdr_len; struct _http_reply *reply = NULL; *************** *** 141,158 **** httpState->reply_hdr_state += 2; return; } ! /* need to take the lowest, non-zero pointer to the end of the headers. ! * some objects have \n\n separating header and body, but \r\n\r\n in ! * body text. */ ! t1 = strstr(httpState->reply_hdr, "\r\n\r\n"); ! t2 = strstr(httpState->reply_hdr, "\n\n"); ! if (t1 && t2) ! t = t2 < t1 ? t2 : t1; ! else ! t = t2 ? t2 : t1; if (!t) return; /* headers not complete */ ! t += (t == t1 ? 4 : 2); *t = '\0'; reply = entry->mem_obj->reply; reply->hdr_sz = t - httpState->reply_hdr; --- 188,199 ---- httpState->reply_hdr_state += 2; return; } ! /* Find the end of the headers */ ! t = mime_headers_end(httpState->reply_hdr); if (!t) + /* XXX: Here we could check for buffer overflow... */ return; /* headers not complete */ ! /* Cut after end of headers */ *t = '\0'; reply = entry->mem_obj->reply; reply->hdr_sz = t - httpState->reply_hdr; *************** *** 160,209 **** httpState->reply_hdr_state++; } if (httpState->reply_hdr_state == 1) { - headers = xstrdup(httpState->reply_hdr); httpState->reply_hdr_state++; debug(11, 9, "GOT HTTP REPLY HDR:\n---------\n%s\n----------\n", httpState->reply_hdr); ! t = strtok(headers, "\n"); ! while (t) { ! s = t + strlen(t); ! while (*s == '\r') ! *s-- = '\0'; ! if (!strncasecmp(t, "HTTP", 4)) { ! sscanf(t + 1, "%lf", &reply->version); ! if ((t = strchr(t, ' '))) { ! t++; ! reply->code = atoi(t); ! } ! } else if (!strncasecmp(t, "Content-type:", 13)) { ! if ((t = strchr(t, ' '))) { ! t++; ! strncpy(reply->content_type, t, HTTP_REPLY_FIELD_SZ - 1); ! } ! } else if (!strncasecmp(t, "Content-length:", 15)) { ! if ((t = strchr(t, ' '))) { ! t++; ! reply->content_length = atoi(t); ! } ! } else if (!strncasecmp(t, "Date:", 5)) { ! if ((t = strchr(t, ' '))) { ! t++; ! strncpy(reply->date, t, HTTP_REPLY_FIELD_SZ - 1); ! } ! } else if (!strncasecmp(t, "Expires:", 8)) { ! if ((t = strchr(t, ' '))) { ! t++; ! strncpy(reply->expires, t, HTTP_REPLY_FIELD_SZ - 1); ! } ! } else if (!strncasecmp(t, "Last-Modified:", 14)) { ! if ((t = strchr(t, ' '))) { ! t++; ! strncpy(reply->last_modified, t, HTTP_REPLY_FIELD_SZ - 1); ! } ! } ! t = strtok(NULL, "\n"); ! } ! safe_free(headers); if (reply->code) debug(11, 3, "httpProcessReplyHeader: HTTP CODE: %d\n", reply->code); switch (reply->code) { --- 201,212 ---- httpState->reply_hdr_state++; } if (httpState->reply_hdr_state == 1) { httpState->reply_hdr_state++; debug(11, 9, "GOT HTTP REPLY HDR:\n---------\n%s\n----------\n", httpState->reply_hdr); ! /* Parse headers into reply structure */ ! httpParseHeaders(httpState->reply_hdr,reply); ! /* Check if object is cacheable or not based on reply code */ if (reply->code) debug(11, 3, "httpProcessReplyHeader: HTTP CODE: %d\n", reply->code); switch (reply->code) { *************** *** 440,448 **** buflen += 512; /* lots of extra */ if (req->method == METHOD_POST && httpState->req_hdr) { ! if ((t = strstr(httpState->req_hdr, "\r\n\r\n"))) { ! post_buf = xstrdup(t + 4); ! *(t + 4) = '\0'; } } /* Since we limit the URL read to a 4K page, I doubt that the --- 443,451 ---- buflen += 512; /* lots of extra */ if (req->method == METHOD_POST && httpState->req_hdr) { ! if ((t = mime_headers_end(httpState->req_hdr))){ ! post_buf = xstrdup(t); ! *t = '\0'; } } /* Since we limit the URL read to a 4K page, I doubt that the diff -N -c -r -X exclude_files squid-1.0.beta8/src/http.h squid-1.0.beta8.henrik/src/http.h *** squid-1.0.beta8/src/http.h Thu May 23 19:07:19 1996 --- squid-1.0.beta8.henrik/src/http.h Thu May 23 19:07:48 1996 *************** *** 31,34 **** --- 31,35 ---- extern int httpCachable _PARAMS((char *, int)); extern int proxyhttpStart _PARAMS((edge *, char *, StoreEntry *)); extern int httpStart _PARAMS((int, char *, request_t *, char *, StoreEntry *)); + extern void httpParseHeaders _PARAMS((char *, struct _http_reply *)); extern void httpProcessReplyHeader _PARAMS((HttpStateData *, char *, int)); diff -N -c -r -X exclude_files squid-1.0.beta8/src/icp.c squid-1.0.beta8.henrik/src/icp.c *** squid-1.0.beta8/src/icp.c Thu May 23 19:07:20 1996 --- squid-1.0.beta8.henrik/src/icp.c Thu May 23 19:07:48 1996 *************** *** 1326,1333 **** req_hdr = t; req_hdr_sz = icpState->offset - (req_hdr - inbuf); ! /* The request is received when a empty header line is receied */ ! if (!strstr(req_hdr, "\r\n\r\n") && !strstr(req_hdr, "\n\n")) { xfree(inbuf); return 0; /* not a complete request */ } --- 1326,1333 ---- req_hdr = t; req_hdr_sz = icpState->offset - (req_hdr - inbuf); ! /* Check if headers are received */ ! if (!mime_headers_end(req_hdr)) { xfree(inbuf); return 0; /* not a complete request */ } *************** *** 1349,1359 **** content_length = atoi(t); debug(12, 3, "parseHttpRequest: Expecting POST Content-Length of %d\n", content_length); ! if ((t = strstr(req_hdr, "\r\n\r\n"))) { ! post_data = t + 4; ! } else if ((t = strstr(req_hdr, "\n\n"))) { ! post_data = t + 2; ! } else { debug(12, 1, "parseHttpRequest: Can't find end of headers in POST request?\n"); xfree(inbuf); return 0; /* not a complete request */ --- 1349,1355 ---- content_length = atoi(t); debug(12, 3, "parseHttpRequest: Expecting POST Content-Length of %d\n", content_length); ! if (!(post_data = mime_headers_end(req_hdr))) { debug(12, 1, "parseHttpRequest: Can't find end of headers in POST request?\n"); xfree(inbuf); return 0; /* not a complete request */ diff -N -c -r -X exclude_files squid-1.0.beta8/src/mime.c squid-1.0.beta8.henrik/src/mime.c *** squid-1.0.beta8/src/mime.c Thu May 23 19:07:20 1996 --- squid-1.0.beta8.henrik/src/mime.c Thu May 23 19:07:49 1996 *************** *** 50,55 **** --- 50,85 ---- return NULL; } + /* need to take the lowest, non-zero pointer to the end of the headers. + * some objects have \n\n separating header and body, but \r\n\r\n in + * body text. */ + char *mime_headers_end(char *mime) + { + char *p1,*p2; + char *end=NULL; + + p1=strstr(mime,"\r\n\r\n"); + p2=strstr(mime,"\n\n"); + + if(p1) + end=p1+4; + if(p2 && p2