PRInt32 profileNameIndex, delimIndex; PRInt32 serviceIndex;
int profileNameIndex, delimIndex; int serviceIndex;
NS_IMETHODIMP nsProfile::ProcessPREGInfo(const char* data){	nsresult rv = NS_OK;  	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);	PRInt32 profileNameIndex, delimIndex;	PRInt32 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("");    rv = OpenRegistry();    if (NS_FAILED(rv)) return rv;    	char *curProfile = nsnull;	rv = GetCurrentProfile(&curProfile);	if (NS_SUCCEEDED(rv))	{		if (userProfileName.mLength > 0)			rv = RenameProfile(curProfile, userProfileName.ToNewCString());		if (NS_SUCCEEDED(rv))		{            nsRegistryKey key;                        rv = m_reg->GetSubtree(nsIRegistry::Common, REGISTRY_PROFILE_SUBTREE_STRING, &key);                        if (NS_SUCCEEDED(rv))                {                    nsRegistryKey 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, REGISTRY_NC_PROFILE_NAME_STRING, userProfileName.ToNewCString());                                }							else                                {#if defined(DEBUG_profile)									printf("Profiles : Could not set NetCenter properties.\n" );#endif                                }														rv = m_reg->SetString(key, REGISTRY_CURRENT_PROFILE_STRING, 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, REGISTRY_NC_SERVICE_DENIAL_STRING, userServiceDenial.ToNewCString());                        rv = m_reg->SetString(key, REGISTRY_HAVE_PREG_INFO_STRING, REGISTRY_TRUE_STRING);                        if (NS_FAILED(rv))                {#if defined(DEBUG_profile)                    printf("Couldn't set Preg info flag.\n" );#endif                }        }	}    PR_FREEIF(curProfile);	return rv;}