nsresult nsFTPDirListingConv::GetHeaders(nsACString& headers, nsIURI* uri) { nsresult rv = NS_OK; // build up 300 line headers.AppendLiteral("300: "); // Bug 111117 - don't print the password nsCAutoString pw; nsCAutoString spec; uri->GetPassword(pw); if (!pw.IsEmpty()) { rv = uri->SetPassword(EmptyCString()); if (NS_FAILED(rv)) return rv; rv = uri->GetAsciiSpec(spec); if (NS_FAILED(rv)) return rv; headers.Append(spec); rv = uri->SetPassword(pw); if (NS_FAILED(rv)) return rv; } else { rv = uri->GetAsciiSpec(spec); if (NS_FAILED(rv)) return rv; headers.Append(spec); } headers.Append(char(nsCRT::LF)); // END 300: // build up the column heading; 200: headers.AppendLiteral("200: filename content-length last-modified file-type\n"); // END 200: return rv; }
void AppendKeyPrefix(nsILoadContextInfo* aInfo, nsACString &_retval) { /** * This key is used to salt file hashes. When form of the key is changed * cache entries will fail to find on disk. * * IMPORTANT NOTE: * Keep the attributes list sorted according their ASCII code. */ OriginAttributes const *oa = aInfo->OriginAttributesPtr(); nsAutoCString suffix; oa->CreateSuffix(suffix); if (!suffix.IsEmpty()) { AppendTagWithValue(_retval, 'O', suffix); } if (aInfo->IsAnonymous()) { _retval.AppendLiteral("a,"); } if (aInfo->IsPrivate()) { _retval.AppendLiteral("p,"); } }
void nsHttpRequestHead::Flatten(nsACString &buf, bool pruneProxyHeaders) { RecursiveMutexAutoLock mon(mRecursiveMutex); // note: the first append is intentional. buf.Append(mMethod); buf.Append(' '); buf.Append(mRequestURI); buf.AppendLiteral(" HTTP/"); switch (mVersion) { case NS_HTTP_VERSION_1_1: buf.AppendLiteral("1.1"); break; case NS_HTTP_VERSION_0_9: buf.AppendLiteral("0.9"); break; default: buf.AppendLiteral("1.0"); } buf.AppendLiteral("\r\n"); mHeaders.Flatten(buf, pruneProxyHeaders, false); }
nsresult nsUnixSystemProxySettings::GetProxyFromGConf(const nsACString& aScheme, const nsACString& aHost, PRInt32 aPort, nsACString& aResult) { PRBool masterProxySwitch = PR_FALSE; mGConf->GetBool(NS_LITERAL_CSTRING("/system/http_proxy/use_http_proxy"), &masterProxySwitch); if (!IsProxyMode("manual") || !masterProxySwitch) { aResult.AppendLiteral("DIRECT"); return NS_OK; } nsCOMPtr<nsIArray> ignoreList; if (NS_SUCCEEDED(mGConf->GetStringList(NS_LITERAL_CSTRING("/system/http_proxy/ignore_hosts"), getter_AddRefs(ignoreList))) && ignoreList) { PRUint32 len = 0; ignoreList->GetLength(&len); for (PRUint32 i = 0; i < len; ++i) { nsCOMPtr<nsISupportsString> str = do_QueryElementAt(ignoreList, i); if (str) { nsAutoString s; if (NS_SUCCEEDED(str->GetData(s)) && !s.IsEmpty()) { if (GConfIgnoreHost(NS_ConvertUTF16toUTF8(s), aHost)) { aResult.AppendLiteral("DIRECT"); return NS_OK; } } } } } PRBool useHttpProxyForAll = PR_FALSE; // This setting sometimes doesn't exist, don't bail on failure mGConf->GetBool(NS_LITERAL_CSTRING("/system/http_proxy/use_same_proxy"), &useHttpProxyForAll); nsresult rv; if (!useHttpProxyForAll) { rv = SetProxyResultFromGConf("/system/proxy/socks_", "SOCKS", aResult); if (NS_SUCCEEDED(rv)) return rv; } if (aScheme.LowerCaseEqualsLiteral("http") || useHttpProxyForAll) { rv = SetProxyResultFromGConf("/system/http_proxy/", "PROXY", aResult); } else if (aScheme.LowerCaseEqualsLiteral("https")) { rv = SetProxyResultFromGConf("/system/proxy/secure_", "PROXY", aResult); } else if (aScheme.LowerCaseEqualsLiteral("ftp")) { rv = SetProxyResultFromGConf("/system/proxy/ftp_", "PROXY", aResult); } else { rv = NS_ERROR_FAILURE; } if (NS_FAILED(rv)) { aResult.AppendLiteral("DIRECT"); } return NS_OK; }
nsresult nsUnixSystemProxySettings::GetProxyForURI(const nsACString & aSpec, const nsACString & aScheme, const nsACString & aHost, const int32_t aPort, nsACString & aResult) { nsresult rv; if (!mProxyFactory) { mProxyFactory = px_proxy_factory_new(); } NS_ENSURE_TRUE(mProxyFactory, NS_ERROR_NOT_AVAILABLE); char **proxyArray = nullptr; proxyArray = px_proxy_factory_get_proxies(mProxyFactory, PromiseFlatCString(aSpec).get()); NS_ENSURE_TRUE(proxyArray, NS_ERROR_NOT_AVAILABLE); // Translate libproxy's output to PAC string as expected // libproxy returns an array of proxies in the format: // <procotol>://[username:password@]proxy:port // or // direct:// // // PAC format: "PROXY proxy1.foo.com:8080; PROXY proxy2.foo.com:8080; DIRECT" // but nsISystemProxySettings allows "PROXY http://proxy.foo.com:8080" as well. int c = 0; while (proxyArray[c] != nullptr) { if (!aResult.IsEmpty()) { aResult.AppendLiteral("; "); } // figure out the scheme, and we can't use nsIIOService::NewURI because // this is not the main thread. char *colon = strchr (proxyArray[c], ':'); uint32_t schemelen = colon ? colon - proxyArray[c] : 0; if (schemelen < 1) { c++; continue; } if (schemelen == 6 && !strncasecmp(proxyArray[c], "direct", 6)) { aResult.AppendLiteral("DIRECT"); } else { aResult.AppendLiteral("PROXY "); aResult.Append(proxyArray[c]); } c++; } PR_Free(proxyArray); return NS_OK; }
nsresult nsUnixSystemProxySettings::GetProxyFromGSettings(const nsACString& aScheme, const nsACString& aHost, int32_t aPort, nsACString& aResult) { nsCString proxyMode; nsresult rv = mProxySettings->GetString(NS_LITERAL_CSTRING("mode"), proxyMode); NS_ENSURE_SUCCESS(rv, rv); // return NS_ERROR_FAILURE when no proxy is set if (!proxyMode.EqualsLiteral("manual")) { return NS_ERROR_FAILURE; } nsCOMPtr<nsIArray> ignoreList; if (NS_SUCCEEDED(mProxySettings->GetStringList(NS_LITERAL_CSTRING("ignore-hosts"), getter_AddRefs(ignoreList))) && ignoreList) { uint32_t len = 0; ignoreList->GetLength(&len); for (uint32_t i = 0; i < len; ++i) { nsCOMPtr<nsISupportsCString> str = do_QueryElementAt(ignoreList, i); if (str) { nsCString s; if (NS_SUCCEEDED(str->GetData(s)) && !s.IsEmpty()) { if (HostIgnoredByProxy(s, aHost)) { aResult.AppendLiteral("DIRECT"); return NS_OK; } } } } } if (aScheme.LowerCaseEqualsLiteral("http")) { rv = SetProxyResultFromGSettings("org.gnome.system.proxy.http", "PROXY", aResult); } else if (aScheme.LowerCaseEqualsLiteral("https")) { rv = SetProxyResultFromGSettings("org.gnome.system.proxy.https", "PROXY", aResult); /* Try to use HTTP proxy when HTTPS proxy is not explicitly defined */ if (rv != NS_OK) rv = SetProxyResultFromGSettings("org.gnome.system.proxy.http", "PROXY", aResult); } else if (aScheme.LowerCaseEqualsLiteral("ftp")) { rv = SetProxyResultFromGSettings("org.gnome.system.proxy.ftp", "PROXY", aResult); } else { rv = NS_ERROR_FAILURE; } if (rv != NS_OK) { /* If proxy for scheme is not specified, use SOCKS proxy for all schemes */ rv = SetProxyResultFromGSettings("org.gnome.system.proxy.socks", "SOCKS", aResult); } if (NS_FAILED(rv)) { aResult.AppendLiteral("DIRECT"); } return NS_OK; }
void nsHttpResponseHead::Flatten(nsACString &buf, bool pruneTransients) { if (mVersion == NS_HTTP_VERSION_0_9) return; buf.AppendLiteral("HTTP/"); if (mVersion == NS_HTTP_VERSION_1_1) buf.AppendLiteral("1.1 "); else buf.AppendLiteral("1.0 "); buf.Append(nsPrintfCString("%u", unsigned(mStatus)) + NS_LITERAL_CSTRING(" ") + mStatusText + NS_LITERAL_CSTRING("\r\n")); if (!pruneTransients) { mHeaders.Flatten(buf, false); return; } // otherwise, we need to iterate over the headers and only flatten // those that are appropriate. uint32_t i, count = mHeaders.Count(); for (i=0; i<count; ++i) { nsHttpAtom header; const char *value = mHeaders.PeekHeaderAt(i, header); if (!value || header == nsHttp::Connection || header == nsHttp::Proxy_Connection || header == nsHttp::Keep_Alive || header == nsHttp::WWW_Authenticate || header == nsHttp::Proxy_Authenticate || header == nsHttp::Trailer || header == nsHttp::Transfer_Encoding || header == nsHttp::Upgrade // XXX this will cause problems when we start honoring // Cache-Control: no-cache="set-cookie", what to do? || header == nsHttp::Set_Cookie) continue; // otherwise, write out the "header: value\r\n" line buf.Append(nsDependentCString(header.get()) + NS_LITERAL_CSTRING(": ") + nsDependentCString(value) + NS_LITERAL_CSTRING("\r\n")); } }
void GeckoChildProcessHost::SetChildLogName(const char* varName, const char* origLogName, nsACString &buffer) { // We currently have no portable way to launch child with environment // different than parent. So temporarily change NSPR_LOG_FILE so child // inherits value we want it to have. (NSPR only looks at NSPR_LOG_FILE at // startup, so it's 'safe' to play with the parent's environment this way.) buffer.Assign(varName); #ifdef XP_WIN // On Windows we must expand relative paths because sandboxing rules // bound only to full paths. fopen fowards to NtCreateFile which checks // the path against the sanboxing rules as passed to fopen (left relative). char absPath[MAX_PATH + 2]; if (_fullpath(absPath, origLogName, sizeof(absPath))) { buffer.Append(absPath); } else #endif { buffer.Append(origLogName); } // Append child-specific postfix to name buffer.AppendLiteral(".child-"); buffer.AppendInt(mChildCounter); // Passing temporary to PR_SetEnv is ok here if we keep the temporary // for the time we launch the sub-process. It's copied to the new // environment. PR_SetEnv(buffer.BeginReading()); }
void nsHttpHeaderArray::Flatten(nsACString &buf, bool pruneProxyHeaders) { uint32_t i, count = mHeaders.Length(); for (i = 0; i < count; ++i) { const nsEntry &entry = mHeaders[i]; // prune proxy headers if requested if (pruneProxyHeaders && ((entry.header == nsHttp::Proxy_Authorization) || (entry.header == nsHttp::Proxy_Connection))) continue; buf.Append(entry.header); buf.AppendLiteral(": "); buf.Append(entry.value); buf.AppendLiteral("\r\n"); } }
NS_IMETHODIMP nsMsgIdentity::GetDoBccList(nsACString& aValue) { if (!mPrefBranch) return NS_ERROR_NOT_INITIALIZED; nsCString val; nsresult rv = mPrefBranch->GetCharPref("doBccList", getter_Copies(val)); aValue = val; if (NS_SUCCEEDED(rv)) return rv; bool bccSelf = false; rv = GetBccSelf(&bccSelf); NS_ENSURE_SUCCESS(rv,rv); if (bccSelf) GetEmail(aValue); bool bccOthers = false; rv = GetBccOthers(&bccOthers); NS_ENSURE_SUCCESS(rv,rv); nsCString others; rv = GetBccList(others); NS_ENSURE_SUCCESS(rv,rv); if (bccOthers && !others.IsEmpty()) { if (bccSelf) aValue.AppendLiteral(","); aValue.Append(others); } return SetDoBccList(aValue); }
nsresult _OldStorage::AssembleCacheKey(nsIURI *aURI, nsACString const & aIdExtension, nsACString & aCacheKey) { // Copied from nsHttpChannel::AssembleCacheKey aCacheKey.Truncate(); if (mLoadInfo->IsAnonymous()) { aCacheKey.AssignLiteral("anon&"); } if (!aIdExtension.IsEmpty()) { aCacheKey.AppendPrintf("id=%s&", aIdExtension.BeginReading()); } nsresult rv; nsCOMPtr<nsIURI> noRefURI; rv = aURI->CloneIgnoringRef(getter_AddRefs(noRefURI)); NS_ENSURE_SUCCESS(rv, rv); nsAutoCString uriSpec; rv = noRefURI->GetAsciiSpec(uriSpec); NS_ENSURE_SUCCESS(rv, rv); if (!aCacheKey.IsEmpty()) { aCacheKey.AppendLiteral("uri="); } aCacheKey.Append(uriSpec); return NS_OK; }
void OriginAttributes::CreateSuffix(nsACString& aStr) const { UniquePtr<URLParams> params(new URLParams()); nsAutoString value; // // Important: While serializing any string-valued attributes, perform a // release-mode assertion to make sure that they don't contain characters that // will break the quota manager when it uses the serialization for file // naming (see addonId below). // if (mAppId != nsIScriptSecurityManager::NO_APP_ID) { value.AppendInt(mAppId); params->Set(NS_LITERAL_STRING("appId"), value); } if (mInIsolatedMozBrowser) { params->Set(NS_LITERAL_STRING("inBrowser"), NS_LITERAL_STRING("1")); } if (!mAddonId.IsEmpty()) { if (mAddonId.FindCharInSet(dom::quota::QuotaManager::kReplaceChars) != kNotFound) { #ifdef MOZ_CRASHREPORTER CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("Crash_AddonId"), NS_ConvertUTF16toUTF8(mAddonId)); #endif MOZ_CRASH(); } params->Set(NS_LITERAL_STRING("addonId"), mAddonId); } if (mUserContextId != nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID) { value.Truncate(); value.AppendInt(mUserContextId); params->Set(NS_LITERAL_STRING("userContextId"), value); } if (!mSignedPkg.IsEmpty()) { MOZ_RELEASE_ASSERT(mSignedPkg.FindCharInSet(dom::quota::QuotaManager::kReplaceChars) == kNotFound); params->Set(NS_LITERAL_STRING("signedPkg"), mSignedPkg); } aStr.Truncate(); params->Serialize(value); if (!value.IsEmpty()) { aStr.AppendLiteral("^"); aStr.Append(NS_ConvertUTF16toUTF8(value)); } // In debug builds, check the whole string for illegal characters too (just in case). #ifdef DEBUG nsAutoCString str; str.Assign(aStr); MOZ_ASSERT(str.FindCharInSet(dom::quota::QuotaManager::kReplaceChars) == kNotFound); #endif }
void nsHttpHeaderArray::FlattenOriginalHeader(nsACString &buf) { uint32_t i, count = mHeaders.Length(); for (i = 0; i < count; ++i) { const nsEntry &entry = mHeaders[i]; // Skip changed header. if (entry.variety == eVarietyResponse) { continue; } buf.Append(entry.header); buf.AppendLiteral(": "); buf.Append(entry.value); buf.AppendLiteral("\r\n"); } }
/* static */ void ContentChild::AppendProcessId(nsACString& aName) { if (!aName.IsEmpty()) { aName.AppendLiteral(" "); } unsigned pid = getpid(); aName.Append(nsPrintfCString("(pid %u)", pid)); }
nsresult ImportMessageRunnable::HandleHeaderLine(const nsCString &aHeaderLine, nsACString &aHeaders) { aHeaders.Append(aHeaderLine); aHeaders.AppendLiteral(MSG_LINEBREAK); nsMsgMessageFlagType flag = 0; if (IsBeckyStatusHeader(aHeaderLine) && ConvertBeckyStatusToMozillaStatus(aHeaderLine, &flag)) { char *statusLine; statusLine = PR_smprintf(X_MOZILLA_STATUS_FORMAT MSG_LINEBREAK, flag); aHeaders.Append(statusLine); PR_smprintf_free(statusLine); aHeaders.AppendLiteral(X_MOZILLA_KEYWORDS); } return NS_OK; }
void nsHttpHeaderArray::Flatten(nsACString &buf, bool pruneProxyHeaders, bool pruneTransients) { uint32_t i, count = mHeaders.Length(); for (i = 0; i < count; ++i) { const nsEntry &entry = mHeaders[i]; // Skip original header. if (entry.variety == eVarietyResponseNetOriginal) { continue; } // prune proxy headers if requested if (pruneProxyHeaders && ((entry.header == nsHttp::Proxy_Authorization) || (entry.header == nsHttp::Proxy_Connection))) { continue; } if (pruneTransients && (entry.value.IsEmpty() || entry.header == nsHttp::Connection || entry.header == nsHttp::Proxy_Connection || entry.header == nsHttp::Keep_Alive || entry.header == nsHttp::WWW_Authenticate || entry.header == nsHttp::Proxy_Authenticate || entry.header == nsHttp::Trailer || entry.header == nsHttp::Transfer_Encoding || entry.header == nsHttp::Upgrade || // XXX this will cause problems when we start honoring // Cache-Control: no-cache="set-cookie", what to do? entry.header == nsHttp::Set_Cookie)) { continue; } if (entry.headerNameOriginal.IsEmpty()) { buf.Append(entry.header); } else { buf.Append(entry.headerNameOriginal); } buf.AppendLiteral(": "); buf.Append(entry.value); buf.AppendLiteral("\r\n"); } }
NS_IMETHODIMP nsLocalFile::GetRelativeDescriptor(nsIFile *fromFile, nsACString& _retval) { NS_ENSURE_ARG_POINTER(fromFile); const int32_t kMaxNodesInPath = 32; // // _retval will be UTF-8 encoded // nsresult rv; _retval.Truncate(0); nsAutoString thisPath, fromPath; PRUnichar *thisNodes[kMaxNodesInPath], *fromNodes[kMaxNodesInPath]; int32_t thisNodeCnt, fromNodeCnt, nodeIndex; rv = GetPath(thisPath); if (NS_FAILED(rv)) return rv; rv = fromFile->GetPath(fromPath); if (NS_FAILED(rv)) return rv; // get raw pointer to mutable string buffer PRUnichar *thisPathPtr; thisPath.BeginWriting(thisPathPtr); PRUnichar *fromPathPtr; fromPath.BeginWriting(fromPathPtr); thisNodeCnt = SplitPath(thisPathPtr, thisNodes, kMaxNodesInPath); fromNodeCnt = SplitPath(fromPathPtr, fromNodes, kMaxNodesInPath); if (thisNodeCnt < 0 || fromNodeCnt < 0) return NS_ERROR_FAILURE; for (nodeIndex = 0; nodeIndex < thisNodeCnt && nodeIndex < fromNodeCnt; ++nodeIndex) { #ifdef XP_WIN if (_wcsicmp(thisNodes[nodeIndex], fromNodes[nodeIndex])) break; #else if (nsCRT::strcmp(thisNodes[nodeIndex], fromNodes[nodeIndex])) break; #endif } int32_t branchIndex = nodeIndex; for (nodeIndex = branchIndex; nodeIndex < fromNodeCnt; nodeIndex++) _retval.AppendLiteral("../"); for (nodeIndex = branchIndex; nodeIndex < thisNodeCnt; nodeIndex++) { NS_ConvertUTF16toUTF8 nodeStr(thisNodes[nodeIndex]); _retval.Append(nodeStr); if (nodeIndex + 1 < thisNodeCnt) _retval.Append('/'); } return NS_OK; }
NS_IMETHODIMP nsAbLDAPCard::BuildRdn(nsIAbLDAPAttributeMap *aAttributeMap, const uint32_t aAttrCount, const char **aAttributes, nsACString &aRdn) { NS_ENSURE_ARG_POINTER(aAttributeMap); NS_ENSURE_ARG_POINTER(aAttributes); nsresult rv; nsCString attr; nsAutoCString prop; nsCString propvalue; aRdn.Truncate(); for (uint32_t i = 0; i < aAttrCount; ++i) { attr.Assign(nsDependentCString(aAttributes[i])); // Lookup the property corresponding to the attribute rv = aAttributeMap->GetProperty(attr, prop); NS_ENSURE_SUCCESS(rv, rv); // Get the property value rv = GetPropertyAsAUTF8String(prop.get(), propvalue); // XXX The case where an attribute needed to build the Relative // Distinguished Name is not set needs to be handled by the caller, // so as to let the user know what is missing. if (NS_FAILED(rv) || propvalue.IsEmpty()) { NS_ERROR("nsAbLDAPCard::BuildRdn: a required attribute is not set"); return NS_ERROR_NOT_INITIALIZED; } aRdn.Append(attr); aRdn.AppendLiteral("="); aRdn.Append(propvalue); if (i < aAttrCount - 1) aRdn.AppendLiteral("+"); } return NS_OK; }
nsresult getStatus(nsACString& desc) { if(!gStatusReportProgress) desc.AssignLiteral("Init"); else { desc.AssignLiteral("Running: There are "); desc.AppendInt(gNumReporters); desc.AppendLiteral(" reporters"); } return NS_OK; }
static void GetDocLoadEventType(AccEvent* aEvent, nsACString& aEventType) { uint32_t type = aEvent->GetEventType(); if (type == nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_STOPPED) { aEventType.AssignLiteral("load stopped"); } else if (type == nsIAccessibleEvent::EVENT_DOCUMENT_LOAD_COMPLETE) { aEventType.AssignLiteral("load complete"); } else if (type == nsIAccessibleEvent::EVENT_DOCUMENT_RELOAD) { aEventType.AssignLiteral("reload"); } else if (type == nsIAccessibleEvent::EVENT_STATE_CHANGE) { AccStateChangeEvent* event = downcast_accEvent(aEvent); if (event->GetState() == states::BUSY) { aEventType.AssignLiteral("busy "); if (event->IsStateEnabled()) aEventType.AppendLiteral("true"); else aEventType.AppendLiteral("false"); } } }
nsresult nsDOMStorageDBWrapper::CreateDomainScopeDBKey(const nsACString& aAsciiDomain, nsACString& aKey) { if (aAsciiDomain.IsEmpty()) return NS_ERROR_NOT_AVAILABLE; ReverseString(aAsciiDomain, aKey); aKey.AppendLiteral("."); return NS_OK; }
/* static */ nsresult nsPrincipal::GetOriginForURI(nsIURI* aURI, nsACString& aOrigin) { if (!aURI) { return NS_ERROR_FAILURE; } nsCOMPtr<nsIURI> origin = NS_GetInnermostURI(aURI); if (!origin) { return NS_ERROR_FAILURE; } nsAutoCString hostPort; // chrome: URLs don't have a meaningful origin, so make // sure we just get the full spec for them. // XXX this should be removed in favor of the solution in // bug 160042. bool isChrome; nsresult rv = origin->SchemeIs("chrome", &isChrome); if (NS_SUCCEEDED(rv) && !isChrome) { rv = origin->GetAsciiHost(hostPort); // Some implementations return an empty string, treat it as no support // for asciiHost by that implementation. if (hostPort.IsEmpty()) { rv = NS_ERROR_FAILURE; } } int32_t port; if (NS_SUCCEEDED(rv) && !isChrome) { rv = origin->GetPort(&port); } if (NS_SUCCEEDED(rv) && !isChrome) { if (port != -1) { hostPort.Append(':'); hostPort.AppendInt(port, 10); } rv = origin->GetScheme(aOrigin); NS_ENSURE_SUCCESS(rv, rv); aOrigin.AppendLiteral("://"); aOrigin.Append(hostPort); } else { rv = origin->GetAsciiSpec(aOrigin); NS_ENSURE_SUCCESS(rv, rv); } return NS_OK; }
nsresult CreateReversedDomain(const nsACString& aAsciiDomain, nsACString& aKey) { if (aAsciiDomain.IsEmpty()) { return NS_ERROR_NOT_AVAILABLE; } ReverseString(aAsciiDomain, aKey); aKey.AppendLiteral("."); return NS_OK; }
nsresult nsAbManager::AppendProperty(const char *aProperty, const PRUnichar *aValue, nsACString &aResult) { NS_ENSURE_ARG_POINTER(aValue); aResult += aProperty; // if the string is not safe "as is", base64 encode it if (IsSafeLDIFString(aValue)) { aResult.AppendLiteral(": "); aResult.Append(NS_LossyConvertUTF16toASCII(aValue)); } else { char *base64Str = PL_Base64Encode(NS_ConvertUTF16toUTF8(aValue).get(), 0, nsnull); if (!base64Str) return NS_ERROR_OUT_OF_MEMORY; aResult.AppendLiteral(":: "); aResult.Append(nsDependentCString(base64Str)); PR_Free(base64Str); } return NS_OK; }
static nsresult GetProxyFromEnvironment(const nsACString& aScheme, const nsACString& aHost, PRInt32 aPort, nsACString& aResult) { nsCAutoString envVar; envVar.Append(aScheme); envVar.AppendLiteral("_proxy"); const char* proxyVal = PR_GetEnv(envVar.get()); if (!proxyVal) { proxyVal = PR_GetEnv("all_proxy"); if (!proxyVal) { // Return failure so that the caller can detect the failure and // fall back to other proxy detection (e.g., WPAD) return NS_ERROR_FAILURE; } } const char* noProxyVal = PR_GetEnv("no_proxy"); if (noProxyVal && IsInNoProxyList(aHost, aPort, noProxyVal)) { aResult.AppendLiteral("DIRECT"); return NS_OK; } // Use our URI parser to crack the proxy URI nsCOMPtr<nsIURI> proxyURI; nsresult rv = NS_NewURI(getter_AddRefs(proxyURI), proxyVal); NS_ENSURE_SUCCESS(rv, rv); // Is there a way to specify "socks://" or something in these environment // variables? I can't find any documentation. PRBool isHTTP; rv = proxyURI->SchemeIs("http", &isHTTP); NS_ENSURE_SUCCESS(rv, rv); if (!isHTTP) return NS_ERROR_UNKNOWN_PROTOCOL; nsCAutoString proxyHost; rv = proxyURI->GetHost(proxyHost); NS_ENSURE_SUCCESS(rv, rv); PRInt32 proxyPort; rv = proxyURI->GetPort(&proxyPort); NS_ENSURE_SUCCESS(rv, rv); SetProxyResult("PROXY", proxyHost, proxyPort, aResult); return NS_OK; }
/* ACString ConvertUTF8toACE (in AUTF8String input); */ NS_IMETHODIMP nsIDNService::ConvertUTF8toACE(const nsACString & input, nsACString & ace) { // protect against bogus input NS_ENSURE_TRUE(IsUTF8(input), NS_ERROR_UNEXPECTED); nsresult rv; NS_ConvertUTF8toUCS2 ustr(input); // map ideographic period to ASCII period etc. normalizeFullStops(ustr); PRUint32 len, offset; len = 0; offset = 0; nsCAutoString encodedBuf; nsAString::const_iterator start, end; ustr.BeginReading(start); ustr.EndReading(end); ace.Truncate(); // encode nodes if non ASCII while (start != end) { len++; if (*start++ == (PRUnichar)'.') { rv = stringPrepAndACE(Substring(ustr, offset, len - 1), encodedBuf); NS_ENSURE_SUCCESS(rv, rv); ace.Append(encodedBuf); ace.Append('.'); offset += len; len = 0; } } // add extra node for multilingual test bed if (mMultilingualTestBed) ace.AppendLiteral("mltbd."); // encode the last node if non ASCII if (len) { rv = stringPrepAndACE(Substring(ustr, offset, len), encodedBuf); NS_ENSURE_SUCCESS(rv, rv); ace.Append(encodedBuf); } return NS_OK; }
nsresult nsDOMStorageDBWrapper::CreateOriginScopeDBKey(nsIURI* aUri, nsACString& aKey) { nsresult rv; rv = CreateDomainScopeDBKey(aUri, aKey); if (NS_FAILED(rv)) return rv; nsCAutoString scheme; rv = aUri->GetScheme(scheme); NS_ENSURE_SUCCESS(rv, rv); aKey.AppendLiteral(":"); aKey.Append(scheme); PRInt32 port = NS_GetRealPort(aUri); if (port != -1) { aKey.AppendLiteral(":"); aKey.Append(nsPrintfCString(32, "%d", port)); } return NS_OK; }
nsresult nsIDNService::UTF8toACE(const nsACString & input, nsACString & ace, bool allowUnassigned, bool convertAllLabels) { nsresult rv; NS_ConvertUTF8toUTF16 ustr(input); // map ideographic period to ASCII period etc. normalizeFullStops(ustr); uint32_t len, offset; len = 0; offset = 0; nsAutoCString encodedBuf; nsAString::const_iterator start, end; ustr.BeginReading(start); ustr.EndReading(end); ace.Truncate(); // encode nodes if non ASCII while (start != end) { len++; if (*start++ == (char16_t)'.') { rv = stringPrepAndACE(Substring(ustr, offset, len - 1), encodedBuf, allowUnassigned, convertAllLabels); NS_ENSURE_SUCCESS(rv, rv); ace.Append(encodedBuf); ace.Append('.'); offset += len; len = 0; } } // add extra node for multilingual test bed if (mMultilingualTestBed) ace.AppendLiteral("mltbd."); // encode the last node if non ASCII if (len) { rv = stringPrepAndACE(Substring(ustr, offset, len), encodedBuf, allowUnassigned, convertAllLabels); NS_ENSURE_SUCCESS(rv, rv); ace.Append(encodedBuf); } return NS_OK; }
void nsExpandedPrincipal::GetScriptLocation(nsACString& aStr) { aStr.Assign("[Expanded Principal ["); for (size_t i = 0; i < mPrincipals.Length(); ++i) { if (i != 0) { aStr.AppendLiteral(", "); } nsAutoCString spec; nsJSPrincipals::get(mPrincipals.ElementAt(i))->GetScriptLocation(spec); aStr.Append(spec); } aStr.Append("]]"); }
nsresult nsExpandedPrincipal::GetOriginInternal(nsACString& aOrigin) { aOrigin.AssignLiteral("[Expanded Principal ["); for (size_t i = 0; i < mPrincipals.Length(); ++i) { if (i != 0) { aOrigin.AppendLiteral(", "); } nsAutoCString subOrigin; nsresult rv = mPrincipals.ElementAt(i)->GetOrigin(subOrigin); NS_ENSURE_SUCCESS(rv, rv); aOrigin.Append(subOrigin); } aOrigin.Append("]]"); return NS_OK; }