Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Static Private Attributes | Friends
InternetSearchDataSource Class Reference

#include <nsInternetSearchService.h>

Collaboration diagram for InternetSearchDataSource:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIINTERNETSEARCHSERVICE
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIRDFDATASOURCE
NS_DECL_NSIOBSERVER 
InternetSearchDataSource (void)
virtual ~InternetSearchDataSource (void)
NS_METHOD Init ()
void DeferredInit ()

Protected Member Functions

nsresult GetSearchEngineToPing (nsIRDFResource **theResource, nsCString &updateURL)
PRBool isEngineURI (nsIRDFResource *aResource)
PRBool isSearchURI (nsIRDFResource *aResource)
PRBool isSearchCategoryURI (nsIRDFResource *aResource)
PRBool isSearchCategoryEngineURI (nsIRDFResource *aResource)
PRBool isSearchCategoryEngineBasenameURI (nsIRDFNode *aResource)
PRBool isSearchCommand (nsIRDFResource *aResource)
nsresult resolveSearchCategoryEngineURI (nsIRDFResource *source, nsIRDFResource **trueEngine)
nsresult BeginSearchRequest (nsIRDFResource *source, PRBool doNetworkRequest)
nsresult FindData (nsIRDFResource *engine, nsIRDFLiteral **data)
nsresult EngineFileFromResource (nsIRDFResource *aEngineResource, nsILocalFile **aResult)
nsresult updateDataHintsInGraph (nsIRDFResource *engine, const PRUnichar *data)
nsresult updateAtom (nsIRDFDataSource *db, nsIRDFResource *src, nsIRDFResource *prop, nsIRDFNode *newValue, PRBool *dirtyFlag)
nsresult validateEngine (nsIRDFResource *engine)
nsresult DoSearch (nsIRDFResource *source, nsIRDFResource *engine, const nsString &fullURL, const nsString &text)
nsresult MapEncoding (const nsString &numericEncoding, nsString &stringEncoding)
const char *const MapScriptCodeToCharsetName (PRUint32 aScriptCode)
nsresult SaveEngineInfoIntoGraph (nsIFile *file, nsIFile *icon, const PRUnichar *hint, const PRUnichar *data, PRBool isSystemSearchFile)
nsresult GetSearchEngineList (nsIFile *spec, PRBool isSystemSearchFile)
nsresult GetCategoryList ()
nsresult ReadFileContents (nsILocalFile *baseFilename, nsString &sourceContents)
nsresult DecodeData (const char *aCharset, const PRUnichar *aInString, PRUnichar **aOutString)
nsresult GetData (const PRUnichar *data, const char *sectionToFind, PRUint32 sectionNum, const char *attribToFind, nsString &value)
nsresult GetNumInterpretSections (const PRUnichar *data, PRUint32 &numInterpretSections)
nsresult GetInputs (const PRUnichar *data, nsString &engineName, nsString &userVar, const nsString &text, nsString &input, PRInt16 direction, PRUint16 pageNumber, PRUint16 *whichButtons)
PRInt32 computeIndex (nsAutoString &factor, PRUint16 page, PRInt16 direction)
nsresult GetURL (nsIRDFResource *source, nsIRDFLiteral **aResult)
nsresult validateEngineNow (nsIRDFResource *engine)
nsresult webSearchFinalize (nsIChannel *channel, nsIInternetSearchContext *context)
nsresult ParseHTML (nsIURI *aURL, nsIRDFResource *mParent, nsIRDFResource *engine, const PRUnichar *htmlPage, PRInt32 htmlPageSize)
nsresult SetHint (nsIRDFResource *mParent, nsIRDFResource *hintRes)
nsresult ConvertEntities (nsString &str, PRBool removeHTMLFlag=PR_TRUE, PRBool removeCRLFsFlag=PR_TRUE, PRBool trimWhiteSpaceFlag=PR_TRUE)
nsresult saveContents (nsIChannel *channel, nsIInternetSearchContext *context, PRUint32 contextType)
char * getSearchURI (nsIRDFResource *src)
nsresult addToBookmarks (nsIRDFResource *src)
nsresult addQueryToBookmarks (nsIRDFResource *src)
nsresult filterResult (nsIRDFResource *src)
nsresult filterSite (nsIRDFResource *src)
nsresult clearFilters (void)
PRBool isSearchResultFiltered (const nsString &href)
nsresult AddSearchEngineInternal (const char *engineURL, const char *iconURL, const PRUnichar *suggestedTitle, const PRUnichar *suggestedCategory, nsIRDFResource *aOldEngineResource)

Static Protected Member Functions

static void FireTimer (nsITimer *aTimer, void *aClosure)

Protected Attributes

nsCOMPtr< nsITimermTimer
PRBool busySchedule
nsCOMPtr< nsIRDFResourcebusyResource
nsString mQueryEncodingStr

Static Protected Attributes

static nsIRDFDataSourcemInner = nsnull
static nsCOMPtr< nsIRDFDataSourcemLocalstore
static nsCOMPtr< nsISupportsArraymUpdateArray
static nsCOMPtr< nsILoadGroupmBackgroundLoadGroup
static nsCOMPtr< nsILoadGroupmLoadGroup
static nsCOMPtr< nsIRDFDataSourcecategoryDataSource
static nsCOMPtr< nsIPrefprefs

Static Private Attributes

static PRInt32 gRefCnt = 0
static PRInt32 gBrowserSearchMode = 0
static PRBool gEngineListBuilt = PR_FALSE
static nsIRDFResourcekNC_SearchResult
static nsIRDFResourcekNC_SearchEngineRoot
static nsIRDFResourcekNC_LastSearchRoot
static nsIRDFResourcekNC_LastSearchMode
static nsIRDFResourcekNC_SearchCategoryRoot
static nsIRDFResourcekNC_SearchResultsSitesRoot
static nsIRDFResourcekNC_FilterSearchURLsRoot
static nsIRDFResourcekNC_FilterSearchSitesRoot
static nsIRDFResourcekNC_SearchType
static nsIRDFResourcekNC_Ref
static nsIRDFResourcekNC_Child
static nsIRDFResourcekNC_Title
static nsIRDFResourcekNC_Data
static nsIRDFResourcekNC_Name
static nsIRDFResourcekNC_Description
static nsIRDFResourcekNC_Version
static nsIRDFResourcekNC_actionButton
static nsIRDFResourcekNC_actionBar
static nsIRDFResourcekNC_searchForm
static nsIRDFResourcekNC_LastText
static nsIRDFResourcekNC_URL
static nsIRDFResourcekRDF_InstanceOf
static nsIRDFResourcekRDF_type
static nsIRDFResourcekNC_loading
static nsIRDFResourcekNC_HTML
static nsIRDFResourcekNC_Icon
static nsIRDFResourcekNC_StatusIcon
static nsIRDFResourcekNC_Banner
static nsIRDFResourcekNC_Site
static nsIRDFResourcekNC_Relevance
static nsIRDFResourcekNC_Date
static nsIRDFResourcekNC_RelevanceSort
static nsIRDFResourcekNC_PageRank
static nsIRDFResourcekNC_Engine
static nsIRDFResourcekNC_Price
static nsIRDFResourcekNC_PriceSort
static nsIRDFResourcekNC_Availability
static nsIRDFResourcekNC_BookmarkSeparator
static nsIRDFResourcekNC_Update
static nsIRDFResourcekNC_UpdateIcon
static nsIRDFResourcekNC_UpdateCheckDays
static nsIRDFResourcekWEB_LastPingDate
static nsIRDFResourcekWEB_LastPingModDate
static nsIRDFResourcekWEB_LastPingContentLen
static nsIRDFResourcekNC_SearchCommand_AddToBookmarks
static nsIRDFResourcekNC_SearchCommand_AddQueryToBookmarks
static nsIRDFResourcekNC_SearchCommand_FilterResult
static nsIRDFResourcekNC_SearchCommand_FilterSite
static nsIRDFResourcekNC_SearchCommand_ClearFilters
static nsIRDFLiteralkTrueLiteral

Friends

int PR_CALLBACK searchModePrefCallback (const char *pref, void *aClosure)

Detailed Description

Definition at line 55 of file nsInternetSearchService.h.


Constructor & Destructor Documentation

Definition at line 430 of file nsInternetSearchService.cpp.

{
       if (gRefCnt++ == 0)
       {
              nsresult rv = CallGetService(kRDFServiceCID, &gRDFService);
              NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service");

              rv = CallGetService(kRDFContainerUtilsCID, &gRDFC);
              NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF container utils");

              gRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_SearchEngineRoot),
                             &kNC_SearchEngineRoot);
              gRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_LastSearchRoot),
                             &kNC_LastSearchRoot);
              gRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_SearchResultsSitesRoot),
                             &kNC_SearchResultsSitesRoot);
              gRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_FilterSearchURLsRoot),
                             &kNC_FilterSearchURLsRoot);
              gRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_FilterSearchSitesRoot),
                             &kNC_FilterSearchSitesRoot);
              gRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_SearchCategoryRoot),
                             &kNC_SearchCategoryRoot);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "SearchMode"),
                             &kNC_LastSearchMode);

              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "searchtype"),
                             &kNC_SearchType);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "SearchResult"),
                             &kNC_SearchResult);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "ref"),
                             &kNC_Ref);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "child"),
                             &kNC_Child);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "title"),
                             &kNC_Title);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "data"),
                             &kNC_Data);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Name"),
                             &kNC_Name);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Description"),
                             &kNC_Description);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Version"),
                             &kNC_Version);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "actionButton"),
                             &kNC_actionButton);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "actionBar"),
                             &kNC_actionBar);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "searchForm"),
                             &kNC_searchForm);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "LastText"),
                             &kNC_LastText);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "URL"),
                             &kNC_URL);
              gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "instanceOf"),
                             &kRDF_InstanceOf);
              gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "type"),
                             &kRDF_type);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "loading"),
                             &kNC_loading);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "HTML"),
                             &kNC_HTML);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Icon"),
                             &kNC_Icon);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "StatusIcon"),
                             &kNC_StatusIcon);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Banner"),
                             &kNC_Banner);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Site"),
                             &kNC_Site);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Relevance"),
                             &kNC_Relevance);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Relevance?sort=true"),
                             &kNC_RelevanceSort);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Date"),
                             &kNC_Date);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "PageRank"),
                             &kNC_PageRank);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Engine"),
                             &kNC_Engine);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Price"),
                             &kNC_Price);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Price?sort=true"),
                             &kNC_PriceSort);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Availability"),
                             &kNC_Availability);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "BookmarkSeparator"),
                             &kNC_BookmarkSeparator);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Update"),
                             &kNC_Update);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "UpdateIcon"),
                             &kNC_UpdateIcon);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "UpdateCheckDays"),
                             &kNC_UpdateCheckDays);
              gRDFService->GetResource(NS_LITERAL_CSTRING(WEB_NAMESPACE_URI "LastPingDate"),
                             &kWEB_LastPingDate);
              gRDFService->GetResource(NS_LITERAL_CSTRING(WEB_NAMESPACE_URI "LastPingModDate"),
                             &kWEB_LastPingModDate);
              gRDFService->GetResource(NS_LITERAL_CSTRING(WEB_NAMESPACE_URI "LastPingContentLen"),
                             &kWEB_LastPingContentLen);

              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "command?cmd=addtobookmarks"),
                             &kNC_SearchCommand_AddToBookmarks);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "command?cmd=addquerytobookmarks"),
                             &kNC_SearchCommand_AddQueryToBookmarks);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "command?cmd=filterresult"),
                             &kNC_SearchCommand_FilterResult);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "command?cmd=filtersite"),
                             &kNC_SearchCommand_FilterSite);
              gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "command?cmd=clearfilters"),
                             &kNC_SearchCommand_ClearFilters);

              gRDFService->GetLiteral(NS_LITERAL_STRING("true").get(), &kTrueLiteral);

              prefs = do_GetService(kPrefCID);
              if (prefs)
              {
                     prefs->RegisterCallback("browser.search.mode", searchModePrefCallback, this);
                     prefs->GetIntPref("browser.search.mode", &gBrowserSearchMode);
              }
       }
}

Here is the call graph for this function:

Definition at line 554 of file nsInternetSearchService.cpp.

{
       if (--gRefCnt == 0)
       {
              NS_IF_RELEASE(kNC_SearchResult);
              NS_IF_RELEASE(kNC_SearchEngineRoot);
              NS_IF_RELEASE(kNC_LastSearchRoot);
              NS_IF_RELEASE(kNC_LastSearchMode);
              NS_IF_RELEASE(kNC_SearchCategoryRoot);
              NS_IF_RELEASE(kNC_SearchResultsSitesRoot);
              NS_IF_RELEASE(kNC_FilterSearchURLsRoot);
              NS_IF_RELEASE(kNC_FilterSearchSitesRoot);
              NS_IF_RELEASE(kNC_SearchType);
              NS_IF_RELEASE(kNC_Ref);
              NS_IF_RELEASE(kNC_Child);
              NS_IF_RELEASE(kNC_Title);
              NS_IF_RELEASE(kNC_Data);
              NS_IF_RELEASE(kNC_Name);
              NS_IF_RELEASE(kNC_Description);
              NS_IF_RELEASE(kNC_Version);
              NS_IF_RELEASE(kNC_actionButton);
              NS_IF_RELEASE(kNC_actionBar);
              NS_IF_RELEASE(kNC_searchForm);
              NS_IF_RELEASE(kNC_LastText);
              NS_IF_RELEASE(kNC_URL);
              NS_IF_RELEASE(kRDF_InstanceOf);
              NS_IF_RELEASE(kRDF_type);
              NS_IF_RELEASE(kNC_loading);
              NS_IF_RELEASE(kNC_HTML);
              NS_IF_RELEASE(kNC_Icon);
              NS_IF_RELEASE(kNC_StatusIcon);
              NS_IF_RELEASE(kNC_Banner);
              NS_IF_RELEASE(kNC_Site);
              NS_IF_RELEASE(kNC_Relevance);
              NS_IF_RELEASE(kNC_RelevanceSort);
              NS_IF_RELEASE(kNC_Date);
              NS_IF_RELEASE(kNC_PageRank);
              NS_IF_RELEASE(kNC_Engine);
              NS_IF_RELEASE(kNC_Price);
              NS_IF_RELEASE(kNC_PriceSort);
              NS_IF_RELEASE(kNC_Availability);
              NS_IF_RELEASE(kNC_BookmarkSeparator);
              NS_IF_RELEASE(kNC_Update);
              NS_IF_RELEASE(kNC_UpdateIcon);
              NS_IF_RELEASE(kNC_UpdateCheckDays);
              NS_IF_RELEASE(kWEB_LastPingDate);
              NS_IF_RELEASE(kWEB_LastPingModDate);
              NS_IF_RELEASE(kWEB_LastPingContentLen);

              NS_IF_RELEASE(kNC_SearchCommand_AddToBookmarks);
              NS_IF_RELEASE(kNC_SearchCommand_AddQueryToBookmarks);
              NS_IF_RELEASE(kNC_SearchCommand_FilterResult);
              NS_IF_RELEASE(kNC_SearchCommand_FilterSite);
              NS_IF_RELEASE(kNC_SearchCommand_ClearFilters);

              NS_IF_RELEASE(kTrueLiteral);

              NS_IF_RELEASE(mInner);

              mUpdateArray = nsnull;
              mLocalstore = nsnull;
              mBackgroundLoadGroup = nsnull;
              mLoadGroup = nsnull;
              categoryDataSource = nsnull;              

              if (mTimer)
              {
                     // be sure to cancel the timer, as it holds a
                     // weak reference back to InternetSearchDataSource
                     mTimer->Cancel();
                     mTimer = nsnull;
              }

              if (prefs)
              {
                     prefs->UnregisterCallback("browser.search.mode", searchModePrefCallback, this);
                     prefs = nsnull;
              }

    NS_IF_RELEASE(gRDFC);

              if (gRDFService)
              {
                     gRDFService->UnregisterDataSource(this);
      NS_RELEASE(gRDFService);
              }
       }
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 2016 of file nsInternetSearchService.cpp.

{
       if (!src)     return(NS_ERROR_UNEXPECTED);
       if (!mInner)  return(NS_ERROR_UNEXPECTED);

       nsresult rv;
       nsCOMPtr<nsIRDFNode> refNode;
       if (NS_FAILED(rv = mInner->GetTarget(kNC_LastSearchRoot, kNC_Ref, PR_TRUE,
              getter_AddRefs(refNode))))
              return(rv);
       nsCOMPtr<nsIRDFLiteral>     urlLiteral (do_QueryInterface(refNode));
       if (!urlLiteral)
         return(NS_ERROR_UNEXPECTED);
       const PRUnichar      *uriUni = nsnull;
       urlLiteral->GetValueConst(&uriUni);

       nsCOMPtr<nsIRDFNode> textNode;
       if (NS_FAILED(rv = mInner->GetTarget(kNC_LastSearchRoot, kNC_LastText, PR_TRUE,
              getter_AddRefs(textNode))))
              return(rv);
       nsCOMPtr<nsIRDFLiteral> textLiteral = do_QueryInterface(textNode);
       nsXPIDLString value;
       if (textLiteral)
       {
              const PRUnichar *textUni = nsnull;
              textLiteral->GetValueConst(&textUni);
       nsAutoString name;
              name.Assign(textUni);
              // replace pluses with spaces
              name.ReplaceChar(PRUnichar('+'), PRUnichar(' '));

       nsCOMPtr<nsIStringBundleService>
       stringService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));
       if (NS_SUCCEEDED(rv) && stringService)
       {
              nsCOMPtr<nsIStringBundle> bundle;
              rv = stringService->CreateBundle(SEARCH_PROPERTIES, getter_AddRefs(bundle));
              if (bundle)
              {
                     const PRUnichar *strings[] = { name.get() };
                     rv = bundle->FormatStringFromName(NS_LITERAL_STRING("searchTitle").get(), strings, 1, 
                            getter_Copies(value));
                     }
              }
       }

#ifndef MOZ_PLACES
       nsCOMPtr<nsIRDFDataSource>  datasource;
       if (NS_SUCCEEDED(rv = gRDFService->GetDataSource("rdf:bookmarks", getter_AddRefs(datasource))))
       {
              nsCOMPtr<nsIBookmarksService> bookmarks (do_QueryInterface(datasource));
              if (bookmarks)
                     rv = bookmarks->AddBookmarkImmediately(uriUni, value.get(),
                                             nsIBookmarksService::BOOKMARK_SEARCH_TYPE, nsnull);
       }
#endif

       return(NS_OK);
}

Here is the call graph for this function:

nsresult InternetSearchDataSource::AddSearchEngineInternal ( const char *  engineURL,
const char *  iconURL,
const PRUnichar suggestedTitle,
const PRUnichar suggestedCategory,
nsIRDFResource aOldEngineResource 
) [protected]

Definition at line 2451 of file nsInternetSearchService.cpp.

{
       NS_PRECONDITION(engineURL != nsnull, "null ptr");
       if (!engineURL)      return(NS_ERROR_NULL_POINTER);
       // Note: iconURL, suggestedTitle & suggestedCategory
       // can be null or empty strings, which is OK

#ifdef DEBUG_SEARCH_OUTPUT
       printf("AddSearchEngine: engine='%s'\n", engineURL);
#endif

       nsresult      rv = NS_OK;

       // mBackgroundLoadGroup is a dynamically created singleton
       if (!mBackgroundLoadGroup)
       {
              if (NS_FAILED(rv = NS_NewLoadGroup(getter_AddRefs(mBackgroundLoadGroup), nsnull)))
                     return(rv);
              if (!mBackgroundLoadGroup)
                     return(NS_ERROR_UNEXPECTED);
       }

       // download engine
       nsCOMPtr<nsIInternetSearchContext> engineContext;
  rv = NS_NewInternetSearchContext
         (aOldEngineResource? nsIInternetSearchContext::ENGINE_DOWNLOAD_UPDATE_CONTEXT:
                              nsIInternetSearchContext::ENGINE_DOWNLOAD_NEW_CONTEXT,
          nsnull, aOldEngineResource, nsnull, suggestedCategory,
          getter_AddRefs(engineContext));
  NS_ENSURE_SUCCESS(rv, rv);

       if (!engineContext)  return(NS_ERROR_UNEXPECTED);

       nsCOMPtr<nsIURI>     engineURI;
       if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(engineURI), engineURL)))
              return(rv);

       nsCOMPtr<nsIChannel> engineChannel;
       if (NS_FAILED(rv = NS_NewChannel(getter_AddRefs(engineChannel), engineURI, nsnull, mBackgroundLoadGroup)))
              return(rv);
    
       if (NS_FAILED(rv = engineChannel->AsyncOpen(this, engineContext)))
              return(rv);

       // download icon
       nsCOMPtr<nsIInternetSearchContext> iconContext;
  rv = NS_NewInternetSearchContext
         (aOldEngineResource? nsIInternetSearchContext::ICON_DOWNLOAD_UPDATE_CONTEXT:
                              nsIInternetSearchContext::ICON_DOWNLOAD_NEW_CONTEXT,
          nsnull, aOldEngineResource, nsnull, suggestedCategory,
          getter_AddRefs(iconContext));
  NS_ENSURE_SUCCESS(rv, rv);

       if (!iconContext)    return(NS_ERROR_UNEXPECTED);

       if (iconURL && (*iconURL))
       {
              nsCOMPtr<nsIURI>     iconURI;
              if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(iconURI), iconURL)))
                     return(rv);

              nsCOMPtr<nsIChannel> iconChannel;
              if (NS_FAILED(rv = NS_NewChannel(getter_AddRefs(iconChannel), iconURI, nsnull, mBackgroundLoadGroup)))
                     return(rv);
              if (NS_FAILED(rv = iconChannel->AsyncOpen(this, iconContext)))
                     return(rv);
       }
       return(NS_OK);
}

