nsCOMPtr<nsIPrefService> pserv(do_QueryInterface(prefs)); if (pserv) {      PRBool engineIsNotDefault = PR_FALSE; nsCOMPtr<nsIPrefBranch> rootBranch(do_QueryInterface(pserv)); nsCOMPtr<nsIPrefBranch> defaultBranch; pserv->GetDefaultBranch("", getter_AddRefs(defaultBranch));  if (defaultBranch) { nsXPIDLString defaultEngineNameStr; nsCOMPtr<nsIPrefLocalizedString> defaultEngineName; rv = defaultBranch->GetComplexValue("browser.search.defaultenginename", NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(defaultEngineName)); defaultEngineName->GetData(getter_Copies(defaultEngineNameStr));  nsXPIDLString selectedEngineNameStr; nsCOMPtr<nsIPrefLocalizedString> selectedEngineName; rv = rootBranch->GetComplexValue("browser.search.selectedEngine", NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(selectedEngineName)); if (selectedEngineName) { selectedEngineName->GetData(getter_Copies(selectedEngineNameStr)); engineIsNotDefault = !defaultEngineNameStr.Equals(selectedEngineNameStr); } else { engineIsNotDefault = PR_FALSE;    } }  PRInt32 i = 0; char prefNameBuf[1096]; do { ++i; sprintf(prefNameBuf, "browser.search.param.%s.%d.", NS_ConvertUCS2toUTF8(engineName).get(), i);  nsCOMPtr<nsIPrefBranch> pb; rv = pserv->GetBranch(prefNameBuf, getter_AddRefs(pb)); if (NS_FAILED(rv)) break;  nsCOMPtr<nsIPrefLocalizedString> parameter; nsXPIDLString parameterStr; rv = pb->GetComplexValue(engineIsNotDefault ? "custom" : "default", NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(parameter)); if (NS_FAILED(rv)) break;  parameter->GetData(getter_Copies(parameterStr));  if (!parameterStr.IsEmpty()) { if (!input.IsEmpty()) input.Append(NS_LITERAL_STRING("&")); input += parameterStr; } } while (1);   nsCOMPtr<nsIStringBundleService> stringService(do_GetService(NS_STRINGBUNDLE_CONTRACTID)); nsCOMPtr<nsIStringBundle> bundle; rv = stringService->CreateBundle(SEARCHCONFIG_PROPERTIES, getter_AddRefs(bundle)); nsCOMPtr<nsIStringBundle> intlBundle; rv = stringService->CreateBundle(INTL_PROPERTIES, getter_AddRefs(intlBundle));  nsXPIDLString langName; intlBundle->GetStringFromName(NS_LITERAL_STRING("general.useragent.locale").get(), getter_Copies(langName));  nsAutoString keyTemplate(NS_LITERAL_STRING("browser.search.param.")); keyTemplate += engineName; keyTemplate.Append(NS_LITERAL_STRING(".release"));  nsXPIDLString releaseValue; NS_NAMED_LITERAL_STRING(distributionID, MOZ_DISTRIBUTION_ID); const PRUnichar* strings[] = { distributionID.get(), langName.get() }; bundle->FormatStringFromName(keyTemplate.get(), strings, 2, getter_Copies(releaseValue));  if (!releaseValue.IsEmpty()) { if (!input.IsEmpty()) input.Append(NS_LITERAL_STRING("&")); input += releaseValue; }   nsCOMPtr<nsIPrefBranch> pb; rv = pserv->GetBranch("", getter_AddRefs(pb)); if (NS_FAILED(rv)) return rv;  i = 0; do { ++i; sprintf(prefNameBuf, "browser.search.order.%d", i);  nsCOMPtr<nsIPrefLocalizedString> orderEngineName; rv = pb->GetComplexValue(prefNameBuf, NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(orderEngineName)); if (NS_FAILED(rv)) break;  nsXPIDLString orderEngineNameStr; orderEngineName->GetData(getter_Copies(orderEngineNameStr)); if (orderEngineNameStr.Equals(engineName)) break; } while (PR_TRUE);  if (NS_SUCCEEDED(rv)) { sprintf(prefNameBuf, "browser.search.order.%s.%d", NS_ConvertUCS2toUTF8(engineName).get(), i);  nsCOMPtr<nsIPrefLocalizedString> orderParam; rv = rootBranch->GetComplexValue(prefNameBuf, NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(orderParam)); if (NS_FAILED(rv)) { sprintf(prefNameBuf, "browser.search.order.%s", NS_ConvertUCS2toUTF8(engineName).get()); rv = rootBranch->GetComplexValue(prefNameBuf, NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(orderParam)); }  if (NS_SUCCEEDED(rv)) { nsXPIDLString orderParamStr; orderParam->GetData(getter_Copies(orderParamStr));  if (!orderParamStr.IsEmpty()) { if (!input.IsEmpty()) input.Append(NS_LITERAL_STRING("&")); input += orderParamStr; } } }  rv = NS_OK; }
InternetSearchDataSource::GetInputs(const nsString &data, nsString &userVar,					const nsString &text, nsString &input){	nsAutoString	buffer(data);	nsresult	rv = NS_OK;	PRBool		inSection = PR_FALSE;	while(buffer.Length() > 0)	{		PRInt32 eol = buffer.FindCharInSet("\r\n", 0);		if (eol < 0)	break;		nsAutoString	line("");		if (eol > 0)		{			buffer.Left(line, eol);		}		buffer.Cut(0, eol+1);		if (line.Length() < 1)	continue;		// skip empty lines		if (line[0] == PRUnichar('#'))	continue;	// skip comments		line = line.Trim(" \t");		if (inSection == PR_FALSE)		{			if (line[0] != PRUnichar('<'))	continue;			line.Cut(0, 1);			inSection = PR_TRUE;		}		PRInt32	len = line.Length();		if (len > 0)		{			if (line[len-1] == PRUnichar('>'))			{				inSection = PR_FALSE;				line.SetLength(len-1);			}		}		if (inSection == PR_TRUE)	continue;		// look for inputs		if (line.Find("input", PR_TRUE) == 0)		{			line.Cut(0, 6);			line = line.Trim(" \t");						// first look for name attribute			nsAutoString	nameAttrib("");			PRInt32	nameOffset = line.Find("name", PR_TRUE);			if (nameOffset >= 0)			{				PRInt32 equal = line.FindChar(PRUnichar('='), PR_TRUE, nameOffset);				if (equal >= 0)				{					PRInt32	startQuote = line.FindChar(PRUnichar('\"'), PR_TRUE, equal + 1);					if (startQuote >= 0)					{						PRInt32	endQuote = line.FindChar(PRUnichar('\"'), PR_TRUE, startQuote + 1);						if (endQuote > 0)						{							line.Mid(nameAttrib, startQuote+1, endQuote-startQuote-1);						}					}					else					{						nameAttrib = line;						nameAttrib.Cut(0, equal+1);						nameAttrib = nameAttrib.Trim(" \t");						PRInt32 space = nameAttrib.FindCharInSet(" \t", 0);						if (space > 0)						{							nameAttrib.Truncate(space);						}					}				}			}			if (nameAttrib.Length() <= 0)	continue;			// first look for value attribute			nsAutoString	valueAttrib("");			PRInt32	valueOffset = line.Find("value", PR_TRUE);			if (valueOffset >= 0)			{				PRInt32 equal = line.FindChar(PRUnichar('='), PR_TRUE, valueOffset);				if (equal >= 0)				{					PRInt32	startQuote = line.FindChar(PRUnichar('\"'), PR_TRUE, equal + 1);					if (startQuote >= 0)					{						PRInt32	endQuote = line.FindChar(PRUnichar('\"'), PR_TRUE, startQuote + 1);						if (endQuote >= 0)						{							line.Mid(valueAttrib, startQuote+1, endQuote-startQuote-1);						}					}					else					{						// if value attribute's "value" isn't quoted, get the first word... ?						valueAttrib = line;						valueAttrib.Cut(0, equal+1);						valueAttrib = valueAttrib.Trim(" \t");						PRInt32 space = valueAttrib.FindCharInSet(" \t>", 0);						if (space > 0)						{							valueAttrib.Truncate(space);						}					}				}			}			else if (line.Find("user", PR_TRUE) >= 0)			{				userVar = nameAttrib;				valueAttrib = text;			}						// XXX should ignore if  mode=browser  is specified			// XXX need to do this better			if (line.RFind("mode=browser", PR_TRUE) >= 0)				continue;			if ((nameAttrib.Length() > 0) && (valueAttrib.Length() > 0))			{				if (input.Length() > 0)				{					input += "&";				}				input += nameAttrib;				input += "=";				input += valueAttrib;			}		}	}	return(rv);}