int main() { void *ed; char buf[1024],*r,datebuf[32]; printf("%ld\n",date2secs("2011-04-05 10:33:28")); printf("%ld\n",date2secs("2011-4-5 10:33:28")); printf("%ld\n",http_atotm("Fri, 15 Apr 2011 2:33:28 GMT")); ed = extract_date_init(); if(!ed) return 0; while(fgets(buf,1024,stdin)) { trim(buf); if(strcasecmp("exit",buf) == 0) break; r = extract_date(ed,buf,datebuf); if(r) printf("DATE: %s\n",datebuf); else printf("No DATE\n"); } extract_date_free(ed); return 0; }
static int update_cookie_field (struct cookie *cookie, const char *name_b, const char *name_e, const char *value_b, const char *value_e) { assert (name_b != NULL && name_e != NULL); if (!cookie->attr) { if (!VALUE_EXISTS) return 0; cookie->attr = strdupdelim (name_b, name_e); cookie->value = strdupdelim (value_b, value_e); return 1; } if (NAME_IS ("domain")) { if (!VALUE_NON_EMPTY) return 0; FREE_MAYBE (cookie->domain); cookie->domain = strdupdelim (value_b, value_e); return 1; } else if (NAME_IS ("path")) { if (!VALUE_NON_EMPTY) return 0; FREE_MAYBE (cookie->path); cookie->path = strdupdelim (value_b, value_e); return 1; } else if (NAME_IS ("expires")) { char *value_copy; time_t expires; if (!VALUE_NON_EMPTY) return 0; BOUNDED_TO_ALLOCA (value_b, value_e, value_copy); expires = http_atotm (value_copy); if (expires != -1) { cookie->permanent = 1; cookie->expiry_time = (unsigned long)expires; } else /* Error in expiration spec. Assume default (cookie valid for this session.) #### Should we return 0 and invalidate the cookie? */ ; /* According to netscape's specification, expiry time in the past means that discarding of a matching cookie is requested. */ if (cookie->expiry_time < cookies_now) cookie->discard_requested = 1; return 1; } else if (NAME_IS ("max-age")) { double maxage = -1; char *value_copy; if (!VALUE_NON_EMPTY) return 0; BOUNDED_TO_ALLOCA (value_b, value_e, value_copy); sscanf (value_copy, "%lf", &maxage); if (maxage == -1) /* something is wrong. */ return 0; cookie->permanent = 1; cookie->expiry_time = (unsigned long)cookies_now + (unsigned long)maxage; /* According to rfc2109, a cookie with max-age of 0 means that discarding of a matching cookie is requested. */ if (maxage == 0) cookie->discard_requested = 1; return 1; } else if (NAME_IS ("secure")) { /* ignore value completely */ cookie->secure = 1; return 1; } else /* Unrecognized attribute; ignore it. */ return 1; }