]> code.citadel.org Git - citadel.git/blobdiff - webcit/fmt_date.c
Clean up the RSS feed. Attempt to read If-Modified-Since header.
[citadel.git] / webcit / fmt_date.c
index 2b6148954905a90be9d344980a14275a1ffb98a9..70efe6c2879cfb26e42db88cbfb9662d9e127273 100644 (file)
@@ -145,6 +145,86 @@ void httpdate(char *buf, time_t thetime)
 }
 
 
-
-
-
+/*
+ * Break down the timestamp used in HTTP headers
+ * Should read rfc1123 and rfc850 dates OK
+ * FIXME won't read asctime
+ * Doesn't understand timezone, but we only should be using GMT/UTC anyway
+ */
+time_t httpdate_to_timestamp(const char *buf)
+{
+       time_t t = 0;
+       struct tm tt;
+       char *c;
+
+lprintf(3, "datestamp %s\n", buf);
+       /* Skip day of week, to number */
+       for (c = buf; *c < '0' && *c > '9'; c++)
+               ;
+
+       /* Get day of month */
+       tt.tm_mday = 0;
+       for (; *c != ' ' && *c != '-'; c++)
+               tt.tm_mday += 10 * (*c - '0');
+       c++;
+
+       /* Get month */
+       switch (*c) {
+       case 'A':       /* April, August */
+               tt.tm_mon = (c[1] == 'p') ? 3 : 7;
+               break;
+       case 'D':       /* December */
+               tt.tm_mon = 11;
+               break;
+       case 'F':       /* February */
+               tt.tm_mon = 1;
+               break;
+       case 'M':       /* March, May */
+               tt.tm_mon = (c[2] == 'r') ? 2 : 4;
+               break;
+       case 'J':       /* January, June, July */
+               tt.tm_mon = (c[2] == 'n') ? ((c[1] == 'a') ? 0 : 5) : 6;
+               break;
+       case 'N':       /* November */
+               tt.tm_mon = 10;
+               break;
+       case 'O':       /* October */
+               tt.tm_mon = 9;
+               break;
+       case 'S':       /* September */
+               tt.tm_mon = 8;
+               break;
+       default:
+               return 0;
+               break;  /* NOTREACHED */
+       }
+       c += 4;
+
+       /* Get year */
+       for (; *c != ' '; c++)
+               tt.tm_year += 10 * (*c - '0');
+       c++;
+       /* Y2K business for rfc850 dates */
+       if (tt.tm_year > 69)
+               tt.tm_year += 1900;
+       else
+               tt.tm_year += 2000;
+
+       /* Get hour */
+       for (; *c != ':'; c++)
+               tt.tm_hour += 10 * (*c - '0');
+       c++;
+
+       /* Get minute */
+       for (; *c != ':'; c++)
+               tt.tm_min += 10 * (*c - '0');
+       c++;
+
+       /* Get second */
+       for (; *c && *c != ' '; c++)
+               tt.tm_sec += 10 * (*c - '0');
+
+       /* Got everything; let's go */
+       t = mktime(&tt);
+       return t;
+}