int domain_length;
COOKIE_GetCookie(char * address) {  char *name=0;  cookie_CookieStruct * cookie_s;  PRBool first=PR_TRUE;  PRBool xxx = PR_FALSE;  time_t cur_time = get_current_time();  int host_length;  int domain_length;  /* return string to build */  char * rv=0;  /* disable cookies if the user's prefs say so */  if(COOKIE_GetBehaviorPref() == COOKIE_DontUse) {    return NULL;  }  if (!PL_strncasecmp(address, "https", 5)) {     xxx = PR_TRUE;  }  /* search for all cookies */  cookie_LockList();  if (cookie_cookieList == nsnull) {    cookie_UnlockList();    return NULL;  }  char *host = cookie_ParseURL(address, GET_HOST_PART);  char *path = cookie_ParseURL(address, GET_PATH_PART);  PRInt32 count = cookie_cookieList->Count();  for (PRInt32 i = 0; i < count; ++i) {    cookie_s = NS_STATIC_CAST(cookie_CookieStruct*, cookie_cookieList->ElementAt(i));    if (cookie_s == nsnull) {      continue;    }    if(!cookie_s->host) {      continue;    }    /* check the host or domain first */    if(cookie_s->isDomain) {      char *cp;      domain_length = PL_strlen(cookie_s->host);      /* calculate the host length by looking at all characters up to a       * colon or '\0'.  That way we won't include port numbers in domains       */      for(cp=host; *cp != '\0' && *cp != ':'; cp++) {        ; /* null body */       }      host_length = cp - host;      if(domain_length > host_length ||          PL_strncasecmp(cookie_s->host, &host[host_length - domain_length], domain_length)) {//      HG20476 -- @@??        /* no match. FAIL */        continue;      }    } else if(PL_strcasecmp(host, cookie_s->host)) {      /* hostname matchup failed. FAIL */      continue;    }    /* shorter strings always come last so there can be no ambiquity */    if(cookie_s->path && !PL_strncmp(path, cookie_s->path, PL_strlen(cookie_s->path))) {      /* if the cookie is xxx and the path isn't, dont send it */      if (cookie_s->xxx & !xxx) {        continue; /* back to top of while */      }      /* check for expired cookies */      if( cookie_s->expires && (cookie_s->expires < cur_time) ) {        /* expire and remove the cookie */        cookie_FreeCookie(cookie_s);        /* start the list parsing over :( we must also start the string over */        PR_FREEIF(rv);        rv = NULL;        i = -1;        first = PR_TRUE; /* reset first */        continue;      }      if(first) {        first = PR_FALSE;      } else {        StrAllocCat(rv, "; ");      }      if(cookie_s->name && *cookie_s->name != '\0') {        cookie_s->lastAccessed = cur_time;        StrAllocCopy(name, cookie_s->name);        StrAllocCat(name, "=");#ifdef PREVENT_DUPLICATE_NAMES        /* make sure we don't have a previous name mapping already in the string */        if(!rv || !PL_strstr(rv, name)) {          StrAllocCat(rv, name);          StrAllocCat(rv, cookie_s->cookie);        }#else        StrAllocCat(rv, name);        StrAllocCat(rv, cookie_s->cookie);#endif /* PREVENT_DUPLICATE_NAMES */      } else {        StrAllocCat(rv, cookie_s->cookie);      }    }  }  cookie_UnlockList();  PR_FREEIF(name);  PR_FREEIF(path);  PR_FREEIF(host);  /* may be NULL */  return(rv);}