michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: Implementation for a file system RDF data store. michael@0: */ michael@0: michael@0: #include "nsFileSystemDataSource.h" michael@0: michael@0: #include // for toupper() michael@0: #include michael@0: #include "nsArrayEnumerator.h" michael@0: #include "nsCOMArray.h" michael@0: #include "nsISupportsArray.h" michael@0: #include "nsIRDFDataSource.h" michael@0: #include "nsIRDFObserver.h" michael@0: #include "nsIServiceManager.h" michael@0: #include "nsXPIDLString.h" michael@0: #include "nsRDFCID.h" michael@0: #include "rdfutil.h" michael@0: #include "rdf.h" michael@0: #include "nsEnumeratorUtils.h" michael@0: #include "nsIURL.h" michael@0: #include "nsIFileURL.h" michael@0: #include "nsNetUtil.h" michael@0: #include "nsIChannel.h" michael@0: #include "nsIFile.h" michael@0: #include "nsEscape.h" michael@0: #include "nsCRTGlue.h" michael@0: #include "nsAutoPtr.h" michael@0: michael@0: #ifdef XP_WIN michael@0: #include "windef.h" michael@0: #include "winbase.h" michael@0: #include "nsILineInputStream.h" michael@0: #include "nsDirectoryServiceDefs.h" michael@0: #endif michael@0: michael@0: #define NS_MOZICON_SCHEME "moz-icon:" michael@0: michael@0: static const char kFileProtocol[] = "file://"; michael@0: michael@0: bool michael@0: FileSystemDataSource::isFileURI(nsIRDFResource *r) michael@0: { michael@0: bool isFileURIFlag = false; michael@0: const char *uri = nullptr; michael@0: michael@0: r->GetValueConst(&uri); michael@0: if ((uri) && (!strncmp(uri, kFileProtocol, sizeof(kFileProtocol) - 1))) michael@0: { michael@0: // XXX HACK HACK HACK michael@0: if (!strchr(uri, '#')) michael@0: { michael@0: isFileURIFlag = true; michael@0: } michael@0: } michael@0: return(isFileURIFlag); michael@0: } michael@0: michael@0: michael@0: michael@0: bool michael@0: FileSystemDataSource::isDirURI(nsIRDFResource* source) michael@0: { michael@0: nsresult rv; michael@0: const char *uri = nullptr; michael@0: michael@0: rv = source->GetValueConst(&uri); michael@0: if (NS_FAILED(rv)) return(false); michael@0: michael@0: nsCOMPtr aDir; michael@0: michael@0: rv = NS_GetFileFromURLSpec(nsDependentCString(uri), getter_AddRefs(aDir)); michael@0: if (NS_FAILED(rv)) return(false); michael@0: michael@0: bool isDirFlag = false; michael@0: michael@0: rv = aDir->IsDirectory(&isDirFlag); michael@0: if (NS_FAILED(rv)) return(false); michael@0: michael@0: return(isDirFlag); michael@0: } michael@0: michael@0: michael@0: nsresult michael@0: FileSystemDataSource::Init() michael@0: { michael@0: nsresult rv; michael@0: michael@0: mRDFService = do_GetService("@mozilla.org/rdf/rdf-service;1"); michael@0: NS_ENSURE_TRUE(mRDFService, NS_ERROR_FAILURE); michael@0: michael@0: rv = mRDFService->GetResource(NS_LITERAL_CSTRING("NC:FilesRoot"), michael@0: getter_AddRefs(mNC_FileSystemRoot)); michael@0: nsresult tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "child"), michael@0: getter_AddRefs(mNC_Child)); michael@0: if (NS_FAILED(tmp)) { michael@0: rv = tmp; michael@0: } michael@0: tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Name"), michael@0: getter_AddRefs(mNC_Name)); michael@0: if (NS_FAILED(tmp)) { michael@0: rv = tmp; michael@0: } michael@0: tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "URL"), michael@0: getter_AddRefs(mNC_URL)); michael@0: if (NS_FAILED(tmp)) { michael@0: rv = tmp; michael@0: } michael@0: tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Icon"), michael@0: getter_AddRefs(mNC_Icon)); michael@0: if (NS_FAILED(tmp)) { michael@0: rv = tmp; michael@0: } michael@0: tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Content-Length"), michael@0: getter_AddRefs(mNC_Length)); michael@0: if (NS_FAILED(tmp)) { michael@0: rv = tmp; michael@0: } michael@0: tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "IsDirectory"), michael@0: getter_AddRefs(mNC_IsDirectory)); michael@0: if (NS_FAILED(tmp)) { michael@0: rv = tmp; michael@0: } michael@0: tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(WEB_NAMESPACE_URI "LastModifiedDate"), michael@0: getter_AddRefs(mWEB_LastMod)); michael@0: if (NS_FAILED(tmp)) { michael@0: rv = tmp; michael@0: } michael@0: tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "FileSystemObject"), michael@0: getter_AddRefs(mNC_FileSystemObject)); michael@0: if (NS_FAILED(tmp)) { michael@0: rv = tmp; michael@0: } michael@0: tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "pulse"), michael@0: getter_AddRefs(mNC_pulse)); michael@0: if (NS_FAILED(tmp)) { michael@0: rv = tmp; michael@0: } michael@0: tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "instanceOf"), michael@0: getter_AddRefs(mRDF_InstanceOf)); michael@0: if (NS_FAILED(tmp)) { michael@0: rv = tmp; michael@0: } michael@0: tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "type"), michael@0: getter_AddRefs(mRDF_type)); michael@0: michael@0: static const char16_t kTrue[] = {'t','r','u','e','\0'}; michael@0: static const char16_t kFalse[] = {'f','a','l','s','e','\0'}; michael@0: michael@0: tmp = mRDFService->GetLiteral(kTrue, getter_AddRefs(mLiteralTrue)); michael@0: if (NS_FAILED(tmp)) { michael@0: rv = tmp; michael@0: } michael@0: tmp = mRDFService->GetLiteral(kFalse, getter_AddRefs(mLiteralFalse)); michael@0: if (NS_FAILED(tmp)) { michael@0: rv = tmp; michael@0: } michael@0: NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); michael@0: michael@0: #ifdef USE_NC_EXTENSION michael@0: rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "extension"), michael@0: getter_AddRefs(mNC_extension)); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: #endif michael@0: michael@0: #ifdef XP_WIN michael@0: rv = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "IEFavorite"), michael@0: getter_AddRefs(mNC_IEFavoriteObject)); michael@0: tmp = mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "IEFavoriteFolder"), michael@0: getter_AddRefs(mNC_IEFavoriteFolder)); michael@0: if (NS_FAILED(tmp)) { michael@0: rv = tmp; michael@0: } michael@0: NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); michael@0: michael@0: nsCOMPtr file; michael@0: NS_GetSpecialDirectory(NS_WIN_FAVORITES_DIR, getter_AddRefs(file)); michael@0: if (file) michael@0: { michael@0: nsCOMPtr furi; michael@0: NS_NewFileURI(getter_AddRefs(furi), file); michael@0: NS_ENSURE_TRUE(furi, NS_ERROR_FAILURE); michael@0: michael@0: file->GetNativePath(ieFavoritesDir); michael@0: } michael@0: #endif michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: //static michael@0: nsresult michael@0: FileSystemDataSource::Create(nsISupports* aOuter, const nsIID& aIID, void **aResult) michael@0: { michael@0: NS_ENSURE_NO_AGGREGATION(aOuter); michael@0: michael@0: nsRefPtr self = new FileSystemDataSource(); michael@0: if (!self) michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: michael@0: nsresult rv = self->Init(); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: return self->QueryInterface(aIID, aResult); michael@0: } michael@0: michael@0: NS_IMPL_ISUPPORTS(FileSystemDataSource, nsIRDFDataSource) michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::GetURI(char **uri) michael@0: { michael@0: NS_PRECONDITION(uri != nullptr, "null ptr"); michael@0: if (! uri) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: if ((*uri = NS_strdup("rdf:files")) == nullptr) michael@0: return NS_ERROR_OUT_OF_MEMORY; michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::GetSource(nsIRDFResource* property, michael@0: nsIRDFNode* target, michael@0: bool tv, michael@0: nsIRDFResource** source /* out */) michael@0: { michael@0: NS_PRECONDITION(property != nullptr, "null ptr"); michael@0: if (! property) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: NS_PRECONDITION(target != nullptr, "null ptr"); michael@0: if (! target) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: NS_PRECONDITION(source != nullptr, "null ptr"); michael@0: if (! source) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: *source = nullptr; michael@0: return NS_RDF_NO_VALUE; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::GetSources(nsIRDFResource *property, michael@0: nsIRDFNode *target, michael@0: bool tv, michael@0: nsISimpleEnumerator **sources /* out */) michael@0: { michael@0: // NS_NOTYETIMPLEMENTED("write me"); michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::GetTarget(nsIRDFResource *source, michael@0: nsIRDFResource *property, michael@0: bool tv, michael@0: nsIRDFNode **target /* out */) michael@0: { michael@0: NS_PRECONDITION(source != nullptr, "null ptr"); michael@0: if (! source) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: NS_PRECONDITION(property != nullptr, "null ptr"); michael@0: if (! property) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: NS_PRECONDITION(target != nullptr, "null ptr"); michael@0: if (! target) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: *target = nullptr; michael@0: michael@0: nsresult rv = NS_RDF_NO_VALUE; michael@0: michael@0: // we only have positive assertions in the file system data source. michael@0: if (! tv) michael@0: return NS_RDF_NO_VALUE; michael@0: michael@0: if (source == mNC_FileSystemRoot) michael@0: { michael@0: if (property == mNC_pulse) michael@0: { michael@0: nsIRDFLiteral *pulseLiteral; michael@0: mRDFService->GetLiteral(MOZ_UTF16("12"), &pulseLiteral); michael@0: *target = pulseLiteral; michael@0: return NS_OK; michael@0: } michael@0: } michael@0: else if (isFileURI(source)) michael@0: { michael@0: if (property == mNC_Name) michael@0: { michael@0: nsCOMPtr name; michael@0: rv = GetName(source, getter_AddRefs(name)); michael@0: if (NS_FAILED(rv)) return(rv); michael@0: if (!name) rv = NS_RDF_NO_VALUE; michael@0: if (rv == NS_RDF_NO_VALUE) return(rv); michael@0: return name->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target); michael@0: } michael@0: else if (property == mNC_URL) michael@0: { michael@0: nsCOMPtr url; michael@0: rv = GetURL(source, nullptr, getter_AddRefs(url)); michael@0: if (NS_FAILED(rv)) return(rv); michael@0: if (!url) rv = NS_RDF_NO_VALUE; michael@0: if (rv == NS_RDF_NO_VALUE) return(rv); michael@0: michael@0: return url->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target); michael@0: } michael@0: else if (property == mNC_Icon) michael@0: { michael@0: nsCOMPtr url; michael@0: bool isFavorite = false; michael@0: rv = GetURL(source, &isFavorite, getter_AddRefs(url)); michael@0: if (NS_FAILED(rv)) return(rv); michael@0: if (isFavorite || !url) rv = NS_RDF_NO_VALUE; michael@0: if (rv == NS_RDF_NO_VALUE) return(rv); michael@0: michael@0: const char16_t *uni = nullptr; michael@0: url->GetValueConst(&uni); michael@0: if (!uni) return(NS_RDF_NO_VALUE); michael@0: nsAutoString urlStr; michael@0: urlStr.Assign(NS_LITERAL_STRING(NS_MOZICON_SCHEME).get()); michael@0: urlStr.Append(uni); michael@0: michael@0: rv = mRDFService->GetLiteral(urlStr.get(), getter_AddRefs(url)); michael@0: if (NS_FAILED(rv) || !url) return(NS_RDF_NO_VALUE); michael@0: return url->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target); michael@0: } michael@0: else if (property == mNC_Length) michael@0: { michael@0: nsCOMPtr fileSize; michael@0: rv = GetFileSize(source, getter_AddRefs(fileSize)); michael@0: if (NS_FAILED(rv)) return(rv); michael@0: if (!fileSize) rv = NS_RDF_NO_VALUE; michael@0: if (rv == NS_RDF_NO_VALUE) return(rv); michael@0: michael@0: return fileSize->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target); michael@0: } michael@0: else if (property == mNC_IsDirectory) michael@0: { michael@0: *target = (isDirURI(source)) ? mLiteralTrue : mLiteralFalse; michael@0: NS_ADDREF(*target); michael@0: return NS_OK; michael@0: } michael@0: else if (property == mWEB_LastMod) michael@0: { michael@0: nsCOMPtr lastMod; michael@0: rv = GetLastMod(source, getter_AddRefs(lastMod)); michael@0: if (NS_FAILED(rv)) return(rv); michael@0: if (!lastMod) rv = NS_RDF_NO_VALUE; michael@0: if (rv == NS_RDF_NO_VALUE) return(rv); michael@0: michael@0: return lastMod->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target); michael@0: } michael@0: else if (property == mRDF_type) michael@0: { michael@0: nsCString type; michael@0: rv = mNC_FileSystemObject->GetValueUTF8(type); michael@0: if (NS_FAILED(rv)) return(rv); michael@0: michael@0: #ifdef XP_WIN michael@0: // under Windows, if its an IE favorite, return that type michael@0: if (!ieFavoritesDir.IsEmpty()) michael@0: { michael@0: nsCString uri; michael@0: rv = source->GetValueUTF8(uri); michael@0: if (NS_FAILED(rv)) return(rv); michael@0: michael@0: NS_ConvertUTF8toUTF16 theURI(uri); michael@0: michael@0: if (theURI.Find(ieFavoritesDir) == 0) michael@0: { michael@0: if (theURI[theURI.Length() - 1] == '/') michael@0: { michael@0: rv = mNC_IEFavoriteFolder->GetValueUTF8(type); michael@0: } michael@0: else michael@0: { michael@0: rv = mNC_IEFavoriteObject->GetValueUTF8(type); michael@0: } michael@0: if (NS_FAILED(rv)) return(rv); michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: NS_ConvertUTF8toUTF16 url(type); michael@0: nsCOMPtr literal; michael@0: mRDFService->GetLiteral(url.get(), getter_AddRefs(literal)); michael@0: rv = literal->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target); michael@0: return(rv); michael@0: } michael@0: else if (property == mNC_pulse) michael@0: { michael@0: nsCOMPtr pulseLiteral; michael@0: mRDFService->GetLiteral(MOZ_UTF16("12"), getter_AddRefs(pulseLiteral)); michael@0: rv = pulseLiteral->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target); michael@0: return(rv); michael@0: } michael@0: else if (property == mNC_Child) michael@0: { michael@0: // Oh this is evil. Somebody kill me now. michael@0: nsCOMPtr children; michael@0: rv = GetFolderList(source, false, true, getter_AddRefs(children)); michael@0: if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE)) return(rv); michael@0: michael@0: bool hasMore; michael@0: rv = children->HasMoreElements(&hasMore); michael@0: if (NS_FAILED(rv)) return(rv); michael@0: michael@0: if (hasMore) michael@0: { michael@0: nsCOMPtr isupports; michael@0: rv = children->GetNext(getter_AddRefs(isupports)); michael@0: if (NS_FAILED(rv)) return(rv); michael@0: michael@0: return isupports->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target); michael@0: } michael@0: } michael@0: #ifdef USE_NC_EXTENSION michael@0: else if (property == mNC_extension) michael@0: { michael@0: nsCOMPtr extension; michael@0: rv = GetExtension(source, getter_AddRefs(extension)); michael@0: if (!extension) rv = NS_RDF_NO_VALUE; michael@0: if (rv == NS_RDF_NO_VALUE) return(rv); michael@0: return extension->QueryInterface(NS_GET_IID(nsIRDFNode), (void**) target); michael@0: } michael@0: #endif michael@0: } michael@0: michael@0: return(NS_RDF_NO_VALUE); michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::GetTargets(nsIRDFResource *source, michael@0: nsIRDFResource *property, michael@0: bool tv, michael@0: nsISimpleEnumerator **targets /* out */) michael@0: { michael@0: NS_PRECONDITION(source != nullptr, "null ptr"); michael@0: if (! source) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: NS_PRECONDITION(property != nullptr, "null ptr"); michael@0: if (! property) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: NS_PRECONDITION(targets != nullptr, "null ptr"); michael@0: if (! targets) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: *targets = nullptr; michael@0: michael@0: // we only have positive assertions in the file system data source. michael@0: if (! tv) michael@0: return NS_RDF_NO_VALUE; michael@0: michael@0: nsresult rv; michael@0: michael@0: if (source == mNC_FileSystemRoot) michael@0: { michael@0: if (property == mNC_Child) michael@0: { michael@0: return GetVolumeList(targets); michael@0: } michael@0: else if (property == mNC_pulse) michael@0: { michael@0: nsCOMPtr pulseLiteral; michael@0: mRDFService->GetLiteral(MOZ_UTF16("12"), michael@0: getter_AddRefs(pulseLiteral)); michael@0: return NS_NewSingletonEnumerator(targets, pulseLiteral); michael@0: } michael@0: } michael@0: else if (isFileURI(source)) michael@0: { michael@0: if (property == mNC_Child) michael@0: { michael@0: return GetFolderList(source, false, false, targets); michael@0: } michael@0: else if (property == mNC_Name) michael@0: { michael@0: nsCOMPtr name; michael@0: rv = GetName(source, getter_AddRefs(name)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: return NS_NewSingletonEnumerator(targets, name); michael@0: } michael@0: else if (property == mNC_URL) michael@0: { michael@0: nsCOMPtr url; michael@0: rv = GetURL(source, nullptr, getter_AddRefs(url)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: return NS_NewSingletonEnumerator(targets, url); michael@0: } michael@0: else if (property == mRDF_type) michael@0: { michael@0: nsCString uri; michael@0: rv = mNC_FileSystemObject->GetValueUTF8(uri); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: NS_ConvertUTF8toUTF16 url(uri); michael@0: michael@0: nsCOMPtr literal; michael@0: rv = mRDFService->GetLiteral(url.get(), getter_AddRefs(literal)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: return NS_NewSingletonEnumerator(targets, literal); michael@0: } michael@0: else if (property == mNC_pulse) michael@0: { michael@0: nsCOMPtr pulseLiteral; michael@0: rv = mRDFService->GetLiteral(MOZ_UTF16("12"), michael@0: getter_AddRefs(pulseLiteral)); michael@0: if (NS_FAILED(rv)) return rv; michael@0: michael@0: return NS_NewSingletonEnumerator(targets, pulseLiteral); michael@0: } michael@0: } michael@0: michael@0: return NS_NewEmptyEnumerator(targets); michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::Assert(nsIRDFResource *source, michael@0: nsIRDFResource *property, michael@0: nsIRDFNode *target, michael@0: bool tv) michael@0: { michael@0: return NS_RDF_ASSERTION_REJECTED; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::Unassert(nsIRDFResource *source, michael@0: nsIRDFResource *property, michael@0: nsIRDFNode *target) michael@0: { michael@0: return NS_RDF_ASSERTION_REJECTED; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::Change(nsIRDFResource* aSource, michael@0: nsIRDFResource* aProperty, michael@0: nsIRDFNode* aOldTarget, michael@0: nsIRDFNode* aNewTarget) michael@0: { michael@0: return NS_RDF_ASSERTION_REJECTED; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::Move(nsIRDFResource* aOldSource, michael@0: nsIRDFResource* aNewSource, michael@0: nsIRDFResource* aProperty, michael@0: nsIRDFNode* aTarget) michael@0: { michael@0: return NS_RDF_ASSERTION_REJECTED; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::HasAssertion(nsIRDFResource *source, michael@0: nsIRDFResource *property, michael@0: nsIRDFNode *target, michael@0: bool tv, michael@0: bool *hasAssertion /* out */) michael@0: { michael@0: NS_PRECONDITION(source != nullptr, "null ptr"); michael@0: if (! source) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: NS_PRECONDITION(property != nullptr, "null ptr"); michael@0: if (! property) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: NS_PRECONDITION(target != nullptr, "null ptr"); michael@0: if (! target) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: NS_PRECONDITION(hasAssertion != nullptr, "null ptr"); michael@0: if (! hasAssertion) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: // we only have positive assertions in the file system data source. michael@0: *hasAssertion = false; michael@0: michael@0: if (! tv) { michael@0: return NS_OK; michael@0: } michael@0: michael@0: if ((source == mNC_FileSystemRoot) || isFileURI(source)) michael@0: { michael@0: if (property == mRDF_type) michael@0: { michael@0: nsCOMPtr resource( do_QueryInterface(target) ); michael@0: if (resource.get() == mRDF_type) michael@0: { michael@0: *hasAssertion = true; michael@0: } michael@0: } michael@0: #ifdef USE_NC_EXTENSION michael@0: else if (property == mNC_extension) michael@0: { michael@0: // Cheat just a little here by making dirs always match michael@0: if (isDirURI(source)) michael@0: { michael@0: *hasAssertion = true; michael@0: } michael@0: else michael@0: { michael@0: nsCOMPtr extension; michael@0: GetExtension(source, getter_AddRefs(extension)); michael@0: if (extension.get() == target) michael@0: { michael@0: *hasAssertion = true; michael@0: } michael@0: } michael@0: } michael@0: #endif michael@0: else if (property == mNC_IsDirectory) michael@0: { michael@0: bool isDir = isDirURI(source); michael@0: bool isEqual = false; michael@0: target->EqualsNode(mLiteralTrue, &isEqual); michael@0: if (isEqual) michael@0: { michael@0: *hasAssertion = isDir; michael@0: } michael@0: else michael@0: { michael@0: target->EqualsNode(mLiteralFalse, &isEqual); michael@0: if (isEqual) michael@0: *hasAssertion = !isDir; michael@0: } michael@0: } michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, bool *result) michael@0: { michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, bool *result) michael@0: { michael@0: *result = false; michael@0: michael@0: if (aSource == mNC_FileSystemRoot) michael@0: { michael@0: *result = (aArc == mNC_Child || aArc == mNC_pulse); michael@0: } michael@0: else if (isFileURI(aSource)) michael@0: { michael@0: if (aArc == mNC_pulse) michael@0: { michael@0: *result = true; michael@0: } michael@0: else if (isDirURI(aSource)) michael@0: { michael@0: #ifdef XP_WIN michael@0: *result = isValidFolder(aSource); michael@0: #else michael@0: *result = true; michael@0: #endif michael@0: } michael@0: else if (aArc == mNC_pulse || aArc == mNC_Name || aArc == mNC_Icon || michael@0: aArc == mNC_URL || aArc == mNC_Length || aArc == mWEB_LastMod || michael@0: aArc == mNC_FileSystemObject || aArc == mRDF_InstanceOf || michael@0: aArc == mRDF_type) michael@0: { michael@0: *result = true; michael@0: } michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::ArcLabelsIn(nsIRDFNode *node, michael@0: nsISimpleEnumerator ** labels /* out */) michael@0: { michael@0: // NS_NOTYETIMPLEMENTED("write me"); michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::ArcLabelsOut(nsIRDFResource *source, michael@0: nsISimpleEnumerator **labels /* out */) michael@0: { michael@0: NS_PRECONDITION(source != nullptr, "null ptr"); michael@0: if (! source) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: NS_PRECONDITION(labels != nullptr, "null ptr"); michael@0: if (! labels) michael@0: return NS_ERROR_NULL_POINTER; michael@0: michael@0: if (source == mNC_FileSystemRoot) michael@0: { michael@0: nsCOMArray resources; michael@0: resources.SetCapacity(2); michael@0: michael@0: resources.AppendObject(mNC_Child); michael@0: resources.AppendObject(mNC_pulse); michael@0: michael@0: return NS_NewArrayEnumerator(labels, resources); michael@0: } michael@0: else if (isFileURI(source)) michael@0: { michael@0: nsCOMArray resources; michael@0: resources.SetCapacity(2); michael@0: michael@0: if (isDirURI(source)) michael@0: { michael@0: #ifdef XP_WIN michael@0: if (isValidFolder(source)) michael@0: { michael@0: resources.AppendObject(mNC_Child); michael@0: } michael@0: #else michael@0: resources.AppendObject(mNC_Child); michael@0: #endif michael@0: resources.AppendObject(mNC_pulse); michael@0: } michael@0: michael@0: return NS_NewArrayEnumerator(labels, resources); michael@0: } michael@0: michael@0: return NS_NewEmptyEnumerator(labels); michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::GetAllResources(nsISimpleEnumerator** aCursor) michael@0: { michael@0: NS_NOTYETIMPLEMENTED("sorry!"); michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::AddObserver(nsIRDFObserver *n) michael@0: { michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::RemoveObserver(nsIRDFObserver *n) michael@0: { michael@0: return NS_ERROR_NOT_IMPLEMENTED; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::GetAllCmds(nsIRDFResource* source, michael@0: nsISimpleEnumerator/**/** commands) michael@0: { michael@0: return(NS_NewEmptyEnumerator(commands)); michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::IsCommandEnabled(nsISupportsArray/**/* aSources, michael@0: nsIRDFResource* aCommand, michael@0: nsISupportsArray/**/* aArguments, michael@0: bool* aResult) michael@0: { michael@0: return(NS_ERROR_NOT_IMPLEMENTED); michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::DoCommand(nsISupportsArray/**/* aSources, michael@0: nsIRDFResource* aCommand, michael@0: nsISupportsArray/**/* aArguments) michael@0: { michael@0: return(NS_ERROR_NOT_IMPLEMENTED); michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::BeginUpdateBatch() michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: FileSystemDataSource::EndUpdateBatch() michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: michael@0: michael@0: nsresult michael@0: FileSystemDataSource::GetVolumeList(nsISimpleEnumerator** aResult) michael@0: { michael@0: nsCOMArray volumes; michael@0: nsCOMPtr vol; michael@0: michael@0: #ifdef XP_WIN michael@0: michael@0: int32_t driveType; michael@0: wchar_t drive[32]; michael@0: int32_t volNum; michael@0: michael@0: for (volNum = 0; volNum < 26; volNum++) michael@0: { michael@0: swprintf( drive, L"%c:\\", volNum + (char16_t)'A'); michael@0: michael@0: driveType = GetDriveTypeW(drive); michael@0: if (driveType != DRIVE_UNKNOWN && driveType != DRIVE_NO_ROOT_DIR) michael@0: { michael@0: nsAutoCString url; michael@0: url.AppendPrintf("file:///%c|/", volNum + 'A'); michael@0: nsresult rv = mRDFService->GetResource(url, getter_AddRefs(vol)); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: volumes.AppendObject(vol); michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: #ifdef XP_UNIX michael@0: mRDFService->GetResource(NS_LITERAL_CSTRING("file:///"), getter_AddRefs(vol)); michael@0: volumes.AppendObject(vol); michael@0: #endif michael@0: michael@0: return NS_NewArrayEnumerator(aResult, volumes); michael@0: } michael@0: michael@0: michael@0: michael@0: #ifdef XP_WIN michael@0: bool michael@0: FileSystemDataSource::isValidFolder(nsIRDFResource *source) michael@0: { michael@0: bool isValid = true; michael@0: if (ieFavoritesDir.IsEmpty()) return(isValid); michael@0: michael@0: nsresult rv; michael@0: nsCString uri; michael@0: rv = source->GetValueUTF8(uri); michael@0: if (NS_FAILED(rv)) return(isValid); michael@0: michael@0: NS_ConvertUTF8toUTF16 theURI(uri); michael@0: if (theURI.Find(ieFavoritesDir) == 0) michael@0: { michael@0: isValid = false; michael@0: michael@0: nsCOMPtr folderEnum; michael@0: if (NS_SUCCEEDED(rv = GetFolderList(source, true, false, getter_AddRefs(folderEnum)))) michael@0: { michael@0: bool hasAny = false, hasMore; michael@0: while (NS_SUCCEEDED(folderEnum->HasMoreElements(&hasMore)) && michael@0: hasMore) michael@0: { michael@0: hasAny = true; michael@0: michael@0: nsCOMPtr isupports; michael@0: if (NS_FAILED(rv = folderEnum->GetNext(getter_AddRefs(isupports)))) michael@0: break; michael@0: nsCOMPtr res = do_QueryInterface(isupports); michael@0: if (!res) break; michael@0: michael@0: nsCOMPtr nameLiteral; michael@0: if (NS_FAILED(rv = GetName(res, getter_AddRefs(nameLiteral)))) michael@0: break; michael@0: michael@0: const char16_t *uniName; michael@0: if (NS_FAILED(rv = nameLiteral->GetValueConst(&uniName))) michael@0: break; michael@0: nsAutoString name(uniName); michael@0: michael@0: // An empty folder, or a folder that contains just "desktop.ini", michael@0: // is considered to be a IE Favorite; otherwise, its a folder michael@0: if (!name.LowerCaseEqualsLiteral("desktop.ini")) michael@0: { michael@0: isValid = true; michael@0: break; michael@0: } michael@0: } michael@0: if (!hasAny) isValid = true; michael@0: } michael@0: } michael@0: return(isValid); michael@0: } michael@0: #endif michael@0: michael@0: michael@0: michael@0: nsresult michael@0: FileSystemDataSource::GetFolderList(nsIRDFResource *source, bool allowHidden, michael@0: bool onlyFirst, nsISimpleEnumerator** aResult) michael@0: { michael@0: if (!isDirURI(source)) michael@0: return(NS_RDF_NO_VALUE); michael@0: michael@0: nsresult rv; michael@0: michael@0: const char *parentURI = nullptr; michael@0: rv = source->GetValueConst(&parentURI); michael@0: if (NS_FAILED(rv)) michael@0: return(rv); michael@0: if (!parentURI) michael@0: return(NS_ERROR_UNEXPECTED); michael@0: michael@0: nsCOMPtr aIURI; michael@0: if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(aIURI), nsDependentCString(parentURI)))) michael@0: return(rv); michael@0: michael@0: nsCOMPtr fileURL = do_QueryInterface(aIURI); michael@0: if (!fileURL) michael@0: return NS_OK; michael@0: michael@0: nsCOMPtr aDir; michael@0: if (NS_FAILED(rv = fileURL->GetFile(getter_AddRefs(aDir)))) michael@0: return(rv); michael@0: michael@0: // ensure that we DO NOT resolve aliases michael@0: aDir->SetFollowLinks(false); michael@0: michael@0: nsCOMPtr dirContents; michael@0: if (NS_FAILED(rv = aDir->GetDirectoryEntries(getter_AddRefs(dirContents)))) michael@0: return(rv); michael@0: if (!dirContents) michael@0: return(NS_ERROR_UNEXPECTED); michael@0: michael@0: nsCOMArray resources; michael@0: bool hasMore; michael@0: while(NS_SUCCEEDED(rv = dirContents->HasMoreElements(&hasMore)) && michael@0: hasMore) michael@0: { michael@0: nsCOMPtr isupports; michael@0: if (NS_FAILED(rv = dirContents->GetNext(getter_AddRefs(isupports)))) michael@0: break; michael@0: michael@0: nsCOMPtr aFile = do_QueryInterface(isupports); michael@0: if (!aFile) michael@0: break; michael@0: michael@0: if (!allowHidden) michael@0: { michael@0: bool hiddenFlag = false; michael@0: if (NS_FAILED(rv = aFile->IsHidden(&hiddenFlag))) michael@0: break; michael@0: if (hiddenFlag) michael@0: continue; michael@0: } michael@0: michael@0: nsAutoString leafStr; michael@0: if (NS_FAILED(rv = aFile->GetLeafName(leafStr))) michael@0: break; michael@0: if (leafStr.IsEmpty()) michael@0: continue; michael@0: michael@0: nsAutoCString fullURI; michael@0: fullURI.Assign(parentURI); michael@0: if (fullURI.Last() != '/') michael@0: { michael@0: fullURI.Append('/'); michael@0: } michael@0: michael@0: char *escLeafStr = nsEscape(NS_ConvertUTF16toUTF8(leafStr).get(), url_Path); michael@0: leafStr.Truncate(); michael@0: michael@0: if (!escLeafStr) michael@0: continue; michael@0: michael@0: nsAutoCString leaf(escLeafStr); michael@0: NS_Free(escLeafStr); michael@0: escLeafStr = nullptr; michael@0: michael@0: // using nsEscape() [above] doesn't escape slashes, so do that by hand michael@0: int32_t aOffset; michael@0: while ((aOffset = leaf.FindChar('/')) >= 0) michael@0: { michael@0: leaf.Cut((uint32_t)aOffset, 1); michael@0: leaf.Insert("%2F", (uint32_t)aOffset); michael@0: } michael@0: michael@0: // append the encoded name michael@0: fullURI.Append(leaf); michael@0: michael@0: bool dirFlag = false; michael@0: rv = aFile->IsDirectory(&dirFlag); michael@0: if (NS_SUCCEEDED(rv) && dirFlag) michael@0: { michael@0: fullURI.Append('/'); michael@0: } michael@0: michael@0: nsCOMPtr fileRes; michael@0: mRDFService->GetResource(fullURI, getter_AddRefs(fileRes)); michael@0: michael@0: resources.AppendObject(fileRes); michael@0: michael@0: if (onlyFirst) michael@0: break; michael@0: } michael@0: michael@0: return NS_NewArrayEnumerator(aResult, resources); michael@0: } michael@0: michael@0: nsresult michael@0: FileSystemDataSource::GetLastMod(nsIRDFResource *source, nsIRDFDate **aResult) michael@0: { michael@0: *aResult = nullptr; michael@0: michael@0: nsresult rv; michael@0: const char *uri = nullptr; michael@0: michael@0: rv = source->GetValueConst(&uri); michael@0: if (NS_FAILED(rv)) return(rv); michael@0: if (!uri) michael@0: return(NS_ERROR_UNEXPECTED); michael@0: michael@0: nsCOMPtr aIURI; michael@0: if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(aIURI), nsDependentCString(uri)))) michael@0: return(rv); michael@0: michael@0: nsCOMPtr fileURL = do_QueryInterface(aIURI); michael@0: if (!fileURL) michael@0: return NS_OK; michael@0: michael@0: nsCOMPtr aFile; michael@0: if (NS_FAILED(rv = fileURL->GetFile(getter_AddRefs(aFile)))) michael@0: return(rv); michael@0: if (!aFile) michael@0: return(NS_ERROR_UNEXPECTED); michael@0: michael@0: // ensure that we DO NOT resolve aliases michael@0: aFile->SetFollowLinks(false); michael@0: michael@0: PRTime lastModDate; michael@0: if (NS_FAILED(rv = aFile->GetLastModifiedTime(&lastModDate))) michael@0: return(rv); michael@0: michael@0: // convert from milliseconds to seconds michael@0: mRDFService->GetDateLiteral(lastModDate * PR_MSEC_PER_SEC, aResult); michael@0: michael@0: return(NS_OK); michael@0: } michael@0: michael@0: michael@0: michael@0: nsresult michael@0: FileSystemDataSource::GetFileSize(nsIRDFResource *source, nsIRDFInt **aResult) michael@0: { michael@0: *aResult = nullptr; michael@0: michael@0: nsresult rv; michael@0: const char *uri = nullptr; michael@0: michael@0: rv = source->GetValueConst(&uri); michael@0: if (NS_FAILED(rv)) michael@0: return(rv); michael@0: if (!uri) michael@0: return(NS_ERROR_UNEXPECTED); michael@0: michael@0: nsCOMPtr aIURI; michael@0: if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(aIURI), nsDependentCString(uri)))) michael@0: return(rv); michael@0: michael@0: nsCOMPtr fileURL = do_QueryInterface(aIURI); michael@0: if (!fileURL) michael@0: return NS_OK; michael@0: michael@0: nsCOMPtr aFile; michael@0: if (NS_FAILED(rv = fileURL->GetFile(getter_AddRefs(aFile)))) michael@0: return(rv); michael@0: if (!aFile) michael@0: return(NS_ERROR_UNEXPECTED); michael@0: michael@0: // ensure that we DO NOT resolve aliases michael@0: aFile->SetFollowLinks(false); michael@0: michael@0: // don't do anything with directories michael@0: bool isDir = false; michael@0: if (NS_FAILED(rv = aFile->IsDirectory(&isDir))) michael@0: return(rv); michael@0: if (isDir) michael@0: return(NS_RDF_NO_VALUE); michael@0: michael@0: int64_t aFileSize64; michael@0: if (NS_FAILED(rv = aFile->GetFileSize(&aFileSize64))) michael@0: return(rv); michael@0: michael@0: // convert 64bits to 32bits michael@0: int32_t aFileSize32 = int32_t(aFileSize64); michael@0: mRDFService->GetIntLiteral(aFileSize32, aResult); michael@0: michael@0: return(NS_OK); michael@0: } michael@0: michael@0: michael@0: michael@0: nsresult michael@0: FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult) michael@0: { michael@0: nsresult rv; michael@0: const char *uri = nullptr; michael@0: michael@0: rv = source->GetValueConst(&uri); michael@0: if (NS_FAILED(rv)) michael@0: return(rv); michael@0: if (!uri) michael@0: return(NS_ERROR_UNEXPECTED); michael@0: michael@0: nsCOMPtr aIURI; michael@0: if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(aIURI), nsDependentCString(uri)))) michael@0: return(rv); michael@0: michael@0: nsCOMPtr fileURL = do_QueryInterface(aIURI); michael@0: if (!fileURL) michael@0: return NS_OK; michael@0: michael@0: nsCOMPtr aFile; michael@0: if (NS_FAILED(rv = fileURL->GetFile(getter_AddRefs(aFile)))) michael@0: return(rv); michael@0: if (!aFile) michael@0: return(NS_ERROR_UNEXPECTED); michael@0: michael@0: // ensure that we DO NOT resolve aliases michael@0: aFile->SetFollowLinks(false); michael@0: michael@0: nsAutoString name; michael@0: if (NS_FAILED(rv = aFile->GetLeafName(name))) michael@0: return(rv); michael@0: if (name.IsEmpty()) michael@0: return(NS_ERROR_UNEXPECTED); michael@0: michael@0: #ifdef XP_WIN michael@0: // special hack for IE favorites under Windows; strip off the michael@0: // trailing ".url" or ".lnk" at the end of IE favorites names michael@0: int32_t nameLen = name.Length(); michael@0: if ((strncmp(uri, ieFavoritesDir.get(), ieFavoritesDir.Length()) == 0) && (nameLen > 4)) michael@0: { michael@0: nsAutoString extension; michael@0: name.Right(extension, 4); michael@0: if (extension.LowerCaseEqualsLiteral(".url") || michael@0: extension.LowerCaseEqualsLiteral(".lnk")) michael@0: { michael@0: name.Truncate(nameLen - 4); michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: mRDFService->GetLiteral(name.get(), aResult); michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: michael@0: michael@0: #ifdef USE_NC_EXTENSION michael@0: nsresult michael@0: FileSystemDataSource::GetExtension(nsIRDFResource *source, nsIRDFLiteral **aResult) michael@0: { michael@0: nsCOMPtr name; michael@0: nsresult rv = GetName(source, getter_AddRefs(name)); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: const char16_t* unicodeLeafName; michael@0: rv = name->GetValueConst(&unicodeLeafName); michael@0: if (NS_FAILED(rv)) michael@0: return rv; michael@0: michael@0: nsAutoString filename(unicodeLeafName); michael@0: int32_t lastDot = filename.RFindChar('.'); michael@0: if (lastDot == -1) michael@0: { michael@0: mRDFService->GetLiteral(EmptyString().get(), aResult); michael@0: } michael@0: else michael@0: { michael@0: nsAutoString extension; michael@0: filename.Right(extension, (filename.Length() - lastDot)); michael@0: mRDFService->GetLiteral(extension.get(), aResult); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: #endif michael@0: michael@0: #ifdef XP_WIN michael@0: nsresult michael@0: FileSystemDataSource::getIEFavoriteURL(nsIRDFResource *source, nsString aFileURL, nsIRDFLiteral **urlLiteral) michael@0: { michael@0: nsresult rv = NS_OK; michael@0: michael@0: *urlLiteral = nullptr; michael@0: michael@0: nsCOMPtr f; michael@0: NS_GetFileFromURLSpec(NS_ConvertUTF16toUTF8(aFileURL), getter_AddRefs(f)); michael@0: michael@0: bool value; michael@0: michael@0: if (NS_SUCCEEDED(f->IsDirectory(&value)) && value) michael@0: { michael@0: if (isValidFolder(source)) michael@0: return(NS_RDF_NO_VALUE); michael@0: aFileURL.AppendLiteral("desktop.ini"); michael@0: } michael@0: else if (aFileURL.Length() > 4) michael@0: { michael@0: nsAutoString extension; michael@0: michael@0: aFileURL.Right(extension, 4); michael@0: if (!extension.LowerCaseEqualsLiteral(".url")) michael@0: { michael@0: return(NS_RDF_NO_VALUE); michael@0: } michael@0: } michael@0: michael@0: nsCOMPtr strm; michael@0: NS_NewLocalFileInputStream(getter_AddRefs(strm),f); michael@0: nsCOMPtr linereader = do_QueryInterface(strm, &rv); michael@0: michael@0: nsAutoString line; michael@0: nsAutoCString cLine; michael@0: while(NS_SUCCEEDED(rv)) michael@0: { michael@0: bool isEOF; michael@0: rv = linereader->ReadLine(cLine, &isEOF); michael@0: CopyASCIItoUTF16(cLine, line); michael@0: michael@0: if (isEOF) michael@0: { michael@0: if (line.Find("URL=", true) == 0) michael@0: { michael@0: line.Cut(0, 4); michael@0: rv = mRDFService->GetLiteral(line.get(), urlLiteral); michael@0: break; michael@0: } michael@0: else if (line.Find("CDFURL=", true) == 0) michael@0: { michael@0: line.Cut(0, 7); michael@0: rv = mRDFService->GetLiteral(line.get(), urlLiteral); michael@0: break; michael@0: } michael@0: line.Truncate(); michael@0: } michael@0: } michael@0: michael@0: return(rv); michael@0: } michael@0: #endif michael@0: michael@0: michael@0: michael@0: nsresult michael@0: FileSystemDataSource::GetURL(nsIRDFResource *source, bool *isFavorite, nsIRDFLiteral** aResult) michael@0: { michael@0: if (isFavorite) *isFavorite = false; michael@0: michael@0: nsresult rv; michael@0: nsCString uri; michael@0: michael@0: rv = source->GetValueUTF8(uri); michael@0: if (NS_FAILED(rv)) michael@0: return(rv); michael@0: michael@0: NS_ConvertUTF8toUTF16 url(uri); michael@0: michael@0: #ifdef XP_WIN michael@0: // under Windows, if its an IE favorite, munge the URL michael@0: if (!ieFavoritesDir.IsEmpty()) michael@0: { michael@0: if (url.Find(ieFavoritesDir) == 0) michael@0: { michael@0: if (isFavorite) *isFavorite = true; michael@0: rv = getIEFavoriteURL(source, url, aResult); michael@0: return(rv); michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: // if we fall through to here, its not any type of bookmark michael@0: // stored in the platform native file system, so just set the URL michael@0: michael@0: mRDFService->GetLiteral(url.get(), aResult); michael@0: michael@0: return(NS_OK); michael@0: }