nsresult PendingPACQuery::Start(PRUint32 flags) { if (mDNSRequest) return NS_OK; // already started nsresult rv; nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) { NS_WARNING("unable to get the DNS service"); return rv; } nsCAutoString host; rv = mURI->GetAsciiHost(host); if (NS_FAILED(rv)) return rv; rv = dns->AsyncResolve(host, flags, this, NS_GetCurrentThread(), getter_AddRefs(mDNSRequest)); if (NS_FAILED(rv)) NS_WARNING("DNS AsyncResolve failed"); return rv; }
NS_IMETHODIMP nsAbQueryLDAPMessageListener::OnLDAPInit(nsILDAPConnection *aConn, nsresult aStatus) { nsresult rv; nsXPIDLString passwd; // Make sure that the Init() worked properly NS_ENSURE_SUCCESS(aStatus, aStatus); if (!mDirectoryQuery) return NS_ERROR_NULL_POINTER; // If mLogin is set, we're expected to use it to get a password. // if (!mDirectoryQuery->mLogin.IsEmpty()) { // XXX hack until nsUTF8AutoString exists #define nsUTF8AutoString nsCAutoString nsUTF8AutoString spec; PRBool status; // we're going to use the URL spec of the server as the "realm" for // wallet to remember the password by / for. // rv = mDirectoryQuery->mDirectoryUrl->GetSpec(spec); if (NS_FAILED(rv)) { NS_ERROR("nsAbQueryLDAPMessageListener::OnLDAPInit(): GetSpec" " failed\n"); return NS_ERROR_FAILURE; } // get the string bundle service // nsCOMPtr<nsIStringBundleService> stringBundleSvc(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv)); if (NS_FAILED(rv)) { NS_ERROR("nsAbQueryLDAPMessageListener::OnLDAPInit():" " error getting string bundle service"); return rv; } // get the LDAP string bundle // nsCOMPtr<nsIStringBundle> ldapBundle; rv = stringBundleSvc->CreateBundle( "chrome://mozldap/locale/ldap.properties", getter_AddRefs(ldapBundle)); if (NS_FAILED(rv)) { NS_ERROR("nsAbQueryLDAPMessageListener::OnLDAPInit():" " error creating string bundle" " chrome://mozldap/locale/ldap.properties"); return rv; } // get the title for the authentication prompt // nsXPIDLString authPromptTitle; rv = ldapBundle->GetStringFromName( NS_LITERAL_STRING("authPromptTitle").get(), getter_Copies(authPromptTitle)); if (NS_FAILED(rv)) { NS_ERROR("nsAbQueryLDAPMessageListener::OnLDAPInit():" "error getting 'authPromptTitle' string from bundle " "chrome://mozldap/locale/ldap.properties"); return rv; } // get the host name for the auth prompt // nsCAutoString host; rv = mUrl->GetAsciiHost(host); if (NS_FAILED(rv)) { return NS_ERROR_FAILURE; } // hostTemp is only necessary to work around a code-generation // bug in egcs 1.1.2 (the version of gcc that comes with Red Hat 6.2), // which is the default compiler for Mozilla on linux at the moment. // NS_ConvertASCIItoUCS2 hostTemp(host); const PRUnichar *hostArray[1] = { hostTemp.get() }; // format the hostname into the authprompt text string // nsXPIDLString authPromptText; rv = ldapBundle->FormatStringFromName( NS_LITERAL_STRING("authPromptText").get(), hostArray, sizeof(hostArray) / sizeof(const PRUnichar *), getter_Copies(authPromptText)); if (NS_FAILED(rv)) { NS_ERROR("nsAbQueryLDAPMessageListener::OnLDAPInit():" "error getting 'authPromptText' string from bundle " "chrome://mozldap/locale/ldap.properties"); return rv; } // get the window watcher service, so we can get an auth prompter // nsCOMPtr<nsIWindowWatcher> windowWatcherSvc = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); if (NS_FAILED(rv)) { NS_ERROR("nsAbQueryLDAPMessageListener::OnLDAPInit():" " couldn't get window watcher service."); return rv; } // get the addressbook window, as it will be used to parent the auth // prompter dialog // nsCOMPtr<nsIDOMWindow> abDOMWindow; rv = windowWatcherSvc->GetWindowByName( NS_LITERAL_STRING("addressbookWindow").get(), nsnull, getter_AddRefs(abDOMWindow)); if (NS_FAILED(rv)) { NS_ERROR("nsAbQueryLDAPMessageListener::OnLDAPInit():" " error getting addressbook Window"); return rv; } // get the auth prompter itself // nsCOMPtr<nsIAuthPrompt> authPrompter; rv = windowWatcherSvc->GetNewAuthPrompter( abDOMWindow, getter_AddRefs(authPrompter)); if (NS_FAILED(rv)) { NS_ERROR("nsAbQueryLDAPMessageListener::OnLDAPInit():" " error getting auth prompter"); return rv; } // get authentication password, prompting the user if necessary // rv = authPrompter->PromptPassword( authPromptTitle.get(), authPromptText.get(), NS_ConvertUTF8toUCS2(spec).get(), nsIAuthPrompt::SAVE_PASSWORD_PERMANENTLY, getter_Copies(passwd), &status); if (NS_FAILED(rv) || !status) { return NS_ERROR_FAILURE; } } // Initiate the LDAP operation nsCOMPtr<nsILDAPOperation> ldapOperation = do_CreateInstance(NS_LDAPOPERATION_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsILDAPMessageListener> proxyListener; rv = NS_GetProxyForObject(NS_UI_THREAD_EVENTQ, NS_GET_IID(nsILDAPMessageListener), NS_STATIC_CAST(nsILDAPMessageListener *, this), PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs(proxyListener)); rv = ldapOperation->Init(mConnection, proxyListener, nsnull); NS_ENSURE_SUCCESS(rv, rv); // Bind rv = ldapOperation->SimpleBind(NS_ConvertUCS2toUTF8(passwd)); NS_ENSURE_SUCCESS(rv, rv); return rv; }