PRBool openalready = PR_FALSE;
NS_IMETHODIMP nsProfile::ProcessPREGInfo(const char* data){	nsresult rv = NS_OK;    PRBool openalready = PR_FALSE;     	nsString aCookie(data);	char *pregCookie = nsnull;	char *profileName = nsnull;	char *service_denial = nsnull;	if ( (aCookie.ToNewCString()) != nsnull )	{		pregCookie = PL_strstr(aCookie.ToNewCString(), PREG_COOKIE);		//In the original scenario you must UnEscape the string		//PL_strstr(nsUnescape(uregCookie),PREG_USERNAME);		if (pregCookie)		{			profileName		= PL_strstr(pregCookie, PREG_USERNAME);			service_denial	= PL_strstr(pregCookie, PREG_DENIAL);		}	}	else	{		// cookie information is not available		return NS_ERROR_FAILURE;	}	nsAutoString pName;	nsAutoString serviceState;	if (profileName) 		pName.SetString(profileName);	if (service_denial) 		serviceState.SetString(service_denial);	int profileNameIndex, delimIndex;	int serviceIndex;	nsString userProfileName, userServiceDenial;	if (pName.Length())	{		profileNameIndex = pName.Find("=", 0);		delimIndex    = pName.Find("[-]", profileNameIndex-1);    		pName.Mid(userProfileName, profileNameIndex+1,delimIndex-(profileNameIndex+1));#if defined(DEBUG_profile)  		printf("\nProfiles : PREG Cookie user profile name = %s\n", userProfileName.ToNewCString());#endif	}	if (serviceState.Length())	{		serviceIndex  = serviceState.Find("=", 0);		delimIndex    = serviceState.Find("[-]", serviceIndex-1);		serviceState.Mid(userServiceDenial, serviceIndex+1,delimIndex-(serviceIndex+1));#if defined(DEBUG_profile)  		printf("\nProfiles : PREG Cookie netcenter service option = %s\n", userServiceDenial.ToNewCString());#endif	}	// User didn't provide any information.	// No Netcenter info is available.	// User will hit the Preg info screens on the next run.	if ((userProfileName.mLength == 0) && (userServiceDenial.mLength == 0))		return NS_ERROR_FAILURE;	// If user denies registration, ignore the information entered.	if (userServiceDenial.mLength > 0)		userProfileName.SetString("");	char *curProfile = nsnull;	rv = GetCurrentProfile(&curProfile);	if (NS_SUCCEEDED(rv))	{		if (userProfileName.mLength > 0)			rv = RenameProfile(curProfile, userProfileName.ToNewCString());		if (NS_SUCCEEDED(rv))		{		    // Check result.			if (m_reg != nsnull)			{				// Open the registry.				rv = m_reg->IsOpen( &openalready );						if ( !openalready )					rv = m_reg->OpenDefault();    				if (NS_SUCCEEDED(rv))				{					nsIRegistry::Key key;					rv = m_reg->GetSubtree(nsIRegistry::Common, "Profiles", &key);					if (NS_SUCCEEDED(rv))					{						nsIRegistry::Key newKey;								if (userProfileName.mLength > 0)						{							rv = m_reg->GetSubtree(key, userProfileName.ToNewCString(), &newKey);											if (NS_SUCCEEDED(rv))							{								// Register new info								rv = m_reg->SetString(newKey, "NCProfileName", userProfileName.ToNewCString());							}							else							{#if defined(DEBUG_profile)									printf("Profiles : Could not set NetCenter properties.\n" );#endif							}														rv = m_reg->SetString(key, "CurrentProfile", userProfileName.ToNewCString());							if (NS_FAILED(rv))							{#if defined(DEBUG_profile)									printf("Couldn't set CurrentProfile name.\n" );#endif							}						}					}					else					{#if defined(DEBUG_profile)							printf("Registry : Couldn't get Profiles subtree.\n");#endif					}					if (userServiceDenial.mLength > 0)						rv = m_reg->SetString(key, "NCServiceDenial", userServiceDenial.ToNewCString());					rv = m_reg->SetString(key, "HavePregInfo", "true");					if (NS_FAILED(rv))					{#if defined(DEBUG_profile)							printf("Couldn't set Preg info flag.\n" );#endif					}					if (!openalready)						m_reg->Close();				}				else				{#if defined(DEBUG_profile)						printf("Couldn't open registry.\n");#endif				}			}			else			{#if defined(DEBUG_profile)					printf("Registry Object is NULL.\n");#endif				return NS_ERROR_FAILURE;			}		}	}	return rv;}