Here is the call graph for this function:

Definition at line 1973 of file nsInternetSearchService.cpp.

{
       if (!src)     return(NS_ERROR_UNEXPECTED);
       if (!mInner)  return(NS_ERROR_UNEXPECTED);

       nsresult             rv;
       nsCOMPtr<nsIRDFNode> nameNode;
       // Note: nameLiteral needs to stay in scope for the life of "name"
       nsCOMPtr<nsIRDFLiteral>     nameLiteral;
       const PRUnichar             *name = nsnull;
       if (NS_SUCCEEDED(rv = mInner->GetTarget(src, kNC_Name, PR_TRUE, getter_AddRefs(nameNode))))
       {
              nameLiteral = do_QueryInterface(nameNode);
              if (nameLiteral)
              {
                     nameLiteral->GetValueConst(&name);
              }
       }

#ifndef MOZ_PLACES
       nsCOMPtr<nsIRDFDataSource>  datasource;
       if (NS_SUCCEEDED(rv = gRDFService->GetDataSource("rdf:bookmarks", getter_AddRefs(datasource))))
       {
              nsCOMPtr<nsIBookmarksService> bookmarks (do_QueryInterface(datasource));
              if (bookmarks)
              {
                     char   *uri = getSearchURI(src);
                     if (uri)
                     {
                            rv = bookmarks->AddBookmarkImmediately(NS_ConvertUTF8toUTF16(uri).get(),
                                               name, nsIBookmarksService::BOOKMARK_SEARCH_TYPE, nsnull);
                            Recycle(uri);
                     }
              }
       }
#endif

       return(NS_OK);
}

Here is the call graph for this function:

nsresult InternetSearchDataSource::BeginSearchRequest ( nsIRDFResource source,
PRBool  doNetworkRequest 
) [protected]

Definition at line 3229 of file nsInternetSearchService.cpp.

{
        nsresult            rv = NS_OK;
       const char           *sourceURI = nsnull;

       if (NS_FAILED(rv = source->GetValueConst(&sourceURI)))
              return(rv);
       nsAutoString         uri;
       uri.AssignWithConversion(sourceURI);

       if (uri.Find("internetsearch:") != 0)
              return(NS_ERROR_FAILURE);

       // forget about any previous search results
       ClearResults(PR_TRUE);

       // forget about any previous search sites
       ClearResultSearchSites();

       // remember the last search query
       const PRUnichar      *uriUni = uri.get();
       nsCOMPtr<nsIRDFLiteral>     uriLiteral;
       if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(uriUni, getter_AddRefs(uriLiteral))))
       {
              rv = mInner->Assert(kNC_LastSearchRoot, kNC_Ref, uriLiteral, PR_TRUE);
       }

       uri.Cut(0, strlen("internetsearch:"));

       nsVoidArray   *engineArray = new nsVoidArray;
       if (!engineArray)
              return(NS_ERROR_FAILURE);

       nsAutoString  text;

       // parse up attributes

       while(!uri.IsEmpty())
       {
              nsAutoString  item;

              PRInt32 andOffset = uri.Find("&");
              if (andOffset >= 0)
              {
                     uri.Left(item, andOffset);
                     uri.Cut(0, andOffset + 1);
              }
              else
              {
                     item = uri;
                     uri.Truncate();
              }

              PRInt32 equalOffset = item.Find("=");
              if (equalOffset < 0) break;
              
              nsAutoString  attrib, value;
              item.Left(attrib, equalOffset);
              value = item;
              value.Cut(0, equalOffset + 1);
              
              if (!attrib.IsEmpty() && !value.IsEmpty())
              {
                     if (attrib.LowerCaseEqualsLiteral("engine"))
                     {
                            if ((value.Find(kEngineProtocol) == 0) ||
                                   (value.Find(kURINC_SearchCategoryEnginePrefix) == 0))
                            {
                                   char   *val = ToNewCString(value);
                                   if (val)
                                   {
                                          engineArray->AppendElement(val);
                                   }
                            }
                     }
                     else if (attrib.LowerCaseEqualsLiteral("text"))
                     {
                            text = value;
                     }
              }
       }

       mInner->Assert(source, kNC_loading, kTrueLiteral, PR_TRUE);

       PRBool requestInitiated = PR_FALSE;

       // loop over specified search engines
       while (engineArray->Count() > 0)
       {
              char *baseFilename = (char *)(engineArray->ElementAt(0));
              engineArray->RemoveElementAt(0);
              if (!baseFilename)   continue;

#ifdef DEBUG_SEARCH_OUTPUT
              printf("Search engine to query: '%s'\n", baseFilename);
#endif

              nsCOMPtr<nsIRDFResource>    engine;
              gRDFService->GetResource(nsDependentCString(baseFilename), getter_AddRefs(engine));
              nsCRT::free(baseFilename);
              baseFilename = nsnull;
              if (!engine)  continue;

              // if its a engine from a search category, then get its "#Name",
              // and map from that back to the real engine reference; if an
              // error occurs, finish processing the rest of the engines,
              // don't just break/return out
              if (isSearchCategoryEngineURI(engine))
              {
                     nsCOMPtr<nsIRDFResource>    trueEngine;
                     rv = resolveSearchCategoryEngineURI(engine, getter_AddRefs(trueEngine));
                     if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE))    return(rv);
                     if (!trueEngine)     continue;

                     engine = trueEngine;
              }

              // mark this as a search site
              if (mInner)
              {
                     mInner->Assert(kNC_SearchResultsSitesRoot, kNC_Child, engine, PR_TRUE);
              }

    if (doNetworkRequest)
              {
                     DoSearch(source, engine, EmptyString(), text);
                     requestInitiated = PR_TRUE;
              }
       }
       
       delete engineArray;
       engineArray = nsnull;

  if (!requestInitiated)
       {
              Stop();
       }

       return(rv);
}

Here is the call graph for this function:

Definition at line 2278 of file nsInternetSearchService.cpp.

{
       if (!mInner)  return(NS_ERROR_UNEXPECTED);

       nsresult                    rv;
       nsCOMPtr<nsISimpleEnumerator>      arcs;
       PRBool                      hasMore = PR_TRUE;
       nsCOMPtr<nsISupports>              arc;

       // remove all filtered URLs
       if (NS_SUCCEEDED(rv = mLocalstore->GetTargets(kNC_FilterSearchURLsRoot, kNC_Child,
              PR_TRUE, getter_AddRefs(arcs))))
       {
              hasMore = PR_TRUE;
    while (hasMore)
              {
      if (NS_FAILED(arcs->HasMoreElements(&hasMore)) || !hasMore)
                            break;
                     if (NS_FAILED(arcs->GetNext(getter_AddRefs(arc))))
                            break;

                     nsCOMPtr<nsIRDFLiteral>     filterURL (do_QueryInterface(arc));
                     if (!filterURL)      continue;
                     
                     mLocalstore->Unassert(kNC_FilterSearchURLsRoot, kNC_Child, filterURL);
              }
       }

       // remove all filtered sites
       if (NS_SUCCEEDED(rv = mLocalstore->GetTargets(kNC_FilterSearchSitesRoot, kNC_Child,
              PR_TRUE, getter_AddRefs(arcs))))
       {
              hasMore = PR_TRUE;
    while (hasMore)
              {
      if (NS_FAILED(arcs->HasMoreElements(&hasMore)) || !hasMore)
                            break;
                     if (NS_FAILED(arcs->GetNext(getter_AddRefs(arc))))
                            break;

                     nsCOMPtr<nsIRDFLiteral>     filterSiteLiteral (do_QueryInterface(arc));
                     if (!filterSiteLiteral)     continue;
                     
                     mLocalstore->Unassert(kNC_FilterSearchSitesRoot, kNC_Child, filterSiteLiteral);
              }
       }

       // flush localstore
       nsCOMPtr<nsIRDFRemoteDataSource> remoteLocalStore (do_QueryInterface(mLocalstore));
       if (remoteLocalStore)
       {
              remoteLocalStore->Flush();
       }

       return(NS_OK);
}

Here is the call graph for this function:

PRInt32 InternetSearchDataSource::computeIndex ( nsAutoString factor,
PRUint16  page,
PRInt16  direction 
) [protected]

Definition at line 4997 of file nsInternetSearchService.cpp.

{
  // XXX get page
  PRInt32 errorCode, index = 0;
  PRInt32 factorInt = factor.ToInteger(&errorCode);
  
  if (NS_SUCCEEDED(errorCode))
  {
    // if factor is garbled assume 10
    if (factorInt <= 0)
      factorInt = 10;

    if (direction < 0)
    {
      // don't pass back a negative index!
      if (0 <= (page - 1))
        --page;
    }
    index = factorInt * page;
  }

  return index;
}

Here is the caller graph for this function:

nsresult InternetSearchDataSource::ConvertEntities ( nsString str,
PRBool  removeHTMLFlag = PR_TRUE,
PRBool  removeCRLFsFlag = PR_TRUE,
PRBool  trimWhiteSpaceFlag = PR_TRUE 
) [protected]

Definition at line 6292 of file nsInternetSearchService.cpp.

{
       PRInt32       startOffset = 0, ampOffset, semiOffset, offset;

       // do this before converting entities
  if (removeHTMLFlag)
       {
              // munge out anything inside of HTML "<" / ">" tags
              while ((offset = nameStr.FindChar(PRUnichar('<'), 0)) >= 0)
              {
                     PRInt32       offsetEnd = nameStr.FindChar(PRUnichar('>'), offset+1);
                     if (offsetEnd <= offset)    break;
                     nameStr.Cut(offset, offsetEnd - offset + 1);
              }
       }
       while ((ampOffset = nameStr.FindChar(PRUnichar('&'), startOffset)) >= 0)
       {
              if ((semiOffset = nameStr.FindChar(PRUnichar(';'), ampOffset+1)) <= ampOffset)
                     break;

              nsAutoString  entityStr;
              nameStr.Mid(entityStr, ampOffset, semiOffset-ampOffset+1);
              nameStr.Cut(ampOffset, semiOffset-ampOffset+1);

              PRUnichar     entityChar = 0;
              if (entityStr.LowerCaseEqualsLiteral("&quot;"))  entityChar = PRUnichar('\"');
              else if (entityStr.LowerCaseEqualsLiteral("&amp;"))     entityChar = PRUnichar('&');
              else if (entityStr.LowerCaseEqualsLiteral("&nbsp;"))    entityChar = PRUnichar(' ');
              else if (entityStr.LowerCaseEqualsLiteral("&lt;"))             entityChar = PRUnichar('<');
              else if (entityStr.LowerCaseEqualsLiteral("&gt;"))             entityChar = PRUnichar('>');
              else if (entityStr.LowerCaseEqualsLiteral("&iexcl;"))   entityChar = PRUnichar(161);
              else if (entityStr.LowerCaseEqualsLiteral("&cent;"))    entityChar = PRUnichar(162);
              else if (entityStr.LowerCaseEqualsLiteral("&pound;"))   entityChar = PRUnichar(163);
              else if (entityStr.LowerCaseEqualsLiteral("&curren;"))  entityChar = PRUnichar(164);
              else if (entityStr.LowerCaseEqualsLiteral("&yen;"))     entityChar = PRUnichar(165);
              else if (entityStr.LowerCaseEqualsLiteral("&brvbar;"))  entityChar = PRUnichar(166);
              else if (entityStr.LowerCaseEqualsLiteral("&sect;"))    entityChar = PRUnichar(167);
              else if (entityStr.LowerCaseEqualsLiteral("&uml;"))     entityChar = PRUnichar(168);
              else if (entityStr.LowerCaseEqualsLiteral("&copy;"))    entityChar = PRUnichar(169);
              else if (entityStr.LowerCaseEqualsLiteral("&ordf;"))    entityChar = PRUnichar(170);
              else if (entityStr.LowerCaseEqualsLiteral("&laquo;"))   entityChar = PRUnichar(171);
              else if (entityStr.LowerCaseEqualsLiteral("&not;"))     entityChar = PRUnichar(172);
              else if (entityStr.LowerCaseEqualsLiteral("&shy;"))     entityChar = PRUnichar(173);
              else if (entityStr.LowerCaseEqualsLiteral("&reg;"))     entityChar = PRUnichar(174);
              else if (entityStr.LowerCaseEqualsLiteral("&macr;"))    entityChar = PRUnichar(175);
              else if (entityStr.LowerCaseEqualsLiteral("&deg;"))     entityChar = PRUnichar(176);
              else if (entityStr.LowerCaseEqualsLiteral("&plusmn;"))  entityChar = PRUnichar(177);
              else if (entityStr.LowerCaseEqualsLiteral("&sup2;"))    entityChar = PRUnichar(178);
              else if (entityStr.LowerCaseEqualsLiteral("&sup3;"))    entityChar = PRUnichar(179);
              else if (entityStr.LowerCaseEqualsLiteral("&acute;"))   entityChar = PRUnichar(180);
              else if (entityStr.LowerCaseEqualsLiteral("&micro;"))   entityChar = PRUnichar(181);
              else if (entityStr.LowerCaseEqualsLiteral("&para;"))    entityChar = PRUnichar(182);
              else if (entityStr.LowerCaseEqualsLiteral("&middot;"))  entityChar = PRUnichar(183);
              else if (entityStr.LowerCaseEqualsLiteral("&cedil;"))   entityChar = PRUnichar(184);
              else if (entityStr.LowerCaseEqualsLiteral("&sup1;"))    entityChar = PRUnichar(185);
              else if (entityStr.LowerCaseEqualsLiteral("&ordm;"))    entityChar = PRUnichar(186);
              else if (entityStr.LowerCaseEqualsLiteral("&raquo;"))   entityChar = PRUnichar(187);
              else if (entityStr.LowerCaseEqualsLiteral("&frac14;"))  entityChar = PRUnichar(188);
              else if (entityStr.LowerCaseEqualsLiteral("&frac12;"))  entityChar = PRUnichar(189);
              else if (entityStr.LowerCaseEqualsLiteral("&frac34;"))  entityChar = PRUnichar(190);
              else if (entityStr.LowerCaseEqualsLiteral("&iquest;"))  entityChar = PRUnichar(191);
              else if (entityStr.LowerCaseEqualsLiteral("&agrave;"))  entityChar = PRUnichar(192);
              else if (entityStr.LowerCaseEqualsLiteral("&aacute;"))  entityChar = PRUnichar(193);
              else if (entityStr.LowerCaseEqualsLiteral("&acirc;"))   entityChar = PRUnichar(194);
              else if (entityStr.LowerCaseEqualsLiteral("&atilde;"))  entityChar = PRUnichar(195);
              else if (entityStr.LowerCaseEqualsLiteral("&auml;"))    entityChar = PRUnichar(196);
              else if (entityStr.LowerCaseEqualsLiteral("&aring;"))   entityChar = PRUnichar(197);
              else if (entityStr.LowerCaseEqualsLiteral("&aelig;"))   entityChar = PRUnichar(198);
              else if (entityStr.LowerCaseEqualsLiteral("&ccedil;"))  entityChar = PRUnichar(199);
              else if (entityStr.LowerCaseEqualsLiteral("&egrave;"))  entityChar = PRUnichar(200);
              else if (entityStr.LowerCaseEqualsLiteral("&eacute;"))  entityChar = PRUnichar(201);
              else if (entityStr.LowerCaseEqualsLiteral("&ecirc;"))   entityChar = PRUnichar(202);
              else if (entityStr.LowerCaseEqualsLiteral("&euml;"))    entityChar = PRUnichar(203);
              else if (entityStr.LowerCaseEqualsLiteral("&igrave;"))  entityChar = PRUnichar(204);
              else if (entityStr.LowerCaseEqualsLiteral("&iacute;"))  entityChar = PRUnichar(205);
              else if (entityStr.LowerCaseEqualsLiteral("&icirc;"))   entityChar = PRUnichar(206);
              else if (entityStr.LowerCaseEqualsLiteral("&iuml;"))    entityChar = PRUnichar(207);
              else if (entityStr.LowerCaseEqualsLiteral("&eth;"))     entityChar = PRUnichar(208);
              else if (entityStr.LowerCaseEqualsLiteral("&ntilde;"))  entityChar = PRUnichar(209);
              else if (entityStr.LowerCaseEqualsLiteral("&ograve;"))  entityChar = PRUnichar(210);
              else if (entityStr.LowerCaseEqualsLiteral("&oacute;"))  entityChar = PRUnichar(211);
              else if (entityStr.LowerCaseEqualsLiteral("&ocirc;"))   entityChar = PRUnichar(212);
              else if (entityStr.LowerCaseEqualsLiteral("&otilde;"))  entityChar = PRUnichar(213);
              else if (entityStr.LowerCaseEqualsLiteral("&ouml;"))    entityChar = PRUnichar(214);
              else if (entityStr.LowerCaseEqualsLiteral("&times;"))   entityChar = PRUnichar(215);
              else if (entityStr.LowerCaseEqualsLiteral("&oslash;"))  entityChar = PRUnichar(216);
              else if (entityStr.LowerCaseEqualsLiteral("&ugrave;"))  entityChar = PRUnichar(217);
              else if (entityStr.LowerCaseEqualsLiteral("&uacute;"))  entityChar = PRUnichar(218);
              else if (entityStr.LowerCaseEqualsLiteral("&ucirc;"))   entityChar = PRUnichar(219);
              else if (entityStr.LowerCaseEqualsLiteral("&uuml;"))    entityChar = PRUnichar(220);
              else if (entityStr.LowerCaseEqualsLiteral("&yacute;"))  entityChar = PRUnichar(221);
              else if (entityStr.LowerCaseEqualsLiteral("&thorn;"))   entityChar = PRUnichar(222);
              else if (entityStr.LowerCaseEqualsLiteral("&szlig;"))   entityChar = PRUnichar(223);
              else if (entityStr.LowerCaseEqualsLiteral("&agrave;"))  entityChar = PRUnichar(224);
              else if (entityStr.LowerCaseEqualsLiteral("&aacute;"))  entityChar = PRUnichar(225);
              else if (entityStr.LowerCaseEqualsLiteral("&acirc;"))   entityChar = PRUnichar(226);
              else if (entityStr.LowerCaseEqualsLiteral("&atilde;"))  entityChar = PRUnichar(227);
              else if (entityStr.LowerCaseEqualsLiteral("&auml;"))    entityChar = PRUnichar(228);
              else if (entityStr.LowerCaseEqualsLiteral("&aring;"))   entityChar = PRUnichar(229);
              else if (entityStr.LowerCaseEqualsLiteral("&aelig;"))   entityChar = PRUnichar(230);
              else if (entityStr.LowerCaseEqualsLiteral("&ccedil;"))  entityChar = PRUnichar(231);
              else if (entityStr.LowerCaseEqualsLiteral("&egrave;"))  entityChar = PRUnichar(232);
              else if (entityStr.LowerCaseEqualsLiteral("&eacute;"))  entityChar = PRUnichar(233);
              else if (entityStr.LowerCaseEqualsLiteral("&ecirc;"))   entityChar = PRUnichar(234);
              else if (entityStr.LowerCaseEqualsLiteral("&euml;"))    entityChar = PRUnichar(235);
              else if (entityStr.LowerCaseEqualsLiteral("&igrave;"))  entityChar = PRUnichar(236);
              else if (entityStr.LowerCaseEqualsLiteral("&iacute;"))  entityChar = PRUnichar(237);
              else if (entityStr.LowerCaseEqualsLiteral("&icirc;"))   entityChar = PRUnichar(238);
              else if (entityStr.LowerCaseEqualsLiteral("&iuml;"))    entityChar = PRUnichar(239);
              else if (entityStr.LowerCaseEqualsLiteral("&eth;"))     entityChar = PRUnichar(240);
              else if (entityStr.LowerCaseEqualsLiteral("&ntilde;"))  entityChar = PRUnichar(241);
              else if (entityStr.LowerCaseEqualsLiteral("&ograve;"))  entityChar = PRUnichar(242);
              else if (entityStr.LowerCaseEqualsLiteral("&oacute;"))  entityChar = PRUnichar(243);
              else if (entityStr.LowerCaseEqualsLiteral("&ocirc;"))   entityChar = PRUnichar(244);
              else if (entityStr.LowerCaseEqualsLiteral("&otilde;"))  entityChar = PRUnichar(245);
              else if (entityStr.LowerCaseEqualsLiteral("&ouml;"))    entityChar = PRUnichar(246);
              else if (entityStr.LowerCaseEqualsLiteral("&divide;"))  entityChar = PRUnichar(247);
              else if (entityStr.LowerCaseEqualsLiteral("&oslash;"))  entityChar = PRUnichar(248);
              else if (entityStr.LowerCaseEqualsLiteral("&ugrave;"))  entityChar = PRUnichar(249);
              else if (entityStr.LowerCaseEqualsLiteral("&uacute;"))  entityChar = PRUnichar(250);
              else if (entityStr.LowerCaseEqualsLiteral("&ucirc;"))   entityChar = PRUnichar(251);
              else if (entityStr.LowerCaseEqualsLiteral("&uuml;"))    entityChar = PRUnichar(252);
              else if (entityStr.LowerCaseEqualsLiteral("&yacute;"))  entityChar = PRUnichar(253);
              else if (entityStr.LowerCaseEqualsLiteral("&thorn;"))   entityChar = PRUnichar(254);
              else if (entityStr.LowerCaseEqualsLiteral("&yuml;"))    entityChar = PRUnichar(255);

              startOffset = ampOffset;
              if (entityChar != 0)
              {
                     nameStr.Insert(entityChar, ampOffset);
                     ++startOffset;
              }
       }

  if (removeCRLFsFlag)
       {
              // cut out any CRs or LFs
              while ((offset = nameStr.FindCharInSet("\n\r", 0)) >= 0)
              {
                     nameStr.Cut(offset, 1);
              }
       }

  if (trimWhiteSpaceFlag)
       {
              // trim name
              nameStr.Trim(" \t");
       }

       return(NS_OK);
}

