StrAllocCat(rv, "; BP=");
StrAllocCat(rv, "; "); StrAllocCat(rv, "BP=");
NET_GetCookie(MWContext * context, char * address){	char *name=0;	char *host = NET_ParseURL(address, GET_HOST_PART);	char *path = NET_ParseURL(address, GET_PATH_PART);    XP_List * list_ptr;    net_CookieStruct * cookie_s;	Bool first=TRUE;	HG26748	time_t cur_time = time(NULL);	int host_length;	int domain_length;	/* return string to build */	char * rv=0;	/* disable cookie's if the user's prefs say so	 */	if(NET_GetCookieBehaviorPref() == NET_DontUse)		return NULL;	HG98476	/* search for all cookies	 */	net_lock_cookie_list();	list_ptr = net_cookie_list;    while((cookie_s = (net_CookieStruct *) XP_ListNextObject(list_ptr))!=0)      {		if(!cookie_s->host)			continue;		/* check the host or domain first		 */		if(cookie_s->is_domain)		  {			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 secure and the path isn't			 * dont send it			 */			HG83764						/* check for expired cookies			 */			if( cookie_s->expires && (cookie_s->expires < cur_time) )			  {				/* expire and remove the cookie 				 */		   		net_FreeCookie(cookie_s);				/* start the list parsing over :(				 * we must also start the string over				 */				PR_FREEIF(rv);				rv = NULL;				list_ptr = net_cookie_list;				first = TRUE; /* reset first */				continue;			  }			if(first)				first = FALSE;			else				StrAllocCat(rv, "; ");						if(cookie_s->name && *cookie_s->name != '\0')			  {				cookie_s->last_accessed = 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);			  }          }	  }#if defined(MOZ_BRPROF)    /*     * Okay, this is a horrible hack. It looks for a URL with     * 'iiop/BRPROF' in it (our little browsing profile reader), and     * if it finds it, it uploads the browsing profile cookie.     *     * The _real_ way to do this would be to     *     * 1) See if the user has enabled the preference to even allow us     *    to send out the cookie to _anyone_.     *     * 2) See if the specific site has asked for and received     *    permission to be sent the cookie.     */    if (PL_strstr(address, "iiop/BRPROF")) {      extern PRBool BP_GetProfile(char* *aProfileCookie);      char* profile;      if (BP_GetProfile(&profile)) {        if (! first)          StrAllocCat(rv, "; BP=");        StrAllocCat(rv, profile);        PL_strfree(profile);      }    }#endif    	  net_unlock_cookie_list();	PR_FREEIF(name);	PR_Free(path);	PR_Free(host);	/* may be NULL */	return(rv);}