nsresult nsClientAuthRememberService::Init() { if (!mSettingsTable.Init()) return NS_ERROR_OUT_OF_MEMORY; nsCOMPtr<nsIProxyObjectManager> proxyman(do_GetService(NS_XPCOMPROXY_CONTRACTID)); if (!proxyman) return NS_ERROR_FAILURE; nsCOMPtr<nsIObserverService> observerService(do_GetService("@mozilla.org/observer-service;1")); nsCOMPtr<nsIObserverService> proxiedObserver; NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, NS_GET_IID(nsIObserverService), observerService, NS_PROXY_SYNC, getter_AddRefs(proxiedObserver)); if (proxiedObserver) { proxiedObserver->AddObserver(this, "profile-before-change", PR_TRUE); } return NS_OK; }
/* void getInterface (in nsIIDRef uuid, [iid_is (uuid), retval] out nsQIResult result); */ NS_IMETHODIMP nsSDRContext::GetInterface(const nsIID & uuid, void * *result) { if (!uuid.Equals(NS_GET_IID(nsIPrompt))) return NS_ERROR_NO_INTERFACE; nsCOMPtr<nsIPrompt> prompter; nsresult rv; nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; rv = wwatch->GetNewPrompter(0, getter_AddRefs(prompter)); if (!prompter) return NS_ERROR_FAILURE; nsCOMPtr<nsIPrompt> proxyPrompt; rv = NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, NS_GET_IID(nsIPrompt), prompter, NS_PROXY_SYNC, getter_AddRefs(proxyPrompt)); if (!proxyPrompt) return NS_ERROR_FAILURE; *result = proxyPrompt; NS_ADDREF((nsIPrompt*)*result); return NS_OK; }
NS_IMETHODIMP nsLDAPChannel::SetLoadGroup(nsILoadGroup* aLoadGroup) { mUnproxiedLoadGroup = aLoadGroup; // in the case where the LDAP callbacks happen on the connection thread, // we'll need to call into the loadgroup from there // #if INVOKE_LDAP_CALLBACKS_ON_MAIN_THREAD mLoadGroup = mUnproxiedLoadGroup; #else nsresult rv; // get and save a proxy for the load group // rv = NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, kILoadGroupIID, mUnproxiedLoadGroup, NS_PROXY_SYNC|NS_PROXY_ALWAYS, getter_AddRefs(mLoadGroup)); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPChannel::SetLoadGroup(): could not create proxy " "event"); return NS_ERROR_FAILURE; } #endif return NS_OK; }
int main() { NS_InitEmbedding(NULL, NULL); InvokeTestTarget *test = new InvokeTestTarget(); /* here we make the global 'check for alloc failure' checker happy */ if(!test) return 1; InvokeTestTargetInterface* proxy; NS_GetProxyForObject(NS_UI_THREAD_EVENTQ, kTheCID, test, PROXY_SYNC | PROXY_ALWAYS, (void**)(&proxy)); char* buffer; proxy->PassTwoStrings("", "a", "b", &buffer); NS_RELEASE(test); extern int x_main(); x_main(); return NS_OK; }
void nsNSSCertificateDB::DisplayCertificateAlert(nsIInterfaceRequestor *ctx, const char *stringID, nsIX509Cert *certToShow) { nsPSMUITracker tracker; if (!tracker.isUIForbidden()) { nsCOMPtr<nsIInterfaceRequestor> my_cxt = ctx; if (!my_cxt) my_cxt = new PipUIContext(); // This shall be replaced by embedding ovverridable prompts // as discussed in bug 310446, and should make use of certToShow. nsresult rv; nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv)); if (NS_SUCCEEDED(rv)) { nsAutoString tmpMessage; nssComponent->GetPIPNSSBundleString(stringID, tmpMessage); // The interface requestor object may not be safe, so proxy the call to get // the nsIPrompt. nsCOMPtr<nsIInterfaceRequestor> proxiedCallbacks; NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, NS_GET_IID(nsIInterfaceRequestor), my_cxt, NS_PROXY_SYNC, getter_AddRefs(proxiedCallbacks)); nsCOMPtr<nsIPrompt> prompt (do_GetInterface(proxiedCallbacks)); if (!prompt) return; // Finally, get a proxy for the nsIPrompt nsCOMPtr<nsIPrompt> proxyPrompt; NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, NS_GET_IID(nsIPrompt), prompt, NS_PROXY_SYNC, getter_AddRefs(proxyPrompt)); proxyPrompt->Alert(nsnull, tmpMessage.get()); } } }
NS_IMETHODIMP nsDNSService::AsyncResolve(const nsACString &hostname, PRUint32 flags, nsIDNSListener *listener, nsIEventTarget *eventTarget, nsICancelable **result) { // grab reference to global host resolver and IDN service. beware // simultaneous shutdown!! nsRefPtr<nsHostResolver> res; nsCOMPtr<nsIIDNService> idn; { nsAutoLock lock(mLock); res = mResolver; idn = mIDN; } NS_ENSURE_TRUE(res, NS_ERROR_OFFLINE); const nsACString *hostPtr = &hostname; nsresult rv; nsCAutoString hostACE; if (idn && !IsASCII(hostname)) { if (NS_SUCCEEDED(idn->ConvertUTF8toACE(hostname, hostACE))) hostPtr = &hostACE; } nsCOMPtr<nsIDNSListener> listenerProxy; nsCOMPtr<nsIEventQueue> eventQ = do_QueryInterface(eventTarget); // TODO(darin): make XPCOM proxies support any nsIEventTarget impl if (eventQ) { rv = NS_GetProxyForObject(eventQ, NS_GET_IID(nsIDNSListener), listener, PROXY_ASYNC | PROXY_ALWAYS, getter_AddRefs(listenerProxy)); if (NS_FAILED(rv)) return rv; listener = listenerProxy; } PRUint16 af = GetAFForLookup(*hostPtr); nsDNSAsyncRequest *req = new nsDNSAsyncRequest(res, *hostPtr, listener, flags, af); if (!req) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(*result = req); // addref for resolver; will be released when OnLookupComplete is called. NS_ADDREF(req); rv = res->ResolveHost(req->mHost.get(), flags, af, req); if (NS_FAILED(rv)) { NS_RELEASE(req); NS_RELEASE(*result); } return rv; }
nsresult TimerThread::Init() { PR_LOG(gTimerLog, PR_LOG_DEBUG, ("TimerThread::Init [%d]\n", mInitialized)); if (mInitialized) { if (!mThread) return NS_ERROR_FAILURE; return NS_OK; } if (PR_AtomicSet(&mInitInProgress, 1) == 0) { // We hold on to mThread to keep the thread alive. nsresult rv = NS_NewThread(getter_AddRefs(mThread), this); if (NS_FAILED(rv)) { mThread = nsnull; } else { nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1"); // We must not use the observer service from a background thread! if (observerService && !NS_IsMainThread()) { nsCOMPtr<nsIObserverService> result = nsnull; NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, NS_GET_IID(nsIObserverService), observerService, NS_PROXY_ASYNC, getter_AddRefs(result)); observerService.swap(result); } // We'll be released at xpcom shutdown if (observerService) { observerService->AddObserver(this, "sleep_notification", PR_FALSE); observerService->AddObserver(this, "wake_notification", PR_FALSE); } } PR_Lock(mLock); mInitialized = PR_TRUE; PR_NotifyAllCondVar(mCondVar); PR_Unlock(mLock); } else { PR_Lock(mLock); while (!mInitialized) { PR_WaitCondVar(mCondVar, PR_INTERVAL_NO_TIMEOUT); } PR_Unlock(mLock); } if (!mThread) return NS_ERROR_FAILURE; return NS_OK; }
nsresult nsConsoleService::GetProxyForListener(nsIConsoleListener* aListener, nsIConsoleListener** aProxy) { /* * Would it be better to catch that case and leave the listener unproxied? */ return NS_GetProxyForObject(NS_PROXY_TO_CURRENT_THREAD, NS_GET_IID(nsIConsoleListener), aListener, NS_PROXY_ASYNC | NS_PROXY_ALWAYS, (void**) aProxy); }
nsIStringBundle *nsEudoraStringBundle::GetStringBundleProxy( void) { if (!m_pBundle) return( nsnull); nsIStringBundle *strProxy = nsnull; // create a proxy object if we aren't on the same thread? NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, NS_GET_IID(nsIStringBundle), m_pBundle, NS_PROXY_SYNC | NS_PROXY_ALWAYS, (void **) &strProxy); return( strProxy); }
// void initConnection (); // nsresult nsLDAPSyncQuery::InitConnection() { nsCOMPtr<nsILDAPMessageListener> selfProxy; nsresult rv; // temp for xpcom return values // create an LDAP connection // mConnection = do_CreateInstance("@mozilla.org/network/ldap-connection;1", &rv); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPSyncQuery::InitConnection(): could " "not create @mozilla.org/network/ldap-connection;1"); FinishLDAPQuery(); return NS_ERROR_FAILURE; } // have we been properly initialized? // if (!mServerURL) { NS_ERROR("nsLDAPSyncQuery::InitConnection(): mServerURL " "is NULL"); FinishLDAPQuery(); return NS_ERROR_NOT_INITIALIZED; } // get a proxy object so the callback happens on the main thread // rv = NS_GetProxyForObject(NS_PROXY_TO_CURRENT_THREAD, NS_GET_IID(nsILDAPMessageListener), static_cast<nsILDAPMessageListener *>(this), NS_PROXY_ASYNC | NS_PROXY_ALWAYS, getter_AddRefs(selfProxy)); if (NS_FAILED(rv)) { FinishLDAPQuery(); NS_ERROR("nsLDAPSyncQuery::InitConnection(): couldn't " "create proxy to this object for callback"); return NS_ERROR_FAILURE; } rv = mConnection->Init(mServerURL, EmptyCString(), selfProxy, nsnull, mProtocolVersion); if (NS_FAILED(rv)) { FinishLDAPQuery(); return NS_ERROR_UNEXPECTED; // this should never happen } return NS_OK; }
// initialize the channel // nsresult nsLDAPChannel::Init(nsIURI *uri) { nsresult rv; mStatus = NS_OK; mURI = uri; mLoadFlags = LOAD_NORMAL; mReadPipeOffset = 0; mReadPipeClosed = PR_FALSE; // create an LDAP connection // mConnection = do_CreateInstance("@mozilla.org/network/ldap-connection;1", &rv); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPChannel::Init(): could not create " "@mozilla.org/network/ldap-connection;1"); return NS_ERROR_FAILURE; } // i think that in the general case, it will be worthwhile to leave the // callbacks for this channel be invoked on the LDAP connection thread. // however, for the moment, I want to leave the code that invokes it on // the main thread here (though turned off), because it provides a // useful demonstration of why PLEvents' lack of priorities hurts us // (in this case in ldap: searches that return a lot of results). // #if INVOKE_LDAP_CALLBACKS_ON_MAIN_THREAD // get a proxy for this callback, saving it off in mCallback // rv = NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, kILDAPMessageListenerIID, static_cast<nsILDAPMessageListener *>(this), NS_PROXY_ASYNC|NS_PROXY_ALWAYS, getter_AddRefs(mCallback)); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPChannel::Init(): could not create proxy object"); return NS_ERROR_FAILURE; } #else mCallback = this; #endif return NS_OK; }
// void onLDAPInit (in nsresult aStatus); // NS_IMETHODIMP nsLDAPSyncQuery::OnLDAPInit(nsILDAPConnection *aConn, nsresult aStatus) { nsresult rv; // temp for xpcom return values nsCOMPtr<nsILDAPMessageListener> selfProxy; // create and initialize an LDAP operation (to be used for the bind) // mOperation = do_CreateInstance("@mozilla.org/network/ldap-operation;1", &rv); if (NS_FAILED(rv)) { FinishLDAPQuery(); return NS_ERROR_FAILURE; } // get a proxy object so the callback happens on the main thread // rv = NS_GetProxyForObject(NS_PROXY_TO_CURRENT_THREAD, NS_GET_IID(nsILDAPMessageListener), static_cast<nsILDAPMessageListener *>(this), NS_PROXY_ASYNC | NS_PROXY_ALWAYS, getter_AddRefs(selfProxy)); if (NS_FAILED(rv)) { FinishLDAPQuery(); return NS_ERROR_FAILURE; } // our OnLDAPMessage accepts all result callbacks // rv = mOperation->Init(mConnection, selfProxy, nsnull); if (NS_FAILED(rv)) { FinishLDAPQuery(); return NS_ERROR_UNEXPECTED; // this should never happen } // kick off a bind operation // rv = mOperation->SimpleBind(EmptyCString()); if (NS_FAILED(rv)) { FinishLDAPQuery(); return NS_ERROR_FAILURE; } return NS_OK; }
NS_IMETHODIMP nsServerSocket::AsyncListen(nsIServerSocketListener *aListener) { // ensuring mFD implies ensuring mLock NS_ENSURE_TRUE(mFD, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(mListener == nsnull, NS_ERROR_IN_PROGRESS); { nsAutoLock lock(mLock); nsresult rv = NS_GetProxyForObject(NS_PROXY_TO_CURRENT_THREAD, NS_GET_IID(nsIServerSocketListener), aListener, NS_PROXY_ASYNC | NS_PROXY_ALWAYS, getter_AddRefs(mListener)); if (NS_FAILED(rv)) return rv; mListenerTarget = NS_GetCurrentThread(); } return PostEvent(this, &nsServerSocket::OnMsgAttach); }
nsresult nsEudoraCompose::CreateComponents( void) { nsresult rv = NS_OK; if (!m_pIOService) { IMPORT_LOG0( "Creating nsIOService\n"); NS_WITH_PROXIED_SERVICE(nsIIOService, service, NS_IOSERVICE_CONTRACTID, NS_PROXY_TO_MAIN_THREAD, &rv); if (NS_FAILED(rv)) return( rv); m_pIOService = service; NS_IF_ADDREF( m_pIOService); } NS_IF_RELEASE( m_pMsgFields); if (!m_pMsgSend) { rv = CallCreateInstance( kMsgSendCID, &m_pMsgSend); if (NS_SUCCEEDED( rv) && m_pMsgSend) { rv = NS_GetProxyForObject( NS_PROXY_TO_MAIN_THREAD, NS_GET_IID(nsIMsgSend), m_pMsgSend, NS_PROXY_SYNC, (void**)&m_pSendProxy); if (NS_FAILED( rv)) { m_pSendProxy = nsnull; NS_RELEASE( m_pMsgSend); m_pMsgSend = nsnull; } } } if (!m_pListener && NS_SUCCEEDED( rv)) { rv = EudoraSendListener::CreateSendListener( &m_pListener); } if (NS_SUCCEEDED(rv) && m_pMsgSend) { rv = CallCreateInstance( kMsgCompFieldsCID, &m_pMsgFields); if (NS_SUCCEEDED(rv) && m_pMsgFields) { // IMPORT_LOG0( "nsOutlookCompose - CreateComponents succeeded\n"); m_pMsgFields->SetForcePlainText( PR_FALSE); return( NS_OK); } } return NS_ERROR_FAILURE; }
NS_IMETHODIMP nsProtectedAuthThread::Login(nsIObserver *aObserver) { NS_ENSURE_ARG(aObserver); if (!mMutex) return NS_ERROR_FAILURE; if (!mSlot) // We need pointer to the slot return NS_ERROR_FAILURE; nsCOMPtr<nsIObserver> observerProxy; nsresult rv = NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, NS_GET_IID(nsIObserver), aObserver, NS_PROXY_SYNC | NS_PROXY_ALWAYS, getter_AddRefs(observerProxy)); if (NS_FAILED(rv)) return rv; PR_Lock(mMutex); if (mIAmRunning || mLoginReady) { PR_Unlock(mMutex); return NS_OK; } observerProxy.swap(mStatusObserver); mIAmRunning = PR_TRUE; mThreadHandle = PR_CreateThread(PR_USER_THREAD, nsProtectedAuthThreadRunner, static_cast<void*>(this), PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0); // bool thread_started_ok = (threadHandle != nsnull); // we might want to return "thread started ok" to caller in the future NS_ASSERTION(mThreadHandle, "Could not create nsProtectedAuthThreadRunner thread\n"); PR_Unlock(mMutex); return NS_OK; }
NS_IMETHODIMP nsLDAPChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks) { nsresult rv; // save off the callbacks // mCallbacks = aNotificationCallbacks; if (mCallbacks) { // get the (unproxied) event sink interface // nsCOMPtr<nsIProgressEventSink> eventSink; rv = mCallbacks->GetInterface(NS_GET_IID(nsIProgressEventSink), getter_AddRefs(eventSink)); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPChannel::SetNotificationCallbacks(): " "mCallbacks->GetInterface failed"); return NS_ERROR_FAILURE; } #if INVOKE_LDAP_CALLBACKS_ON_MAIN_THREAD mEventSink = eventSink; #else // get a proxy for this callback, saving it off in mEventSink // rv = NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, kIProgressEventSink, eventSink, NS_PROXY_ASYNC | NS_PROXY_ALWAYS, getter_AddRefs(mEventSink)); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPChannel::SetNotificationCallbacks(): " "couldn't get proxy for event sink"); return NS_ERROR_FAILURE; } #endif } return NS_OK; }
NS_IMETHODIMP nsLDAPChannel::AsyncOpen(nsIStreamListener* aListener, nsISupports* aCtxt) { nsresult rv; nsCAutoString host; // slurp out relevant pieces of the URL // rv = mURI->GetAsciiHost(host); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPChannel::AsyncRead(): mURI->GetAsciiHost failed\n"); return NS_ERROR_FAILURE; } // we don't currently allow for a default host // if (host.IsEmpty()) return NS_ERROR_MALFORMED_URI; // QI to nsILDAPURL so that we can call one of the methods on that iface // nsCOMPtr<nsILDAPURL> mLDAPURL = do_QueryInterface(mURI, &rv); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPChannel::AsyncRead(): QI to nsILDAPURL failed\n"); return NS_ERROR_FAILURE; } rv = NS_CheckPortSafety(mURI); if (NS_FAILED(rv)) return rv; // save off the args // mResponseContext = aCtxt; mUnproxiedListener = aListener; // add ourselves to the appropriate loadgroup // if (mLoadGroup) { mLoadGroup->AddRequest(this, mResponseContext); } // since the LDAP SDK does all the socket management, we don't have // an underlying transport channel to create an nsIInputStream to hand // back to the nsIStreamListener. So we do it ourselves: // if (!mReadPipeIn) { // get a new pipe, propagating any error upwards // rv = NS_NewPipe(getter_AddRefs(mReadPipeIn), getter_AddRefs(mReadPipeOut), 0, 0, PR_TRUE, PR_FALSE, 0); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPChannel::AsyncRead(): unable to create new pipe"); return NS_ERROR_FAILURE; } } // get an AsyncStreamListener to proxy for mListener, if we're // compiled to have the LDAP callbacks happen on the LDAP connection= // thread. // #if INVOKE_LDAP_CALLBACKS_ON_MAIN_THREAD mListener = aListener; #else rv = NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, NS_GET_IID(nsIStreamListener), mUnproxiedListener, NS_PROXY_ASYNC | NS_PROXY_ALWAYS, getter_AddRefs(mListener)); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPChannel::AsyncRead(): unable to create new " "AsyncStreamListener"); return NS_ERROR_FAILURE; } #endif // we already know the content type, so we can fire this now // mUnproxiedListener->OnStartRequest(this, mResponseContext); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPChannel::AsyncRead(): error firing OnStartRequest"); return NS_ERROR_FAILURE; } // initialize it with the defaults // XXXdmose - need to deal with bind name // Need to deal with VERSION2 pref - don't know how to get it from here. rv = mConnection->Init(mLDAPURL, EmptyCString(), this, nsnull, nsILDAPConnection::VERSION3); switch (rv) { case NS_OK: break; case NS_ERROR_OUT_OF_MEMORY: case NS_ERROR_NOT_AVAILABLE: case NS_ERROR_FAILURE: return rv; case NS_ERROR_ILLEGAL_VALUE: default: return NS_ERROR_UNEXPECTED; } // create and initialize an LDAP operation (to be used for the bind) // mCurrentOperation = do_CreateInstance( "@mozilla.org/network/ldap-operation;1", &rv); if (NS_FAILED(rv)) { return NS_ERROR_FAILURE; } // our OnLDAPMessage accepts all result callbacks // rv = mCurrentOperation->Init(mConnection, mCallback, nsnull); if (NS_FAILED(rv)) return NS_ERROR_UNEXPECTED; // this should never happen // kick off a bind operation // PR_LOG(gLDAPLogModule, PR_LOG_DEBUG, ("initiating SimpleBind\n")); rv = mCurrentOperation->SimpleBind(EmptyCString()); if (NS_FAILED(rv)) { // XXXdmose better error handling / passthrough; deal with password // NS_WARNING("mCurrentOperation->SimpleBind failed."); return(rv); } return NS_OK; }
char* PR_CALLBACK PK11PasswordPrompt(PK11SlotInfo* slot, PRBool retry, void* arg) { nsNSSShutDownPreventionLock locker; nsresult rv = NS_OK; PRUnichar *password = nsnull; PRBool value = PR_FALSE; nsIInterfaceRequestor *ir = static_cast<nsIInterfaceRequestor*>(arg); nsCOMPtr<nsIPrompt> proxyPrompt; /* TODO: Retry should generate a different dialog message */ /* if (retry) return nsnull; */ if (!ir) { nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); if (!wwatch) return nsnull; nsCOMPtr<nsIPrompt> prompter; wwatch->GetNewPrompter(0, getter_AddRefs(prompter)); if (!prompter) return nsnull; NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, NS_GET_IID(nsIPrompt), prompter, NS_PROXY_SYNC, getter_AddRefs(proxyPrompt)); if (!proxyPrompt) return nsnull; } else { // The interface requestor object may not be safe, so // proxy the call to get the nsIPrompt. nsCOMPtr<nsIInterfaceRequestor> proxiedCallbacks; NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, NS_GET_IID(nsIInterfaceRequestor), ir, NS_PROXY_SYNC, getter_AddRefs(proxiedCallbacks)); // Get the desired interface nsCOMPtr<nsIPrompt> prompt(do_GetInterface(proxiedCallbacks)); if (!prompt) { NS_ASSERTION(PR_FALSE, "callbacks does not implement nsIPrompt"); return nsnull; } // Finally, get a proxy for the nsIPrompt NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, NS_GET_IID(nsIPrompt), prompt, NS_PROXY_SYNC, getter_AddRefs(proxyPrompt)); } if (PK11_ProtectedAuthenticationPath(slot)) return ShowProtectedAuthPrompt(slot, ir); nsAutoString promptString; nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv)); if (NS_FAILED(rv)) return nsnull; const PRUnichar* formatStrings[1] = { ToNewUnicode(NS_ConvertUTF8toUTF16(PK11_GetTokenName(slot))) }; rv = nssComponent->PIPBundleFormatStringFromName("CertPassPrompt", formatStrings, 1, promptString); nsMemory::Free(const_cast<PRUnichar*>(formatStrings[0])); if (NS_FAILED(rv)) return nsnull; { nsPSMUITracker tracker; if (tracker.isUIForbidden()) { rv = NS_ERROR_NOT_AVAILABLE; } else { rv = proxyPrompt->PromptPassword(nsnull, promptString.get(), &password, nsnull, nsnull, &value); } } if (NS_SUCCEEDED(rv) && value) { char* str = ToNewUTF8String(nsDependentString(password)); NS_Free(password); return str; } return nsnull; }
nsresult nsLDAPSyncQuery::StartLDAPSearch() { nsresult rv; nsCOMPtr<nsILDAPMessageListener> selfProxy; // for callback // create and initialize an LDAP operation (to be used for the search // mOperation = do_CreateInstance("@mozilla.org/network/ldap-operation;1", &rv); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPSyncQuery::StartLDAPSearch(): couldn't " "create @mozilla.org/network/ldap-operation;1"); FinishLDAPQuery(); return NS_ERROR_FAILURE; } // get a proxy object so the callback happens on the main thread // rv = NS_GetProxyForObject(NS_PROXY_TO_CURRENT_THREAD, NS_GET_IID(nsILDAPMessageListener), static_cast<nsILDAPMessageListener *>(this), NS_PROXY_ASYNC | NS_PROXY_ALWAYS, getter_AddRefs(selfProxy)); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPSyncQuery::StartLDAPSearch(): couldn't " "create proxy to this object for callback"); FinishLDAPQuery(); return NS_ERROR_FAILURE; } // initialize the LDAP operation object // rv = mOperation->Init(mConnection, selfProxy, nsnull); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPSyncQuery::StartLDAPSearch(): couldn't " "initialize LDAP operation"); FinishLDAPQuery(); return NS_ERROR_UNEXPECTED; } // get the search filter associated with the directory server url; // nsCAutoString urlFilter; rv = mServerURL->GetFilter(urlFilter); if (NS_FAILED(rv)) { FinishLDAPQuery(); return NS_ERROR_UNEXPECTED; } // get the base dn to search // nsCAutoString dn; rv = mServerURL->GetDn(dn); if (NS_FAILED(rv)) { FinishLDAPQuery(); return NS_ERROR_UNEXPECTED; } // and the scope // PRInt32 scope; rv = mServerURL->GetScope(&scope); if (NS_FAILED(rv)) { FinishLDAPQuery(); return NS_ERROR_UNEXPECTED; } rv = mServerURL->GetAttributes(&mAttrCount, &mAttrs); if (NS_FAILED(rv)) { FinishLDAPQuery(); return NS_ERROR_UNEXPECTED; } // time to kick off the search. // rv = mOperation->SearchExt(dn, scope, urlFilter, mAttrCount, const_cast<const char **>(mAttrs), 0, 0); if (NS_FAILED(rv)) { FinishLDAPQuery(); return NS_ERROR_FAILURE; } return NS_OK; }
void nsPKCS12Blob::handleError(int myerr) { nsPSMUITracker tracker; if (tracker.isUIForbidden()) { return; } nsresult rv; int prerr = PORT_GetError(); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("PKCS12: NSS/NSPR error(%d)", prerr)); PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("PKCS12: I called(%d)", myerr)); nsCOMPtr<nsINSSComponent> nssComponent(do_GetService(kNSSComponentCID, &rv)); if (NS_FAILED(rv)) return; nsCOMPtr<nsIPrompt> errPrompt; nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); if (wwatch) { wwatch->GetNewPrompter(0, getter_AddRefs(errPrompt)); if (errPrompt) { nsCOMPtr<nsIPrompt> proxyPrompt; NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD, NS_GET_IID(nsIPrompt), errPrompt, NS_PROXY_SYNC, getter_AddRefs(proxyPrompt)); if (!proxyPrompt) return; } else { return; } } else { return; } nsAutoString errorMsg; switch (myerr) { case PIP_PKCS12_RESTORE_OK: rv = nssComponent->GetPIPNSSBundleString("SuccessfulP12Restore", errorMsg); if (NS_FAILED(rv)) return; errPrompt->Alert(nsnull, errorMsg.get()); return; case PIP_PKCS12_BACKUP_OK: rv = nssComponent->GetPIPNSSBundleString("SuccessfulP12Backup", errorMsg); if (NS_FAILED(rv)) return; errPrompt->Alert(nsnull, errorMsg.get()); return; case PIP_PKCS12_USER_CANCELED: return; /* Just ignore it for now */ case PIP_PKCS12_NOSMARTCARD_EXPORT: rv = nssComponent->GetPIPNSSBundleString("PKCS12InfoNoSmartcardBackup", errorMsg); if (NS_FAILED(rv)) return; errPrompt->Alert(nsnull, errorMsg.get()); return; case PIP_PKCS12_RESTORE_FAILED: rv = nssComponent->GetPIPNSSBundleString("PKCS12UnknownErrRestore", errorMsg); if (NS_FAILED(rv)) return; errPrompt->Alert(nsnull, errorMsg.get()); return; case PIP_PKCS12_BACKUP_FAILED: rv = nssComponent->GetPIPNSSBundleString("PKCS12UnknownErrBackup", errorMsg); if (NS_FAILED(rv)) return; errPrompt->Alert(nsnull, errorMsg.get()); return; case PIP_PKCS12_NSS_ERROR: switch (prerr) { // The following errors have the potential to be "handled", by asking // the user (via a dialog) whether s/he wishes to continue case 0: break; case SEC_ERROR_PKCS12_CERT_COLLISION: /* pop a dialog saying the cert is already in the database */ /* ask to keep going? what happens if one collision but others ok? */ // The following errors cannot be "handled", notify the user (via an alert) // that the operation failed. #if 0 // XXX a boy can dream... // but the PKCS12 lib never throws this error // but then again, how would it? anyway, convey the info below case SEC_ERROR_PKCS12_PRIVACY_PASSWORD_INCORRECT: rv = nssComponent->GetPIPNSSBundleString("PKCS12PasswordInvalid", errorMsg); if (NS_FAILED(rv)) return; errPrompt->Alert(nsnull, errorMsg.get()); break; #endif case SEC_ERROR_BAD_PASSWORD: rv = nssComponent->GetPIPNSSBundleString("PK11BadPassword", errorMsg); if (NS_FAILED(rv)) return; errPrompt->Alert(nsnull, errorMsg.get()); break; case SEC_ERROR_BAD_DER: case SEC_ERROR_PKCS12_CORRUPT_PFX_STRUCTURE: case SEC_ERROR_PKCS12_INVALID_MAC: rv = nssComponent->GetPIPNSSBundleString("PKCS12DecodeErr", errorMsg); if (NS_FAILED(rv)) return; errPrompt->Alert(nsnull, errorMsg.get()); break; case SEC_ERROR_PKCS12_DUPLICATE_DATA: rv = nssComponent->GetPIPNSSBundleString("PKCS12DupData", errorMsg); if (NS_FAILED(rv)) return; errPrompt->Alert(nsnull, errorMsg.get()); break; default: rv = nssComponent->GetPIPNSSBundleString("PKCS12UnknownErr", errorMsg); if (NS_FAILED(rv)) return; errPrompt->Alert(nsnull, errorMsg.get()); } break; case 0: default: rv = nssComponent->GetPIPNSSBundleString("PKCS12UnknownErr", errorMsg); if (NS_FAILED(rv)) return; errPrompt->Alert(nsnull, errorMsg.get()); break; } }