Here is the caller graph for this function:

nsresult InternetSearchDataSource::DecodeData ( const char *  aCharset,
const PRUnichar aInString,
PRUnichar **  aOutString 
) [protected]

Definition at line 3458 of file nsInternetSearchService.cpp.

{
       nsresult rv;
    
       nsCOMPtr <nsICharsetConverterManager> charsetConv = 
          do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
       NS_ENSURE_SUCCESS(rv, rv);

       nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
       rv = charsetConv->GetUnicodeDecoder(aCharset, getter_AddRefs(unicodeDecoder));

       // Use the sherlock default charset in case of failure
       if (NS_FAILED(rv))
              rv = charsetConv->GetUnicodeDecoderRaw("x-mac-roman", getter_AddRefs(unicodeDecoder));
       NS_ENSURE_SUCCESS(rv, rv);

       // This fixes the corruption occured in InternetSearchDataSource::ReadFileContents()
       // (eg. aValue contains "0x0082 0x00a1" for "0x82 0xa1" shift_jis double-byte char)
       NS_LossyConvertUCS2toASCII value(aInString);

       PRInt32 srcLength = value.Length();
       PRInt32 outUnicodeLen;
       rv = unicodeDecoder->GetMaxLength(value.get(), srcLength, &outUnicodeLen);
       NS_ENSURE_SUCCESS(rv, rv);

       *aOutString = NS_REINTERPRET_CAST(PRUnichar*, nsMemory::Alloc((outUnicodeLen + 1) * sizeof(PRUnichar)));
       NS_ENSURE_TRUE(*aOutString, NS_ERROR_OUT_OF_MEMORY);

       rv = unicodeDecoder->Convert(value.get(), &srcLength, *aOutString, &outUnicodeLen);
       NS_ENSURE_SUCCESS(rv, rv);
       (*aOutString)[outUnicodeLen] = (PRUnichar)'\0';

       return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 974 of file nsInternetSearchService.cpp.

{
  if (gEngineListBuilt)
    return;

  nsresult rv;

  nsCOMPtr<nsIProperties> dirSvc
    (do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
  if (!dirSvc)
    return;

  gEngineListBuilt = PR_TRUE;

  // get available search engines
  nsCOMPtr<nsISimpleEnumerator> dirlist;
  rv = dirSvc->Get(NS_APP_SEARCH_DIR_LIST,
                   NS_GET_IID(nsISimpleEnumerator), getter_AddRefs(dirlist));
  if (NS_SUCCEEDED(rv))
  {
    PRBool more;
    while (NS_SUCCEEDED(dirlist->HasMoreElements(&more)) && more) {
      nsCOMPtr<nsISupports> suppfile;
      nsCOMPtr<nsIFile> dir;
      dirlist->GetNext(getter_AddRefs(suppfile));
      dir = do_QueryInterface(suppfile);
      if (dir)
      {
        GetSearchEngineList(dir, PR_FALSE);
      }
    }
  }

  // read in category list
  GetCategoryList();
}

Here is the call graph for this function:

nsresult InternetSearchDataSource::DoSearch ( nsIRDFResource source,
nsIRDFResource engine,
const nsString fullURL,
const nsString text 
) [protected]

Definition at line 3962 of file nsInternetSearchService.cpp.

{
       nsresult      rv;
       nsAutoString  textTemp(text);

       if (!mInner)  return(NS_RDF_NO_VALUE);
//     Note: source can be null
//     if (!source)  return(NS_ERROR_NULL_POINTER);
       if (!engine)  return(NS_ERROR_NULL_POINTER);

       validateEngine(engine);

       nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
       nsAutoString                action, methodStr, input, userVar;

       nsCOMPtr<nsIRDFLiteral>            dataLit;
       if (NS_FAILED(rv = FindData(engine, getter_AddRefs(dataLit))) ||
              (rv == NS_RDF_NO_VALUE))    return(rv);

       const PRUnichar                    *dataUni = nsnull;
       dataLit->GetValueConst(&dataUni);
       if (!dataUni)               return(NS_RDF_NO_VALUE);

       if (!fullURL.IsEmpty())
       {
              action.Assign(fullURL);
              methodStr.AssignLiteral("get");
       }
       else
       {
              if (NS_FAILED(rv = GetData(dataUni, "search", 0, "action", action)))  return(rv);
              if (NS_FAILED(rv = GetData(dataUni, "search", 0, "method", methodStr)))      return(rv);
       }

       nsAutoString  encodingStr, resultEncodingStr;

       // first look for "interpret/charset"... if that isn't specified,
       // then fall back to looking for "interpret/resultEncoding" (a decimal)
       GetData(dataUni, "interpret", 0, "charset", resultEncodingStr);
       if (resultEncodingStr.IsEmpty())
       {
              GetData(dataUni, "interpret", 0, "resultEncoding", encodingStr);      // decimal string values
              MapEncoding(encodingStr, resultEncodingStr);
       }
       // rjc note: ignore "interpret/resultTranslationEncoding" as well as
       // "interpret/resultTranslationFont" since we always convert results to Unicode
       if (!resultEncodingStr.IsEmpty())
       {
              nsCOMPtr <nsICharsetConverterManager> charsetConv = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
              if (NS_SUCCEEDED(rv))
              {
                  NS_LossyConvertUCS2toASCII charset(resultEncodingStr);
                  rv = charsetConv->GetUnicodeDecoder(charset.get(),
                                                      getter_AddRefs(unicodeDecoder));
              }
       }

       // first look for "search/queryCharset"... if that isn't specified,
       // then fall back to looking for "search/queryEncoding" (a decimal)
       nsAutoString    queryEncodingStr;
       GetData(dataUni, "search", 0, "queryCharset", queryEncodingStr);
       if (queryEncodingStr.IsEmpty())
       {
              GetData(dataUni, "search", 0, "queryEncoding", encodingStr);          // decimal string values
              MapEncoding(encodingStr, queryEncodingStr);
       }
       if (!queryEncodingStr.IsEmpty())
       {
              // convert from escaped-UTF_8, to unicode, and then to
              // the charset indicated by the dataset in question

              char   *utf8data = ToNewUTF8String(textTemp);
              if (utf8data)
              {
                     nsCOMPtr<nsITextToSubURI> textToSubURI = 
                              do_GetService(kTextToSubURICID, &rv);
                     if (NS_SUCCEEDED(rv) && (textToSubURI))
                     {
                            PRUnichar     *uni = nsnull;
                            if (NS_SUCCEEDED(rv = textToSubURI->UnEscapeAndConvert("UTF-8", utf8data, &uni)) && (uni))
                            {
                                   char          *charsetData = nsnull;
                                   nsCAutoString queryencodingstrC;
                                   queryencodingstrC.AssignWithConversion(queryEncodingStr);
                                   if (NS_SUCCEEDED(rv = textToSubURI->ConvertAndEscape(queryencodingstrC.get(), uni, &charsetData))
                                           && (charsetData))
                                   {
                                          textTemp.AssignWithConversion(charsetData);
                                          Recycle(charsetData);
                                   }
                                   Recycle(uni);
                            }
                     }
                     Recycle(utf8data);
              }
       }

       if (fullURL.IsEmpty() && methodStr.LowerCaseEqualsLiteral("get"))
       {
    nsAutoString engineNameStr;
       GetData(dataUni, "search", 0, "name", engineNameStr);

    if (NS_FAILED(rv = GetInputs(dataUni, engineNameStr, userVar, textTemp, input, 0, 0, 0)))  return(rv);
              if (input.IsEmpty())                      return(NS_ERROR_UNEXPECTED);

              // HTTP Get method support
              action += input;
       }

       nsCOMPtr<nsIInternetSearchContext> context;
       if (NS_FAILED(rv = NS_NewInternetSearchContext(nsIInternetSearchContext::WEB_SEARCH_CONTEXT,
              source, engine, unicodeDecoder, nsnull, getter_AddRefs(context))))
              return(rv);
       if (!context) return(NS_ERROR_UNEXPECTED);

       nsCOMPtr<nsIURI>     url;
       if (NS_SUCCEEDED(rv = NS_NewURI(getter_AddRefs(url), action)))
       {
              nsCOMPtr<nsIChannel> channel;
              if (NS_SUCCEEDED(rv = NS_NewChannel(getter_AddRefs(channel), url, nsnull, mLoadGroup)))
              {

                     // send a "MultiSearch" header
                     nsCOMPtr<nsIHttpChannel> httpMultiChannel (do_QueryInterface(channel));
                     if (httpMultiChannel)
                     {
                httpMultiChannel->SetRequestHeader(NS_LITERAL_CSTRING("MultiSearch"),
                                                   NS_LITERAL_CSTRING("true"),
                                                   PR_FALSE);
                     }

                     // get it just from the cache if we can (do not validate)
                     channel->SetLoadFlags(nsIRequest::LOAD_FROM_CACHE);

                     if (methodStr.LowerCaseEqualsLiteral("post"))
                     {
                            nsCOMPtr<nsIHttpChannel> httpChannel (do_QueryInterface(channel));
                            if (httpChannel)
                            {
                                httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("POST"));
                                
                                // construct post data to send
                                nsAutoString     postStr;
                                postStr.AssignASCII(POSTHEADER_PREFIX);
                                postStr.AppendInt(input.Length(), 10);
                                postStr.AppendASCII(POSTHEADER_SUFFIX);
                                postStr += input;
                                
                                nsCOMPtr<nsIInputStream>       postDataStream;
                                nsCAutoString                  poststrC;
                                poststrC.AssignWithConversion(postStr);
                                if (NS_SUCCEEDED(rv = NS_NewPostDataStream(getter_AddRefs(postDataStream),
                                                                      PR_FALSE, poststrC, 0)))
                                {
                                   nsCOMPtr<nsIUploadChannel> uploadChannel(do_QueryInterface(httpChannel));
                                   NS_ASSERTION(uploadChannel, "http must support nsIUploadChannel");
                                   uploadChannel->SetUploadStream(postDataStream, EmptyCString(), -1);
                                }
                            }
                     }
                     
                     nsCOMPtr<nsIRequest> request;
      rv = channel->AsyncOpen(this, context);
              }
       }

       // dispose of any last HTML results page
       if (mInner)
       {
              nsCOMPtr<nsIRDFNode> htmlNode;
              if (NS_SUCCEEDED(rv = mInner->GetTarget(engine, kNC_HTML, PR_TRUE, getter_AddRefs(htmlNode)))
                     && (rv != NS_RDF_NO_VALUE))
              {
                     rv = mInner->Unassert(engine, kNC_HTML, htmlNode);
              }
       }

       // start "loading" animation for this search engine
       if (NS_SUCCEEDED(rv) && (mInner))
       {
              // remove status icon so that loading icon style can be used
              nsCOMPtr<nsIRDFNode>        engineIconNode = nsnull;
              mInner->GetTarget(engine, kNC_StatusIcon, PR_TRUE, getter_AddRefs(engineIconNode));
              if (engineIconNode)
              {
                     rv = mInner->Unassert(engine, kNC_StatusIcon, engineIconNode);
              }

              mInner->Assert(engine, kNC_loading, kTrueLiteral, PR_TRUE);
       }

       return(rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult InternetSearchDataSource::EngineFileFromResource ( nsIRDFResource aEngineResource,
nsILocalFile **  aResult 
) [protected]

Definition at line 3424 of file nsInternetSearchService.cpp.

{
  nsresult rv = NS_OK;

  // get resource uri
  const char *engineURI = nsnull;
  rv = aResource->GetValueConst(&engineURI);
  NS_ENSURE_SUCCESS(rv, rv);

  // remove protocol from uri and get escaped file path
  nsCAutoString nativePath;
  nativePath.Assign(engineURI);

  NS_ENSURE_TRUE(StringBeginsWith(nativePath,
                                  NS_LITERAL_CSTRING(kEngineProtocol)),
                 NS_ERROR_FAILURE);
  nativePath.Cut(0, sizeof(kEngineProtocol) - 1);

  // unescape it
  NS_UnescapeURL(nativePath);

#ifdef DEBUG_SEARCH_OUTPUT
  printf("InternetSearchDataSource::EngineFileFromResource\n"
         "File Path: %s\n",
         nativePath.get());
#endif

  rv = NS_NewNativeLocalFile(nativePath, PR_TRUE, aResult);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2079 of file nsInternetSearchService.cpp.

{
       if (!aResource)      return(NS_ERROR_UNEXPECTED);
       if (!mInner)  return(NS_ERROR_UNEXPECTED);

       // remove all anonymous resources which have this as a #URL
       char   *uri = getSearchURI(aResource);
       if (!uri)     return(NS_ERROR_UNEXPECTED);
       nsAutoString  url;
       url.AssignWithConversion(uri);
       Recycle(uri);

       nsresult                    rv;
       nsCOMPtr<nsIRDFLiteral>     urlLiteral;
       if (NS_FAILED(rv = gRDFService->GetLiteral(url.get(), getter_AddRefs(urlLiteral)))
              || (urlLiteral == nsnull))  return(NS_ERROR_UNEXPECTED);

       // add aResource into a list of nodes to filter out
       PRBool alreadyFiltered = PR_FALSE;
  rv = mLocalstore->HasAssertion(kNC_FilterSearchURLsRoot, kNC_Child,
         urlLiteral, PR_TRUE, &alreadyFiltered);
  if (NS_SUCCEEDED(rv) && alreadyFiltered)
       {
              // already filtered, nothing to do
              return(rv);
       }

       // filter this URL out
       mLocalstore->Assert(kNC_FilterSearchURLsRoot, kNC_Child, urlLiteral, PR_TRUE);

       // flush localstore
       nsCOMPtr<nsIRDFRemoteDataSource> remoteLocalStore (do_QueryInterface(mLocalstore));
       if (remoteLocalStore)
       {
              remoteLocalStore->Flush();
       }

       nsCOMPtr<nsISimpleEnumerator>      anonArcs;
       if (NS_SUCCEEDED(rv = mInner->GetSources(kNC_URL, urlLiteral, PR_TRUE,
              getter_AddRefs(anonArcs))))
       {
              PRBool               hasMoreAnonArcs = PR_TRUE;
    while (hasMoreAnonArcs)
              {
      if (NS_FAILED(anonArcs->HasMoreElements(&hasMoreAnonArcs)) ||
          !hasMoreAnonArcs)
        break;
                     nsCOMPtr<nsISupports>       anonArc;
                     if (NS_FAILED(anonArcs->GetNext(getter_AddRefs(anonArc))))
                            break;
                     nsCOMPtr<nsIRDFResource> anonChild (do_QueryInterface(anonArc));
                     if (!anonChild)      continue;

                     PRBool isSearchResult = PR_FALSE;
      rv = mInner->HasAssertion(anonChild, kRDF_type, kNC_SearchResult,
                                PR_TRUE, &isSearchResult);
      if (NS_FAILED(rv) || !isSearchResult)
                            continue;

                     nsCOMPtr<nsIRDFResource>    anonParent;
                     if (NS_FAILED(rv = mInner->GetSource(kNC_Child, anonChild, PR_TRUE,
                            getter_AddRefs(anonParent))))      continue;
                     if (!anonParent)     continue;

                     mInner->Unassert(anonParent, kNC_Child, anonChild);
              }
       }

       return(NS_OK);
}

Here is the call graph for this function:

Definition at line 2153 of file nsInternetSearchService.cpp.

{
       if (!aResource)      return(NS_ERROR_UNEXPECTED);
       if (!mInner)  return(NS_ERROR_UNEXPECTED);

       char   *uri = getSearchURI(aResource);
       if (!uri)     return(NS_ERROR_UNEXPECTED);
       nsAutoString  host;
       host.AssignWithConversion(uri);
       Recycle(uri);

       // determine site (host name)
       PRInt32              slashOffset1 = host.Find("://");
       if (slashOffset1 < 1)                     return(NS_ERROR_UNEXPECTED);
       PRInt32       slashOffset2 = host.FindChar(PRUnichar('/'), slashOffset1 + 3);
       if (slashOffset2 <= slashOffset1)  return(NS_ERROR_UNEXPECTED);
       host.Truncate(slashOffset2 + 1);

       nsresult                    rv;
       nsCOMPtr<nsIRDFLiteral>     urlLiteral;
       if (NS_FAILED(rv = gRDFService->GetLiteral(host.get(), getter_AddRefs(urlLiteral)))
              || (urlLiteral == nsnull))  return(NS_ERROR_UNEXPECTED);

       // add aResource into a list of nodes to filter out
       PRBool alreadyFiltered = PR_FALSE;
  rv = mLocalstore->HasAssertion(kNC_FilterSearchSitesRoot, kNC_Child,
         urlLiteral, PR_TRUE, &alreadyFiltered);
  if (NS_SUCCEEDED(rv) && alreadyFiltered)
       {
              // already filtered, nothing to do
              return(rv);
       }

       // filter this site out
       mLocalstore->Assert(kNC_FilterSearchSitesRoot, kNC_Child, urlLiteral, PR_TRUE);

       // flush localstore
       nsCOMPtr<nsIRDFRemoteDataSource> remoteLocalStore (do_QueryInterface(mLocalstore));
       if (remoteLocalStore)
       {
              remoteLocalStore->Flush();
       }

       // remove all anonymous resources which have this as a site

       nsCOMPtr<nsISupportsArray>  array;
       nsCOMPtr<nsIRDFResource>    aRes;
       nsCOMPtr<nsISimpleEnumerator>      cursor;
       PRBool                      hasMore;

       rv = NS_NewISupportsArray(getter_AddRefs(array));
       if (NS_FAILED(rv)) return rv;

       if (NS_FAILED(rv = GetAllResources(getter_AddRefs(cursor))))   return(rv);
       if (!cursor)  return(NS_ERROR_UNEXPECTED);

       hasMore = PR_TRUE;
  while (hasMore)
       {
              if (NS_FAILED(rv = cursor->HasMoreElements(&hasMore)))  return(rv);
    if (!hasMore)
      break;
              
              nsCOMPtr<nsISupports>       isupports;
              if (NS_FAILED(rv = cursor->GetNext(getter_AddRefs(isupports))))
                            return(rv);
              if (!isupports)      return(NS_ERROR_UNEXPECTED);
              aRes = do_QueryInterface(isupports);
              if (!aRes)    return(NS_ERROR_UNEXPECTED);

              if ((aRes.get() == kNC_LastSearchRoot) || (isSearchURI(aRes)))
              {
                     array->AppendElement(aRes);
              }
       }

       PRUint32      count;
       if (NS_FAILED(rv = array->Count(&count))) return(rv);
       for (PRUint32 loop=0; loop<count; loop++)
       {
              nsCOMPtr<nsIRDFResource> aSearchRoot (do_QueryElementAt(array, loop));
              if (!aSearchRoot)    break;

              if (NS_SUCCEEDED(rv = mInner->GetTargets(aSearchRoot, kNC_Child,
                     PR_TRUE, getter_AddRefs(cursor))))
              {
                     hasMore = PR_TRUE;
      while (hasMore)
                     {
        if (NS_FAILED(cursor->HasMoreElements(&hasMore)) || !hasMore)
          break;

                            nsCOMPtr<nsISupports>              arc;
                            if (NS_FAILED(cursor->GetNext(getter_AddRefs(arc))))
                                   break;
                            aRes = do_QueryInterface(arc);
                            if (!aRes)    break;

                            uri = getSearchURI(aRes);
                            if (!uri)     return(NS_ERROR_UNEXPECTED);
                            nsAutoString  site;
                            site.AssignWithConversion(uri);
                            Recycle(uri);

                            // determine site (host name)
                            slashOffset1 = site.Find("://");
                            if (slashOffset1 < 1)                     return(NS_ERROR_UNEXPECTED);
                            slashOffset2 = site.FindChar(PRUnichar('/'), slashOffset1 + 3);
                            if (slashOffset2 <= slashOffset1)  return(NS_ERROR_UNEXPECTED);
                            site.Truncate(slashOffset2 + 1);

                            if (site.Equals(host, nsCaseInsensitiveStringComparator()))
                            {
                                   mInner->Unassert(aSearchRoot, kNC_Child, aRes);
                            }
                     }
              }
       }

       return(NS_OK);
}

Here is the call graph for this function:

Definition at line 3373 of file nsInternetSearchService.cpp.

{
       if (!engine)  return(NS_ERROR_NULL_POINTER);
       if (!dataLit) return(NS_ERROR_NULL_POINTER);

       *dataLit = nsnull;

       if (!mInner)  return(NS_RDF_NO_VALUE);

       nsresult             rv;

       nsCOMPtr<nsIRDFNode> dataTarget = nsnull;
       if (NS_SUCCEEDED((rv = mInner->GetTarget(engine, kNC_Data, PR_TRUE,
              getter_AddRefs(dataTarget)))) && (dataTarget))
       {
              nsCOMPtr<nsIRDFLiteral>     aLiteral (do_QueryInterface(dataTarget));
              if (!aLiteral)
                     return(NS_ERROR_UNEXPECTED);
              *dataLit = aLiteral;
              NS_IF_ADDREF(*dataLit);
              return(NS_OK);
       }

        nsCOMPtr<nsILocalFile> engineFile;
        rv = EngineFileFromResource(engine, getter_AddRefs(engineFile));
        if (NS_FAILED(rv)) return rv;

        nsString     data;
        rv = ReadFileContents(engineFile, data);

       if (NS_FAILED(rv))
       {
              return(rv);
       }

       // save file contents
       if (data.IsEmpty())  return(NS_ERROR_UNEXPECTED);

       rv = updateDataHintsInGraph(engine, data.get());

       nsCOMPtr<nsIRDFLiteral>     aLiteral;
       if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(data.get(), getter_AddRefs(aLiteral))))
       {
              *dataLit = aLiteral;
              NS_IF_ADDREF(*dataLit);
       }
       
       return(rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void InternetSearchDataSource::FireTimer ( nsITimer aTimer,
void aClosure 
) [static, protected]

Definition at line 704 of file nsInternetSearchService.cpp.

{
       InternetSearchDataSource *search = NS_STATIC_CAST(InternetSearchDataSource *, aClosure);
       if (!search)  return;

  if (!search->busySchedule)
       {
              nsresult                    rv;
              nsCOMPtr<nsIRDFResource>    searchURI;
              nsCAutoString               updateURL;
              if (NS_FAILED(rv = search->GetSearchEngineToPing(getter_AddRefs(searchURI), updateURL)))
                     return;
              if (!searchURI)                    return;
              if (updateURL.IsEmpty())    return;

              search->busyResource = searchURI;

              nsCOMPtr<nsIInternetSearchContext> engineContext;
              if (NS_FAILED(rv = NS_NewInternetSearchContext(nsIInternetSearchContext::ENGINE_UPDATE_HEAD_CONTEXT,
                     nsnull, searchURI, nsnull, nsnull, getter_AddRefs(engineContext))))
                     return;
              if (!engineContext)  return;

              nsCOMPtr<nsIURI>     uri;
              if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(uri), updateURL.get())))  return;

              nsCOMPtr<nsIChannel> channel;
              if (NS_FAILED(rv = NS_NewChannel(getter_AddRefs(channel), uri, nsnull)))     return;

              channel->SetLoadFlags(nsIRequest::VALIDATE_ALWAYS);

              nsCOMPtr<nsIHttpChannel> httpChannel (do_QueryInterface(channel));
              if (!httpChannel)    return;

              // rjc says: just check "HEAD" info for whether a search file has changed
        httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("HEAD"));
              if (NS_SUCCEEDED(rv = channel->AsyncOpen(search, engineContext)))
              {
                     search->busySchedule = PR_TRUE;

#ifdef DEBUG_SEARCH_UPDATES
                     printf("    InternetSearchDataSource::FireTimer - Pinging '%s'\n", (char *)updateURL.get());
#endif
              }
       }
#ifdef DEBUG_SEARCH_UPDATES
else
       {
       printf("    InternetSearchDataSource::FireTimer - busy pinging.\n");
       }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1369 of file nsInternetSearchService.cpp.

{
       nsIRDFDataSource     *ds;
       nsresult rv = CallCreateInstance(kRDFXMLDataSourceCID, &ds);
       if (NS_FAILED(rv))   return(rv);
       if (!ds)             return(NS_ERROR_UNEXPECTED);

       categoryDataSource = do_QueryInterface(ds);
       NS_RELEASE(ds);
       ds = nsnull;
       if (!categoryDataSource)    return(NS_ERROR_UNEXPECTED);

       nsCOMPtr<nsIRDFRemoteDataSource> remoteCategoryDataSource (do_QueryInterface(categoryDataSource));
       if (!remoteCategoryDataSource)     return(NS_ERROR_UNEXPECTED);

       // get search.rdf
              
  nsCOMPtr<nsIFile> searchFile;
  nsCAutoString searchFileURLSpec;

  rv = NS_GetSpecialDirectory(NS_APP_SEARCH_50_FILE, getter_AddRefs(searchFile));
  if (NS_FAILED(rv)) return rv;
  NS_GetURLSpecFromFile(searchFile, searchFileURLSpec);
  if (NS_FAILED(rv)) return rv;
       rv = remoteCategoryDataSource->Init(searchFileURLSpec.get());
  if (NS_FAILED(rv)) return rv;
    
       // synchronous read
       rv = remoteCategoryDataSource->Refresh(PR_TRUE);
       if (NS_FAILED(rv))   return(rv);

       // ensure that all search engine references actually exist; if not, forget about them

       PRBool                      isDirtyFlag = PR_FALSE;
       nsCOMPtr<nsIRDFContainer>   categoryRoot;
       rv = gRDFC->MakeSeq(categoryDataSource, kNC_SearchCategoryRoot, getter_AddRefs(categoryRoot));
       if (NS_FAILED(rv))   return(rv);
       if (!categoryRoot)   return(NS_ERROR_UNEXPECTED);

       rv = categoryRoot->Init(categoryDataSource, kNC_SearchCategoryRoot);
       if (NS_FAILED(rv))   return(rv);

       PRInt32              numCategories = 0;
       rv = categoryRoot->GetCount(&numCategories);
       if (NS_FAILED(rv))   return(rv);

       // Note: one-based
       for (PRInt32 catLoop=1; catLoop <= numCategories; catLoop++)
       {
              nsCOMPtr<nsIRDFResource>    aCategoryOrdinal;
              rv = gRDFC->IndexToOrdinalResource(catLoop,
                     getter_AddRefs(aCategoryOrdinal));
              if (NS_FAILED(rv))   break;
              if (!aCategoryOrdinal)      break;

              nsCOMPtr<nsIRDFNode>        aCategoryNode;
              rv = categoryDataSource->GetTarget(kNC_SearchCategoryRoot, aCategoryOrdinal,
                     PR_TRUE, getter_AddRefs(aCategoryNode));
              if (NS_FAILED(rv))   break;
              nsCOMPtr<nsIRDFResource> aCategoryRes (do_QueryInterface(aCategoryNode));
              if (!aCategoryRes)   break;
              const  char                 *catResURI = nsnull;
              aCategoryRes->GetValueConst(&catResURI);
              if (!catResURI)             break;
              nsAutoString         categoryStr;
              categoryStr.AssignWithConversion(kURINC_SearchCategoryPrefix);
              categoryStr.AppendWithConversion(catResURI);

              nsCOMPtr<nsIRDFResource>    searchCategoryRes;
              if (NS_FAILED(rv = gRDFService->GetUnicodeResource(categoryStr,
                     getter_AddRefs(searchCategoryRes))))      break;

              nsCOMPtr<nsIRDFContainer> categoryContainer;
              rv = gRDFC->MakeSeq(categoryDataSource, searchCategoryRes,
                     getter_AddRefs(categoryContainer));
              if (NS_FAILED(rv))   continue;

              rv = categoryContainer->Init(categoryDataSource, searchCategoryRes);
              if (NS_FAILED(rv))   return(rv);

              PRInt32              numEngines = 0;
              rv = categoryContainer->GetCount(&numEngines);
              if (NS_FAILED(rv))   break;

              // Note: one-based, and loop backwards as we might be removing entries
              for (PRInt32 engineLoop=numEngines; engineLoop >= 1; engineLoop--)
              {
                     nsCOMPtr<nsIRDFResource>    aEngineOrdinal;
                     rv = gRDFC->IndexToOrdinalResource(engineLoop,
                            getter_AddRefs(aEngineOrdinal));
                     if (NS_FAILED(rv))   break;
                     if (!aEngineOrdinal) break;

                     nsCOMPtr<nsIRDFNode>        aEngineNode;
                     rv = categoryDataSource->GetTarget(searchCategoryRes, aEngineOrdinal,
                            PR_TRUE, getter_AddRefs(aEngineNode));
                     if (NS_FAILED(rv))   break;
                     nsCOMPtr<nsIRDFResource> aEngineRes (do_QueryInterface(aEngineNode));
                     if (!aEngineRes)     break;

                     if (isSearchCategoryEngineURI(aEngineRes))
                     {
                            nsCOMPtr<nsIRDFResource>    trueEngine;
                            rv = resolveSearchCategoryEngineURI(aEngineRes,
                                   getter_AddRefs(trueEngine));
                            if (NS_FAILED(rv) || (!trueEngine))
                            {
                                   // unable to resolve, so forget about this engine reference
#ifdef DEBUG
                                   const  char          *catEngineURI = nsnull;
                                   aEngineRes->GetValueConst(&catEngineURI);
                                   if (catEngineURI)
                                   {
                                          printf("**** Stale search engine reference to '%s'\n",
                                                 catEngineURI);
                                   }
#endif
                                   nsCOMPtr<nsIRDFNode> staleCatEngine;
                                   rv = categoryContainer->RemoveElementAt(engineLoop, PR_TRUE,
                                          getter_AddRefs(staleCatEngine));
                                   isDirtyFlag = PR_TRUE;
                            }
                     }
              }
       }

  if (isDirtyFlag)
       {
              if (remoteCategoryDataSource)
              {
                     remoteCategoryDataSource->Flush();
              }
       }

       return(rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult InternetSearchDataSource::GetData ( const PRUnichar data,
const char *  sectionToFind,
PRUint32  sectionNum,
const char *  attribToFind,
nsString value 
) [protected]

Definition at line 4549 of file nsInternetSearchService.cpp.

{
       nsString      buffer(dataUni);

       nsresult      rv = NS_RDF_NO_VALUE;
       PRBool        inSection = PR_FALSE;

       nsAutoString  section;
       section.AssignLiteral("<");
       section.AppendWithConversion(sectionToFind);

       while(!buffer.IsEmpty())
       {
              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.IsEmpty())  continue;            // skip empty lines
              if (line[0] == PRUnichar('#'))     continue;     // skip comments
              line.Trim(" \t");
    if (!inSection)
              {
                     PRInt32       sectionOffset = nsString_Find(section, line, PR_TRUE);
                     if (sectionOffset < 0)      continue;
                     if (sectionNum > 0)
                     {
                            --sectionNum;
                            continue;
                     }
                     line.Cut(0, sectionOffset + section.Length() + 1);
                     inSection = PR_TRUE;
              }
              line.Trim(" \t");
              PRInt32       len = line.Length();
              if (len > 0)
              {
                     if (line[len-1] == PRUnichar('>'))
                     {
                            inSection = PR_FALSE;
                            line.SetLength(len-1);
                     }
              }
              PRInt32 equal = line.FindChar(PRUnichar('='));
              if (equal < 0)       continue;                   // skip lines with no equality
              
              nsAutoString  attrib;
              if (equal > 0)
              {
                     line.Left(attrib, equal /* - 1 */);
              }
              attrib.Trim(" \t");
              if (attrib.EqualsIgnoreCase(attribToFind))
              {
                     line.Cut(0, equal+1);
                     line.Trim(" \t");
                     value = line;

                     // strip of any enclosing quotes and trailing comments
                     if ((value[0] == PRUnichar('\"')) || (value[0] == PRUnichar('\'')))
                     {
                            PRUnichar quoteChar = value[0];
                            value.Cut(0,1);
                            if (!value.IsEmpty())
                            {
                                   PRInt32 quoteEnd = value.FindChar(quoteChar);
                                   if (quoteEnd >= 0)
                                   {
                                          value.Truncate(quoteEnd);
                                   }
                            }
                     }
                     else
                     {
                            PRInt32 commentOffset = value.FindCharInSet("# \t", 0);
                            if (commentOffset >= 0)
                            {
                                   value.Truncate(commentOffset);
                            }
                            value.Trim(" \t");
                     }
                     rv = NS_OK;
                     break;
              }
       }
       return(rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult InternetSearchDataSource::GetInputs ( const PRUnichar data,
nsString engineName,
nsString userVar,
const nsString text,
nsString input,
PRInt16  direction,
PRUint16  pageNumber,
PRUint16 whichButtons 
) [protected]

Definition at line 4644 of file nsInternetSearchService.cpp.

{
       nsString      buffer(dataUni);

       nsresult      rv = NS_OK;
       PRBool        inSection = PR_FALSE;
  PRBool    inDirInput; // directional input: "inputnext" or "inputprev"
  PRBool    foundInput = PR_FALSE;

       while(!buffer.IsEmpty())
       {
              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.IsEmpty())  continue;            // skip empty lines
              if (line[0] == PRUnichar('#'))     continue;     // skip comments
              line.Trim(" \t");
    if (!inSection)
              {
                     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)
      continue;

              // look for inputs
              if (line.Find("input", PR_TRUE) == 0)
              {
      line.Cut(0, 5);

      // look for "inputnext" or "inputprev"
      inDirInput = PR_FALSE;

      if (line.Find("next", PR_TRUE) == 0)
      {
        inDirInput = PR_TRUE;
        if (whichButtons)
          *whichButtons |= kHaveNext;
      }

      if (line.Find("prev", PR_TRUE) == 0)
      {
        inDirInput = PR_TRUE;
        if (whichButtons)
          *whichButtons |= kHavePrev;
      }

      if (inDirInput)
        line.Cut(0, 4);
      
                     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('='), nameOffset);
                            if (equal >= 0)
                            {
                                   PRInt32       startQuote = line.FindChar(PRUnichar('\"'), equal + 1);
                                   if (startQuote >= 0)
                                   {
                                          PRInt32       endQuote = line.FindChar(PRUnichar('\"'), startQuote + 1);
                                          if (endQuote > 0)
                                          {
                                                 line.Mid(nameAttrib, startQuote+1, endQuote-startQuote-1);
                                                 line.Cut(0, endQuote + 1);
                                          }
                                   }
                                   else
                                   {
                                          nameAttrib = line;
                                          nameAttrib.Cut(0, equal+1);
                                          nameAttrib.Trim(" \t");
                                          PRInt32 space = nameAttrib.FindCharInSet(" \t", 0);
                                          if (space > 0)
                                          {
                                                 nameAttrib.Truncate(space);
                                                 line.Cut(0, equal+1+space);
                                          }
                                          else
                                          {
                                                 line.Truncate();
                                          }
                                   }
                            }
                     }
      if (foundInput && nameAttrib.IsEmpty()) 
        continue;

                     // first look for value attribute
                     nsAutoString  valueAttrib;

      PRInt32  valueOffset;
      if (!inDirInput)
        valueOffset = line.Find("value", PR_TRUE);
      else
        valueOffset = line.Find("factor", PR_TRUE);
                     if (valueOffset >= 0)
                     {
                            PRInt32 equal = line.FindChar(PRUnichar('='), valueOffset);
                            if (equal >= 0)
                            {
                                   PRInt32       startQuote = line.FindChar(PRUnichar('\"'), equal + 1);
                                   if (startQuote >= 0)
                                   {
                                          PRInt32       endQuote = line.FindChar(PRUnichar('\"'), 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.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.Assign(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 (!valueAttrib.IsEmpty())
                     {
        // Here's how we construct the input string:
        // <input> is first: Name Attr: Prefix      Data           Example:
        // YES               EMPTY      None        <value>        ACTION<value>
        // YES               NON-EMPTY  ?           <name>=<value> ACTION?<name>=<value>
        // NO                EMPTY      ----------- <ignored> -------------
        // NO                NON-EMPTY  &           <name>=<value> ACTION?<n1>=<v1>&<n2>=<v2>
                            if (!input.IsEmpty())
                                   input.AppendLiteral("&");
        else if (!nameAttrib.IsEmpty()) 
          input.AppendLiteral("?");

        if (!nameAttrib.IsEmpty()) 
        {
                              input += nameAttrib;
          input.AppendLiteral("=");
        }

        // Indicate that we've already found an input, so we cannot have any 
        // inputs after this that do not have names. I could be more sophisticated
        // than this but I don't care right now since I'm only doing this for one
        // plugin. --ben
        foundInput = PR_TRUE;

        if (!inDirInput)
          input += valueAttrib;
        else
          input.AppendInt( computeIndex(valueAttrib, pageNumber, direction) );
                     }
              }
       }

  // Now add the default vs. non-default parameters, which come from 
  // preferences and are part of the pre-configuration.
  nsCOMPtr<nsIPrefService> pserv(do_QueryInterface(prefs));
  if (pserv) 
  {
    // If the pref "browser.search.defaultenginename" has a user value, that
    // means the user has changed the engine in the list. This implies that
    // the selected engine was _not_ configured as the default by the 
    // distributor, because if the value of the pref matched, prefHasUserValue
    // would return false. 
    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));
      if (NS_SUCCEEDED(rv)) {
        defaultEngineName->GetData(getter_Copies(defaultEngineNameStr));

        nsXPIDLString selectedEngineNameStr;
        nsCOMPtr<nsIPrefLocalizedString> selectedEngineName;
        rv = rootBranch->GetComplexValue("browser.search.selectedEngine", 
                                         NS_GET_IID(nsIPrefLocalizedString),
                                         getter_AddRefs(selectedEngineName));
        if (NS_SUCCEEDED(rv) && selectedEngineName) {
          selectedEngineName->GetData(getter_Copies(selectedEngineNameStr));
          engineIsNotDefault = !defaultEngineNameStr.Equals(selectedEngineNameStr);
        }
        else {
          engineIsNotDefault = PR_FALSE; // The selected engine *is* the default
                                         // since the user has not changed the
                                         // selected item in the list causing
                                         // the selectedEngine pref to be set.
        }
      }
    }

    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);

    // Now add the release identifier
    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;
    }

    // Now add order parameters.
    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;
  }

       return(rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult InternetSearchDataSource::GetNumInterpretSections ( const PRUnichar data,
PRUint32 numInterpretSections 
) [protected]

Definition at line 4503 of file nsInternetSearchService.cpp.

{
       numInterpretSections = 0;

       nsString      buffer(dataUni);

       NS_NAMED_LITERAL_STRING(section, "<interpret");
       PRBool        inSection = PR_FALSE;

       while(!buffer.IsEmpty())
       {
              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.IsEmpty())  continue;            // skip empty lines
              if (line[0] == PRUnichar('#'))     continue;     // skip comments
              line.Trim(" \t");
    if (!inSection)
              {
                     PRInt32       sectionOffset = nsString_Find(section, line, PR_TRUE);
                     if (sectionOffset < 0)      continue;
                     line.Cut(0, sectionOffset + section.Length() + 1);
                     inSection = PR_TRUE;
                     ++numInterpretSections;                   // increment # of sections
              }
              line.Trim(" \t");
              PRInt32       len = line.Length();
              if (len > 0)
              {
                     if (line[len-1] == PRUnichar('>'))
                     {
                            inSection = PR_FALSE;
                            line.SetLength(len-1);
                     }
              }
       }
       return(NS_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult InternetSearchDataSource::GetSearchEngineList ( nsIFile spec,
PRBool  isSystemSearchFile 
) [protected]

Definition at line 4347 of file nsInternetSearchService.cpp.

{
        nsresult                   rv = NS_OK;

    if (!mInner)
    {
       return(NS_RDF_NO_VALUE);
    }

    PRBool hasMore = PR_FALSE;
    nsCOMPtr<nsISimpleEnumerator> dirIterator;
    rv = searchDir->GetDirectoryEntries(getter_AddRefs(dirIterator));
    if (NS_FAILED(rv)) return rv;

    nsCOMPtr<nsIFile> dirEntry;
       while ((rv = dirIterator->HasMoreElements(&hasMore)) == NS_OK && hasMore)
       {
              rv = dirIterator->GetNext((nsISupports**)getter_AddRefs(dirEntry));
        if (NS_FAILED(rv))
          continue;

        // Ignore hidden files/directories
        PRBool isHidden;
        rv = dirEntry->IsHidden(&isHidden);
        if (NS_FAILED(rv) || isHidden)
          continue;

        PRBool isDirectory;
        rv = dirEntry->IsDirectory(&isDirectory);
        if (NS_FAILED(rv))
          continue;
        if (isDirectory)
        {
          GetSearchEngineList(dirEntry, isSystemSearchFile);
          continue;
        }

        // Skip over empty files
        // Note: use GetFileSize even on Mac [instead of GetFileSizeWithResFork()]
        // as we want the size of ONLY the data fork
        PRInt64 fileSize;
        rv = dirEntry->GetFileSize(&fileSize);
        if (NS_FAILED(rv) || (fileSize == 0))
            continue;
    
        nsAutoString uri;
        rv = dirEntry->GetPath(uri);
        if (NS_FAILED(rv))
        continue;

              PRInt32              len = uri.Length();
              if (len < 5)
              {
                     continue;
              }

              // check the extension (must be ".src")
              nsAutoString  extension;
              if ((uri.Right(extension, 4) != 4) || (!extension.LowerCaseEqualsLiteral(".src")))
              {
                     continue;
              }

              // check for various icons
              PRBool        foundIconFlag = PR_FALSE;
              nsAutoString  temp;
              
              nsCOMPtr<nsILocalFile> iconFile, loopFile;

                static const char *extensions[] = {
                        ".gif",
                        ".jpg",
                        ".jpeg",
                        ".png",
                        nsnull,
                };

                for (int ext_count = 0; extensions[ext_count] != nsnull; ext_count++) {
                        temp = Substring(uri, 0, uri.Length()-4);
                        temp.Append(NS_ConvertASCIItoUCS2(extensions[ext_count]));
                        rv = NS_NewLocalFile(temp, PR_TRUE, getter_AddRefs(loopFile));
                        if (NS_FAILED(rv)) return rv;
                        rv = loopFile->Exists(&foundIconFlag);
                        if (NS_FAILED(rv)) return rv;
                        if (!foundIconFlag) continue;
                        rv = loopFile->IsFile(&foundIconFlag);
                        if (NS_FAILED(rv)) return rv;
                        if (foundIconFlag) 
                        {
                                iconFile = loopFile;
                                break;
                        } 
                }
              
              SaveEngineInfoIntoGraph(dirEntry, iconFile, nsnull, nsnull, isSystemSearchFile);
       }

#ifdef MOZ_PHOENIX
    if (!gReorderedEngineList)
      ReorderEngineList();
#endif
       return(rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult InternetSearchDataSource::GetSearchEngineToPing ( nsIRDFResource **  theResource,
nsCString updateURL 
) [protected]

Definition at line 646 of file nsInternetSearchService.cpp.

{
       nsresult      rv = NS_OK;

       *theEngine = nsnull;
       updateURL.Truncate();

       if (!mUpdateArray)   return(NS_OK);

       PRUint32      numEngines = 0;
       if (NS_FAILED(rv = mUpdateArray->Count(&numEngines)))   return(rv);
       if (numEngines < 1)  return(NS_OK);

       nsCOMPtr<nsIRDFResource> aRes (do_QueryElementAt(mUpdateArray, 0));

       // note: important to remove element from array
       mUpdateArray->RemoveElementAt(0);

       if (aRes)
       {
              if (isSearchCategoryEngineURI(aRes))
              {
                     nsCOMPtr<nsIRDFResource>    trueEngine;
                     rv = resolveSearchCategoryEngineURI(aRes, getter_AddRefs(trueEngine));
                     if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE))    return(rv);
                     if (!trueEngine)     return(NS_RDF_NO_VALUE);

                     aRes = trueEngine;
              }

              if (!aRes)    return(NS_OK);

              *theEngine = aRes.get();
              NS_ADDREF(*theEngine);

              // get update URL
              nsCOMPtr<nsIRDFNode> aNode;
              if (NS_SUCCEEDED(rv = mInner->GetTarget(aRes, kNC_Update, PR_TRUE, getter_AddRefs(aNode)))
                            && (rv != NS_RDF_NO_VALUE))
              {
                     nsCOMPtr<nsIRDFLiteral>     aLiteral (do_QueryInterface(aNode));
                     if (aLiteral)
                     {
                            const PRUnichar      *updateUni = nsnull;
                            aLiteral->GetValueConst(&updateUni);
                            if (updateUni)
                            {
                                   updateURL.AssignWithConversion(updateUni);
                            }
                     }
              }
       }
       return(rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1944 of file nsInternetSearchService.cpp.

{
       char   *uri = nsnull;

       if (src)
       {
              nsresult             rv;
              nsCOMPtr<nsIRDFNode> srcNode;
              if (NS_SUCCEEDED(rv = mInner->GetTarget(src, kNC_URL, PR_TRUE, getter_AddRefs(srcNode))))
              {
                     nsCOMPtr<nsIRDFLiteral>     urlLiteral (do_QueryInterface(srcNode));
                     if (urlLiteral)
                     {
                            const PRUnichar      *uriUni = nsnull;
                            urlLiteral->GetValueConst(&uriUni);
                            if (uriUni)
                            {
                                   nsAutoString  uriString(uriUni);
                                   uri = ToNewUTF8String(uriString);
                            }
                     }
              }
       }
       return(uri);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult InternetSearchDataSource::GetURL ( nsIRDFResource source,
nsIRDFLiteral **  aResult 
) [protected]

Definition at line 5025 of file nsInternetSearchService.cpp.

{
        const char   *uri = nsnull;
       source->GetValueConst( &uri );
       nsAutoString  url;
       url.AssignWithConversion(uri);
       nsIRDFLiteral *literal;
       gRDFService->GetLiteral(url.get(), &literal);
        *aResult = literal;
        return NS_OK;
}

Here is the call graph for this function:

Definition at line 926 of file nsInternetSearchService.cpp.

{
       nsresult      rv = NS_ERROR_OUT_OF_MEMORY;

       if (NS_FAILED(rv = CallCreateInstance(kRDFInMemoryDataSourceCID, &mInner)))
              return(rv);

       // get localstore, as we'll be using it
       if (NS_FAILED(rv = gRDFService->GetDataSource("rdf:local-store", getter_AddRefs(mLocalstore))))
              return(rv);

       if (NS_FAILED(rv = NS_NewISupportsArray(getter_AddRefs(mUpdateArray))))
              return(rv);

       // register this as a named data source with the service manager
       if (NS_FAILED(rv = gRDFService->RegisterDataSource(this, PR_FALSE)))
              return(rv);

       rv = NS_NewLoadGroup(getter_AddRefs(mLoadGroup), nsnull);
       NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create load group");

       if (!mTimer)
       {
              busySchedule = PR_FALSE;
              mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
              if (mTimer)
              {
                     mTimer->InitWithFuncCallback(InternetSearchDataSource::FireTimer, this,
                                                     SEARCH_UPDATE_TIMEOUT, nsITimer::TYPE_REPEATING_SLACK);
                     // Note: don't addref "this" as we'll cancel the timer in the
                     //       InternetSearchDataSource destructor
              }
       }

       gEngineListBuilt = PR_FALSE;

       // Register as a profile change obsevrer
  nsCOMPtr<nsIObserverService> observerService = 
           do_GetService("@mozilla.org/observer-service;1", &rv);
  if (observerService) {
    observerService->AddObserver(this, "profile-before-change", PR_TRUE);
    observerService->AddObserver(this, "profile-do-change", PR_TRUE);
  }

       return(rv);
}

Here is the call graph for this function:

Definition at line 760 of file nsInternetSearchService.cpp.

{
       PRBool        isEngineURIFlag = PR_FALSE;
       const char    *uri = nsnull;
       
       r->GetValueConst(&uri);
       if ((uri) && (!strncmp(uri, kEngineProtocol, sizeof(kEngineProtocol) - 1)))
       {
              isEngineURIFlag = PR_TRUE;
       }
       return(isEngineURIFlag);
}

Here is the call graph for this function:

Definition at line 824 of file nsInternetSearchService.cpp.

{
       PRBool        isSearchCategoryEngineBasenameURIFlag = PR_FALSE;

       nsCOMPtr<nsIRDFResource> aRes (do_QueryInterface(r));
       if (aRes)
       {
              const char    *uri = nsnull;
              aRes->GetValueConst(&uri);
              if ((uri) && (!nsCRT::strncmp(uri, kURINC_SearchCategoryEngineBasenamePrefix,
                     (int)sizeof(kURINC_SearchCategoryEngineBasenamePrefix) - 1)))
              {
                     isSearchCategoryEngineBasenameURIFlag = PR_TRUE;
              }
       }
       else
       {
              nsCOMPtr<nsIRDFLiteral>     aLit (do_QueryInterface(r));
              if (aLit)
              {
                     const  PRUnichar     *uriUni = nsnull;
                     aLit->GetValueConst(&uriUni);
                     if ((uriUni) && (!nsCRT::strncmp(uriUni,
                                                  NS_ConvertASCIItoUCS2(kURINC_SearchCategoryEngineBasenamePrefix).get(),
                            (int)sizeof(kURINC_SearchCategoryEngineBasenamePrefix) - 1)))
                     {
                            isSearchCategoryEngineBasenameURIFlag = PR_TRUE;
                     }
              }
       }
       return(isSearchCategoryEngineBasenameURIFlag);
}

Here is the call graph for this function:

Definition at line 808 of file nsInternetSearchService.cpp.

{
       PRBool        isSearchCategoryEngineURIFlag = PR_FALSE;
       const char    *uri = nsnull;
       
       r->GetValueConst(&uri);
       if ((uri) && (!strncmp(uri, kURINC_SearchCategoryEnginePrefix, sizeof(kURINC_SearchCategoryEnginePrefix) - 1)))
       {
              isSearchCategoryEngineURIFlag = PR_TRUE;
       }
       return(isSearchCategoryEngineURIFlag);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 792 of file nsInternetSearchService.cpp.

{
       PRBool        isSearchCategoryURIFlag = PR_FALSE;
       const char    *uri = nsnull;
       
       r->GetValueConst(&uri);
       if ((uri) && (!strncmp(uri, kURINC_SearchCategoryPrefix, sizeof(kURINC_SearchCategoryPrefix) - 1)))
       {
              isSearchCategoryURIFlag = PR_TRUE;
       }
       return(isSearchCategoryURIFlag);
}

Here is the call graph for this function:

Definition at line 860 of file nsInternetSearchService.cpp.

{
       PRBool        isSearchCommandFlag = PR_FALSE;
       const char    *uri = nsnull;
       
       if (NS_SUCCEEDED(r->GetValueConst( &uri )) && (uri))
       {
              if (!strncmp(uri, kSearchCommand, sizeof(kSearchCommand) - 1))
              {
                     isSearchCommandFlag = PR_TRUE;
              }
       }
       return(isSearchCommandFlag);
}

Here is the call graph for this function:

Definition at line 2338 of file nsInternetSearchService.cpp.

{
       PRBool        filterStatus = PR_FALSE;
       nsresult      rv;

       const PRUnichar      *hrefUni = hrefStr.get();
       if (!hrefUni) return(filterStatus);

       // check if this specific URL is to be filtered out
       nsCOMPtr<nsIRDFLiteral>     hrefLiteral;
       if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(hrefUni, getter_AddRefs(hrefLiteral))))
       {
              if (NS_SUCCEEDED(rv = mLocalstore->HasAssertion(kNC_FilterSearchURLsRoot,
                     kNC_Child, hrefLiteral, PR_TRUE, &filterStatus)))
              {
      if (filterStatus)
                     {
                            return(filterStatus);
                     }
              }
       }

       // check if this specific Site is to be filtered out

       // determine site (host name)
       nsAutoString  host(hrefStr);
       PRInt32              slashOffset1 = host.Find("://");
       if (slashOffset1 < 1)                     return(NS_ERROR_UNEXPECTED);
       PRInt32       slashOffset2 = host.FindChar(PRUnichar('/'), slashOffset1 + 3);
       if (slashOffset2 <= slashOffset1)  return(NS_ERROR_UNEXPECTED);
       host.Truncate(slashOffset2 + 1);

       nsCOMPtr<nsIRDFLiteral>     urlLiteral;
       if (NS_FAILED(rv = gRDFService->GetLiteral(host.get(), getter_AddRefs(urlLiteral)))
              || (urlLiteral == nsnull))  return(NS_ERROR_UNEXPECTED);

       rv = mLocalstore->HasAssertion(kNC_FilterSearchSitesRoot, kNC_Child, urlLiteral,
              PR_TRUE, &filterStatus);

       return(filterStatus);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 776 of file nsInternetSearchService.cpp.

{
       PRBool        isSearchURIFlag = PR_FALSE;
       const char    *uri = nsnull;
       
       r->GetValueConst(&uri);
       if ((uri) && (!strncmp(uri, kSearchProtocol, sizeof(kSearchProtocol) - 1)))
       {
              isSearchURIFlag = PR_TRUE;
       }
       return(isSearchURIFlag);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult InternetSearchDataSource::MapEncoding ( const nsString numericEncoding,
nsString stringEncoding 
) [protected]

Definition at line 3735 of file nsInternetSearchService.cpp.

{
       // XXX we need to have a full table of numeric --> string conversions

       struct encodings     encodingList[] =
       {
              {      "0", "x-mac-roman"   },
              {      "6", "x-mac-greek"   },
              {      "35", "x-mac-turkish"       },
              {      "513", "ISO-8859-1"  },
              {      "514", "ISO-8859-2"  },
              {      "517", "ISO-8859-5"  },
              {      "518", "ISO-8859-6"  },
              {      "519", "ISO-8859-7"  },
              {      "520", "ISO-8859-8"  },
              {      "521", "ISO-8859-9"  },
              {      "1049", "IBM864"     },
              {      "1280", "windows-1252"      },
              {      "1281", "windows-1250"      },
              {      "1282", "windows-1251"      },
              {      "1283", "windows-1253"      },
              {      "1284", "windows-1254"      },
              {      "1285", "windows-1255"      },
              {      "1286", "windows-1256"      },
              {      "1536", "us-ascii"   },
              {      "1584", "GB2312"     },
              {      "1585", "x-gbk"             },
              {      "1600", "EUC-KR"     },
              {      "2080", "ISO-2022-JP"       },
              {      "2096", "ISO-2022-CN"       },
              {      "2112", "ISO-2022-KR"       },
              {      "2336", "EUC-JP"     },
              {      "2352", "GB2312"     },
              {      "2353", "x-euc-tw"   },
              {      "2368", "EUC-KR"     },
              {      "2561", "Shift_JIS"  },
              {      "2562", "KOI8-R"     },
              {      "2563", "Big5"              },
              {      "2565", "HZ-GB-2312" },

              {      nsnull, nsnull              }
       };

  if (!numericEncoding.IsEmpty())  {
    for (PRUint32 i = 0; encodingList[i].numericEncoding != nsnull; i++)
    {
      if (numericEncoding.EqualsASCII(encodingList[i].numericEncoding)) 
      {
        stringEncoding.AssignASCII(encodingList[i].stringEncoding);
        return NS_OK;
      }
    }
  }

  // Still no encoding, fall back to default charset if possible
  nsXPIDLString defCharset;
  nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
  if (prefs)
    prefs->GetLocalizedUnicharPref("intl.charset.default", getter_Copies(defCharset));

  if (!defCharset.IsEmpty())
    stringEncoding = defCharset;
  else
    // make "ISO-8859-1" as the default (not "UTF-8")
    stringEncoding.AssignLiteral("ISO-8859-1");

  return(NS_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 3808 of file nsInternetSearchService.cpp.

{
       // Script codes listed here are taken from Inside Macintosh Text.
       // Used TECGetTextEncodingInternetName to map script code to charset name.
       // Some are edited to match with standard name (e.g. "x-mac-japanese" -> "Shift_JIS").
       // In case no converter can be found for a charset name, 
       // the default sherlock charset "x-mac-roman" should be used.
       // 
        static const char* const scriptList[] =
       {
              "x-mac-roman",           // 0
              "Shift_JIS",             // 1
              "Big5",                  // 2
              "EUC-KR",                // 3
              "X-MAC-ARABIC",          // 4
              "X-MAC-HEBREW",          // 5
              "X-MAC-GREEK",           // 6
              "X-MAC-CYRILLIC",        // 7
              "X-MAC-DEVANAGARI" ,     // 9
              "X-MAC-GURMUKHI",        // 10
              "X-MAC-GUJARATI",        // 11
              "X-MAC-ORIYA",           // 12
              "X-MAC-BENGALI",         // 13
              "X-MAC-TAMIL",           // 14
              "X-MAC-TELUGU",          // 15
              "X-MAC-KANNADA",         // 16
              "X-MAC-MALAYALAM",       // 17
              "X-MAC-SINHALESE",       // 18
              "X-MAC-BURMESE",         // 19
              "X-MAC-KHMER",           // 20
              "X-MAC-THAI",            // 21
              "X-MAC-LAOTIAN",         // 22
              "X-MAC-GEORGIAN",        // 23
              "X-MAC-ARMENIAN",        // 24
              "GB2312",                // 25
              "X-MAC-TIBETAN",         // 26
              "X-MAC-MONGOLIAN",       // 27
              "X-MAC-ETHIOPIC",        // 28
              "X-MAC-CENTRALEURROMAN", // 29
              "X-MAC-VIETNAMESE",      // 30
              "X-MAC-EXTARABIC",       // 31
       };

        if (aScriptCode >= NS_ARRAY_LENGTH(scriptList))
          aScriptCode = 0;

       return scriptList[aScriptCode];
}

Here is the caller graph for this function:

nsresult InternetSearchDataSource::ParseHTML ( nsIURI aURL,
nsIRDFResource mParent,
nsIRDFResource engine,
const PRUnichar htmlPage,
PRInt32  htmlPageSize 
) [protected]

Definition at line 5450 of file nsInternetSearchService.cpp.

{
       // get data out of graph
       nsresult      rv;
       nsCOMPtr<nsIRDFNode> dataNode;
       if (NS_FAILED(rv = mInner->GetTarget(mEngine, kNC_Data, PR_TRUE, getter_AddRefs(dataNode))))
       {
              return(rv);
       }
       nsCOMPtr<nsIRDFLiteral>     dataLiteral (do_QueryInterface(dataNode));
       if (!dataLiteral)    return(NS_ERROR_NULL_POINTER);

       const PRUnichar      *dataUni = nsnull;
       if (NS_FAILED(rv = dataLiteral->GetValueConst(&dataUni)))
              return(rv);
       if (!dataUni) return(NS_ERROR_NULL_POINTER);

       // get name of this engine once
       nsAutoString  engineStr;
       GetData(dataUni, "search", 0, "name", engineStr);

       // pre-compute host (we might discard URLs that match this)
       nsCAutoString hostName;
       aURL->GetAsciiHost(hostName);

       // pre-compute server path (we might discard URLs that match this)
       nsAutoString  serverPathStr;
       nsCAutoString serverPath;
       aURL->GetPath(serverPath);
       if (!serverPath.IsEmpty())
       {
        AppendUTF8toUTF16(serverPath, serverPathStr);
        serverPath.Truncate();

              PRInt32 serverOptionsOffset = serverPathStr.FindChar(PRUnichar('?'));
              if (serverOptionsOffset >= 0)      serverPathStr.Truncate(serverOptionsOffset);
       }

       PRBool        hasPriceFlag = PR_FALSE, hasAvailabilityFlag = PR_FALSE, hasRelevanceFlag = PR_FALSE;
       PRBool        hasDateFlag = PR_FALSE;
       PRBool        skipLocalFlag = PR_FALSE, useAllHREFsFlag = PR_FALSE;
       PRInt32              pageRank = 1;
       PRUint32      numInterpretSections, numResults = 0;

       GetNumInterpretSections(dataUni, numInterpretSections);
       if (numInterpretSections < 1)
       {
              // if no <interpret> sections, use all the HREFS on the page
              numInterpretSections = 1;
              useAllHREFsFlag = PR_TRUE;
              skipLocalFlag = PR_TRUE;
       }

#ifdef DEBUG
       PRTime        now;
       now = PR_Now();
  printf("\nStart processing search results:   %u bytes \n", htmlPageSize); 
#endif

       // need to handle multiple <interpret> sections, per spec
       for (PRUint32 interpretSectionNum=0; interpretSectionNum < numInterpretSections; interpretSectionNum++)
       {
              nsAutoString  resultListStartStr, resultListEndStr;
              nsAutoString  resultItemStartStr, resultItemEndStr;
              nsAutoString  relevanceStartStr, relevanceEndStr;
              nsAutoString  bannerStartStr, bannerEndStr, skiplocalStr;
              nsAutoString  priceStartStr, priceEndStr, availStartStr, availEndStr;
              nsAutoString  dateStartStr, dateEndStr;
              nsAutoString  nameStartStr, nameEndStr;
              nsAutoString  emailStartStr, emailEndStr;
              nsAutoString  browserResultTypeStr;
              browserResultTypeStr.AssignLiteral("result");           // default to "result"

              // use a nsDependentString so that "htmlPage" data isn't copied
              nsDependentString  htmlResults(htmlPage, htmlPageSize);
              PRUint32           startIndex = 0L, stopIndex = htmlPageSize;

    if (!useAllHREFsFlag)
              {
                     GetData(dataUni, "interpret", interpretSectionNum, "resultListStart", resultListStartStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "resultListEnd", resultListEndStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "resultItemStart", resultItemStartStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "resultItemEnd", resultItemEndStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "relevanceStart", relevanceStartStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "relevanceEnd", relevanceEndStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "bannerStart", bannerStartStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "bannerEnd", bannerEndStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "skiplocal", skiplocalStr);
                     skipLocalFlag = (skiplocalStr.LowerCaseEqualsLiteral("true")) ? PR_TRUE : PR_FALSE;

                     // shopping channel support
                     GetData(dataUni, "interpret", interpretSectionNum, "priceStart", priceStartStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "priceEnd", priceEndStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "availStart", availStartStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "availEnd", availEndStr);

                     // news channel support
                     GetData(dataUni, "interpret", interpretSectionNum, "dateStart", dateStartStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "dateEnd", dateEndStr);

                     // people channel support
                     GetData(dataUni, "interpret", interpretSectionNum, "nameStart", nameStartStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "nameEnd", nameEndStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "emailStart", emailStartStr);
                     GetData(dataUni, "interpret", interpretSectionNum, "emailEnd", emailEndStr);

                     // special browser support
                     GetData(dataUni, "interpret", interpretSectionNum, "browserResultType", browserResultTypeStr);
                     if (browserResultTypeStr.IsEmpty())
                     {
                            browserResultTypeStr.AssignLiteral("result");    // default to "result"
                     }
              }

              // look for banner
              nsCOMPtr<nsIRDFLiteral>     bannerLiteral;
              if ((!bannerStartStr.IsEmpty()) && (!bannerEndStr.IsEmpty()))
              {
                     PRInt32       bannerStart = nsString_Find(bannerStartStr, htmlResults, PR_TRUE);
                     if (bannerStart >= 0)
                     {
                            startIndex = bannerStart;

                            PRInt32       bannerEnd = nsString_Find(bannerEndStr, htmlResults, PR_TRUE, bannerStart + bannerStartStr.Length());
                            if (bannerEnd > bannerStart)
                            {
                                   stopIndex = bannerEnd - 1;

                                   nsAutoString  htmlBanner;
                                   htmlResults.Mid(htmlBanner, bannerStart, bannerEnd - bannerStart - 1);
                                   if (!htmlBanner.IsEmpty())
                                   {
                                          const PRUnichar      *bannerUni = htmlBanner.get();
                                          if (bannerUni)
                                          {
                                                 gRDFService->GetLiteral(bannerUni, getter_AddRefs(bannerLiteral));
                                          }
                                   }
                            }
                     }
              }

              if (!resultListStartStr.IsEmpty())
              {
                     PRInt32       resultListStart = nsString_Find(resultListStartStr, htmlResults, PR_TRUE);
                     if (resultListStart >= 0)
                     {
        startIndex = resultListStart + resultListStartStr.Length();
                     }
      else if (!useAllHREFsFlag)
                     {
                            // if we have multiple <INTERPRET> sections but can't find the startIndex
                            // of a result list block, just continue on with the the next block
                            continue;
                     }
              }
              if (!resultListEndStr.IsEmpty())
              {
                     // rjc note: use RFind to find the LAST
                     // occurrence of resultListEndStr

                  nsAString::const_iterator originalStart, start, end;
                  htmlResults.BeginReading(start);
                  htmlResults.EndReading(end);
                  originalStart = start;
                  
                  if (RFindInReadable(resultListEndStr, start, end))
                     stopIndex = Distance(originalStart, start);
              }

              PRBool trimItemStart = PR_TRUE;
              PRBool trimItemEnd = PR_FALSE;            // rjc note: testing shows we should NEVER trim end???

              // if resultItemStartStr is not specified, try making it just be "HREF="
              if (resultItemStartStr.IsEmpty())
              {
                     resultItemStartStr.AssignLiteral("HREF=");
                     trimItemStart = PR_FALSE;
              }

              // if resultItemEndStr is not specified, try making it the same as resultItemStartStr
              if (resultItemEndStr.IsEmpty())
              {
                     resultItemEndStr = resultItemStartStr;
                     trimItemEnd = PR_TRUE;
              }

              while(startIndex < stopIndex)
              {
                     PRInt32       resultItemStart;
                     resultItemStart = nsString_Find(resultItemStartStr, htmlResults, PR_TRUE, startIndex);
                     if (resultItemStart < 0)    break;

                     PRInt32       resultItemEnd;
      if (trimItemStart)
                     {
                            resultItemStart += resultItemStartStr.Length();
                            resultItemEnd = nsString_Find(resultItemEndStr, htmlResults, PR_TRUE, resultItemStart);
                     }
                     else
                     {
                            resultItemEnd = nsString_Find(resultItemEndStr, htmlResults, PR_TRUE, resultItemStart + resultItemStartStr.Length());
                     }

                     if (resultItemEnd < 0)
                     {
                            resultItemEnd = stopIndex;
                     }
      else if (!trimItemEnd && resultItemEnd >= 0)
                     {
                            resultItemEnd += resultItemEndStr.Length();
                     }

                     // forced to use an nsAutoString (which copies)
                     // as CBufDescriptor doesn't guarantee null terminator
                     if (resultItemEnd - resultItemStart - 1 <= 0)    break;
                     nsAutoString resultItem(&htmlPage[resultItemStart],
                            resultItemEnd - resultItemStart - 1);

                     if (resultItem.IsEmpty())   break;

                     // advance startIndex here so that, from this point onward, "continue" can be used
                     startIndex = resultItemEnd;

#ifdef DEBUG_SEARCH_OUTPUT
                     char   *results = ToNewCString(resultItem);
                     if (results)
                     {
                            printf("\n----- Search result: '%s'\n\n", results);
                            nsCRT::free(results);
                            results = nsnull;
                     }
#endif

                     // look for href
                     PRInt32       hrefOffset = resultItem.Find("HREF=", PR_TRUE);
                     if (hrefOffset < 0)
                     {
#ifdef DEBUG_SEARCH_OUTPUT
                            printf("\n***** Unable to find HREF!\n\n");
#endif
                            continue;
                     }

                     nsAutoString  hrefStr;
                     PRInt32              quoteStartOffset = resultItem.FindCharInSet("\"\'>", hrefOffset);
                     PRInt32              quoteEndOffset;
                     if (quoteStartOffset < hrefOffset)
                     {
                            // handle case where HREF isn't quoted
                            quoteStartOffset = hrefOffset + strlen("HREF=");
                            quoteEndOffset = resultItem.FindChar('>', quoteStartOffset);
                            if (quoteEndOffset < quoteStartOffset)    continue;
                     }
                     else
                     {
                            if (resultItem[quoteStartOffset] == PRUnichar('>'))
                            {
                                   // handle case where HREF isn't quoted
                                   quoteEndOffset = quoteStartOffset;
                                   quoteStartOffset = hrefOffset + strlen("HREF=") -1;
                            }
                            else
                            {
                                   quoteEndOffset = resultItem.FindCharInSet("\"\'", quoteStartOffset + 1);
                                   if (quoteEndOffset < hrefOffset)   continue;
                            }
                     }
                     resultItem.Mid(hrefStr, quoteStartOffset + 1, quoteEndOffset - quoteStartOffset - 1);

                     ConvertEntities(hrefStr, PR_FALSE, PR_TRUE, PR_FALSE);

                     if (hrefStr.IsEmpty())      continue;

                     char          *absURIStr = nsnull;
                     nsCAutoString hrefstrC;
                     hrefstrC.AssignWithConversion(hrefStr);

                     if (NS_SUCCEEDED(rv = NS_MakeAbsoluteURI(&absURIStr, hrefstrC.get(), aURL))
                         && (absURIStr))
                     {
                            hrefStr.AssignWithConversion(absURIStr);

                            nsCOMPtr<nsIURI>     absURI;
                            rv = NS_NewURI(getter_AddRefs(absURI), absURIStr);
                            nsCRT::free(absURIStr);
                            absURIStr = nsnull;

        if (absURI && skipLocalFlag)
                            {
                                   nsCAutoString absPath;
                                   absURI->GetPath(absPath);
                                   if (!absPath.IsEmpty())
                                   {
                        NS_ConvertUTF8toUCS2 absPathStr(absPath);
                                          PRInt32 pathOptionsOffset = absPathStr.FindChar(PRUnichar('?'));
                                          if (pathOptionsOffset >= 0)
                                                 absPathStr.Truncate(pathOptionsOffset);
                                          PRBool pathsMatchFlag = serverPathStr.Equals(absPathStr, nsCaseInsensitiveStringComparator());
            if (pathsMatchFlag)
              continue;
                                   }

                                   if (!hostName.IsEmpty())
                                   {
                                          nsCAutoString absHost;
                                          absURI->GetAsciiHost(absHost);
                                          if (!absHost.IsEmpty())
                                          {
                                                 PRBool hostsMatchFlag = !nsCRT::strcasecmp(hostName.get(), absHost.get());
              if (hostsMatchFlag)
                continue;
                                          }
                                   }
                            }
                     }

                     // if this result is to be filtered out, notice it now
      if (isSearchResultFiltered(hrefStr))
                            continue;

                     nsAutoString  site(hrefStr);

#ifdef DEBUG_SEARCH_OUTPUT
                     char *hrefCStr = ToNewCString(hrefStr);
                     if (hrefCStr)
                     {
                            printf("HREF: '%s'\n", hrefCStr);
                            nsCRT::free(hrefCStr);
                            hrefCStr = nsnull;
                     }
#endif

                     nsCOMPtr<nsIRDFResource>    res;

                     // save HREF attribute as URL
                     if (NS_SUCCEEDED(rv = gRDFService->GetAnonymousResource(getter_AddRefs(res))))
                     {
                            const PRUnichar      *hrefUni = hrefStr.get();
                            if (hrefUni)
                            {
                                   nsCOMPtr<nsIRDFLiteral>     hrefLiteral;
                                   if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(hrefUni, getter_AddRefs(hrefLiteral))))
                                   {
                                          mInner->Assert(res, kNC_URL, hrefLiteral, PR_TRUE);
                                   }
                            }
                     }

                     if (NS_FAILED(rv))   continue;
                     
                     // set HTML response chunk
                     const PRUnichar      *htmlResponseUni = resultItem.get();
                     if (htmlResponseUni && (gBrowserSearchMode>0))
                     {
                            nsCOMPtr<nsIRDFLiteral>     htmlResponseLiteral;
                            if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(htmlResponseUni, getter_AddRefs(htmlResponseLiteral))))
                            {
                                   if (htmlResponseLiteral)
                                   {
                                          mInner->Assert(res, kNC_HTML, htmlResponseLiteral, PR_TRUE);
                                   }
                            }
                     }
                     
                     // set banner (if we have one)
                     if (bannerLiteral)
                     {
                            mInner->Assert(res, kNC_Banner, bannerLiteral, PR_TRUE);
                     }

                     // look for Site (if it isn't already set)
                     nsCOMPtr<nsIRDFNode>        oldSiteRes = nsnull;
                     mInner->GetTarget(res, kNC_Site, PR_TRUE, getter_AddRefs(oldSiteRes));
                     if (!oldSiteRes)
                     {
                            PRInt32       protocolOffset = site.FindChar(':', 0);
                            if (protocolOffset >= 0)
                            {
                                   site.Cut(0, protocolOffset+1);
                                   while (site[0] == PRUnichar('/'))
                                   {
                                          site.Cut(0, 1);
                                   }
                                   PRInt32       slashOffset = site.FindChar('/', 0);
                                   if (slashOffset >= 0)
                                   {
                                          site.Truncate(slashOffset);
                                   }
                                   if (!site.IsEmpty())
                                   {
                                          const PRUnichar      *siteUni = site.get();
                                          if (siteUni)
                                          {
                                                 nsCOMPtr<nsIRDFLiteral>     siteLiteral;
                                                 if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(siteUni, getter_AddRefs(siteLiteral))))
                                                 {
                                                        if (siteLiteral)
                                                        {
                                                               mInner->Assert(res, kNC_Site, siteLiteral, PR_TRUE);
                                                        }
                                                 }
                                          }
                                   }
                            }
                     }

                     // look for name
                     nsAutoString  nameStr;

                     if ((!nameStartStr.IsEmpty()) && (!nameEndStr.IsEmpty()))
                     {
                            PRInt32              nameStart;
                            if ((nameStart = nsString_Find(nameStartStr, resultItem, PR_TRUE)) >= 0)
                            {
                                   nameStart += nameStartStr.Length();
                                   PRInt32       nameEnd = nsString_Find(nameEndStr, resultItem, PR_TRUE, nameStart);
                                   if (nameEnd > nameStart)
                                   {
                                          resultItem.Mid(nameStr, nameStart, nameEnd - nameStart);
                                   }
                            }
                     }

                     if (nameStr.IsEmpty())
                     {
                            PRInt32       anchorEnd = resultItem.FindChar('>', quoteEndOffset);
                            if (anchorEnd < quoteEndOffset)
                            {
#ifdef DEBUG_SEARCH_OUTPUT
                                   printf("\n\nSearch: Unable to find ending > when computing name.\n\n");
#endif
                                   continue;
                            }
                            PRInt32       anchorStop = resultItem.Find("</A>", PR_TRUE, quoteEndOffset);
                            if (anchorStop < anchorEnd)
                            {
#ifdef DEBUG_SEARCH_OUTPUT
                                   printf("\n\nSearch: Unable to find </A> tag to compute name.\n\n");
#endif
                                   continue;
                            }
                            resultItem.Mid(nameStr, anchorEnd + 1, anchorStop - anchorEnd - 1);
                     }

                     ConvertEntities(nameStr);

                     // look for Name (if it isn't already set)
                     nsCOMPtr<nsIRDFNode>        oldNameRes = nsnull;
                     if (!oldNameRes)
                     {
                            if (!nameStr.IsEmpty())
                            {
                                   const PRUnichar      *nameUni = nameStr.get();
                                   if (nameUni)
                                   {
                                          nsCOMPtr<nsIRDFLiteral>     nameLiteral;
                                          if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(nameUni, getter_AddRefs(nameLiteral))))
                                          {
                                                 if (nameLiteral)
                                                 {
                                                        mInner->Assert(res, kNC_Name, nameLiteral, PR_TRUE);
                                                 }
                                          }
                                   }
                            }
                     }

                     // look for date
                     if (!dateStartStr.IsEmpty())
                     {
                            nsAutoString  dateItem;
                            PRInt32              dateStart;
                            if ((dateStart = nsString_Find(dateStartStr, resultItem, PR_TRUE)) >= 0)
                            {
                                   dateStart += dateStartStr.Length();
                                   PRInt32       dateEnd = nsString_Find(dateEndStr, resultItem, PR_TRUE, dateStart);
                                   if (dateEnd > dateStart)
                                   {
                                          resultItem.Mid(dateItem, dateStart, dateEnd - dateStart);
                                   }
                            }
                            
                            // strip out any html tags
                            PRInt32              ltOffset, gtOffset;
                            while ((ltOffset = dateItem.FindChar(PRUnichar('<'))) >= 0)
                            {
                                   if ((gtOffset = dateItem.FindChar(PRUnichar('>'), ltOffset)) <= ltOffset)
                                          break;
                                   dateItem.Cut(ltOffset, gtOffset - ltOffset + 1);
                            }

                            // strip out whitespace and any CR/LFs
                            dateItem.Trim("\n\r\t ");

                            if (!dateItem.IsEmpty())
                            {
                                   const PRUnichar             *dateUni = dateItem.get();
                                   nsCOMPtr<nsIRDFLiteral>     dateLiteral;
                                   if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(dateUni, getter_AddRefs(dateLiteral))))
                                   {
                                          if (dateLiteral)
                                          {
                                                 mInner->Assert(res, kNC_Date, dateLiteral, PR_TRUE);
                                                 hasDateFlag = PR_TRUE;
                                          }
                                   }
                            }
                     }

                     // look for price
                     if (!priceStartStr.IsEmpty())
                     {
                            nsAutoString  priceItem;
                            PRInt32              priceStart;
                            if ((priceStart = nsString_Find(priceStartStr, resultItem, PR_TRUE)) >= 0)
                            {
                                   priceStart += priceStartStr.Length();
                                   PRInt32       priceEnd = nsString_Find(priceEndStr, resultItem, PR_TRUE, priceStart);
                                   if (priceEnd > priceStart)
                                   {
                                          resultItem.Mid(priceItem, priceStart, priceEnd - priceStart);
                                          ConvertEntities(priceItem);
                                   }
                            }
                            if (!priceItem.IsEmpty())
                            {
                                   const PRUnichar             *priceUni = priceItem.get();
                                   nsCOMPtr<nsIRDFLiteral>     priceLiteral;
                                   if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(priceUni, getter_AddRefs(priceLiteral))))
                                   {
                                          if (priceLiteral)
                                          {
                                                 mInner->Assert(res, kNC_Price, priceLiteral, PR_TRUE);
                                                 hasPriceFlag = PR_TRUE;
                                          }
                                   }

                                   PRInt32       priceCharStartOffset = priceItem.FindCharInSet("1234567890");
                                   if (priceCharStartOffset >= 0)
                                   {
                                          priceItem.Cut(0, priceCharStartOffset);
                                          PRInt32       priceErr;
                                          float  val = priceItem.ToFloat(&priceErr);
                                          if (priceItem.FindChar(PRUnichar('.')) >= 0)     val *= 100;

                                          nsCOMPtr<nsIRDFInt>  priceSortLiteral;
                                          if (NS_SUCCEEDED(rv = gRDFService->GetIntLiteral((PRInt32)val, getter_AddRefs(priceSortLiteral))))
                                          {
                                                 if (priceSortLiteral)
                                                 {
                                                        mInner->Assert(res, kNC_PriceSort, priceSortLiteral, PR_TRUE);
                                                 }
                                          }
                                   }
                            }
                            // look for availability (if we looked for price)
                            if (!availStartStr.IsEmpty())
                            {
                                   nsAutoString  availItem;
                                   PRInt32              availStart;
                                   if ((availStart = nsString_Find(availStartStr, resultItem, PR_TRUE)) >= 0)
                                   {
                                          availStart += availStartStr.Length();
                                          PRInt32       availEnd = nsString_Find(availEndStr, resultItem, PR_TRUE, availStart);
                                          if (availEnd > availStart)
                                          {
                                                 resultItem.Mid(availItem, availStart, availEnd - availStart);
                                                 ConvertEntities(availItem);
                                          }
                                   }
                                   if (!availItem.IsEmpty())
                                   {
                                          const PRUnichar             *availUni = availItem.get();
                                          nsCOMPtr<nsIRDFLiteral>     availLiteral;
                                          if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(availUni, getter_AddRefs(availLiteral))))
                                          {
                                                 if (availLiteral)
                                                 {
                                                        mInner->Assert(res, kNC_Availability, availLiteral, PR_TRUE);
                                                        hasAvailabilityFlag = PR_TRUE;
                                                 }
                                          }
                                   }
                            }
                     }

                     // look for relevance
                     nsAutoString  relItem;
                     PRInt32              relStart;
                     if ((relStart = nsString_Find(relevanceStartStr, resultItem, PR_TRUE)) >= 0)
                     {
                            relStart += relevanceStartStr.Length();
                            PRInt32       relEnd = nsString_Find(relevanceEndStr, resultItem, PR_TRUE);
                            if (relEnd > relStart)
                            {
                                   resultItem.Mid(relItem, relStart, relEnd - relStart);
                            }
                     }

                     // look for Relevance (if it isn't already set)
                     nsCOMPtr<nsIRDFNode>        oldRelRes = nsnull;
                     if (!oldRelRes)
                     {
                            if (!relItem.IsEmpty())
                            {
                                   // save real relevance
                                   const PRUnichar      *relUni = relItem.get();
                                   if (relUni)
                                   {
                                          nsAutoString  relStr(relUni);
                                          // take out any characters that aren't numeric or "%"
                                          PRInt32       len = relStr.Length();
                                          for (PRInt32 x=len-1; x>=0; x--)
                                          {
                                                 PRUnichar     ch;
                                                 ch = relStr.CharAt(x);
                                                 if ((ch != PRUnichar('%')) &&
                                                        ((ch < PRUnichar('0')) || (ch > PRUnichar('9'))))
                                                 {
                                                        relStr.Cut(x, 1);
                                                 }
                                          }
                                          // make sure it ends with a "%"
                                          len = relStr.Length();
                                          if (len > 0)
                                          {
                                                 PRUnichar     ch;
                                                 ch = relStr.CharAt(len - 1);
                                                 if (ch != PRUnichar('%'))
                                                 {
                                                        relStr += PRUnichar('%');
                                                 }
                                                 relItem = relStr;
                                                 hasRelevanceFlag = PR_TRUE;
                                          }
                                          else
                                          {
                                                 relItem.Truncate();
                                          }
                                   }
                            }
                            if (relItem.IsEmpty())
                            {
                                   relItem.AssignLiteral("-");
                            }

                            const PRUnichar *relItemUni = relItem.get();
                            nsCOMPtr<nsIRDFLiteral>     relLiteral;
                            if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(relItemUni, getter_AddRefs(relLiteral))))
                            {
                                   if (relLiteral)
                                   {
                                          mInner->Assert(res, kNC_Relevance, relLiteral, PR_TRUE);
                                   }
                            }

                            if ((!relItem.IsEmpty()) && (!relItem.EqualsLiteral("-")))
                            {
                                   // If its a percentage, remove "%"
                                   if (relItem[relItem.Length()-1] == PRUnichar('%'))
                                   {
                                          relItem.Cut(relItem.Length()-1, 1);
                                   }

                                   // left-pad with "0"s and set special sorting value
                                   nsAutoString  zero;
                                   zero.AssignLiteral("000");
                                   if (relItem.Length() < 3)
                                   {
                                          relItem.Insert(zero.get(), 0, zero.Length() - relItem.Length()); 
                                   }
                            }
                            else
                            {
                                   relItem.AssignLiteral("000");
                            }

                            const PRUnichar      *relSortUni = relItem.get();
                            if (relSortUni)
                            {
                                   nsCOMPtr<nsIRDFLiteral>     relSortLiteral;
                                   if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(relSortUni, getter_AddRefs(relSortLiteral))))
                                   {
                                          if (relSortLiteral)
                                          {
                                                 mInner->Assert(res, kNC_RelevanceSort, relSortLiteral, PR_TRUE);
                                          }
                                   }
                            }
                     }

                     // set reference to engine this came from (if it isn't already set)
                     nsCOMPtr<nsIRDFNode>        oldEngineRes = nsnull;
                     if (!oldEngineRes)
                     {
                            if (!engineStr.IsEmpty())
                            {
                                   const PRUnichar             *engineUni = engineStr.get();
                                   nsCOMPtr<nsIRDFLiteral>     engineLiteral;
                                   if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(engineUni, getter_AddRefs(engineLiteral))))
                                   {
                                          if (engineLiteral)
                                          {
                                                 mInner->Assert(res, kNC_Engine, engineLiteral, PR_TRUE);
                                          }
                                   }
                            }
                     }

                     // copy the engine's icon reference (if it has one) onto the result node
                     nsCOMPtr<nsIRDFNode>        engineIconNode = nsnull;
                     mInner->GetTarget(mEngine, kNC_Icon, PR_TRUE, getter_AddRefs(engineIconNode));

                     // if no branding icon, use some default icons
                     nsAutoString  iconChromeDefault;

                     if (browserResultTypeStr.LowerCaseEqualsLiteral("category"))
                            iconChromeDefault.AssignLiteral("chrome://communicator/skin/search/category.gif");
                     else if ((browserResultTypeStr.LowerCaseEqualsLiteral("result")) && (!engineIconNode))
                            iconChromeDefault.AssignLiteral("chrome://communicator/skin/search/result.gif");

                     if (!iconChromeDefault.IsEmpty())
                     {
                            const PRUnichar             *iconUni = iconChromeDefault.get();
                            nsCOMPtr<nsIRDFLiteral>     iconLiteral;
                            if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(iconUni, getter_AddRefs(iconLiteral))))
                            {
                                   if (iconLiteral)
                                   {
                                          mInner->Assert(res, kNC_Icon, iconLiteral, PR_TRUE);
                                   }
                            }
                     }
                     else if (engineIconNode)
                     {
                            rv = mInner->Assert(res, kNC_Icon, engineIconNode, PR_TRUE);
                     }

                     // set result page rank
                     nsCOMPtr<nsIRDFInt>  pageRankLiteral;
                     if (NS_SUCCEEDED(rv = gRDFService->GetIntLiteral(pageRank++, getter_AddRefs(pageRankLiteral))))
                     {
                            rv = mInner->Assert(res, kNC_PageRank, pageRankLiteral, PR_TRUE);
                     }

                     // set the result type
                     if (!browserResultTypeStr.IsEmpty())
                     {
                            const PRUnichar             *resultTypeUni = browserResultTypeStr.get();
                            nsCOMPtr<nsIRDFLiteral>     resultTypeLiteral;
                            if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(resultTypeUni, getter_AddRefs(resultTypeLiteral))))
                            {
                                   if (resultTypeLiteral)
                                   {
                                          mInner->Assert(res, kNC_SearchType, resultTypeLiteral, PR_TRUE);
                                   }
                            }
                     }

                     // set the node type
                     rv = mInner->Assert(res, kRDF_type, kNC_SearchResult, PR_TRUE);

                     // Note: always add in parent-child relationship last!  (if it isn't already set)
