nsresult nsAbAddressCollecter::SetNamesForCard(nsIAbCard *senderCard, const char *fullName, PRBool *aModifiedCard) { char *firstName = nsnull; char *lastName = nsnull; *aModifiedCard = PR_FALSE; nsXPIDLString displayName; nsresult rv = senderCard->GetDisplayName(getter_Copies(displayName)); NS_ENSURE_SUCCESS(rv,rv); // we already have a display name, so don't do anything if (!displayName.IsEmpty()) return NS_OK; senderCard->SetDisplayName(NS_ConvertUTF8toUCS2(fullName).get()); *aModifiedCard = PR_TRUE; rv = SplitFullName(fullName, &firstName, &lastName); if (NS_SUCCEEDED(rv)) { senderCard->SetFirstName(NS_ConvertUTF8toUCS2(firstName).get()); if (lastName) senderCard->SetLastName(NS_ConvertUTF8toUCS2(lastName).get()); } PR_FREEIF(firstName); PR_FREEIF(lastName); 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 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; }
NS_IMETHODIMP nsMsgSearchValueImpl::GetStr(PRUnichar** aResult) { NS_ENSURE_ARG_POINTER(aResult); NS_ENSURE_TRUE(IS_STRING_ATTRIBUTE(mValue.attribute), NS_ERROR_ILLEGAL_VALUE); *aResult = ToNewUnicode(NS_ConvertUTF8toUCS2(mValue.string)); return NS_OK; }
void nsPK11Token::refreshTokenInfo() { mTokenName = NS_ConvertUTF8toUTF16(PK11_GetTokenName(mSlot)); SECStatus srv; CK_TOKEN_INFO tok_info; srv = PK11_GetTokenInfo(mSlot, &tok_info); if (srv == SECSuccess) { // Set the Label field const char *ccLabel = (const char*)tok_info.label; const nsACString &cLabel = Substring( ccLabel, ccLabel+PL_strnlen(ccLabel, sizeof(tok_info.label))); mTokenLabel = NS_ConvertUTF8toUCS2(cLabel); mTokenLabel.Trim(" ", PR_FALSE, PR_TRUE); // Set the Manufacturer field const char *ccManID = (const char*)tok_info.manufacturerID; const nsACString &cManID = Substring( ccManID, ccManID+PL_strnlen(ccManID, sizeof(tok_info.manufacturerID))); mTokenManID = NS_ConvertUTF8toUCS2(cManID); mTokenManID.Trim(" ", PR_FALSE, PR_TRUE); // Set the Hardware Version field mTokenHWVersion.AppendInt(tok_info.hardwareVersion.major); mTokenHWVersion.AppendLiteral("."); mTokenHWVersion.AppendInt(tok_info.hardwareVersion.minor); // Set the Firmware Version field mTokenFWVersion.AppendInt(tok_info.firmwareVersion.major); mTokenFWVersion.AppendLiteral("."); mTokenFWVersion.AppendInt(tok_info.firmwareVersion.minor); // Set the Serial Number field const char *ccSerial = (const char*)tok_info.serialNumber; const nsACString &cSerial = Substring( ccSerial, ccSerial+PL_strnlen(ccSerial, sizeof(tok_info.serialNumber))); mTokenSerialNum = NS_ConvertUTF8toUCS2(cSerial); mTokenSerialNum.Trim(" ", PR_FALSE, PR_TRUE); } }
NS_IMETHODIMP nsCookiePromptService::CookieDialog(nsIDOMWindow *aParent, nsICookie *aCookie, const nsACString &aHostname, PRInt32 aCookiesFromHost, PRBool aChangingCookie, PRBool *aRememberDecision, PRInt32 *aAccept) { nsresult rv; nsCOMPtr<nsIDialogParamBlock> block = do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID,&rv); if (NS_FAILED(rv)) return rv; // since we're setting PRInt32's here, we have to sanitize the PRBool's first. // (myBool != PR_FALSE) is guaranteed to return either 1 or 0. block->SetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, 1); block->SetString(nsICookieAcceptDialog::HOSTNAME, NS_ConvertUTF8toUCS2(aHostname).get()); block->SetInt(nsICookieAcceptDialog::COOKIESFROMHOST, aCookiesFromHost); block->SetInt(nsICookieAcceptDialog::CHANGINGCOOKIE, aChangingCookie != PR_FALSE); nsCOMPtr<nsIMutableArray> objects; rv = NS_NewArray(getter_AddRefs(objects)); if (NS_FAILED(rv)) return rv; rv = objects->AppendElement(aCookie, PR_FALSE); if (NS_FAILED(rv)) return rv; block->SetObjects(objects); nsCOMPtr<nsIWindowWatcher> wwatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIDOMWindow> parent = aParent; if (!parent) { wwatcher->GetActiveWindow(getter_AddRefs(parent)); } nsCOMPtr<nsISupports> arguments = do_QueryInterface(block); nsCOMPtr<nsIDOMWindow> dialog; rv = wwatcher->OpenWindow(parent, "chrome://cookie/content/cookieAcceptDialog.xul", "_blank", "centerscreen,chrome,modal,titlebar", arguments, getter_AddRefs(dialog)); if (NS_FAILED(rv)) return rv; // get back output parameters PRBool tempValue; block->GetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, &tempValue); *aAccept = tempValue; // GetInt returns a PRInt32; we need to sanitize it into PRBool block->GetInt(nsICookieAcceptDialog::REMEMBER_DECISION, &tempValue); *aRememberDecision = (tempValue == 1); return rv; }
nsresult Register(nsIComponentRegistrar* registrar, const char *path) { nsCOMPtr<nsILocalFile> file; nsresult rv = NS_NewLocalFile( NS_ConvertUTF8toUCS2(path), PR_TRUE, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; rv = registrar->AutoRegister(file); return rv; }
NS_IMETHODIMP mozSqlConnectionMysql::GetServerVersion(nsAString &aServerVersion) { if (!mConnection) return NS_ERROR_NOT_INITIALIZED; if (mServerVersion.IsEmpty()){ mServerVersion.Assign(NS_ConvertUTF8toUCS2(mysql_get_server_info(mConnection))); } aServerVersion.Assign(mServerVersion); return NS_OK; }
nsresult mozSqlConnectionMysql::CancelExec() { unsigned long id = mysql_thread_id(mConnection); mysql_kill(mConnection, id); if (mysql_errno(mConnection)) { mErrorMessage.Assign(NS_ConvertUTF8toUCS2(mysql_error(mConnection))); return NS_ERROR_FAILURE; } mysql_ping(mConnection); return NS_OK; }
nsresult nsGopherChannel::PushStreamConverters(nsIStreamListener *listener, nsIStreamListener **result) { nsresult rv; nsCOMPtr<nsIStreamListener> converterListener; nsCOMPtr<nsIStreamConverterService> StreamConvService = do_GetService(kStreamConverterServiceCID, &rv); if (NS_FAILED(rv)) return rv; // What we now do depends on what type of file we have if (mType=='1' || mType=='7') { // Send the directory format back for a directory rv = StreamConvService->AsyncConvertData("text/gopher-dir", APPLICATION_HTTP_INDEX_FORMAT, listener, mUrl, getter_AddRefs(converterListener)); if (NS_FAILED(rv)) return rv; } else if (mType=='0') { // Convert general file rv = StreamConvService->AsyncConvertData("text/plain", "text/html", listener, mListenerContext, getter_AddRefs(converterListener)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsITXTToHTMLConv> converter(do_QueryInterface(converterListener)); if (converter) { nsCAutoString spec; rv = mUrl->GetSpec(spec); converter->SetTitle(NS_ConvertUTF8toUCS2(spec).get()); converter->PreFormatHTML(PR_TRUE); } } NS_IF_ADDREF(*result = converterListener); return NS_OK; }
nsresult nsOSHelperAppService::SetMIMEInfoForType(const char *aMIMEType, nsMIMEInfoBeOS**_retval) { LOG(("-- nsOSHelperAppService::SetMIMEInfoForType: %s\n",aMIMEType)); nsresult rv = NS_ERROR_FAILURE; nsMIMEInfoBeOS* mimeInfo = new nsMIMEInfoBeOS(aMIMEType); if (mimeInfo) { NS_ADDREF(mimeInfo); BMimeType mimeType(aMIMEType); BMessage data; int32 index = 0; BString strData; LOG((" Adding extensions:\n")); if (mimeType.GetFileExtensions(&data) == B_OK) { while (data.FindString("extensions",index,&strData) == B_OK) { // if the file extension includes the '.' then we don't want to include that when we append // it to the mime info object. if (strData.ByteAt(0) == '.') strData.RemoveFirst("."); mimeInfo->AppendExtension(nsDependentCString(strData.String())); LOG((" %s\n",strData.String())); index++; } } char desc[B_MIME_TYPE_LENGTH + 1]; if (mimeType.GetShortDescription(desc) == B_OK) { mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(desc)); } else { if (mimeType.GetLongDescription(desc) == B_OK) { mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(desc)); } else { mimeInfo->SetDescription(NS_ConvertUTF8toUCS2(aMIMEType)); } } LOG((" Description: %s\n",desc)); //set preferred app and app description char appSig[B_MIME_TYPE_LENGTH + 1]; bool doSave = true; if (mimeType.GetPreferredApp(appSig) == B_OK) { LOG((" Got preferred ap\n")); BMimeType app(appSig); entry_ref ref; BEntry entry; BPath path; if ((app.GetAppHint(&ref) == B_OK) && (entry.SetTo(&ref, false) == B_OK) && (entry.GetPath(&path) == B_OK)) { LOG((" Got our path!\n")); nsCOMPtr<nsIFile> handlerFile; rv = GetFileTokenForPath(NS_ConvertUTF8toUCS2(path.Path()).get(), getter_AddRefs(handlerFile)); if (NS_SUCCEEDED(rv)) { mimeInfo->SetDefaultApplication(handlerFile); mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault); mimeInfo->SetDefaultDescription(NS_ConvertUTF8toUCS2(path.Leaf())); LOG((" Preferred App: %s\n",path.Leaf())); doSave = false; } } } if (doSave) { mimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk); LOG((" No Preferred App\n")); } *_retval = mimeInfo; rv = NS_OK; } else rv = NS_ERROR_FAILURE; return rv; }
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); }
NS_IMETHODIMP nsCertPicker::PickByUsage(nsIInterfaceRequestor *ctx, const PRUnichar *selectedNickname, PRInt32 certUsage, PRBool allowInvalid, PRBool allowDuplicateNicknames, PRBool *canceled, nsIX509Cert **_retval) { nsNSSShutDownPreventionLock locker; PRInt32 selectedIndex = -1; PRBool selectionFound = PR_FALSE; PRUnichar **certNicknameList = nsnull; PRUnichar **certDetailsList = nsnull; CERTCertListNode* node = nsnull; nsresult rv = NS_OK; { // Iterate over all certs. This assures that user is logged in to all hardware tokens. CERTCertList *allcerts = nsnull; nsCOMPtr<nsIInterfaceRequestor> ctx = new PipUIContext(); allcerts = PK11_ListCerts(PK11CertListUnique, ctx); CERT_DestroyCertList(allcerts); } /* find all user certs that are valid and for SSL */ /* note that we are allowing expired certs in this list */ CERTCertList *certList = CERT_FindUserCertsByUsage(CERT_GetDefaultCertDB(), (SECCertUsage)certUsage, !allowDuplicateNicknames, !allowInvalid, ctx); CERTCertListCleaner clc(certList); if (!certList) { return NS_ERROR_NOT_AVAILABLE; } CERTCertNicknames *nicknames = getNSSCertNicknamesFromCertList(certList); CERTCertNicknamesCleaner cnc(nicknames); if (!nicknames) { return NS_ERROR_NOT_AVAILABLE; } certNicknameList = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *) * nicknames->numnicknames); certDetailsList = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *) * nicknames->numnicknames); if (!certNicknameList || !certDetailsList) { nsMemory::Free(certNicknameList); nsMemory::Free(certDetailsList); return NS_ERROR_OUT_OF_MEMORY; } PRInt32 CertsToUse; for (CertsToUse = 0, node = CERT_LIST_HEAD(certList); !CERT_LIST_END(node, certList) && CertsToUse < nicknames->numnicknames; node = CERT_LIST_NEXT(node) ) { nsNSSCertificate *tempCert = new nsNSSCertificate(node->cert); if (tempCert) { // XXX we really should be using an nsCOMPtr instead of manually add-refing, // but nsNSSCertificate does not have a default constructor. NS_ADDREF(tempCert); nsAutoString i_nickname(NS_ConvertUTF8toUCS2(nicknames->nicknames[CertsToUse])); nsAutoString nickWithSerial; nsAutoString details; if (!selectionFound) { if (i_nickname == nsDependentString(selectedNickname)) { selectedIndex = CertsToUse; selectionFound = PR_TRUE; } } if (NS_SUCCEEDED(tempCert->FormatUIStrings(i_nickname, nickWithSerial, details))) { certNicknameList[CertsToUse] = ToNewUnicode(nickWithSerial); certDetailsList[CertsToUse] = ToNewUnicode(details); } else { certNicknameList[CertsToUse] = nsnull; certDetailsList[CertsToUse] = nsnull; } NS_RELEASE(tempCert); ++CertsToUse; } } if (CertsToUse) { nsICertPickDialogs *dialogs = nsnull; rv = getNSSDialogs((void**)&dialogs, NS_GET_IID(nsICertPickDialogs), NS_CERTPICKDIALOGS_CONTRACTID); if (NS_SUCCEEDED(rv)) { nsPSMUITracker tracker; if (tracker.isUIForbidden()) { rv = NS_ERROR_NOT_AVAILABLE; } else { /* Throw up the cert picker dialog and get back the index of the selected cert */ rv = dialogs->PickCertificate(ctx, (const PRUnichar**)certNicknameList, (const PRUnichar**)certDetailsList, CertsToUse, &selectedIndex, canceled); } NS_RELEASE(dialogs); } } PRInt32 i; for (i = 0; i < CertsToUse; ++i) { nsMemory::Free(certNicknameList[i]); nsMemory::Free(certDetailsList[i]); } nsMemory::Free(certNicknameList); nsMemory::Free(certDetailsList); if (!CertsToUse) { return NS_ERROR_NOT_AVAILABLE; } if (NS_SUCCEEDED(rv) && !*canceled) { for (i = 0, node = CERT_LIST_HEAD(certList); !CERT_LIST_END(node, certList); ++i, node = CERT_LIST_NEXT(node)) { if (i == selectedIndex) { nsNSSCertificate *cert = new nsNSSCertificate(node->cert); if (!cert) { rv = NS_ERROR_OUT_OF_MEMORY; break; } nsIX509Cert *x509 = 0; nsresult rv = cert->QueryInterface(NS_GET_IID(nsIX509Cert), (void**)&x509); if (NS_FAILED(rv)) { break; } NS_ADDREF(x509); *_retval = x509; NS_RELEASE(cert); break; } } } 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; }
nsresult nsMovemailService::GetNewMail(nsIMsgWindow *aMsgWindow, nsIUrlListener *aUrlListener, nsIMsgFolder *aMsgFolder, nsIMovemailIncomingServer *movemailServer, nsIURI ** aURL) { LOG(("nsMovemailService::GetNewMail")); nsresult rv = NS_OK; nsCOMPtr<nsIMsgIncomingServer> in_server = do_QueryInterface(movemailServer); if (!in_server) return NS_MSG_INVALID_OR_MISSING_SERVER; mMsgWindow = aMsgWindow; // Attempt to locate the mail spool file nsCAutoString spoolPath; rv = LocateSpoolFile(spoolPath); if (NS_FAILED(rv) || spoolPath.IsEmpty()) { Error(MOVEMAIL_SPOOL_FILE_NOT_FOUND, nsnull, 0); return NS_ERROR_FAILURE; } // Create an input stream for the spool file nsCOMPtr<nsILocalFile> spoolFile; rv = NS_NewNativeLocalFile(spoolPath, PR_TRUE, getter_AddRefs(spoolFile)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIInputStream> spoolInputStream; rv = NS_NewLocalFileInputStream(getter_AddRefs(spoolInputStream), spoolFile); if (NS_FAILED(rv)) { const PRUnichar *params[] = { NS_ConvertUTF8toUCS2(spoolPath).get() }; Error(MOVEMAIL_CANT_OPEN_SPOOL_FILE, params, 1); return rv; } // Get a line input interface for the spool file nsCOMPtr<nsILineInputStream> lineInputStream = do_QueryInterface(spoolInputStream, &rv); if (!lineInputStream) return rv; nsCOMPtr<nsIFileSpec> mailDirectory; rv = in_server->GetLocalPath(getter_AddRefs(mailDirectory)); NS_ENSURE_SUCCESS(rv, rv); nsFileSpec fileSpec; mailDirectory->GetFileSpec(&fileSpec); fileSpec += "Inbox"; nsIOFileStream outFileStream(fileSpec); outFileStream.seek(fileSpec.GetFileSize()); nsCOMPtr<nsIMsgFolder> serverFolder; nsCOMPtr<nsIMsgFolder> inbox; nsCOMPtr<nsIMsgFolder> rootMsgFolder; // create a new mail parser nsRefPtr<nsParseNewMailState> newMailParser = new nsParseNewMailState; if (newMailParser == nsnull) return NS_ERROR_OUT_OF_MEMORY; rv = in_server->GetRootFolder(getter_AddRefs(serverFolder)); NS_ENSURE_SUCCESS(rv, rv); rootMsgFolder = do_QueryInterface(serverFolder, &rv); if (!rootMsgFolder) return rv; PRUint32 numFolders; rv = rootMsgFolder->GetFoldersWithFlag(MSG_FOLDER_FLAG_INBOX, 1, &numFolders, getter_AddRefs(inbox)); NS_ENSURE_SUCCESS(rv, rv); rv = newMailParser->Init(serverFolder, inbox, fileSpec, &outFileStream, nsnull, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); in_server->SetServerBusy(PR_TRUE); // Try and obtain the lock for the spool file if (!ObtainSpoolLock(spoolPath.get(), 5)) { nsAutoString lockFile = NS_ConvertUTF8toUCS2(spoolPath); lockFile.AppendLiteral(".lock"); const PRUnichar *params[] = { lockFile.get() }; Error(MOVEMAIL_CANT_CREATE_LOCK, params, 1); return NS_ERROR_FAILURE; } // MIDDLE of the FUN : consume the mailbox data. PRBool isMore = PR_TRUE; nsCAutoString buffer; while (isMore && NS_SUCCEEDED(lineInputStream->ReadLine(buffer, &isMore))) { // If first string is empty and we're now at EOF then abort parsing. if (buffer.IsEmpty() && !isMore) { LOG(("Empty spool file")); break; } buffer += MSG_LINEBREAK; newMailParser->HandleLine(buffer.BeginWriting(), buffer.Length()); outFileStream << buffer.get(); // 'From' lines delimit messages if (isMore && !strncmp(buffer.get(), "From ", 5)) { buffer.AssignLiteral("X-Mozilla-Status: 8000" MSG_LINEBREAK); newMailParser->HandleLine(buffer.BeginWriting(), buffer.Length()); outFileStream << buffer.get(); buffer.AssignLiteral("X-Mozilla-Status2: 00000000" MSG_LINEBREAK); newMailParser->HandleLine(buffer.BeginWriting(), buffer.Length()); outFileStream << buffer.get(); } } outFileStream.flush(); newMailParser->OnStopRequest(nsnull, nsnull, NS_OK); newMailParser->SetDBFolderStream(nsnull); // stream is going away if (outFileStream.is_open()) outFileStream.close(); // Truncate the spool file rv = spoolFile->SetFileSize(0); if (NS_FAILED(rv)) { const PRUnichar *params[] = { NS_ConvertUTF8toUCS2(spoolPath).get() }; Error(MOVEMAIL_CANT_TRUNCATE_SPOOL_FILE, params, 1); } if (!YieldSpoolLock(spoolPath.get())) { nsAutoString spoolLock = NS_ConvertUTF8toUCS2(spoolPath); spoolLock.AppendLiteral(".lock"); const PRUnichar *params[] = { spoolLock.get() }; Error(MOVEMAIL_CANT_DELETE_LOCK, params, 1); } in_server->SetServerBusy(PR_FALSE); LOG(("GetNewMail returning rv=%d", rv)); return rv; }
NS_IMETHODIMP nsPrefBranch::GetComplexValue(const char *aPrefName, const nsIID & aType, void * *_retval) { nsresult rv; nsXPIDLCString utf8String; // we have to do this one first because it's different than all the rest if (aType.Equals(NS_GET_IID(nsIPrefLocalizedString))) { nsCOMPtr<nsIPrefLocalizedString> theString(do_CreateInstance(NS_PREFLOCALIZEDSTRING_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { const char *pref; PRBool bNeedDefault = PR_FALSE; rv = getValidatedPrefName(aPrefName, &pref); if (NS_FAILED(rv)) return rv; if (mIsDefault) { bNeedDefault = PR_TRUE; } else { // if there is no user (or locked) value if (!PREF_HasUserPref(pref) && !PREF_PrefIsLocked(pref)) { bNeedDefault = PR_TRUE; } } // if we need to fetch the default value, do that instead, otherwise use the // value we pulled in at the top of this function if (bNeedDefault) { nsXPIDLString utf16String; rv = GetDefaultFromPropertiesFile(pref, getter_Copies(utf16String)); if (NS_SUCCEEDED(rv)) { rv = theString->SetData(utf16String.get()); } } else { rv = GetCharPref(aPrefName, getter_Copies(utf8String)); if (NS_SUCCEEDED(rv)) { rv = theString->SetData(NS_ConvertUTF8toUCS2(utf8String).get()); } } if (NS_SUCCEEDED(rv)) { nsIPrefLocalizedString *temp = theString; NS_ADDREF(temp); *_retval = (void *)temp; } } return rv; } // if we can't get the pref, there's no point in being here rv = GetCharPref(aPrefName, getter_Copies(utf8String)); if (NS_FAILED(rv)) { return rv; } if (aType.Equals(NS_GET_IID(nsILocalFile))) { nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv)); if (NS_SUCCEEDED(rv)) { rv = file->SetPersistentDescriptor(utf8String); if (NS_SUCCEEDED(rv)) { nsILocalFile *temp = file; NS_ADDREF(temp); *_retval = (void *)temp; return NS_OK; } } return rv; } if (aType.Equals(NS_GET_IID(nsIRelativeFilePref))) { nsACString::const_iterator keyBegin, strEnd; utf8String.BeginReading(keyBegin); utf8String.EndReading(strEnd); // The pref has the format: [fromKey]a/b/c if (*keyBegin++ != '[') return NS_ERROR_FAILURE; nsACString::const_iterator keyEnd(keyBegin); if (!FindCharInReadable(']', keyEnd, strEnd)) return NS_ERROR_FAILURE; nsCAutoString key(Substring(keyBegin, keyEnd)); nsCOMPtr<nsILocalFile> fromFile; nsCOMPtr<nsIProperties> directoryService(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; rv = directoryService->Get(key.get(), NS_GET_IID(nsILocalFile), getter_AddRefs(fromFile)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsILocalFile> theFile; rv = NS_NewNativeLocalFile(EmptyCString(), PR_TRUE, getter_AddRefs(theFile)); if (NS_FAILED(rv)) return rv; rv = theFile->SetRelativeDescriptor(fromFile, Substring(++keyEnd, strEnd)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIRelativeFilePref> relativePref; rv = NS_NewRelativeFilePref(theFile, key, getter_AddRefs(relativePref)); if (NS_FAILED(rv)) return rv; *_retval = relativePref; NS_ADDREF(NS_STATIC_CAST(nsIRelativeFilePref*, *_retval)); return NS_OK; }