TimeOrTag httpHeaderGetTimeOrTag(const HttpHeader * hdr, http_hdr_type id) { TimeOrTag tot; HttpHeaderEntry *e; assert(Headers[id].type == ftDate_1123_or_ETag); /* must be of an appropriate type */ memset(&tot, 0, sizeof(tot)); if ((e = httpHeaderFindEntry(hdr, id))) { const char *str = strBuf(e->value); /* try as an ETag */ if (*str == '"' || (str[0] == 'W' && str[1] == '/')) { tot.tag = str; tot.time = -1; tot.valid = 1; } else { /* or maybe it is time? */ tot.time = parse_rfc1123(str, strLen(e->value)); if (tot.time >= 0) tot.valid = 1; tot.tag = NULL; } } else { tot.time = -1; } return tot; }
int main() { char *x; time_t t, pt; t = time(NULL); x = mkrfc1123(t); printf("HTTP Time: %s\n", x); pt = parse_rfc1123(x); printf("Parsed: %d vs. %d\n", pt, t); }
time_t httpHeaderGetTime(const HttpHeader * hdr, http_hdr_type id) { HttpHeaderEntry *e; time_t value = -1; assert_eid(id); assert(Headers[id].type == ftDate_1123); /* must be of an appropriate type */ if ((e = httpHeaderFindEntry(hdr, id))) { value = parse_rfc1123(strBuf(e->value)); httpHeaderNoteParsedEntry(e->id, e->value, value < 0); } return value; }
TimeOrTag httpHeaderGetTimeOrTag(const HttpHeader * hdr, http_hdr_type id) { TimeOrTag tot; HttpHeaderEntry *e; assert(Headers[id].type == ftDate_1123_or_ETag); /* must be of an appropriate type */ memset(&tot, 0, sizeof(tot)); if ((e = httpHeaderFindEntry(hdr, id))) { const char *str = strBuf(e->value); /* try as an ETag */ if (etagParseInit(&tot.tag, str)) { tot.valid = tot.tag.str != NULL; tot.time = -1; } else { /* or maybe it is time? */ tot.time = parse_rfc1123(str); tot.valid = tot.time >= 0; tot.tag.str = NULL; } } assert(tot.time < 0 || !tot.tag.str); /* paranoid */ return tot; }