#ifdef OLDWAY
                     PRBool        parentHasChildFlag = PR_FALSE;
                     if (mParent)
                     {
                            mInner->HasAssertion(mParent, kNC_Child, res, PR_TRUE, &parentHasChildFlag);
                     }
      if (!parentHasChildFlag)
#endif
                     {
                            if (mParent)
                            {
                                   rv = mInner->Assert(mParent, kNC_Child, res, PR_TRUE);
                            }
                     }

                     // Persist this under kNC_LastSearchRoot
                     if (mInner)
                     {
                            rv = mInner->Assert(kNC_LastSearchRoot, kNC_Child, res, PR_TRUE);
                     }

                     ++numResults;

                     // place a cap on the # of results we can process
                     if (numResults >= MAX_SEARCH_RESULTS_ALLOWED)
                            break;

              }
       }

       // set hints so that the appropriate columns can be displayed
       if (mParent)
       {
    if (hasPriceFlag)
      SetHint(mParent, kNC_Price);
    if (hasAvailabilityFlag)
      SetHint(mParent, kNC_Availability);
    if (hasRelevanceFlag)
      SetHint(mParent, kNC_Relevance);
    if (hasDateFlag)
      SetHint(mParent, kNC_Date);
       }

#ifdef DEBUG
       PRTime        now2;
       now2 = PR_Now();
       PRUint64      loadTime64;
       LL_SUB(loadTime64, now2, now);
       PRUint32      loadTime32;
       LL_L2UI(loadTime32, loadTime64);
       printf("Finished processing search results  (%u microseconds)\n", loadTime32);
