NS_IMETHODIMP mozSqlConnectionMysql::Init(const nsAString &aHost, PRInt32 aPort, const nsAString &aDatabase, const nsAString &aUsername, const nsAString &aPassword) { if (mConnection) return NS_OK; if (aPort == -1) aPort = 0; mConnection = mysql_init((MYSQL *) nsnull); if (!mConnection){ return NS_ERROR_FAILURE; } if (!mysql_real_connect(mConnection, NS_ConvertUCS2toUTF8(aHost).get(), NS_ConvertUCS2toUTF8(aUsername).get(), NS_ConvertUCS2toUTF8(aPassword).get(), NS_ConvertUCS2toUTF8(aDatabase).get(), aPort, nsnull, 0)){ mErrorMessage.Assign(NS_ConvertUTF8toUCS2(mysql_error(mConnection))); mConnection = nsnull; return NS_ERROR_FAILURE; } return NS_OK; }
nsresult mozApocPolicyModelNode::UpdateValue(const nsAString & aNewValue, mozApocNotificationDispatcher const & aNotifier) { MODEL_TRACE(stderr, "apoc data model: Setting value of node '%s' at %p to '%s'\n", PromiseFlatCString(mName).get(), (void*)this, NS_ConvertUCS2toUTF8(aNewValue).get()); NS_ENSURE_TRUE(mozApocHasValue(mAttributes), NS_ERROR_UNEXPECTED); if (!mValue) mValue = new ValueData(aNewValue,aNotifier); else if (mValue->HasValue) mValue->PolicyValue = aNewValue; else { mValue->PolicyValue = aNewValue; mValue->HasValue = PR_TRUE; // remove the original lock-only notification aNotifier.NotifyLockChange(PR_FALSE); } if (!mValue) return NS_ERROR_OUT_OF_MEMORY; aNotifier.NotifyValueChange(mValue->PolicyValue,this->IsProtected()); return NS_OK; }
void nsCSSScanner::OutputError() { if (mError.IsEmpty()) return; #ifdef DEBUG fprintf(stderr, "CSS Error (%s :%u.%u): %s\n", mFileName.get(), mErrorLineNumber, mErrorColNumber, NS_ConvertUCS2toUTF8(mError).get()); #endif // Log it to the Error console if (InitGlobals() && gReportErrors) { nsresult rv; nsCOMPtr<nsIScriptError> errorObject = do_CreateInstance(gScriptErrorFactory, &rv); if (NS_SUCCEEDED(rv)) { rv = errorObject->Init(mError.get(), NS_ConvertASCIItoUCS2(mFileName.get()).get(), EmptyString().get(), mErrorLineNumber, mErrorColNumber, nsIScriptError::warningFlag, "CSS Parser"); if (NS_SUCCEEDED(rv)) gConsoleService->LogMessage(errorObject); } } ClearError(); }
NS_IMETHODIMP nsAbAddressCollecter::CollectUnicodeAddress(const PRUnichar *aAddress, PRBool aCreateCard, PRUint32 aSendFormat) { NS_ENSURE_ARG_POINTER(aAddress); // convert the unicode string to UTF-8... nsresult rv = CollectAddress(NS_ConvertUCS2toUTF8(aAddress).get(), aCreateCard, aSendFormat); NS_ENSURE_SUCCESS(rv,rv); return rv; }
nsresult mozSqlConnectionMysql::RealExec(const nsAString& aQuery, mozISqlResult** aResult, PRInt32* aAffectedRows) { if (!mConnection) return NS_ERROR_NOT_INITIALIZED; if (mysql_query(mConnection, NS_ConvertUCS2toUTF8(aQuery).get())){ mErrorMessage.Assign(NS_ConvertUTF8toUCS2(mysql_error(mConnection))); return NS_ERROR_FAILURE; } if (!aResult){ if (!aAffectedRows) return NS_ERROR_NULL_POINTER; my_ulonglong numrows = (PRInt32)mysql_affected_rows(mConnection); *aAffectedRows = ((numrows == (my_ulonglong)-1) ? 0 : (PRInt32)numrows); return NS_OK; } *aResult = nsnull; MYSQL_RES *rowresults = mysql_store_result(mConnection); if (!rowresults){ mErrorMessage.Assign(NS_ConvertUTF8toUCS2(mysql_error(mConnection))); return NS_ERROR_FAILURE; } mozSqlResult *mozresult = new mozSqlResultMysql(this, aQuery); if (!mozresult){ mysql_free_result(rowresults); return NS_ERROR_OUT_OF_MEMORY; } ((mozSqlResultMysql*)mozresult)->SetResult(rowresults); nsresult rv = mozresult->Init(); if (NS_FAILED(rv)){ delete mozresult; return rv; } *aResult = mozresult; NS_ADDREF(*aResult); return NS_OK; }
NS_IMETHODIMP CBrowserImpl::SetTitle(const PRUnichar* aTitle) { if (! m_pBrowserFrame || gQuitMode) return NS_ERROR_FAILURE; m_pBrowserFrame->SetBrowserFrameTitle(aTitle); char buf[1024]; PRInt32 id = m_pBrowserFrame->GetBrowserId(); sprintf(buf, "%s", NS_ConvertUCS2toUTF8(aTitle).get()); SendSocketMessage(id, CEVENT_TITLE_CHANGE, buf); return NS_OK; }
NS_IMETHODIMP CBrowserImpl::OnStatusChange(nsIWebProgress* aWebProgress, nsIRequest* aRequest, nsresult aStatus, const PRUnichar* aMessage) { if (m_pBrowserFrame) { m_pBrowserFrame->UpdateStatusBarText(aMessage); char buf[1024]; PRInt32 id = m_pBrowserFrame->GetBrowserId(); sprintf(buf, "%s", NS_ConvertUCS2toUTF8(aMessage).get()); SendSocketMessage(id, CEVENT_STATUSTEXT_CHANGE, buf); } return NS_OK; }
NS_IMETHODIMP nsSeamonkeyProfileMigrator::GetSourceHomePageURL(nsACString& aResult) { // Load the source pref file nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID)); psvc->ResetPrefs(); nsCOMPtr<nsIFile> sourcePrefsFile; mSourceProfile->Clone(getter_AddRefs(sourcePrefsFile)); sourcePrefsFile->Append(FILE_NAME_PREFS); psvc->ReadUserPrefs(sourcePrefsFile); nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc)); PRBool hasUserValue; nsCOMPtr<nsIPrefLocalizedString> prefValue; nsresult rv = branch->PrefHasUserValue("browser.startup.homepage", &hasUserValue); if (NS_SUCCEEDED(rv) && hasUserValue) { rv = branch->GetComplexValue("browser.startup.homepage", NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(prefValue)); if (NS_SUCCEEDED(rv) && prefValue) { nsXPIDLString data; prefValue->ToString(getter_Copies(data)); nsCAutoString val; val = ToNewCString(NS_ConvertUCS2toUTF8(data)); aResult.Assign(val); } } psvc->ResetPrefs(); psvc->ReadUserPrefs(nsnull); return NS_OK; }
void nsQuoteList::PrintChain() { printf("Chain: \n"); if (!FirstNode()) { return; } nsQuoteNode* node = FirstNode(); do { printf(" %p %d - ", NS_STATIC_CAST(void*, node), node->mDepthBefore); switch(node->mType) { case (eStyleContentType_OpenQuote): printf("open"); break; case (eStyleContentType_NoOpenQuote): printf("noOpen"); break; case (eStyleContentType_CloseQuote): printf("close"); break; case (eStyleContentType_NoCloseQuote): printf("noClose"); break; default: printf("unknown!!!"); } printf(" %d - %d,", node->Depth(), node->DepthAfter()); if (node->mText) { nsAutoString data; node->mText->GetData(data); printf(" \"%s\",", NS_ConvertUCS2toUTF8(data).get()); } printf("\n"); node = Next(node); } while (node != FirstNode()); }
NS_IMETHODIMP nsSpatialNavigationService::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData) { nsresult rv; if (!strcmp(aTopic,"domwindowopened")) { nsCOMPtr<nsIDOMWindow> chromeWindow = do_QueryInterface(aSubject); nsSpatialNavigation* sn = new nsSpatialNavigation(this); if (!sn) return NS_ERROR_OUT_OF_MEMORY; sn->Init(chromeWindow); mObjects.AppendObject(sn); // the array owns the only reference to sn. return NS_OK; } if (!strcmp(aTopic,"domwindowclosed")) { nsCOMPtr<nsIDOMWindow> chromeWindow = do_QueryInterface(aSubject); // need to find it in our array PRInt32 count = mObjects.Count(); for (PRInt32 i = 0; i < count; i++) { nsISpatialNavigation* sn = mObjects[i]; nsCOMPtr<nsIDOMWindow> attachedWindow; sn->GetAttachedWindow(getter_AddRefs(attachedWindow)); if (attachedWindow == chromeWindow) { sn->Shutdown(); mObjects.RemoveObjectAt(i); return NS_OK; } } return NS_OK; } if (!strcmp(aTopic,"app-startup")) { nsCOMPtr<nsIWindowWatcher> windowWatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); windowWatcher->RegisterNotification(this); nsCOMPtr<nsIPrefBranch2> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); prefBranch->AddObserver("snav.", this, PR_FALSE); return NS_OK; } if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(aSubject); nsXPIDLCString cstr; const char* pref = NS_ConvertUCS2toUTF8(aData).get(); if (!strcmp(pref, "snav.enabled")) { prefBranch->GetBoolPref(pref, &mEnabled); } else if (!strcmp(pref, "snav.ignoreTextFields")) { prefBranch->GetBoolPref(pref, &mIgnoreTextFields); } else if (!strcmp(pref, "snav.directionalBias")) { prefBranch->GetIntPref(pref, &gDirectionalBias); if (gDirectionalBias == 0) gDirectionalBias = 1; } else if (!strcmp(pref, "snav.disableJS")) { prefBranch->GetBoolPref(pref, &mDisableJSWhenFocusing); } else if (!strcmp(pref, "snav.rectFudge")) { prefBranch->GetIntPref(pref, &gRectFudge); } else if (!strcmp(pref, "snav.keyCode.left")) { prefBranch->GetIntPref(pref, &mKeyCodeLeft); } else if (!strcmp(pref, "snav.keyCode.right")) { prefBranch->GetIntPref(pref, &mKeyCodeRight); } else if (!strcmp(pref, "snav.keyCode.up")) { prefBranch->GetIntPref(pref, &mKeyCodeUp); } else if (!strcmp(pref, "snav.keyCode.down")) { prefBranch->GetIntPref(pref, &mKeyCodeDown); } else if (!strcmp(pref, "snav.keyCode.modifier")) { prefBranch->GetIntPref(pref, &mKeyCodeModifier); } return NS_OK; } return NS_OK; }
void nsAbAutoCompleteSession::AddToResult(const PRUnichar* pNickNameStr, const PRUnichar* pDisplayNameStr, const PRUnichar* pFirstNameStr, const PRUnichar* pLastNameStr, const PRUnichar* pEmailStr, const PRUnichar* pNotesStr, const PRUnichar* pDirName, PRUint32 aPopularityIndex, PRBool bIsMailList, PRBool pDefaultMatch, nsIAutoCompleteResults* results) { nsresult rv; PRUnichar* fullAddrStr = nsnull; if (pDefaultMatch) { if (mDefaultDomain[0] == 0) return; nsAutoString aStr(pDisplayNameStr); if (aStr.FindChar('@') == kNotFound) { aStr.Append(PRUnichar('@')); aStr += mDefaultDomain; } fullAddrStr = ToNewUnicode(aStr); } else { if (mParser) { nsXPIDLCString fullAddress; nsXPIDLCString utf8Email; if (bIsMailList) { if (pNotesStr && pNotesStr[0] != 0) utf8Email.Adopt(ToNewUTF8String(nsDependentString(pNotesStr))); else utf8Email.Adopt(ToNewUTF8String(nsDependentString(pDisplayNameStr))); } else utf8Email.Adopt(ToNewUTF8String(nsDependentString(pEmailStr))); mParser->MakeFullAddress(nsnull, NS_ConvertUCS2toUTF8(pDisplayNameStr).get(), utf8Email, getter_Copies(fullAddress)); if (!fullAddress.IsEmpty()) { /* We need to convert back the result from UTF-8 to Unicode */ fullAddrStr = nsCRT::strdup(NS_ConvertUTF8toUCS2(fullAddress.get()).get()); } } if (!fullAddrStr) { //oops, parser problem! I will try to do my best... const PRUnichar * pStr = nsnull; if (bIsMailList) { if (pNotesStr && pNotesStr[0] != 0) pStr = pNotesStr; else pStr = pDisplayNameStr; } else pStr = pEmailStr; // check this so we do not get a bogus entry "someName <>" if (pStr && pStr[0] != 0) { nsAutoString aStr(pDisplayNameStr); aStr.AppendLiteral(" <"); aStr += pStr; aStr.AppendLiteral(">"); fullAddrStr = ToNewUnicode(aStr); } else fullAddrStr = nsnull; } } if (fullAddrStr && ! ItsADuplicate(fullAddrStr, aPopularityIndex, results)) { nsCOMPtr<nsIAutoCompleteItem> newItem = do_CreateInstance(NS_AUTOCOMPLETEITEM_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { nsAbAutoCompleteParam *param = new nsAbAutoCompleteParam(pNickNameStr, pDisplayNameStr, pFirstNameStr, pLastNameStr, pEmailStr, pNotesStr, pDirName, aPopularityIndex, bIsMailList); NS_IF_ADDREF(param); newItem->SetParam(param); NS_IF_RELEASE(param); // how to process the comment column, if at all. this value // comes from "mail.autoComplete.commentColumn", or, if that // doesn't exist, defaults to 0 // // 0 = none // 1 = name of addressbook this card came from // 2 = other per-addressbook format (currrently unused here) // if (mAutoCompleteCommentColumn == 1) { rv = newItem->SetComment(pDirName); if (NS_FAILED(rv)) { NS_WARNING("nsAbAutoCompleteSession::AddToResult():" " newItem->SetComment() failed\n"); } } // if this isn't a default match, set the class name so we can style // this cell with the local addressbook icon (or whatever) // rv = newItem->SetClassName(pDefaultMatch ? "default-match" : "local-abook"); if (NS_FAILED(rv)) { NS_WARNING("nsAbAutoCompleteSession::AddToResult():" " newItem->SetClassName() failed\n"); } newItem->SetValue(nsDependentString(fullAddrStr)); nsCOMPtr<nsISupportsArray> array; rv = results->GetItems(getter_AddRefs(array)); if (NS_SUCCEEDED(rv)) { PRUint32 nbrOfItems; rv = array->Count(&nbrOfItems); PRInt32 insertPosition = 0; for (; insertPosition < nbrOfItems && !pDefaultMatch; insertPosition++) { nsCOMPtr<nsISupports> currentItemParams; nsCOMPtr<nsIAutoCompleteItem> resultItem; nsresult rv = array->QueryElementAt(insertPosition, NS_GET_IID(nsIAutoCompleteItem), getter_AddRefs(resultItem)); if (NS_FAILED(rv)) continue; rv = resultItem->GetParam(getter_AddRefs(currentItemParams)); if (NS_FAILED(rv)) continue; param = (nsAbAutoCompleteParam *)(void *)currentItemParams; if (aPopularityIndex > param->mPopularityIndex) // sort the search results by popularity index break; } rv = array->InsertElementAt(newItem, insertPosition); } } } PR_Free(fullAddrStr); }
found = (val > matchVal); else if (matchMethod.EqualsLiteral("isless")) found = (val < matchVal); return found; } NS_METHOD LocalSearchDataSource::parseDate(const nsAString& aDate, PRInt64 *aResult) { // date is in the form of msec since epoch, but use NSPR to // parse the time PRTime *outTime = NS_STATIC_CAST(PRTime*,aResult); PRStatus err; err = PR_ParseTimeString(NS_ConvertUCS2toUTF8(aDate).get(), PR_FALSE, // PR_FALSE == use current timezone outTime); NS_ENSURE_TRUE(err == 0, NS_ERROR_FAILURE); return NS_OK; } PRBool LocalSearchDataSource::dateMatches(nsIRDFDate *aDate, const nsAString& method, const PRInt64& matchDate) { PRInt64 date; aDate->GetValue(&date);
/** ------------------------------------------------------- * Initialize the nsDeviceContextSpecBeOS * @update dc 2/15/98 * @update syd 3/2/99 */ NS_IMETHODIMP nsDeviceContextSpecBeOS::Init(nsIPrintSettings* aPS) { nsresult rv = NS_ERROR_FAILURE; NS_ASSERTION(nsnull != aPS, "No print settings."); mPrintSettings = aPS; // if there is a current selection then enable the "Selection" radio button if (aPS != nsnull) { PRBool isOn; aPS->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); nsCOMPtr<nsIPref> pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); if (NS_SUCCEEDED(rv)) { (void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn); } } char *path; PRBool reversed = PR_FALSE; PRBool color = PR_FALSE; PRBool tofile = PR_FALSE; PRInt16 printRange = nsIPrintSettings::kRangeAllPages; PRInt32 paper_size = NS_LETTER_SIZE; PRInt32 orientation = NS_PORTRAIT; PRInt32 fromPage = 1; PRInt32 toPage = 1; PRUnichar *command = nsnull; PRInt32 copies = 1; PRUnichar *printer = nsnull; PRUnichar *printfile = nsnull; double dleft = 0.5; double dright = 0.5; double dtop = 0.5; double dbottom = 0.5; rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); if (NS_FAILED(rv)) { return rv; } GlobalPrinters::GetInstance()->FreeGlobalPrinters(); if (aPS != nsnull) { aPS->GetPrinterName(&printer); aPS->GetPrintReversed(&reversed); aPS->GetPrintInColor(&color); aPS->GetPaperSize(&paper_size); aPS->GetOrientation(&orientation); aPS->GetPrintCommand(&command); aPS->GetPrintRange(&printRange); aPS->GetToFileName(&printfile); aPS->GetPrintToFile(&tofile); aPS->GetStartPageRange(&fromPage); aPS->GetEndPageRange(&toPage); aPS->GetNumCopies(&copies); aPS->GetMarginTop(&dtop); aPS->GetMarginLeft(&dleft); aPS->GetMarginBottom(&dbottom); aPS->GetMarginRight(&dright); if (command != nsnull && printfile != nsnull) { // ToDo: Use LocalEncoding instead of UTF-8 (see bug 73446) strcpy(mPrData.command, NS_ConvertUCS2toUTF8(command).get()); strcpy(mPrData.path, NS_ConvertUCS2toUTF8(printfile).get()); } if (printer != nsnull) strcpy(mPrData.printer, NS_ConvertUCS2toUTF8(printer).get()); #ifdef DEBUG_rods printf("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright); printf("printRange %d\n", printRange); printf("fromPage %d\n", fromPage); printf("toPage %d\n", toPage); #endif /* DEBUG_rods */ } else { #ifdef VMS // Note to whoever puts the "lpr" into the prefs file. Please contact me // as I need to make the default be "print" instead of "lpr" for OpenVMS. strcpy(mPrData.command, "print"); #else strcpy(mPrData.command, "lpr ${MOZ_PRINTER_NAME:+'-P'}${MOZ_PRINTER_NAME}"); #endif /* VMS */ } mPrData.top = dtop; mPrData.bottom = dbottom; mPrData.left = dleft; mPrData.right = dright; mPrData.fpf = !reversed; mPrData.grayscale = !color; mPrData.size = paper_size; mPrData.orientation = orientation; mPrData.toPrinter = !tofile; mPrData.copies = copies; // PWD, HOME, or fail if (!printfile) { if ( ( path = PR_GetEnv( "PWD" ) ) == (char *) nsnull ) if ( ( path = PR_GetEnv( "HOME" ) ) == (char *) nsnull ) strcpy(mPrData.path, "mozilla.ps"); if ( path != (char *) nsnull ) sprintf(mPrData.path, "%s/mozilla.ps", path); else return NS_ERROR_FAILURE; } #ifdef NOT_IMPLEMENTED_YET if (mGlobalNumPrinters) { for(int i = 0; (i < mGlobalNumPrinters) && !mQueue; i++) { if (!(mGlobalPrinterList->StringAt(i)->EqualsIgnoreCase(mPrData.printer))) mQueue = PrnDlg.SetPrinterQueue(i); } } #endif /* NOT_IMPLEMENTED_YET */ if (command != nsnull) { nsMemory::Free(command); } if (printfile != nsnull) { nsMemory::Free(printfile); } return rv; }
nsresult nsHTMLContentSerializer::EscapeURI(const nsAString& aURI, nsAString& aEscapedURI) { // URL escape %xx cannot be used in JS. // No escaping if the scheme is 'javascript'. if (IsJavaScript(nsHTMLAtoms::href, aURI)) { aEscapedURI = aURI; return NS_OK; } // nsITextToSubURI does charset convert plus uri escape // This is needed to convert to a document charset which is needed to support existing browsers. // But we eventually want to use UTF-8 instead of a document charset, then the code would be much simpler. // See HTML 4.01 spec, "Appendix B.2.1 Non-ASCII characters in URI attribute values" nsCOMPtr<nsITextToSubURI> textToSubURI; nsAutoString uri(aURI); // in order to use FindCharInSet() nsresult rv = NS_OK; if (!mCharSet.IsEmpty() && !IsASCII(uri)) { textToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); } PRInt32 start = 0; PRInt32 end; nsAutoString part; nsXPIDLCString escapedURI; aEscapedURI.Truncate(0); // Loop and escape parts by avoiding escaping reserved characters (and '%', '#' ). while ((end = uri.FindCharInSet("%#;/?:@&=+$,", start)) != -1) { part = Substring(aURI, start, (end-start)); if (textToSubURI && !IsASCII(part)) { rv = textToSubURI->ConvertAndEscape(mCharSet.get(), part.get(), getter_Copies(escapedURI)); NS_ENSURE_SUCCESS(rv, rv); } else { escapedURI.Adopt(nsEscape(NS_ConvertUCS2toUTF8(part).get(), url_Path)); } AppendASCIItoUTF16(escapedURI, aEscapedURI); // Append a reserved character without escaping. part = Substring(aURI, end, 1); aEscapedURI.Append(part); start = end + 1; } if (start < (PRInt32) aURI.Length()) { // Escape the remaining part. part = Substring(aURI, start, aURI.Length()-start); if (textToSubURI) { rv = textToSubURI->ConvertAndEscape(mCharSet.get(), part.get(), getter_Copies(escapedURI)); NS_ENSURE_SUCCESS(rv, rv); } else { escapedURI.Adopt(nsEscape(NS_ConvertUCS2toUTF8(part).get(), url_Path)); } AppendASCIItoUTF16(escapedURI, aEscapedURI); } 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; }