]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
- Added bottom level support for Content-Range header fields.
authorrousskov <>
Mon, 9 Mar 1998 04:02:07 +0000 (04:02 +0000)
committerrousskov <>
Mon, 9 Mar 1998 04:02:07 +0000 (04:02 +0000)
src/HttpHdrCc.cc
src/HttpHdrExtField.cc
src/HttpHdrRange.cc
src/HttpHeader.cc
src/Makefile.in
src/enums.h
src/mem.cc
src/protos.h
src/structs.h
src/typedefs.h

index 5c3456708a3512e92c96f14b76378f4f337c9e18..bf946125bec5a84b9bb20d447c9d8e3ec880dfe1 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpHdrCc.cc,v 1.4 1998/03/07 23:42:56 rousskov Exp $
+ * $Id: HttpHdrCc.cc,v 1.5 1998/03/08 21:02:07 rousskov Exp $
  *
  * DEBUG: section 65    HTTP Cache Control Header
  * AUTHOR: Alex Rousskov
@@ -151,7 +151,7 @@ httpHdrCcDup(const HttpHdrCc * cc)
 }
 
 void
-httpHdrCcPackValueInto(const HttpHdrCc * cc, Packer * p)
+httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p)
 {
     http_hdr_cc_type flag;
     int pcount = 0;
index 69b3e04b04b40079dae7e58d7a04d264226ab8b0..cf637511c02318cd214c635edf348478f8369565 100644 (file)
@@ -1,8 +1,8 @@
 
 /*
- * $Id: HttpHdrExtField.cc,v 1.1 1998/03/08 18:59:11 rousskov Exp $
+ * $Id: HttpHdrExtField.cc,v 1.2 1998/03/08 21:02:07 rousskov Exp $
  *
- * DEBUG: section 6?    HTTP Header: Extension Field
+ * DEBUG: section 69    HTTP Header: Extension Field
  * AUTHOR: Alex Rousskov
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
index af6a9fc436c8b33b28fbaff766e59d1d97b3897f..23ea2e30bddda4e67787db36a23feef906b1dd78 100644 (file)
@@ -1,8 +1,8 @@
 
 /*
- * $Id: HttpHdrRange.cc,v 1.2 1998/03/07 23:42:57 rousskov Exp $
+ * $Id: HttpHdrRange.cc,v 1.3 1998/03/08 21:02:08 rousskov Exp $
  *
- * DEBUG: section 64    HTTP Content-Range Header
+ * DEBUG: section 64    HTTP Range Header
  * AUTHOR: Alex Rousskov
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -60,6 +60,7 @@
 #define size_diff(a,b) ((a) >= (b) ? ((a)-(b)) : 0)
 static HttpHdrRangeSpec *httpHdrRangeSpecDup(const HttpHdrRangeSpec *spec);
 static int httpHdrRangeSpecCanonize(HttpHdrRangeSpec *spec, size_t clen);
+static void httpHdrRangeSpecPackInto(const HttpHdrRangeSpec *spec, Packer *p);
 
 /* globals */
 static int RangeParsedCount = 0;
@@ -68,7 +69,6 @@ static int RangeParsedCount = 0;
  * Range-Spec
  */
 
-
 static HttpHdrRangeSpec *
 httpHdrRangeSpecCreate()
 {
@@ -128,6 +128,19 @@ httpHdrRangeSpecDup(const HttpHdrRangeSpec *spec)
     return dup;
 }
 
+static void
+httpHdrRangeSpecPackInto(const HttpHdrRangeSpec *spec, Packer *p)
+{
+    if (!known_spec(spec->offset)) /* suffix */
+       packerPrintf(p, "-%d", spec->length);
+    else
+    if (!known_spec(spec->length)) /* trailer */
+       packerPrintf(p, "%d-", spec->offset);
+    else                           /* range */
+       packerPrintf(p, "%d-%d", 
+           spec->offset, spec->offset+spec->length-1);
+}
+
 /* fills "absent" positions in range specification based on response body size 
    returns true if the range is still valid
    range is valid if its intersection with [0,length-1] is not empty
@@ -218,14 +231,15 @@ httpHdrRangeDup(const HttpHdrRange * range)
 }
 
 void
-httpHdrRangePackValueInto(const HttpHdrRange * range, Packer * p)
+httpHdrRangePackInto(const HttpHdrRange * range, Packer * p)
 {
     HttpHdrRangePos pos = HttpHdrRangeInitPos;
     HttpHdrRangeSpec spec;
     assert(range);
     while (httpHdrRangeGetSpec(range, &spec, &pos)) {
-       packerPrintf(p, (pos == HttpHdrRangeInitPos) ? "%d-%d" : ",%d-%d",
-           spec.offset, spec.offset+spec.length-1);
+       if (pos != HttpHdrRangeInitPos)
+           packerAppend(p, ",", 1);
+       httpHdrRangeSpecPackInto(&spec, p);
     }
 }
 
index 32a5cbd726ab1db5ce22a458af25c3bb8647d27e..46b2160fb8f6bca304c6819a7a651a657cb003be 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: HttpHeader.cc,v 1.20 1998/03/08 18:58:40 rousskov Exp $
+ * $Id: HttpHeader.cc,v 1.21 1998/03/08 21:02:09 rousskov Exp $
  *
  * DEBUG: section 55    HTTP Header
  * AUTHOR: Alex Rousskov
@@ -58,8 +58,7 @@
  */
 
 /*
- * HttpHeader entry 
- * ( the concrete type of entry.field is Headers[id].type )
+ * HttpHeader entry (type of entry.field is Headers[id].type)
  */
 struct _HttpHeaderEntry {
     field_store field;
@@ -100,6 +99,7 @@ static field_attrs_t Headers[] =
     {"Content-Encoding", HDR_CONTENT_ENCODING, ftStr},
     {"Content-Length", HDR_CONTENT_LENGTH, ftInt},
     {"Content-MD5", HDR_CONTENT_MD5, ftStr},   /* for now */
+    {"Content-Range", HDR_CONTENT_RANGE, ftPContRange},
     {"Content-Type", HDR_CONTENT_TYPE, ftStr},
     {"Date", HDR_DATE, ftDate_1123},
     {"Etag", HDR_ETAG, ftStr}, /* for now */
@@ -137,8 +137,10 @@ static http_hdr_type ListHeaders[] =
     /* HDR_ALLOW, */
     HDR_CACHE_CONTROL, HDR_CONNECTION,
     HDR_CONTENT_ENCODING,
-    /* HDR_CONTENT_LANGUAGE,  HDR_IF_MATCH, HDR_IF_NONE_MATCH,
-     * HDR_PRAGMA, HDR_TRANSFER_ENCODING, */
+    /* HDR_CONTENT_LANGUAGE, */
+    /*  HDR_IF_MATCH, HDR_IF_NONE_MATCH, HDR_PRAGMA, */
+    HDR_RANGE,
+    /* HDR_TRANSFER_ENCODING, */
     HDR_UPGRADE,               /* HDR_VARY, */
     /* HDR_VIA, HDR_WARNING, */
     HDR_WWW_AUTHENTICATE,
@@ -157,7 +159,7 @@ static http_hdr_type ReplyHeaders[] =
 static int RequestHeadersMask = 0;     /* set run-time using RequestHeaders */
 static http_hdr_type RequestHeaders[] =
 {
-    HDR_OTHER
+    HDR_CONTENT_RANGE, HDR_OTHER
 };
 
 /* when first field is added, this is how much entries we allocate */
@@ -739,6 +741,12 @@ httpHeaderGetRange(const HttpHeader * hdr)
     return httpHeaderGet(hdr, HDR_RANGE).v_prange;
 }
 
+HttpHdrContRange *
+httpHeaderGetContRange(const HttpHeader * hdr)
+{
+    return httpHeaderGet(hdr, HDR_CONTENT_RANGE).v_pcont_range;
+}
+
 /* updates header masks */
 static void
 httpHeaderSyncMasks(HttpHeader * hdr, const HttpHeaderEntry * e, int add)
@@ -812,6 +820,10 @@ httpHeaderEntryClean(HttpHeaderEntry * e)
        if (e->field.v_prange)
            httpHdrRangeDestroy(e->field.v_prange);
        break;
+    case ftPContRange:
+       if (e->field.v_pcont_range)
+           httpHdrContRangeDestroy(e->field.v_pcont_range);
+       break;
     case ftPExtField:
        if (e->field.v_pefield)
            httpHdrExtFieldDestroy(e->field.v_pefield);
@@ -906,6 +918,7 @@ httpHeaderEntryParseExtFieldInit(HttpHeaderEntry * e, int id, const HttpHdrExtFi
 static int
 httpHeaderEntryParseByTypeInit(HttpHeaderEntry * e, int id, const HttpHdrExtField * f)
 {
+    const char *err_entry_descr = NULL;
     int type;
     field_store field;
     assert(e && f);
@@ -915,57 +928,53 @@ httpHeaderEntryParseByTypeInit(HttpHeaderEntry * e, int id, const HttpHdrExtFiel
     httpHeaderFieldInit(&field);
     switch (type) {
     case ftInt:
-       if (!httpHeaderParseInt(strBuf(f->value), &field.v_int)) {
-           Headers[id].stat.errCount++;
-           return 0;
-       }
+       if (!httpHeaderParseInt(strBuf(f->value), &field.v_int))
+           err_entry_descr = "integer field";
        break;
-
     case ftStr:
        field.v_str = stringDup(&f->value);
        break;
-
     case ftDate_1123:
        field.v_time = parse_rfc1123(strBuf(f->value));
        if (field.v_time <= 0)
            Headers[id].stat.errCount++;
        /*
         * if parse_rfc1123 fails we fall through anyway so upper levels
-        * will notice invalid date
+        * will notice invalid date rather than unparsible header
         */
        break;
-
     case ftPCc:
        field.v_pcc = httpHdrCcParseCreate(strBuf(f->value));
-       if (!field.v_pcc) {
-           debug(55, 2) ("failed to parse cc hdr: id: %d, field: '%s: %s'\n",
-               id, strBuf(f->name), strBuf(f->value));
-           Headers[id].stat.errCount++;
-           return 0;
-       }
+       if (!field.v_pcc)
+           err_entry_descr = "cache control hdr";
        break;
-
     case ftPRange:
        field.v_prange = httpHdrRangeParseCreate(strBuf(f->value));
-       if (!field.v_prange) {
-           debug(55, 2) ("failed to parse range hdr: id: %d, field: '%s: %s'\n",
-               id, strBuf(f->name), strBuf(f->value));
-           Headers[id].stat.errCount++;
-           return 0;
-       }
+       if (!field.v_prange)
+           err_entry_descr = "range hdr";
+       break;
+    case ftPContRange:
+       field.v_pcont_range = httpHdrContRangeParseCreate(strBuf(f->value));
+       if (!field.v_pcont_range)
+           err_entry_descr = "content range hdr";
        break;
-
     default:
        debug(55, 2) ("something went wrong with hdr field type analysis: id: %d, type: %d, field: '%s: %s'\n",
            id, type, strBuf(f->name), strBuf(f->value));
        assert(0);
     }
+    /* failure ? */
+    if (err_entry_descr) {
+       debug(55, 2) ("failed to parse %s: id: %d, field: '%s: %s'\n",
+           err_entry_descr, id, strBuf(f->name), strBuf(f->value));
+       Headers[id].stat.errCount++;
+       return 0;
+    }
     /* success, do actual init */
     httpHeaderEntryInit(e, id, field);
     return 1;
 }
 
-
 static HttpHeaderEntry
 httpHeaderEntryClone(const HttpHeaderEntry * e)
 {
@@ -1019,10 +1028,13 @@ httpHeaderEntryPackByType(const HttpHeaderEntry * e, Packer * p)
        packerPrintf(p, "%s", mkrfc1123(e->field.v_time));
        break;
     case ftPCc:
-       httpHdrCcPackValueInto(e->field.v_pcc, p);
+       httpHdrCcPackInto(e->field.v_pcc, p);
        break;
     case ftPRange:
-       httpHdrRangePackValueInto(e->field.v_prange, p);
+       httpHdrRangePackInto(e->field.v_prange, p);
+       break;
+    case ftPContRange:
+       httpHdrContRangePackInto(e->field.v_pcont_range, p);
        break;
     case ftPExtField:
        packerPrintf(p, "%s", e->field.v_pefield->value);
@@ -1082,6 +1094,8 @@ httpHeaderEntryIsValid(const HttpHeaderEntry * e)
        return e->field.v_pcc != NULL;
     case ftPRange:
        return e->field.v_prange != NULL;
+    case ftPContRange:
+       return e->field.v_pcont_range != NULL;
     case ftPExtField:
        return e->field.v_pefield != NULL;
     default:
@@ -1125,6 +1139,8 @@ httpHeaderFieldDup(field_type type, field_store value)
        return ptrField(httpHdrCcDup(value.v_pcc));
     case ftPRange:
        return ptrField(httpHdrRangeDup(value.v_prange));
+    case ftPContRange:
+       return ptrField(httpHdrContRangeDup(value.v_pcont_range));
     case ftPExtField:
        return ptrField(httpHdrExtFieldDup(value.v_pefield));
     default:
@@ -1149,6 +1165,7 @@ httpHeaderFieldBadValue(field_type type)
        return strField(StringNull);
     case ftPCc:
     case ftPRange:
+    case ftPContRange:
     case ftPExtField:
        return ptrField(NULL);
     case ftInvalid:
index ab1e88f9d4aefdd09b4ad3af752d209e4d87d8ab..6126de5e153ce0edcd395873e23ea2fcdb7a7e09 100644 (file)
@@ -1,7 +1,7 @@
 #
 #  Makefile for the Squid Object Cache server
 #
-#  $Id: Makefile.in,v 1.131 1998/03/08 18:58:41 rousskov Exp $
+#  $Id: Makefile.in,v 1.132 1998/03/08 21:02:09 rousskov Exp $
 #
 #  Uncomment and customize the following to suit your needs:
 #
@@ -93,6 +93,7 @@ OBJS          = \
                HttpHdrExtField.o \
                HttpHdrCc.o \
                HttpHdrRange.o \
+               HttpHdrContRange.o \
                HttpHeader.o \
                HttpHeaderTools.o \
                HttpBody.o \
index f4c5cd6f93e27977ea60387aa164e86d5f79c2ed..0475644534279ccdde2269a94c38c719c35c2630 100644 (file)
@@ -174,6 +174,7 @@ typedef enum {
     HDR_CONTENT_ENCODING,
     HDR_CONTENT_LENGTH,
     HDR_CONTENT_MD5,
+    HDR_CONTENT_RANGE,
     HDR_CONTENT_TYPE,
     HDR_DATE,
     HDR_ETAG,
@@ -213,14 +214,11 @@ typedef enum {
 typedef enum {
     ftInvalid = HDR_ENUM_END,  /* to catch nasty errors with hdr_id<->fld_type clashes */
     ftInt,
-#if OLD_CODE
-    ftPChar,
-#else
     ftStr,
-#endif
     ftDate_1123,
     ftPCc,
     ftPRange,
+    ftPContRange,
     ftPExtField
 } field_type;
 
@@ -483,6 +481,7 @@ typedef enum {
     MEM_HTTP_HDR_CC,
     MEM_HTTP_HDR_RANGE_SPEC,
     MEM_HTTP_HDR_RANGE,
+    MEM_HTTP_HDR_CONTENT_RANGE,
     MEM_HTTPSTATEDATA,
     MEM_ICPUDPDATA,
     MEM_CLIENTHTTPREQUEST,
index 6f4a7b36cf09d5d958b65e4c4882abf7edca42c4..8de76521f1384830f7a0434ccfba2a96d736c613 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: mem.cc,v 1.15 1998/03/07 20:46:18 rousskov Exp $
+ * $Id: mem.cc,v 1.16 1998/03/08 21:02:10 rousskov Exp $
  *
  * DEBUG: section 13    High Level Memory Pool Management
  * AUTHOR: Harvest Derived
@@ -217,6 +217,7 @@ memInit(void)
     memDataInit(MEM_HTTP_HDR_CC, "HttpHdrCc", sizeof(HttpHdrCc), 0);
     memDataInit(MEM_HTTP_HDR_RANGE_SPEC, "HttpHdrRangeSpec", sizeof(HttpHdrRangeSpec), 0);
     memDataInit(MEM_HTTP_HDR_RANGE, "HttpHdrRange", sizeof(HttpHdrRange), 0);
+    memDataInit(MEM_HTTP_HDR_CONTENT_RANGE, "HttpHdrContRange", sizeof(HttpHdrContRange), 0);
     memDataInit(MEM_ICPUDPDATA, "icpUdpData", sizeof(icpUdpData), 0);
     memDataInit(MEM_ICP_COMMON_T, "icp_common_t", sizeof(icp_common_t), 0);
     memDataInit(MEM_ICP_PING_DATA, "icp_ping_data", sizeof(icp_ping_data), 0);
index 5f1afd1f7df4ccce138f1f9b4ccd4b21bb24dc19..78b7cd919754388afbd143ca257f4cd0794899d2 100644 (file)
@@ -273,7 +273,7 @@ extern HttpHdrCc *httpHdrCcCreate();
 extern HttpHdrCc *httpHdrCcParseCreate(const char *str);
 extern void httpHdrCcDestroy(HttpHdrCc * cc);
 extern HttpHdrCc *httpHdrCcDup(const HttpHdrCc * cc);
-extern void httpHdrCcPackValueInto(const HttpHdrCc * cc, Packer * p);
+extern void httpHdrCcPackInto(const HttpHdrCc * cc, Packer * p);
 extern void httpHdrCcJoinWith(HttpHdrCc * cc, const HttpHdrCc * new_cc);
 extern void httpHdrCcUpdateStats(const HttpHdrCc * cc, StatHist * hist);
 extern void httpHdrCcStatDumper(StoreEntry * sentry, int idx, double val, double size, int count);
@@ -284,11 +284,18 @@ extern HttpHdrRange *httpHdrRangeParseCreate(const char *range_spec);
 extern int httpHdrRangeParseInit(HttpHdrRange *range, const char *range_spec);
 extern void httpHdrRangeDestroy(HttpHdrRange *range);
 extern HttpHdrRange *httpHdrRangeDup(const HttpHdrRange * range);
-extern void httpHdrRangePackValueInto(const HttpHdrRange * range, Packer * p);
+extern void httpHdrRangePackInto(const HttpHdrRange * range, Packer * p);
 extern void httpHdrRangeJoinWith(HttpHdrRange * range, const HttpHdrRange * new_range);
 /* iterate through specs */
 extern int httpHdrRangeGetSpec(const HttpHdrRange *range, HttpHdrRangeSpec *spec, int *pos);
 
+/* Http Content Range Header Field */
+extern HttpHdrContRange *httpHdrContRangeParseCreate(const char *crange_spec);
+/* returns true if range is valid; inits HttpHdrContRange */
+extern int httpHdrContRangeParseInit(HttpHdrContRange *crange, const char *crange_spec);
+extern void httpHdrContRangeDestroy(HttpHdrContRange *crange);
+extern HttpHdrContRange *httpHdrContRangeDup(const HttpHdrContRange * crange);
+extern void httpHdrContRangePackInto(const HttpHdrContRange * crange, Packer * p);
 
 /* Http Header Tools */
 extern int httpHeaderIdByName(const char *name, int name_len, const field_attrs_t * attrs, int end, int mask);
@@ -324,6 +331,7 @@ extern int httpHeaderGetInt(const HttpHeader * hdr, http_hdr_type id);
 extern time_t httpHeaderGetTime(const HttpHeader * hdr, http_hdr_type id);
 extern HttpHdrCc *httpHeaderGetCc(const HttpHeader * hdr);
 extern HttpHdrRange *httpHeaderGetRange(const HttpHeader * hdr);
+extern HttpHdrContRange *httpHeaderGetContRange(const HttpHeader * hdr);
 extern const char *httpHeaderGetStr(const HttpHeader * hdr, http_hdr_type id);
 int httpHeaderDelFields(HttpHeader * hdr, const char *name);
 /* store report about current header usage and other stats */
index ef39968700ec77731dfb0bd33ed3a5a088af0303..6d8474b82895b03498f55cdd23fc5dcc967e82c1 100644 (file)
@@ -501,6 +501,13 @@ struct _HttpHdrRange {
     Stack specs;
 };
 
+/* http content-range header field */
+struct _HttpHdrContRange {
+    HttpHdrRangeSpec spec;
+    size_t elength; /* entity length, not content length */
+};
+
+
 /* a storage for an entry of one of possible types (for lower level routines) */
 union _field_store {
     int v_int;
@@ -508,6 +515,7 @@ union _field_store {
     String v_str;
     HttpHdrCc *v_pcc;
     HttpHdrRange *v_prange;
+    HttpHdrContRange *v_pcont_range;
     HttpHdrExtField *v_pefield;
 };
 
index f5628af58e1e81fa883255cb37719e448e680f77..b1f3b53dba3b9550075599fcbec43bc3a418e665 100644 (file)
@@ -56,6 +56,7 @@ typedef struct _HttpHeader HttpHeader;
 typedef struct _HttpHdrCc HttpHdrCc;
 typedef struct _HttpHdrRangeSpec HttpHdrRangeSpec;
 typedef struct _HttpHdrRange HttpHdrRange;
+typedef struct _HttpHdrContRange HttpHdrContRange;
 typedef struct _HttpHdrExtField HttpHdrExtField;
 typedef struct _HttpHeaderEntry HttpHeaderEntry;
 typedef struct _HttpHeaderFieldStat HttpHeaderFieldStat;