#endif

       return(NS_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult InternetSearchDataSource::ReadFileContents ( nsILocalFile baseFilename,
nsString sourceContents 
) [protected]

Definition at line 4453 of file nsInternetSearchService.cpp.

{
       nsresult                    rv = NS_ERROR_FAILURE;
       PRInt64                            contentsLen, total = 0;
       char                        *contents;

        NS_ENSURE_ARG_POINTER(localFile);

        sourceContents.Truncate();

        rv = localFile->GetFileSize(&contentsLen);
        if (NS_FAILED(rv)) return rv;
        if (contentsLen > 0)
        {
                contents = new char [contentsLen + 1];
                if (contents)
                {
                        nsCOMPtr<nsIInputStream> inputStream;
                        rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), localFile);
                        if (NS_FAILED(rv)) {
                            delete [] contents;
                            return rv;
                        }
                        PRUint32 howMany;
                        while (total < contentsLen) {
                                rv = inputStream->Read(contents+total, 
                                                       PRUint32(contentsLen),
                                                       &howMany);
                                if (NS_FAILED(rv)) {
                                        delete [] contents;
                                        return rv;
                                }
                                total += howMany;
                        }
                        if (total == contentsLen)
                      {
                            contents[contentsLen] = '\0';
                            sourceContents.AssignWithConversion(contents, contentsLen);
                            rv = NS_OK;
                      }
                     delete [] contents;
                     contents = nsnull;
              }
       }
       return(rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 878 of file nsInternetSearchService.cpp.

{
       *trueEngine = nsnull;

       if ((!categoryDataSource) || (!mInner))   return(NS_ERROR_UNEXPECTED);

       nsresult      rv;
       const char    *uriUni = nsnull;
       if (NS_FAILED(rv = engine->GetValueConst(&uriUni)))     return(rv);
       if (!uriUni)  return(NS_ERROR_NULL_POINTER);

       nsAutoString         uri;
       uri.AssignWithConversion(uriUni);
       if (uri.Find(kURINC_SearchCategoryEngineBasenamePrefix) !=0)   return(NS_ERROR_UNEXPECTED);

       nsCOMPtr<nsIRDFLiteral>     basenameLiteral;
       if (NS_FAILED(rv = gRDFService->GetLiteral(uri.get(),
                     getter_AddRefs(basenameLiteral)))) return(rv);

       nsCOMPtr<nsIRDFResource>    catSrc;
       rv = mInner->GetSource(kNC_URL, basenameLiteral, PR_TRUE, getter_AddRefs(catSrc));
       if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE))    return(rv);
       if (!catSrc)         return(NS_ERROR_UNEXPECTED);

       *trueEngine = catSrc;
       NS_IF_ADDREF(*trueEngine);
       return(NS_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult InternetSearchDataSource::saveContents ( nsIChannel channel,
nsIInternetSearchContext context,
PRUint32  contextType 
) [protected]

Definition at line 2527 of file nsInternetSearchService.cpp.

{
    NS_ASSERTION(contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_NEW_CONTEXT ||
                 contextType == nsIInternetSearchContext::ICON_DOWNLOAD_NEW_CONTEXT ||
                 contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_UPDATE_CONTEXT ||
                 contextType == nsIInternetSearchContext::ICON_DOWNLOAD_UPDATE_CONTEXT,
                 "unexpected context");
       nsresult      rv = NS_OK;

       if (!channel) return(NS_ERROR_UNEXPECTED);
       if (!context) return(NS_ERROR_UNEXPECTED);

       // get real URI
       nsCOMPtr<nsIURI>     channelURI;
       if (NS_FAILED(rv = channel->GetURI(getter_AddRefs(channelURI))))
              return(rv);
       if (!channelURI)
              return(NS_ERROR_NULL_POINTER);

       nsCAutoString baseName;
       if (NS_FAILED(rv = channelURI->GetSpec(baseName)))
              return(rv);

       PRInt32                     slashOffset = baseName.RFindChar(PRUnichar('/'));
       if (slashOffset < 0)        return(NS_ERROR_UNEXPECTED);
       baseName.Cut(0, slashOffset+1);
       if (baseName.IsEmpty())     return(NS_ERROR_UNEXPECTED);

       // make sure that search engines are .src files
       PRInt32       extensionOffset;
       if (contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_NEW_CONTEXT ||
              contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_UPDATE_CONTEXT)
       {
              extensionOffset = baseName.RFind(".src", PR_TRUE);
              if ((extensionOffset < 0) || (extensionOffset != (PRInt32)(baseName.Length()-4)))
              {
                     return(NS_ERROR_UNEXPECTED);
              }
       }

    nsCOMPtr<nsIFile> outFile;
  // If the mode is "UPDATE", the output dir is same as the original file
  // location. Otherwise ("NEW" mode), located in NS_APP_USER_SEARCH_DIR.
  nsCOMPtr<nsIRDFResource> oldResource;
  rv = context->GetEngine(getter_AddRefs(oldResource));

  if (oldResource) {
    nsCOMPtr<nsILocalFile> oldEngineFile;
    rv = EngineFileFromResource(oldResource, getter_AddRefs(oldEngineFile));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = oldEngineFile->GetParent(getter_AddRefs(outFile));
    NS_ENSURE_SUCCESS(rv, rv);
  }
  else {
    rv = NS_GetSpecialDirectory(NS_APP_USER_SEARCH_DIR, getter_AddRefs(outFile));
    if (NS_FAILED(rv))
        return rv;
  }

    PRBool exists;
    rv = outFile->Exists(&exists);
    if (NS_FAILED(rv)) return(rv);
    if (!exists)
    {
        rv = outFile->Create(nsIFile::DIRECTORY_TYPE, 0755);
        if (NS_FAILED(rv)) return(rv);
    }

       const PRUnichar      *dataBuf = nsnull;
       if (NS_FAILED(rv = context->GetBufferConst(&dataBuf)))  return(rv);

       // if no data, then nothing to do
       // Note: do this before opening file, as it would be truncated
       PRInt32              bufferLength = 0;
       if (NS_FAILED(context->GetBufferLength(&bufferLength))) return(rv);
       if (bufferLength < 1)       return(NS_OK);
       
       rv = outFile->Append(NS_ConvertUTF8toUCS2(baseName));
       if (NS_FAILED(rv)) return rv;
       
       // save data to file
       // Note: write out one character at a time, as we might be dealing
       //       with binary data (such as 0x00) [especially for images]
    //
    // XXX - It appears that this is done in order to discard the upper
    // byte of each PRUnichar.  I hope that's OK!!
    //
    if (contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_UPDATE_CONTEXT ||
        contextType == nsIInternetSearchContext::ICON_DOWNLOAD_UPDATE_CONTEXT) {
        // This is an update operation that we triggered.  Remove the old one.
        outFile->Remove(PR_FALSE);
    } else {
        PRBool exists;
        rv = outFile->Exists(&exists);
        if (NS_FAILED(rv) || exists) {
            // We already have a search plugin with this filename; don't
            // replace it (bug 290038).
            return NS_ERROR_UNEXPECTED;
        }
    }

    nsCOMPtr<nsIOutputStream> outputStream, fileOutputStream;
    rv = NS_NewLocalFileOutputStream(getter_AddRefs(fileOutputStream), outFile);
    if (NS_FAILED(rv)) return rv;
    rv = NS_NewBufferedOutputStream(getter_AddRefs(outputStream), fileOutputStream, 4096);
    if (NS_FAILED(rv)) return rv;

    PRUint32 bytesWritten;
    for (PRInt32 loop=0; loop < bufferLength; loop++)
    {
        const char b = (const char) dataBuf[loop];
        outputStream->Write(&b, 1, &bytesWritten);
    }
    outputStream->Flush();         
    outputStream->Close();

    if (contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_NEW_CONTEXT ||
        contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_UPDATE_CONTEXT)
    {
        // check suggested category hint
        const PRUnichar     *hintUni = nsnull;
        rv = context->GetHintConst(&hintUni);

        // update graph with various required info
        SaveEngineInfoIntoGraph(outFile, nsnull, hintUni, dataBuf, PR_FALSE);
    }
    else if (contextType == nsIInternetSearchContext::ICON_DOWNLOAD_NEW_CONTEXT ||
             contextType == nsIInternetSearchContext::ICON_DOWNLOAD_UPDATE_CONTEXT)
    {
        // update graph with icon info
        SaveEngineInfoIntoGraph(nsnull, outFile, nsnull, nsnull, PR_FALSE);
    }

       // after we're all done with the data buffer, get rid of it
       context->Truncate();

       return(rv);
}

Here is the call graph for this function:

nsresult InternetSearchDataSource::SaveEngineInfoIntoGraph ( nsIFile file,
nsIFile icon,
const PRUnichar hint,
const PRUnichar data,
PRBool  isSystemSearchFile 
) [protected]

Definition at line 4158 of file nsInternetSearchService.cpp.

{
       nsresult                    rv = NS_OK;

       if (!file && !icon)  return(NS_ERROR_UNEXPECTED);

       nsCOMPtr<nsIRDFResource>    searchRes;
       nsCOMPtr<nsIRDFResource>    categoryRes;
       nsCOMPtr<nsIFile>           native;

       if (icon != nsnull)
       {
              native = icon;
       }

       if (file != nsnull)
       {
              native = file;
       }

  PRBool exists;
  rv = native->Exists(&exists);
       if (NS_FAILED(rv)) return(rv);
       if (!exists) return(NS_ERROR_UNEXPECTED);

       nsAutoString basename;
       rv = native->GetLeafName(basename);
       if (NS_FAILED(rv)) return rv;

       // ensure that the basename points to the search engine file
       PRInt32              extensionOffset;
       if ((extensionOffset = basename.RFindChar(PRUnichar('.'))) > 0)
       {
              basename.Truncate(extensionOffset);
              basename.AppendLiteral(".src");
       }

  nsCAutoString filePath;
  rv = native->GetNativePath(filePath);
  if (NS_FAILED(rv)) return rv;
  
       nsAutoString  searchURL;
       searchURL.AssignASCII(kEngineProtocol);
       char          *uriCescaped = nsEscape(filePath.get(), url_Path);
       if (!uriCescaped)    return(NS_ERROR_NULL_POINTER);
       searchURL.AppendASCII(uriCescaped);
       nsCRT::free(uriCescaped);

       if ((extensionOffset = searchURL.RFindChar(PRUnichar('.'))) > 0)
       {
              searchURL.Truncate(extensionOffset);
              searchURL.AppendLiteral(".src");
       }

       if (NS_FAILED(rv = gRDFService->GetUnicodeResource(searchURL,
              getter_AddRefs(searchRes))))       return(rv);

       // save the basename reference
       if (!basename.IsEmpty())
       {
              basename.Insert(NS_ConvertASCIItoUTF16(kURINC_SearchCategoryEngineBasenamePrefix), 0);

              if (NS_FAILED(rv = gRDFService->GetUnicodeResource(basename,
                     getter_AddRefs(categoryRes))))     return(rv);

              nsCOMPtr<nsIRDFLiteral>     searchLiteral;
              if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(basename.get(),
                            getter_AddRefs(searchLiteral))))
              {
                     if (file)
                     {
                            updateAtom(mInner, searchRes, kNC_URL, searchLiteral, nsnull);
                     }
              }
       }

       if (!searchRes)             return(NS_ERROR_UNEXPECTED);
       if (!categoryRes)    return(NS_ERROR_UNEXPECTED);

       nsAutoString  iconURL;
       if (icon)
       {
              nsCAutoString iconFileURL;
              if (NS_FAILED(rv = NS_GetURLSpecFromFile(icon, iconFileURL)))
                     return(rv);
              AppendUTF8toUTF16(iconFileURL, iconURL);
       }

       // save icon url (if we have one)
       if (iconURL.Length() > 0)
       {
              nsCOMPtr<nsIRDFLiteral>     iconLiteral;
              if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(iconURL.get(),
                            getter_AddRefs(iconLiteral))))
              {
                     updateAtom(mInner, searchRes, kNC_Icon, iconLiteral, nsnull);
              }
       }

  if (!isSystemSearchFile)
       {
              // mark our private search files, so that we can distinguish
              // between ours and any that are included with the OS
              updateAtom(mInner, searchRes, kNC_SearchType, kNC_Engine, nsnull);
       }

       if (dataUni != nsnull)
       {
              updateDataHintsInGraph(searchRes, dataUni);

              // finally, if we have a category hint, add this new engine into the category (if it exists)
              if (categoryHint && categoryDataSource)
              {
                     nsCOMPtr<nsIRDFLiteral>     catLiteral;
                     rv = gRDFService->GetLiteral(categoryHint, getter_AddRefs(catLiteral));

                     nsCOMPtr<nsIRDFResource>    catSrc;
                     if (catLiteral)
                     {
                            rv = categoryDataSource->GetSource(kNC_Title, catLiteral,
                                   PR_TRUE, getter_AddRefs(catSrc));
                     }

                     const char           *catURI = nsnull;
                     if (catSrc)                               
                     {
                            rv = catSrc->GetValueConst(&catURI);
                     }

                     nsCOMPtr<nsIRDFResource>    catRes;
                     if (catURI)
                     {
                            nsAutoString  catList;
                            catList.AssignASCII(kURINC_SearchCategoryPrefix);
                            catList.AppendWithConversion(catURI);
                            gRDFService->GetUnicodeResource(catList, getter_AddRefs(catRes));
                     }

                     nsCOMPtr<nsIRDFContainer> container;
                     if (catRes)
                     {
                            container = do_CreateInstance(kRDFContainerCID, &rv);
                     }
                     if (container)
                     {
                            rv = container->Init(categoryDataSource, catRes);
                            if (NS_SUCCEEDED(rv))
                            {
                                   rv = gRDFC->MakeSeq(categoryDataSource, catRes, nsnull);
                            }
                            if (NS_SUCCEEDED(rv))
                            {
                                   PRInt32              searchIndex = -1;
                                   if (NS_SUCCEEDED(rv = container->IndexOf(categoryRes, &searchIndex))
                                          && (searchIndex < 0))
                                   {
                                          rv = container->AppendElement(categoryRes);
                                   }
                            }
                            if (NS_SUCCEEDED(rv))
                            {
                                   // flush categoryDataSource
                                   nsCOMPtr<nsIRDFRemoteDataSource>   remoteCategoryStore;
                                   remoteCategoryStore = do_QueryInterface(categoryDataSource);
                                   if (remoteCategoryStore)
                                   {
                                          remoteCategoryStore->Flush();
                                   }
                            }
                     }
              }
       }

       // Note: add the child relationship last
       PRBool hasChildFlag = PR_FALSE;
  rv = mInner->HasAssertion(kNC_SearchEngineRoot, kNC_Child, searchRes,
                            PR_TRUE, &hasChildFlag);
  if (NS_SUCCEEDED(rv) && !hasChildFlag)
       {
              mInner->Assert(kNC_SearchEngineRoot, kNC_Child, searchRes, PR_TRUE);
       }

       return(NS_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult InternetSearchDataSource::SetHint ( nsIRDFResource mParent,
nsIRDFResource hintRes 
) [protected]

Definition at line 6274 of file nsInternetSearchService.cpp.

{
       if (!mInner)  return(NS_OK);

       nsresult      rv;
       PRBool        hasAssertionFlag = PR_FALSE;
  rv = mInner->HasAssertion(mParent, hintRes, kTrueLiteral, PR_TRUE,
                            &hasAssertionFlag);
  if (NS_SUCCEEDED(rv) && !hasAssertionFlag)
       {
              rv = mInner->Assert(mParent, hintRes, kTrueLiteral, PR_TRUE);
       }
       return(rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult InternetSearchDataSource::updateAtom ( nsIRDFDataSource db,
nsIRDFResource src,
nsIRDFResource prop,
nsIRDFNode newValue,
PRBool dirtyFlag 
) [protected]

Definition at line 3692 of file nsInternetSearchService.cpp.

{
       nsresult             rv;
       nsCOMPtr<nsIRDFNode> oldValue;

       if (dirtyFlag != nsnull)
       {
              *dirtyFlag = PR_FALSE;
       }

       if (NS_SUCCEEDED(rv = db->GetTarget(src, prop, PR_TRUE, getter_AddRefs(oldValue))) &&
              (rv != NS_RDF_NO_VALUE))
       {
              rv = db->Change(src, prop, oldValue, newValue);

              if ((oldValue.get() != newValue) && (dirtyFlag != nsnull))
              {
                     *dirtyFlag = PR_TRUE;
              }
       }
       else
       {
              rv = db->Assert(src, prop, newValue, PR_TRUE);
              if (dirtyFlag != nsnull)
              {
                  *dirtyFlag = PR_TRUE;
              }
       }
       return(rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 3494 of file nsInternetSearchService.cpp.

{
       nsresult      rv = NS_OK;

       // save/update search engine data
       nsCOMPtr<nsIRDFLiteral>     dataLiteral;
       if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(dataUni, getter_AddRefs(dataLiteral))))
       {
              updateAtom(mInner, engine, kNC_Data, dataLiteral, nsnull);
       }

       // save/update name of search engine (as specified in file)
       nsAutoString scriptCodeValue;
       const char * charsetName = MapScriptCodeToCharsetName(0);
       nsXPIDLString decodedValue;

       if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "sourceTextEncoding", scriptCodeValue)) && 
              !scriptCodeValue.IsEmpty())
       {
              PRInt32 err;
              PRInt32 scriptCode = scriptCodeValue.ToInteger(&err);
              if (NS_SUCCEEDED(err))
                     charsetName = MapScriptCodeToCharsetName(scriptCode);
       }

       nsAutoString  nameValue;
       if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "name", nameValue)))
       {
              rv = DecodeData(charsetName, nameValue.get(), getter_Copies(decodedValue));
              nsCOMPtr<nsIRDFLiteral>     nameLiteral;
              if (NS_SUCCEEDED(rv) &&
                            NS_SUCCEEDED(rv = gRDFService->GetLiteral(decodedValue.get(),
                                                                      getter_AddRefs(nameLiteral))))
              {
                     rv = updateAtom(mInner, engine, kNC_Name, nameLiteral, nsnull);
              }
       }

       // save/update description of search engine (if specified)
       nsAutoString  descValue;
       if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "description", descValue)))
       {
              rv = DecodeData(charsetName, descValue.get(), getter_Copies(decodedValue));
              nsCOMPtr<nsIRDFLiteral>     descLiteral;
              if (NS_SUCCEEDED(rv) &&
                            NS_SUCCEEDED(rv = gRDFService->GetLiteral(decodedValue.get(),
                                                                      getter_AddRefs(descLiteral))))
              {
                     rv = updateAtom(mInner, engine, kNC_Description, descLiteral, nsnull);
              }
       }

       // save/update version of search engine (if specified)
       nsAutoString  versionValue;
       if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "version", versionValue)))
       {
              nsCOMPtr<nsIRDFLiteral>     versionLiteral;
              if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(versionValue.get(),
                            getter_AddRefs(versionLiteral))))
              {
                     rv = updateAtom(mInner, engine, kNC_Version, versionLiteral, nsnull);
              }
       }

       nsAutoString  buttonValue;
       if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "actionButton", buttonValue)))
       {
              nsCOMPtr<nsIRDFLiteral>     buttonLiteral;
              if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(buttonValue.get(),
                            getter_AddRefs(buttonLiteral))))
              {
                     rv = updateAtom(mInner, engine, kNC_actionButton, buttonLiteral, nsnull);
              }
       }

       nsAutoString  barValue;
       if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "actionBar", barValue)))
       {
              nsCOMPtr<nsIRDFLiteral>     barLiteral;
              if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(barValue.get(),
                            getter_AddRefs(barLiteral))))
              {
                     rv = updateAtom(mInner, engine, kNC_actionBar, barLiteral, nsnull);
              }
       }

       nsAutoString  searchFormValue;
       if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "searchForm", searchFormValue)))
       {
              nsCOMPtr<nsIRDFLiteral>     searchFormLiteral;
              if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(searchFormValue.get(),
                            getter_AddRefs(searchFormLiteral))))
              {
                     rv = updateAtom(mInner, engine, kNC_searchForm, searchFormLiteral, nsnull);
              }
       }


       PRBool updatePrivateFiles = PR_FALSE;

  rv = mInner->HasAssertion(engine, kNC_SearchType, kNC_Engine, PR_TRUE,
                            &updatePrivateFiles);
  if (NS_SUCCEEDED(rv) && updatePrivateFiles)
       {
              // rjc says: so here is our strategy. The spec says that the "search"|"update"
              // attribute MUST refer to a binhex-ed file (i.e. ends with ".src.hqx"). We don't
              // support binhex (due to being cross-platform minded folks) and, even if we did,
              // its not enough info to figure out what the appropriate icon should be.
              // The answer: we're add additional attributes in our private <BROWSER> section
              // to re-define these values. If they aren't there, we'll fallback to the <SEARCH>
              // section values and try and make logical choices:  for example, if we have an
              // "update" URL which ends with ".src.hqx", we'll strip off the ".hqx" part and
              // check to see if it exists... which at least makes it possible for a web site
              // to put up both a binhexed version and a straight text version of the search file.

              // get update URL and # of days to check for updates
              // Note: only check for updates on our private search files
              nsAutoString  updateStr, updateIconStr, updateCheckDaysStr;

              GetData(dataUni, "browser", 0, "update", updateStr);
              if (updateStr.IsEmpty())
              {
                     // fallback to trying "search"|"updateCheckDays"
                     GetData(dataUni, "search", 0, "update", updateStr);

                     // if we have a ".hqx" extension, strip it off
                     nsAutoString  extension;
                     updateStr.Right(extension, 4);
                     if (extension.LowerCaseEqualsLiteral(".hqx"))
                     {
                            updateStr.Truncate(updateStr.Length() - 4);
                     }

                     // now, either way, ensure that we have a ".src" file
                     updateStr.Right(extension, 4);
      if (!extension.LowerCaseEqualsLiteral(".src"))
                     {
                            // and if we don't, toss it
                            updateStr.Truncate();
                     }
              }
              else
              {
                     // note: its OK if the "updateIcon" isn't specified
                     GetData(dataUni, "browser", 0, "updateIcon", updateIconStr);
              }
              if (!updateStr.IsEmpty())
              {
                     GetData(dataUni, "browser", 0, "updateCheckDays", updateCheckDaysStr);
                     if (updateCheckDaysStr.IsEmpty())
                     {
                            // fallback to trying "search"|"updateCheckDays"
                            GetData(dataUni, "search", 0, "updateCheckDays", updateCheckDaysStr);
                     }
              }

              if (!updateStr.IsEmpty() && !updateCheckDaysStr.IsEmpty())
              {
                     nsCOMPtr<nsIRDFLiteral>     updateLiteral;
                     if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(updateStr.get(),
                                   getter_AddRefs(updateLiteral))))
                     {
                            rv = updateAtom(mInner, engine, kNC_Update, updateLiteral, nsnull);
                     }

                     PRInt32       err;
                     PRInt32       updateDays = updateCheckDaysStr.ToInteger(&err);
                     if ((err) || (updateDays < 1))
                     {
                            // default to something sane
                            updateDays = 3;
                     }

                     nsCOMPtr<nsIRDFInt>  updateCheckDaysLiteral;
                     if (NS_SUCCEEDED(rv = gRDFService->GetIntLiteral(updateDays,
                                   getter_AddRefs(updateCheckDaysLiteral))))
                     {
                            rv = updateAtom(mInner, engine, kNC_UpdateCheckDays, updateCheckDaysLiteral, nsnull);
                     }

                     if (!updateIconStr.IsEmpty())
                     {
                            nsCOMPtr<nsIRDFLiteral>     updateIconLiteral;
                            if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(updateIconStr.get(),
                                          getter_AddRefs(updateIconLiteral))))
                            {
                                   rv = updateAtom(mInner, engine, kNC_UpdateIcon, updateIconLiteral, nsnull);
                            }
                     }
              }
       }

       return(rv);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 3859 of file nsInternetSearchService.cpp.

