[links-list] Cookies in links

root martian202002 at yahoo.com
Mon Nov 4 08:06:36 PST 2002


Hello,

   I intend to add persistent cookies and possibly a cookie manager
in links. This will require fixing the parse_http_date function
in session.c (currently broken). Here is my proposed fix. Please
comment specifically on platforms where it won't work. I have tested
it in linux and freebsd.

time_t parse_http_date(const char *date)
{
   const char *months[12] =
           {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

   time_t t = 0;

   /* Mon, 03 Jan 2000 21:29:33 GMT <-http time */
   /* Mon, 03-Jan-2000 21:29:33 GMT <-cookie Expire time */ 

   struct tm tm;
   int i;
   char month[4];
   char *oldTZ;
   
   if (!date) return 0;
   i = sscanf(date, "%*[A-Za-z], %2d%*[ -]%3s%*[ -]%4d %2d:%2d:%2d %*s",
               &tm.tm_mday, month, &tm.tm_year,
                   &tm.tm_hour, &tm.tm_min, &tm.tm_sec); 

   if (i != 6) return 0;

   for (tm.tm_mon = 0; tm.tm_mon < 12; tm.tm_mon++)
       if (!strncmp(month, months[tm.tm_mon], 3)) break;
   if (tm.tm_mon == 12) return 0;   
   tm.tm_year -= 1900;
   
   oldTZ = getenv("TZ");
   setenv("TZ", "UTC", 1);
   t = mktime(&tm);
   oldTZ ? setenv("TZ", oldTZ, 1) : unsetenv("TZ");

   if (t == (time_t) - 1) return 0;
   else return t;
}

Regards,

John.
  
-- 
Unsubscribe: send email to links-list-request at linuxfromscratch.org
and put unsubscribe in the subject header of the message



More information about the links-list mailing list