本文整理汇总了C++中nsACString::AppendLiteral方法的典型用法代码示例。如果您正苦于以下问题:C++ nsACString::AppendLiteral方法的具体用法?C++ nsACString::AppendLiteral怎么用?C++ nsACString::AppendLiteral使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsACString
的用法示例。
在下文中一共展示了nsACString::AppendLiteral方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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;
}
示例2: AppendTagWithValue
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,");
}
}
示例3: mon
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);
}
示例4: SetProxyResultFromGConf
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;
}
示例5: PromiseFlatCString
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:[email protected]]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;
}
示例6: SetProxyResultFromGSettings
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;
}
示例7: unsigned
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"));
}
}
示例8:
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());
}
示例9:
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");
}
}
示例10: SetDoBccList
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);
}
示例11: AssembleCacheKey
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;
}
示例12: params
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
}
示例13:
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");
}
}
示例14: getpid
/* static */ void
ContentChild::AppendProcessId(nsACString& aName)
{
if (!aName.IsEmpty()) {
aName.AppendLiteral(" ");
}
unsigned pid = getpid();
aName.Append(nsPrintfCString("(pid %u)", pid));
}
示例15: ConvertBeckyStatusToMozillaStatus
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;
}