expires = cookie_ParseDate(date);
if (!downgrade || ((unsigned)cookie_ParseDate(date) <= (unsigned)get_current_time())) { expires = cookie_ParseDate(date); }
COOKIE_SetCookieStringFromHttp(char * curURL, char * firstURL, nsIPrompt *aPrompter, const char * setCookieHeader, char * server_date, nsIIOService* ioService, nsIHttpChannel* aHttpChannel) {  /* allow for multiple cookies separated by newlines */   char *newline = PL_strchr(setCookieHeader, '\n');   if(newline) {     *newline = '\0';     COOKIE_SetCookieStringFromHttp(curURL, firstURL, aPrompter, setCookieHeader, server_date, ioService, aHttpChannel);     *newline = '\n';     COOKIE_SetCookieStringFromHttp(curURL, firstURL, aPrompter, newline+1, server_date, ioService, aHttpChannel);     return;   }  /* If the outputFormat is not PRESENT (the url is not going to the screen), and not   *  SAVE AS (shift-click) then    *  the cookie being set is defined as inline so we need to do what the user wants us   *  to based on his preference to deal with foreign cookies. If it's not inline, just set   *  the cookie.   */  char *ptr=nsnull;  time_t gmtCookieExpires=0, expires=0, sDate;  PRBool downgrade = PR_FALSE;  /* check to see if P3P pref is satisfied */  if (cookie_GetBehaviorPref() == PERMISSION_P3P) {    PRInt32 decision = cookie_P3PDecision(curURL, firstURL, ioService, aHttpChannel);    if (decision == P3P_Reject) {      return;    }    if (decision == P3P_Downgrade) {      downgrade = PR_TRUE;    }  }   /* check for foreign cookie if pref says to reject such */  if ((cookie_GetBehaviorPref() == PERMISSION_DontAcceptForeign) &&      cookie_isForeign(curURL, firstURL, ioService)) {    /* it's a foreign cookie so don't set the cookie */    return;  }  /* Determine when the cookie should expire. This is done by taking the difference between    * the server time and the time the server wants the cookie to expire, and adding that    * difference to the client time. This localizes the client time regardless of whether or   * not the TZ environment variable was set on the client.   */  /* Get the time the cookie is supposed to expire according to the expires attribute*/  ptr = PL_strcasestr(setCookieHeader, "expires=");  if(ptr && !downgrade) {    char *date =  ptr+8;    char origLast = '\0';    for(ptr=date; *ptr != '\0'; ptr++) {      if(*ptr == ';') {        origLast = ';';        *ptr = '\0';        break;      }    }    expires = cookie_ParseDate(date);    *ptr=origLast;  }  if (server_date) {    sDate = cookie_ParseDate(server_date);  } else {    sDate = get_current_time();  }  if( sDate && expires ) {    if( expires < sDate ) {      gmtCookieExpires=1;    } else {      gmtCookieExpires = expires - sDate + get_current_time();      // if overflow       if( gmtCookieExpires < get_current_time()) {        gmtCookieExpires = (((unsigned) (~0) << 1) >> 1); // max int       }    }  }  /* If max-age attribute is present, it overrides expires attribute */#define MAXAGE "max-age="  ptr = PL_strcasestr(setCookieHeader, MAXAGE);  if(ptr && !downgrade) {    ptr += PL_strlen(MAXAGE);    gmtCookieExpires = get_current_time() + atoi(ptr);  }  cookie_SetCookieString(curURL, aPrompter, setCookieHeader, gmtCookieExpires, ioService, aHttpChannel);}