{
       nsresult      rv;

  // confirm whether the user wants to update plugins.
  nsCOMPtr<nsIPrefBranch>
    prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  PRBool userAllowed = PR_TRUE;
  rv = prefBranch->GetBoolPref("browser.search.update", &userAllowed);
  // if the pref value is not set or wrong type, don't stop here.
  if (NS_SUCCEEDED(rv) && !userAllowed)
    return NS_OK;

#ifdef DEBUG_SEARCH_UPDATES
       const char    *engineURI = nsnull;
       engine->GetValueConst(&engineURI);
#endif

       // get the engines "updateCheckDays" value
       nsCOMPtr<nsIRDFNode> updateCheckDaysNode;
       rv = mInner->GetTarget(engine, kNC_UpdateCheckDays, PR_TRUE, getter_AddRefs(updateCheckDaysNode));
       if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE))    return(rv);
       nsCOMPtr<nsIRDFInt> updateCheckDaysLiteral (do_QueryInterface(updateCheckDaysNode));
       PRInt32              updateCheckDays;
       updateCheckDaysLiteral->GetValue(&updateCheckDays);
       // convert updateCheckDays from days to seconds;

#ifndef       DEBUG_SEARCH_UPDATES
       PRInt32              updateCheckSecs = updateCheckDays * (60 * 60 * 24);
