if (NS_FAILED(rv = GetData(dataUni, "search", 0, "action", action)))	continue;
if (NS_FAILED(rv = GetData(data, "search", "action", action)))	continue;
InternetSearchDataSource::FindInternetSearchResults(const char *url, PRBool *searchInProgress){	*searchInProgress = PR_FALSE;	if (!mInner)	return(NS_OK);	// if the url doesn't look like a HTTP GET query, just return,	// otherwise strip off the query data	nsAutoString		shortURL;	shortURL.AssignWithConversion(url);	PRInt32			optionsOffset;	if ((optionsOffset = shortURL.FindChar(PRUnichar('?'))) < 0)	return(NS_OK);	shortURL.Truncate(optionsOffset);	// if we haven't already, load in the engines	if (mEngineListBuilt == PR_FALSE)	DeferredInit();	// look in available engines to see if any of them appear	// to match this url (minus the GET options)	PRBool				foundEngine = PR_FALSE;	nsresult			rv;	nsCOMPtr<nsIRDFResource>	engine;	nsCOMPtr<nsISimpleEnumerator>	arcs;	nsAutoString			engineURI;	nsCOMPtr<nsIRDFLiteral>		dataLit;	const PRUnichar			*dataUni = nsnull;	if (NS_SUCCEEDED(rv = mInner->GetTargets(kNC_SearchEngineRoot, kNC_Child,		PR_TRUE, getter_AddRefs(arcs))))	{		PRBool			hasMore = PR_TRUE;		while (hasMore == PR_TRUE)		{			if (NS_FAILED(arcs->HasMoreElements(&hasMore)) || (hasMore == PR_FALSE))				break;			nsCOMPtr<nsISupports>	arc;			if (NS_FAILED(arcs->GetNext(getter_AddRefs(arc))))				break;			engine = do_QueryInterface(arc);			if (!engine)	continue;			const	char	*uri = nsnull;			engine->GetValueConst(&uri);			if (uri)			{				engineURI.AssignWithConversion(uri);			}			if (NS_FAILED(rv = FindData(engine, getter_AddRefs(dataLit))) ||				(rv == NS_RDF_NO_VALUE))	continue;			if (!dataLit)	continue;			dataLit->GetValueConst(&dataUni);			if (!dataUni)	continue;			nsAutoString		action;			if (NS_FAILED(rv = GetData(dataUni, "search", 0, "action", action)))	continue;			if (shortURL.EqualsIgnoreCase(action))			{				foundEngine = PR_TRUE;				break;			}			// extension for engines which can have multiple "actions"			if (NS_FAILED(rv = GetData(dataUni, "browser", 0, "alsomatch", action)))	continue;			if (action.Find(shortURL, PR_TRUE) >= 0)			{				foundEngine = PR_TRUE;				break;			}		}	}	if (foundEngine == PR_TRUE)	{		nsAutoString	searchURL;		searchURL.AssignWithConversion(url);		// look for query option which is the string the user is searching for		nsAutoString	userVar, inputUnused;		if (NS_FAILED(rv = GetInputs(dataUni, userVar, nsAutoString(), inputUnused)))	return(rv);		if (userVar.Length() < 1)	return(NS_RDF_NO_VALUE);		nsAutoString	queryStr;		queryStr.AssignWithConversion("?");		queryStr += userVar;		queryStr.AppendWithConversion("=");		PRInt32		queryOffset;		if ((queryOffset = searchURL.Find(queryStr, PR_TRUE )) < 0)		{			queryStr.AssignWithConversion("&");			queryStr += userVar;			queryStr.AppendWithConversion("=");			queryOffset = searchURL.Find(queryStr, PR_TRUE);		}		nsAutoString	searchText;		if (queryOffset >= 0)		{			PRInt32		andOffset;			searchURL.Right(searchText, searchURL.Length() - queryOffset - queryStr.Length());			if ((andOffset = searchText.FindChar(PRUnichar('&'))) >= 0)			{				searchText.Truncate(andOffset);			}		}		if (searchText.Length() > 0)		{ 			// apply charset conversion to the search text 			if (!mQueryEncodingStr.IsEmpty()) 			{ 				nsCOMPtr<nsITextToSubURI> textToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv); 				if (NS_SUCCEEDED(rv)) 				{ 					nsCAutoString	escapedSearchText; 					escapedSearchText.AssignWithConversion(searchText);					// encoding +'s so as to preserve distinction between + and %2B					escapedSearchText.ReplaceSubstring("%25", "%2B25");					escapedSearchText.ReplaceSubstring("+", "%25"); 					nsCAutoString	aCharset; 					aCharset.AssignWithConversion(mQueryEncodingStr); 					PRUnichar	*uni = nsnull; 					if (NS_SUCCEEDED(rv = textToSubURI->UnEscapeAndConvert(aCharset.get(), escapedSearchText.get(), &uni)) && (uni)) 					{ 						char	*convertedSearchText = nsnull; 						if (NS_SUCCEEDED(rv = textToSubURI->ConvertAndEscape("UTF-8", uni, &convertedSearchText))) 						{							// decoding +'s thereby preserving distinction between + and %2B 							nsCAutoString unescapedSearchText(convertedSearchText);							unescapedSearchText.ReplaceSubstring("%25", "+");							unescapedSearchText.ReplaceSubstring("%2B25", "%25"); 							searchText.AssignWithConversion(unescapedSearchText.get()); 							Recycle(convertedSearchText); 						}						Recycle(uni); 					} 				} 			}			// remember the text of the last search			RememberLastSearchText(searchText.get());			// construct the search query uri			engineURI.InsertWithConversion("internetsearch:engine=", 0);			engineURI.AppendWithConversion("&text=");			engineURI += searchText;#ifdef	DEBUG_SEARCH_OUTPUT			char	*engineMatch = ToNewCString(searchText);			if (engineMatch)			{				printf("FindInternetSearchResults: search for: '%s'\n\n",					engineMatch);				Recycle(engineMatch);				engineMatch = nsnull;			}#endif		}		else		{			// not able to determine engine URI, so just use the search URL			engineURI = searchURL;			// clear the text of the last search			RememberLastSearchText(nsnull);		}		// update "#Ref" on LastSearchRoot		nsCOMPtr<nsIRDFNode>	oldNode;		if (NS_SUCCEEDED(rv = mInner->GetTarget(kNC_LastSearchRoot, kNC_Ref, PR_TRUE,			getter_AddRefs(oldNode))))		{			if (engineURI.Length() > 0)			{				const PRUnichar	*uriUni = engineURI.get();				nsCOMPtr<nsIRDFLiteral>	uriLiteral;				nsresult		temprv;				if ((uriUni) && (NS_SUCCEEDED(temprv = gRDFService->GetLiteral(uriUni,					getter_AddRefs(uriLiteral)))))				{					if (rv != NS_RDF_NO_VALUE)					{						rv = mInner->Change(kNC_LastSearchRoot, kNC_Ref, oldNode, uriLiteral);					}					else					{						rv = mInner->Assert(kNC_LastSearchRoot, kNC_Ref, uriLiteral, PR_TRUE);					}				}			}			else			{				rv = mInner->Unassert(kNC_LastSearchRoot, kNC_Ref, oldNode);			}		}		// forget about any previous search results		ClearResults(PR_FALSE);		// do the search		DoSearch(nsnull, engine, searchURL, nsAutoString());		*searchInProgress = PR_TRUE;	}	return(NS_OK);}