bool ParseHeader(nsACString::const_iterator& aStart, nsACString::const_iterator& aEnd, bool* aWasEmptyHeader) { nsAutoCString headerName, headerValue; if (!FetchUtil::ExtractHeader(aStart, aEnd, headerName, headerValue, aWasEmptyHeader)) { return false; } if (*aWasEmptyHeader) { return true; } if (headerName.LowerCaseEqualsLiteral("content-disposition")) { nsCCharSeparatedTokenizer tokenizer(headerValue, ';'); bool seenFormData = false; while (tokenizer.hasMoreTokens()) { const nsDependentCSubstring& token = tokenizer.nextToken(); if (token.IsEmpty()) { continue; } if (token.EqualsLiteral("form-data")) { seenFormData = true; continue; } if (seenFormData && StringBeginsWith(token, NS_LITERAL_CSTRING("name="))) { mName = StringTail(token, token.Length() - 5); mName.Trim(" \""); continue; } if (seenFormData && StringBeginsWith(token, NS_LITERAL_CSTRING("filename="))) { mFilename = StringTail(token, token.Length() - 9); mFilename.Trim(" \""); continue; } } if (mName.IsVoid()) { // Could not parse a valid entry name. return false; } } else if (headerName.LowerCaseEqualsLiteral("content-type")) { mContentType = headerValue; } return true; }
NS_IMETHODIMP GnomeKeyring::Init() #endif { nsresult ret; nsCOMPtr<nsIServiceManager> servMan; nsCOMPtr<nsIPrefService> prefService; nsCOMPtr<nsIPrefBranch> pref; #ifdef PR_LOGGING gGnomeKeyringLog = PR_NewLogModule("GnomeKeyringLog"); #endif keyringName.AssignLiteral(kDefaultKeyring); ret = NS_GetServiceManager(getter_AddRefs(servMan)); if (ret != NS_OK) { return ret; } ret = servMan->GetServiceByContractID("@mozilla.org/preferences-service;1", NS_GET_IID(nsIPrefService), getter_AddRefs(prefService)); if (ret != NS_OK) { return ret; } ret = prefService->ReadUserPrefs(nullptr); if (ret != NS_OK) { return ret; } ret = prefService->GetBranch(kPrefsBranch, getter_AddRefs(pref)); if (ret != NS_OK) { return ret; } PRInt32 prefType; ret = pref->GetPrefType(kPrefsKeyring, &prefType); if (ret != NS_OK) { return ret; } if (prefType == 32) { char* tempKeyringName; pref->GetCharPref(kPrefsKeyring, &tempKeyringName); keyringName = tempKeyringName; if ( keyringName.IsVoid() || keyringName.IsEmpty() ) keyringName.AssignLiteral(kDefaultKeyring); } /* Create the password keyring, it doesn't hurt if it already exists */ GnomeKeyringResult result = gnome_keyring_create_sync(keyringName.get(), NULL); if ((result != GNOME_KEYRING_RESULT_OK) && (result != GNOME_KEYRING_RESULT_KEYRING_ALREADY_EXISTS)) { NS_ERROR("Can't open or create password keyring!"); return NS_ERROR_FAILURE; } return ret; }
AtkSocketAccessible::AtkSocketAccessible(nsIContent* aContent, nsIWeakReference* aShell, const nsCString& aPlugId) : nsAccessibleWrap(aContent, aShell) { mAtkObject = mai_atk_socket_new(this); if (!mAtkObject) return; // Embeds the children of an AtkPlug, specified by plugId, as the children of // this socket. // Using G_TYPE macros instead of ATK_SOCKET macros to avoid undefined // symbols. if (gCanEmbed && G_TYPE_CHECK_INSTANCE_TYPE(mAtkObject, g_atk_socket_type) && !aPlugId.IsVoid()) { AtkSocket* accSocket = G_TYPE_CHECK_INSTANCE_CAST(mAtkObject, g_atk_socket_type, AtkSocket); g_atk_socket_embed(accSocket, (gchar*)aPlugId.get()); } }
// The end of a body is marked by a CRLF followed by the boundary. So the // CRLF is part of the boundary and not the body, but any prior CRLFs are // part of the body. This will position the iterator at the beginning of the // boundary (after the CRLF). bool ParseBody(const nsACString& aBoundaryString, nsACString::const_iterator& aStart, nsACString::const_iterator& aEnd) { const char* beginning = aStart.get(); // Find the boundary marking the end of the body. nsACString::const_iterator end(aEnd); if (!FindInReadable(aBoundaryString, aStart, end)) { return false; } // We found a boundary, strip the just prior CRLF, and consider // everything else the body section. if (aStart.get() - beginning < 2) { // Only the first entry can have a boundary right at the beginning. Even // an empty body will have a CRLF before the boundary. So this is // a failure. return false; } // Check that there is a CRLF right before the boundary. aStart.advance(-2); // Skip optional hyphens. if (*aStart == '-' && *(aStart.get()+1) == '-') { if (aStart.get() - beginning < 2) { return false; } aStart.advance(-2); } if (*aStart != nsCRT::CR || *(aStart.get()+1) != nsCRT::LF) { return false; } nsAutoCString body(beginning, aStart.get() - beginning); // Restore iterator to after the \r\n as we promised. // We do not need to handle the extra hyphens case since our boundary // parser in PushOverBoundary() aStart.advance(2); if (!mFormData) { mFormData = new nsFormData(); } NS_ConvertUTF8toUTF16 name(mName); if (mFilename.IsVoid()) { mFormData->Append(name, NS_ConvertUTF8toUTF16(body)); } else { // Unfortunately we've to copy the data first since all our strings are // going to free it. We also need fallible alloc, so we can't just use // ToNewCString(). char* copy = static_cast<char*>(moz_xmalloc(body.Length())); if (!copy) { NS_WARNING("Failed to copy File entry body."); return false; } nsCString::const_iterator bodyIter, bodyEnd; body.BeginReading(bodyIter); body.EndReading(bodyEnd); char *p = copy; while (bodyIter != bodyEnd) { *p++ = *bodyIter++; } p = nullptr; nsRefPtr<Blob> file = File::CreateMemoryFile(mParentObject, reinterpret_cast<void *>(copy), body.Length(), NS_ConvertUTF8toUTF16(mFilename), NS_ConvertUTF8toUTF16(mContentType), /* aLastModifiedDate */ 0); Optional<nsAString> dummy; mFormData->Append(name, *file, dummy); } return true; }
bool ParseHeader(nsACString::const_iterator& aStart, nsACString::const_iterator& aEnd, bool* aWasEmptyHeader) { MOZ_ASSERT(aWasEmptyHeader); // Set it to a valid value here so we don't forget later. *aWasEmptyHeader = false; const char* beginning = aStart.get(); nsACString::const_iterator end(aEnd); if (!FindCRLF(aStart, end)) { return false; } if (aStart.get() == beginning) { *aWasEmptyHeader = true; return true; } nsAutoCString header(beginning, aStart.get() - beginning); nsACString::const_iterator headerStart, headerEnd; header.BeginReading(headerStart); header.EndReading(headerEnd); if (!FindCharInReadable(':', headerStart, headerEnd)) { return false; } nsAutoCString headerName(StringHead(header, headerStart.size_backward())); headerName.CompressWhitespace(); if (!NS_IsValidHTTPToken(headerName)) { return false; } nsAutoCString headerValue(Substring(++headerStart, headerEnd)); if (!NS_IsReasonableHTTPHeaderValue(headerValue)) { return false; } headerValue.CompressWhitespace(); if (headerName.LowerCaseEqualsLiteral("content-disposition")) { nsCCharSeparatedTokenizer tokenizer(headerValue, ';'); bool seenFormData = false; while (tokenizer.hasMoreTokens()) { const nsDependentCSubstring& token = tokenizer.nextToken(); if (token.IsEmpty()) { continue; } if (token.EqualsLiteral("form-data")) { seenFormData = true; continue; } if (seenFormData && StringBeginsWith(token, NS_LITERAL_CSTRING("name="))) { mName = StringTail(token, token.Length() - 5); mName.Trim(" \""); continue; } if (seenFormData && StringBeginsWith(token, NS_LITERAL_CSTRING("filename="))) { mFilename = StringTail(token, token.Length() - 9); mFilename.Trim(" \""); continue; } } if (mName.IsVoid()) { // Could not parse a valid entry name. return false; } } else if (headerName.LowerCaseEqualsLiteral("content-type")) { mContentType = headerValue; } return true; }