#else
       // rjc note: for debugging, use as minutes instead days
       PRInt32              updateCheckSecs = updateCheckDays * 60;
#endif

       nsCOMPtr<nsIRDFNode> aNode;
       rv = mLocalstore->GetTarget(engine, kWEB_LastPingDate, PR_TRUE, getter_AddRefs(aNode));
       if (NS_FAILED(rv))   return(rv);

  // if aNode is a valid entry, we should check the durationSecs.
  if (rv != NS_RDF_NO_VALUE) {
    // get last validate date/time
    nsCOMPtr<nsIRDFLiteral> lastCheckLiteral(do_QueryInterface(aNode));
    if (!lastCheckLiteral)
      return NS_ERROR_UNEXPECTED;

    const PRUnichar *lastCheckUni = nsnull;
    lastCheckLiteral->GetValueConst(&lastCheckUni);
    if (!lastCheckUni)
      return NS_ERROR_UNEXPECTED;

    PRInt32 lastCheckInt = 0, err = 0;
    lastCheckInt = nsDependentString(lastCheckUni).ToInteger(&err);
    // signed int32 -> unsigned int32
    rv = (nsresult) err;
    NS_ENSURE_SUCCESS(rv, rv);

    // get the current date/time [from microseconds (PRTime) to seconds]
    PRTime now64 = PR_Now(), temp64, million;
    LL_I2L(million, PR_USEC_PER_SEC);
    LL_DIV(temp64, now64, million);
    PRInt32 now32;
    LL_L2I(now32, temp64);

    // calculate duration since last validation
    // just return if it's too early to check again
    PRInt32 durationSecs = now32 - lastCheckInt;

    if (durationSecs < updateCheckSecs) {
#ifdef DEBUG_SEARCH_UPDATES
      printf("    Search engine '%s' is valid for %d more seconds.\n",
             engineURI, (updateCheckSecs-durationSecs));
#endif
      return NS_OK;
    }
  }

       // search engine needs to be checked again, so add it into the to-be-validated array
       PRInt32              elementIndex = mUpdateArray->IndexOf(engine);
       if (elementIndex < 0)
       {
              mUpdateArray->AppendElement(engine);

#ifdef DEBUG_SEARCH_UPDATES
    printf("    Search engine '%s' is now queued to be validated"
           " via HTTP HEAD method.\n",
           engineURI);
#endif
       }
       else
       {
#ifdef DEBUG_SEARCH_UPDATES
              printf("    Search engine '%s' is already in queue to be validated.\n",
                     engineURI);
#endif
       }
       return(NS_OK);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 5340 of file nsInternetSearchService.cpp.

