예제 #1
0
NS_IMETHODIMP
nsAbOSXDirFactory::GetDirectories(const nsAString &aDirName,
                                  const nsACString &aURI,
                                  const nsACString &aPrefName,
                                  nsISimpleEnumerator **aDirectories)
{
  NS_ENSURE_ARG_POINTER(aDirectories);
  
  *aDirectories = nsnull;

  nsresult rv;
  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIAbDirectory> directory;
  rv = abManager->GetDirectory(NS_LITERAL_CSTRING(NS_ABOSXDIRECTORY_URI_PREFIX "/"),
                               getter_AddRefs(directory));
  NS_ENSURE_SUCCESS(rv, rv);
  
  nsCOMPtr<nsIAbOSXDirectory> osxDirectory(do_QueryInterface(directory, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = osxDirectory->AssertChildNodes();
  NS_ENSURE_SUCCESS(rv, rv);
  
  return NS_NewSingletonEnumerator(aDirectories, osxDirectory);
}
NS_IMETHODIMP
nsAbOSXDirFactory::GetDirectories(const nsAString &aDirName,
                                  const nsACString &aURI,
                                  const nsACString &aPrefName,
                                  nsISimpleEnumerator **aDirectories)
{
  NS_ENSURE_ARG_POINTER(aDirectories);
  
  *aDirectories = nsnull;

  nsresult rv;
  nsCOMPtr<nsIRDFService> rdf =
    do_GetService(NS_RDF_CONTRACTID "/rdf-service;1", &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  
  // We hardcode the root to "moz-abosxdirectory:///".
  nsCOMPtr<nsIRDFResource> resource;
  rv = rdf->GetResource(NS_LITERAL_CSTRING(NS_ABOSXDIRECTORY_URI_PREFIX "/"),
                        getter_AddRefs(resource));
  NS_ENSURE_SUCCESS(rv, rv);
  
  nsCOMPtr<nsIAbOSXDirectory> osxDirectory =
    do_QueryInterface(resource, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  
  rv = osxDirectory->AssertChildNodes();
  NS_ENSURE_SUCCESS(rv, rv);
  
  return NS_NewSingletonEnumerator(aDirectories, osxDirectory);
}
예제 #3
0
NS_IMETHODIMP nsAbMDBDirFactory::GetDirectories(const nsAString &aDirName,
                                                const nsACString &aURI,
                                                const nsACString &aPrefName,
                                                nsISimpleEnumerator **_retval)
{
  NS_ENSURE_ARG_POINTER(_retval);
  
  nsresult rv;

  nsCOMPtr<nsIAbManager> abManager = do_GetService(NS_ABMANAGER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIAbDirectory> directory;
  rv = abManager->GetDirectory(aURI, getter_AddRefs(directory));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = directory->SetDirPrefId(aPrefName);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsILocalFile> dbPath;
  rv = abManager->GetUserProfileDirectory(getter_AddRefs(dbPath));

  nsCOMPtr<nsIAddrDatabase> listDatabase;
  if (NS_SUCCEEDED(rv))
  {
    nsCAutoString fileName;
      
    if (StringBeginsWith(aURI, NS_LITERAL_CSTRING(kMDBDirectoryRoot)))
      fileName = Substring(aURI, kMDBDirectoryRootLen, aURI.Length() - kMDBDirectoryRootLen);

    rv = dbPath->AppendNative(fileName);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIAddrDatabase> addrDBFactory = do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = addrDBFactory->Open(dbPath, true, true, getter_AddRefs(listDatabase));
  }
  NS_ENSURE_SUCCESS(rv, rv);

  rv = listDatabase->GetMailingListsFromDB(directory);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_NewSingletonEnumerator(_retval, directory);
}
예제 #4
0
NS_IMETHODIMP
nsMailDirProvider::GetFiles(const char *aKey,
				nsISimpleEnumerator* *aResult)
{
  if (strcmp(aKey, ISP_DIRECTORY_LIST) != 0)
    return NS_ERROR_FAILURE;

  // The list of isp directories includes the isp directory
  // in the current process dir (i.e. <path to thunderbird.exe>\isp and 
  // <path to thunderbird.exe>\isp\locale 
  // and isp and isp\locale for each active extension

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

  nsCOMPtr<nsIFile> currentProcessDir;
  nsresult rv = dirSvc->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
                   NS_GET_IID(nsIFile), getter_AddRefs(currentProcessDir));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsISimpleEnumerator> directoryEnumerator;
  rv = NS_NewSingletonEnumerator(getter_AddRefs(directoryEnumerator), currentProcessDir);
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsISimpleEnumerator> combinedEnumerator;

#ifdef MOZ_XUL_APP
  nsCOMPtr<nsISimpleEnumerator> extensionsEnum;
  rv = dirSvc->Get(XRE_EXTENSIONS_DIR_LIST,
			    NS_GET_IID(nsISimpleEnumerator),
			    getter_AddRefs(extensionsEnum));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = NS_NewUnionEnumerator(getter_AddRefs(combinedEnumerator), directoryEnumerator, extensionsEnum);
  NS_ENSURE_SUCCESS(rv, rv);
#else
  directoryEnumerator.swap(combinedEnumerator);
#endif
   
  NS_IF_ADDREF(*aResult = new AppendingEnumerator(combinedEnumerator));
  return NS_SUCCESS_AGGREGATE_RESULT;
}
NS_IMETHODIMP
nsAbLDAPDirFactory::GetDirectories(const nsAString &aDirName,
                                   const nsACString &aURI,
                                   const nsACString &aPrefName,
                                   nsISimpleEnumerator **aDirectories)
{
  NS_ENSURE_ARG_POINTER(aDirectories);

  nsresult rv;
  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsIAbDirectory> directory;
  if (Substring(aURI, 0, 5).EqualsLiteral("ldap:") ||
      Substring(aURI, 0, 6).EqualsLiteral("ldaps:")) {
    /*
     * If the URI starts with ldap: or ldaps:
     * then this directory is an LDAP directory.
     *
     * We don't want to use the ldap:// or ldaps:// URI 
     * as the URI because the ldap:// or ldaps:// URI 
     * will contain the hostname, basedn, port, etc.
     * so if those attributes changed, we'll run into the
     * the same problem that we hit with changing username / hostname
     * for mail servers.  To solve this problem, we add an extra
     * level of indirection.  The URI that we generate
     * (the bridge URI) will be moz-abldapdirectory://<prefName>
     * and when we need the hostname, basedn, port, etc,
     * we'll use the <prefName> to get the necessary prefs.
     * note, <prefName> does not change.
     */
    nsAutoCString bridgeURI;
    bridgeURI = NS_LITERAL_CSTRING(kLDAPDirectoryRoot);
    bridgeURI += aPrefName;
    rv = abManager->GetDirectory(bridgeURI, getter_AddRefs(directory));
  }
  else {
    rv = abManager->GetDirectory(aURI, getter_AddRefs(directory));
  }
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_NewSingletonEnumerator(aDirectories, directory);
}
NS_IMETHODIMP
FileSystemDataSource::GetTargets(nsIRDFResource *source,
                                 nsIRDFResource *property,
                                 bool tv,
                                 nsISimpleEnumerator **targets /* out */)
{
    NS_PRECONDITION(source != nullptr, "null ptr");
    if (! source)
        return NS_ERROR_NULL_POINTER;

    NS_PRECONDITION(property != nullptr, "null ptr");
    if (! property)
        return NS_ERROR_NULL_POINTER;

    NS_PRECONDITION(targets != nullptr, "null ptr");
    if (! targets)
        return NS_ERROR_NULL_POINTER;

    *targets = nullptr;

    // we only have positive assertions in the file system data source.
    if (! tv)
        return NS_RDF_NO_VALUE;

    nsresult rv;

    if (source == mNC_FileSystemRoot)
    {
        if (property == mNC_Child)
        {
            return GetVolumeList(targets);
        }
        else if (property == mNC_pulse)
        {
            nsCOMPtr<nsIRDFLiteral> pulseLiteral;
            mRDFService->GetLiteral(MOZ_UTF16("12"),
                                    getter_AddRefs(pulseLiteral));
            return NS_NewSingletonEnumerator(targets, pulseLiteral);
        }
    }
    else if (isFileURI(source))
    {
        if (property == mNC_Child)
        {
            return GetFolderList(source, false, false, targets);
        }
        else if (property == mNC_Name)
        {
            nsCOMPtr<nsIRDFLiteral> name;
            rv = GetName(source, getter_AddRefs(name));
            if (NS_FAILED(rv)) return rv;

            return NS_NewSingletonEnumerator(targets, name);
        }
        else if (property == mNC_URL)
        {
            nsCOMPtr<nsIRDFLiteral> url;
            rv = GetURL(source, nullptr, getter_AddRefs(url));
            if (NS_FAILED(rv)) return rv;

            return NS_NewSingletonEnumerator(targets, url);
        }
        else if (property == mRDF_type)
        {
            nsCString uri;
            rv = mNC_FileSystemObject->GetValueUTF8(uri);
            if (NS_FAILED(rv)) return rv;

            NS_ConvertUTF8toUTF16 url(uri);

            nsCOMPtr<nsIRDFLiteral> literal;
            rv = mRDFService->GetLiteral(url.get(), getter_AddRefs(literal));
            if (NS_FAILED(rv)) return rv;

            return NS_NewSingletonEnumerator(targets, literal);
        }
        else if (property == mNC_pulse)
        {
            nsCOMPtr<nsIRDFLiteral> pulseLiteral;
            rv = mRDFService->GetLiteral(MOZ_UTF16("12"),
                                         getter_AddRefs(pulseLiteral));
            if (NS_FAILED(rv)) return rv;

            return NS_NewSingletonEnumerator(targets, pulseLiteral);
        }
    }

    return NS_NewEmptyEnumerator(targets);
}