{
       // get the current date/time [from microseconds (PRTime) to seconds]
       // also, need to convert from 64 bites to 32 bites as we don't have an easy
       // way to convert from 64 bit number to a string like we do for 32 bit numbers
       PRTime        now64 = PR_Now(), temp64, million;
       LL_I2L(million, PR_USEC_PER_SEC);
       LL_DIV(temp64, now64, million);
       PRInt32              now32;
       LL_L2I(now32, temp64);

       // validate this engine as of now (save as string
       // literal as that's all RDF can currently serialize)
       nsAutoString  nowStr;
       nowStr.AppendInt(now32);

       nsresult             rv;
       nsCOMPtr<nsIRDFLiteral>     nowLiteral;
       if (NS_FAILED(rv = gRDFService->GetLiteral(nowStr.get(),
                     getter_AddRefs(nowLiteral))))      return(rv);
       updateAtom(mLocalstore, engine, kWEB_LastPingDate, nowLiteral, nsnull);

       // flush localstore
       nsCOMPtr<nsIRDFRemoteDataSource> remoteLocalStore (do_QueryInterface(mLocalstore));
       if (remoteLocalStore)
       {
              remoteLocalStore->Flush();
       }
       return(NS_OK);
}

Here is the call graph for this function:

Definition at line 5374 of file nsInternetSearchService.cpp.

{
       nsresult                    rv;
       nsCOMPtr<nsIRDFResource>    mParent;
       if (NS_FAILED(rv = context->GetParent(getter_AddRefs(mParent))))      return(rv);
//     Note: mParent can be null
//     if (!mParent) return(NS_ERROR_NO_INTERFACE);

       nsCOMPtr<nsIRDFResource>    mEngine;
       if (NS_FAILED(rv = context->GetEngine(getter_AddRefs(mEngine))))      return(rv);
       if (!mEngine) return(NS_ERROR_NO_INTERFACE);

       nsCOMPtr<nsIURI> aURL;
       rv = channel->GetURI(getter_AddRefs(aURL));
       if (NS_FAILED(rv)) return rv;

       // copy the engine's icon reference (if it has one) onto the result node
       nsCOMPtr<nsIRDFNode>        engineIconStatusNode = nsnull;
       mInner->GetTarget(mEngine, kNC_Icon, PR_TRUE, getter_AddRefs(engineIconStatusNode));
       if (engineIconStatusNode)
       {
              rv = mInner->Assert(mEngine, kNC_StatusIcon, engineIconStatusNode, PR_TRUE);
       }

       const PRUnichar      *uniBuf = nsnull;
       if (NS_SUCCEEDED(rv = context->GetBufferConst(&uniBuf)) && (uniBuf))
       {
              if (mParent && (gBrowserSearchMode>0))
              {
                     // save HTML result page for this engine
                     nsCOMPtr<nsIRDFLiteral>     htmlLiteral;
                     if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(uniBuf, getter_AddRefs(htmlLiteral))))
                     {
                            rv = mInner->Assert(mEngine, kNC_HTML, htmlLiteral, PR_TRUE);
                     }
              }

              // parse up HTML results
              PRInt32 uniBufLen = 0L;
              if (NS_SUCCEEDED(rv = context->GetBufferLength(&uniBufLen)))
              {
                     rv = ParseHTML(aURL, mParent, mEngine, uniBuf, uniBufLen);
              }
       }
       else
       {
#ifdef DEBUG_SEARCH_OUTPUT
              printf(" *** InternetSearchDataSourceCallback::OnStopRequest:  no data.\n\n");
#endif
       }

       // after we're all done with the html buffer, get rid of it
       context->Truncate();

       // (do this last) potentially remove the loading attribute
       mInner->Unassert(mEngine, kNC_loading, kTrueLiteral);

       if (mLoadGroup)
       {
              PRUint32      count = 0;
              if (NS_SUCCEEDED(rv = mLoadGroup->GetActiveCount(&count)))
              {
                     // is this the last connection in the loadgroup?
                     if (count <= 1)
                     {
                            Stop();
                     }
              }
       }

       return(NS_OK);
}

Here is the call graph for this function:


Friends And Related Function Documentation

int PR_CALLBACK searchModePrefCallback ( const char *  pref,
void aClosure 
) [friend]

Member Data Documentation

Definition at line 133 of file nsInternetSearchService.h.

Definition at line 132 of file nsInternetSearchService.h.

Definition at line 130 of file nsInternetSearchService.h.

Definition at line 63 of file nsInternetSearchService.h.

Definition at line 64 of file nsInternetSearchService.h.

Definition at line 62 of file nsInternetSearchService.h.

Definition at line 87 of file nsInternetSearchService.h.

Definition at line 86 of file nsInternetSearchService.h.

Definition at line 106 of file nsInternetSearchService.h.

Definition at line 97 of file nsInternetSearchService.h.

Definition at line 107 of file nsInternetSearchService.h.

Definition at line 80 of file nsInternetSearchService.h.

Definition at line 82 of file nsInternetSearchService.h.

Definition at line 100 of file nsInternetSearchService.h.

Definition at line 84 of file nsInternetSearchService.h.

Definition at line 103 of file nsInternetSearchService.h.

Definition at line 77 of file nsInternetSearchService.h.

Definition at line 76 of file nsInternetSearchService.h.

Definition at line 94 of file nsInternetSearchService.h.

Definition at line 95 of file nsInternetSearchService.h.

Definition at line 73 of file nsInternetSearchService.h.

Definition at line 72 of file nsInternetSearchService.h.

Definition at line 89 of file nsInternetSearchService.h.

Definition at line 93 of file nsInternetSearchService.h.

Definition at line 83 of file nsInternetSearchService.h.

Definition at line 102 of file nsInternetSearchService.h.

Definition at line 104 of file nsInternetSearchService.h.

Definition at line 105 of file nsInternetSearchService.h.

Definition at line 79 of file nsInternetSearchService.h.

Definition at line 99 of file nsInternetSearchService.h.

Definition at line 101 of file nsInternetSearchService.h.

Definition at line 74 of file nsInternetSearchService.h.

Definition at line 116 of file nsInternetSearchService.h.

Definition at line 115 of file nsInternetSearchService.h.

Definition at line 119 of file nsInternetSearchService.h.

Definition at line 117 of file nsInternetSearchService.h.

Definition at line 118 of file nsInternetSearchService.h.

Definition at line 71 of file nsInternetSearchService.h.

Definition at line 88 of file nsInternetSearchService.h.

Definition at line 70 of file nsInternetSearchService.h.

Definition at line 75 of file nsInternetSearchService.h.

Definition at line 78 of file nsInternetSearchService.h.

Definition at line 98 of file nsInternetSearchService.h.

Definition at line 96 of file nsInternetSearchService.h.

Definition at line 81 of file nsInternetSearchService.h.

Definition at line 108 of file nsInternetSearchService.h.

Definition at line 110 of file nsInternetSearchService.h.

Definition at line 109 of file nsInternetSearchService.h.

Definition at line 90 of file nsInternetSearchService.h.

Definition at line 85 of file nsInternetSearchService.h.

Definition at line 91 of file nsInternetSearchService.h.

Definition at line 92 of file nsInternetSearchService.h.

Definition at line 121 of file nsInternetSearchService.h.

Definition at line 113 of file nsInternetSearchService.h.

Definition at line 111 of file nsInternetSearchService.h.

Definition at line 112 of file nsInternetSearchService.h.

Definition at line 128 of file nsInternetSearchService.h.

Definition at line 124 of file nsInternetSearchService.h.

Definition at line 129 of file nsInternetSearchService.h.

Definition at line 125 of file nsInternetSearchService.h.

Definition at line 134 of file nsInternetSearchService.h.

Definition at line 127 of file nsInternetSearchService.h.

Definition at line 126 of file nsInternetSearchService.h.

Definition at line 131 of file nsInternetSearchService.h.


The documentation for this class was generated from the following files: