void FilesystemHttpSender::Setup() { //SetDownloadFilename(path_.filename().string()); #if BOOST_HAS_FILESYSTEM_V3 == 1 SetContentType(Toolbox::AutodetectMimeType(path_.filename().string())); #else SetContentType(Toolbox::AutodetectMimeType(path_.filename())); #endif }
/* * httpsSendFullResponse * * Sends a full formatted response message to Sock, including the * file indicated by the filename in RequestedFile. The status code * for this call is usually HTTP_OK. */ void httpsSendFullResponse(WOLFSSL *ssl, int StatusCode, char *RequestedFile) { EFS_FILE *fEntityBody = 0; char tempBuffer[NDK_HTTP_DATABUFSIZE]; int EntityLength; /* Open the file */ fEntityBody = efss_fopen( RequestedFile, "rb" ); /* If either failed, report file not found */ if( !fEntityBody ) { https404(ssl); /* file not found */ goto EXIT; } /* Send the HTTP status line */ SetContentType(tempBuffer, RequestedFile); httpsSendStatusLine(ssl, StatusCode, tempBuffer); /* Send the Entity Length */ EntityLength = efss_getfilesize( fEntityBody ); httpsSendEntityLength(ssl, EntityLength); /* We have EFS send the file since it can copy the raw file */ /* data directly to the socket (no intermediate copy) */ efss_filesend( fEntityBody, EntityLength, ssl ); EXIT: if( fEntityBody ) efss_fclose( fEntityBody ); return; }
MIME_DecodeCache_Storage::MIME_DecodeCache_Storage(URL_Rep *url_rep, Cache_Storage *src) : DecodedMIME_Storage(url_rep) { SetContentType(URL_XML_CONTENT); source = NULL; desc = NULL; // Do not take over the source cache element unless initialization was successful #ifdef RAMCACHE_ONLY source = src; #endif }
ECode SendReq::constructor( /* [in] */ ArrayOf<Byte>* contentType, /* [in] */ IEncodedStringValue* from, /* [in] */ Int32 mmsVersion, /* [in] */ ArrayOf<Byte>* transactionId) { MultimediaMessagePdu::constructor(); SetMessageType(IPduHeaders::MESSAGE_TYPE_SEND_REQ); SetContentType(contentType); SetFrom(from); SetMmsVersion(mmsVersion); SetTransactionId(transactionId); return NOERROR; }
EXC_TYPE CAttachInfo::InitContentType (LPCTSTR lpszMIMEType, const BOOLEAN fUpdate) { if (IsEmptyStr(lpszMIMEType)) return EPARAM; LPCTSTR lpszMTD=_tcschr(lpszMIMEType, RFC822_MIMETAG_SEP); if (NULL == lpszMTD) return ENOTPRESENT; *((LPTSTR) lpszMTD) = _T('\0'); EXC_TYPE exc=(fUpdate ? UpdateContentType(lpszMIMEType, (lpszMTD+1)) : SetContentType(lpszMIMEType, (lpszMTD+1))); *((LPTSTR) lpszMTD) = RFC822_MIMETAG_SEP; return exc; }
// initialize the content of this body part with a mail message bool MimeBody::SetMessage(const MimeBody* pMM) { ASSERT(pMM != NULL); int nSize = pMM->GetLength(); if (!AllocateBuffer(nSize+4)) return false; pMM->Store(m_pbText); const char* pszType = GetContentType(); if (!pszType || ::_memicmp(pszType, "message", 7) != 0) SetContentType("message/rfc822", ""); return true; }
// initialize the content of this body part with a mail message bool CMimeBody::SetMessage(const CMimeMessage* pMM) { ASSERT(pMM != NULL); int nSize = pMM->GetLength(); if (!AllocateBuffer(nSize+4)) return false; nSize = pMM->Store((char*)m_pbText, nSize); m_pbText[nSize] = 0; m_nTextSize = nSize; const char* pszType = GetContentType(); if (!pszType || ::memicmp(pszType, "message", 7) != 0) SetContentType("message/rfc822"); //SetTransferEncoding(CMimeConst::EncodingBinary()); // in case the default 7bit cause folding return true; }
EXC_TYPE CAttachInfo::SetInfo (LPCTSTR lpszName, const UINT32 ulSize, // may be zero LPCTSTR lpszPath, // may be NULL/empty LPCTSTR lpszType, LPCTSTR lpszSubType, LPCTSTR lpszCharSet, // may be NULL/empty const RFC822ENCCASE attEnc, LPCTSTR lpszDesc, LPCTSTR lpszID) { Cleanup(); EXC_TYPE exc=EOK; if (EOK == exc) exc = SetName(lpszName, FALSE); if (EOK == exc) exc = SetPath(lpszPath); if (EOK == exc) exc = SetContentType(lpszType, lpszSubType); if (EOK == exc) exc = SetCharSet(lpszCharSet); if (EOK == exc) exc = SetEncoding(attEnc); if (EOK == exc) exc = SetDescription(lpszDesc); if (EOK == exc) exc = SetID(lpszID); if (exc != EOK) Cleanup(); else m_ulSize = ulSize; return exc; }
ECode SendReq::constructor() { MultimediaMessagePdu::constructor(); // try { SetMessageType(IPduHeaders::MESSAGE_TYPE_SEND_REQ); SetMmsVersion(IPduHeaders::CURRENT_MMS_VERSION); // FIXME: Content-type must be decided according to whether // SMIL part present. SetContentType(String("application/vnd.wap.multipart.related").GetBytes()); AutoPtr<IEncodedStringValue> p; CEncodedStringValue::New(IPduHeaders::FROM_INSERT_ADDRESS_TOKEN_STR.GetBytes(), (IEncodedStringValue**)&p); SetFrom(p); SetTransactionId(GenerateTransactionId()); // } catch (InvalidHeaderValueException e) { // // Impossible to reach here since all headers we set above are valid. // Log.e(TAG, "Unexpected InvalidHeaderValueException.", e); // throw new RuntimeException(e); // } return NOERROR; }
void FTPChannelChild::DoOnStartRequest(const PRInt32& aContentLength, const nsCString& aContentType, const PRTime& aLastModified, const nsCString& aEntityID, const IPC::URI& aURI) { LOG(("FTPChannelChild::RecvOnStartRequest [this=%x]\n", this)); SetContentLength(aContentLength); SetContentType(aContentType); mLastModifiedTime = aLastModified; mEntityID = aEntityID; nsCString spec; nsCOMPtr<nsIURI> uri(aURI); uri->GetSpec(spec); nsBaseChannel::URI()->SetSpec(spec); AutoEventEnqueuer ensureSerialDispatch(this); nsresult rv = mListener->OnStartRequest(this, mListenerContext); if (NS_FAILED(rv)) Cancel(rv); }
nsresult nsDataChannel::OpenContentStream(PRBool async, nsIInputStream **result, nsIChannel** channel) { NS_ENSURE_TRUE(URI(), NS_ERROR_NOT_INITIALIZED); nsresult rv; nsCAutoString spec; rv = URI()->GetAsciiSpec(spec); if (NS_FAILED(rv)) return rv; nsCString contentType, contentCharset, dataBuffer; PRBool lBase64; rv = nsDataHandler::ParseURI(spec, contentType, contentCharset, lBase64, dataBuffer); NS_UnescapeURL(dataBuffer); if (lBase64) { // Don't allow spaces in base64-encoded content. This is only // relevant for escaped spaces; other spaces are stripped in // NewURI. dataBuffer.StripWhitespace(); } nsCOMPtr<nsIInputStream> bufInStream; nsCOMPtr<nsIOutputStream> bufOutStream; // create an unbounded pipe. rv = NS_NewPipe(getter_AddRefs(bufInStream), getter_AddRefs(bufOutStream), nsIOService::gDefaultSegmentSize, PR_UINT32_MAX, async, PR_TRUE); if (NS_FAILED(rv)) return rv; PRUint32 contentLen; if (lBase64) { const PRUint32 dataLen = dataBuffer.Length(); PRInt32 resultLen = 0; if (dataLen >= 1 && dataBuffer[dataLen-1] == '=') { if (dataLen >= 2 && dataBuffer[dataLen-2] == '=') resultLen = dataLen-2; else resultLen = dataLen-1; } else { resultLen = dataLen; } resultLen = ((resultLen * 3) / 4); // XXX PL_Base64Decode will return a null pointer for decoding // errors. Since those are more likely than out-of-memory, // should we return NS_ERROR_MALFORMED_URI instead? char * decodedData = PL_Base64Decode(dataBuffer.get(), dataLen, nsnull); if (!decodedData) { return NS_ERROR_OUT_OF_MEMORY; } rv = bufOutStream->Write(decodedData, resultLen, &contentLen); PR_Free(decodedData); } else { rv = bufOutStream->Write(dataBuffer.get(), dataBuffer.Length(), &contentLen); } if (NS_FAILED(rv)) return rv; SetContentType(contentType); SetContentCharset(contentCharset); SetContentLength64(contentLen); NS_ADDREF(*result = bufInStream); return NS_OK; }
void MyCurlCppImpl::SetJpegContent() { SetContentType("image/jpg"); }
nsresult nsDeviceChannel::OpenContentStream(bool aAsync, nsIInputStream** aStream, nsIChannel** aChannel) { if (!aAsync) return NS_ERROR_NOT_IMPLEMENTED; nsCOMPtr<nsIURI> uri = nsBaseChannel::URI(); *aStream = nsnull; *aChannel = nsnull; NS_NAMED_LITERAL_CSTRING(width, "width="); NS_NAMED_LITERAL_CSTRING(height, "height="); nsCAutoString spec; uri->GetSpec(spec); nsCAutoString type; nsRefPtr<nsDeviceCaptureProvider> capture; nsCaptureParams captureParams; captureParams.camera = 0; if (kNotFound != spec.Find(NS_LITERAL_CSTRING("type=image/png"), true, 0, -1)) { type.AssignLiteral("image/png"); SetContentType(type); captureParams.captureAudio = false; captureParams.captureVideo = true; captureParams.timeLimit = 0; captureParams.frameLimit = 1; nsCAutoString buffer; extractAttributeValue(spec.get(), "width=", buffer); nsresult err; captureParams.width = buffer.ToInteger(&err); if (!captureParams.width) captureParams.width = 640; extractAttributeValue(spec.get(), "height=", buffer); captureParams.height = buffer.ToInteger(&err); if (!captureParams.height) captureParams.height = 480; captureParams.bpp = 32; #ifdef MOZ_WIDGET_ANDROID capture = GetAndroidCaptureProvider(); #endif } else if (kNotFound != spec.Find(NS_LITERAL_CSTRING("type=video/x-raw-yuv"), true, 0, -1)) { type.AssignLiteral("video/x-raw-yuv"); SetContentType(type); captureParams.captureAudio = false; captureParams.captureVideo = true; nsCAutoString buffer; extractAttributeValue(spec.get(), "width=", buffer); nsresult err; captureParams.width = buffer.ToInteger(&err); if (!captureParams.width) captureParams.width = 640; extractAttributeValue(spec.get(), "height=", buffer); captureParams.height = buffer.ToInteger(&err); if (!captureParams.height) captureParams.height = 480; captureParams.bpp = 32; captureParams.timeLimit = 0; captureParams.frameLimit = 60000; #ifdef MOZ_WIDGET_ANDROID // only enable if "device.camera.enabled" is true. if (mozilla::Preferences::GetBool("device.camera.enabled", false) == true) capture = GetAndroidCaptureProvider(); #endif } else { return NS_ERROR_NOT_IMPLEMENTED; } if (!capture) return NS_ERROR_FAILURE; return capture->Init(type, &captureParams, aStream); }
// nsDeviceChannel methods nsDeviceChannel::nsDeviceChannel() { SetContentType(NS_LITERAL_CSTRING("image/png")); }
/* build PKCS#7 envelopedData content type, return enveloped size */ int PKCS7_EncodeEnvelopedData(PKCS7* pkcs7, byte* output, word32 outputSz) { int i, ret = 0, idx = 0; int totalSz = 0, padSz = 0, desOutSz = 0; int contentInfoSeqSz, outerContentTypeSz, outerContentSz; byte contentInfoSeq[MAX_SEQ_SZ]; byte outerContentType[MAX_ALGO_SZ]; byte outerContent[MAX_SEQ_SZ]; int envDataSeqSz, verSz; byte envDataSeq[MAX_SEQ_SZ]; byte ver[MAX_VERSION_SZ]; RNG rng; int contentKeyEncSz, blockKeySz; int dynamicFlag = 0; byte contentKeyPlain[MAX_CONTENT_KEY_LEN]; byte contentKeyEnc[MAX_ENCRYPTED_KEY_SZ]; byte* plain; byte* encryptedContent; int recipSz, recipSetSz; byte recip[MAX_RECIP_SZ]; byte recipSet[MAX_SET_SZ]; int encContentOctetSz, encContentSeqSz, contentTypeSz; int contentEncAlgoSz, ivOctetStringSz; byte encContentSeq[MAX_SEQ_SZ]; byte contentType[MAX_ALGO_SZ]; byte contentEncAlgo[MAX_ALGO_SZ]; byte tmpIv[DES_BLOCK_SIZE]; byte ivOctetString[MAX_OCTET_STR_SZ]; byte encContentOctet[MAX_OCTET_STR_SZ]; if (pkcs7 == NULL || pkcs7->content == NULL || pkcs7->contentSz == 0 || pkcs7->encryptOID == 0 || pkcs7->singleCert == NULL) return BAD_FUNC_ARG; if (output == NULL || outputSz == 0) return BAD_FUNC_ARG; /* PKCS#7 only supports DES, 3DES for now */ switch (pkcs7->encryptOID) { case DESb: blockKeySz = DES_KEYLEN; break; case DES3b: blockKeySz = DES3_KEYLEN; break; default: CYASSL_MSG("Unsupported content cipher type"); return ALGO_ID_E; }; /* outer content type */ outerContentTypeSz = SetContentType(ENVELOPED_DATA, outerContentType); /* version, defined as 0 in RFC 2315 */ verSz = SetMyVersion(0, ver, 0); /* generate random content encryption key */ ret = InitRng(&rng); if (ret != 0) return ret; ret = RNG_GenerateBlock(&rng, contentKeyPlain, blockKeySz); if (ret != 0) return ret; /* build RecipientInfo, only handle 1 for now */ recipSz = CreateRecipientInfo(pkcs7->singleCert, pkcs7->singleCertSz, RSAk, blockKeySz, &rng, contentKeyPlain, contentKeyEnc, &contentKeyEncSz, recip, MAX_RECIP_SZ); if (recipSz < 0) { CYASSL_MSG("Failed to create RecipientInfo"); return recipSz; } recipSetSz = SetSet(recipSz, recipSet); /* generate IV for block cipher */ ret = RNG_GenerateBlock(&rng, tmpIv, DES_BLOCK_SIZE); if (ret != 0) return ret; /* EncryptedContentInfo */ contentTypeSz = SetContentType(pkcs7->contentOID, contentType); if (contentTypeSz == 0) return BAD_FUNC_ARG; /* allocate encrypted content buffer, pad if necessary, PKCS#7 padding */ padSz = DES_BLOCK_SIZE - (pkcs7->contentSz % DES_BLOCK_SIZE); desOutSz = pkcs7->contentSz + padSz; if (padSz != 0) { plain = XMALLOC(desOutSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (plain == NULL) { return MEMORY_E; } XMEMCPY(plain, pkcs7->content, pkcs7->contentSz); dynamicFlag = 1; for (i = 0; i < padSz; i++) { plain[pkcs7->contentSz + i] = padSz; } } else { plain = pkcs7->content; desOutSz = pkcs7->contentSz; } encryptedContent = XMALLOC(desOutSz, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (encryptedContent == NULL) { if (dynamicFlag) XFREE(plain, NULL, DYNAMIC_TYPE_TMP_BUFFER); return MEMORY_E; } /* put together IV OCTET STRING */ ivOctetStringSz = SetOctetString(DES_BLOCK_SIZE, ivOctetString); /* build up our ContentEncryptionAlgorithmIdentifier sequence, * adding (ivOctetStringSz + DES_BLOCK_SIZE) for IV OCTET STRING */ contentEncAlgoSz = SetAlgoID(pkcs7->encryptOID, contentEncAlgo, blkType, ivOctetStringSz + DES_BLOCK_SIZE); if (contentEncAlgoSz == 0) return BAD_FUNC_ARG; /* encrypt content */ if (pkcs7->encryptOID == DESb) { Des des; ret = Des_SetKey(&des, contentKeyPlain, tmpIv, DES_ENCRYPTION); if (ret == 0) Des_CbcEncrypt(&des, encryptedContent, plain, desOutSz); if (ret != 0) { XFREE(encryptedContent, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (dynamicFlag) XFREE(plain, NULL, DYNAMIC_TYPE_TMP_BUFFER); return ret; } } else if (pkcs7->encryptOID == DES3b) { Des3 des3; ret = Des3_SetKey(&des3, contentKeyPlain, tmpIv, DES_ENCRYPTION); if (ret == 0) ret = Des3_CbcEncrypt(&des3, encryptedContent, plain, desOutSz); if (ret != 0) { XFREE(encryptedContent, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (dynamicFlag) XFREE(plain, NULL, DYNAMIC_TYPE_TMP_BUFFER); return ret; } } encContentOctetSz = SetImplicit(ASN_OCTET_STRING, 0, desOutSz, encContentOctet); encContentSeqSz = SetSequence(contentTypeSz + contentEncAlgoSz + ivOctetStringSz + DES_BLOCK_SIZE + encContentOctetSz + desOutSz, encContentSeq); /* keep track of sizes for outer wrapper layering */ totalSz = verSz + recipSetSz + recipSz + encContentSeqSz + contentTypeSz + contentEncAlgoSz + ivOctetStringSz + DES_BLOCK_SIZE + encContentOctetSz + desOutSz; /* EnvelopedData */ envDataSeqSz = SetSequence(totalSz, envDataSeq); totalSz += envDataSeqSz; /* outer content */ outerContentSz = SetExplicit(0, totalSz, outerContent); totalSz += outerContentTypeSz; totalSz += outerContentSz; /* ContentInfo */ contentInfoSeqSz = SetSequence(totalSz, contentInfoSeq); totalSz += contentInfoSeqSz; if (totalSz > (int)outputSz) { CYASSL_MSG("Pkcs7_encrypt output buffer too small"); XFREE(encryptedContent, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (dynamicFlag) XFREE(plain, NULL, DYNAMIC_TYPE_TMP_BUFFER); return BUFFER_E; } XMEMCPY(output + idx, contentInfoSeq, contentInfoSeqSz); idx += contentInfoSeqSz; XMEMCPY(output + idx, outerContentType, outerContentTypeSz); idx += outerContentTypeSz; XMEMCPY(output + idx, outerContent, outerContentSz); idx += outerContentSz; XMEMCPY(output + idx, envDataSeq, envDataSeqSz); idx += envDataSeqSz; XMEMCPY(output + idx, ver, verSz); idx += verSz; XMEMCPY(output + idx, recipSet, recipSetSz); idx += recipSetSz; XMEMCPY(output + idx, recip, recipSz); idx += recipSz; XMEMCPY(output + idx, encContentSeq, encContentSeqSz); idx += encContentSeqSz; XMEMCPY(output + idx, contentType, contentTypeSz); idx += contentTypeSz; XMEMCPY(output + idx, contentEncAlgo, contentEncAlgoSz); idx += contentEncAlgoSz; XMEMCPY(output + idx, ivOctetString, ivOctetStringSz); idx += ivOctetStringSz; XMEMCPY(output + idx, tmpIv, DES_BLOCK_SIZE); idx += DES_BLOCK_SIZE; XMEMCPY(output + idx, encContentOctet, encContentOctetSz); idx += encContentOctetSz; XMEMCPY(output + idx, encryptedContent, desOutSz); idx += desOutSz; #ifdef NO_RC4 FreeRng(&rng); #endif XMEMSET(contentKeyPlain, 0, MAX_CONTENT_KEY_LEN); XMEMSET(contentKeyEnc, 0, MAX_ENCRYPTED_KEY_SZ); if (dynamicFlag) XFREE(plain, NULL, DYNAMMIC_TYPE_TMP_BUFFER); XFREE(encryptedContent, NULL, DYNAMIC_TYPE_TMP_BUFFER); return idx; }
void MyCurlCppImpl::SetJsonContent() { SetContentType("application/json"); }
void MyCurlCppImpl::SetPlainTextContent() { SetContentType("text/plain"); }
std::shared_ptr<Aws::Http::HttpResponse> NetlibHttpClient::MakeRequest( Aws::Http::HttpRequest& request, Aws::Utils::RateLimits::RateLimiterInterface* readLimiter, Aws::Utils::RateLimits::RateLimiterInterface* writeLimiter) const { // AWS allows rate limiters to be passed around, but we are doing rate // limiting on the logger plugin side and so don't implement this. if (readLimiter != nullptr || writeLimiter != nullptr) { LOG(WARNING) << "Read/write limiters are unsupported"; } Aws::Http::URI uri = request.GetUri(); uri.SetPath(Aws::Http::URI::URLEncodePath(uri.GetPath())); Aws::String url = uri.GetURIString(); bn::http::client client = TLSTransport().getClient(); bn::http::client::request req(url); for (const auto& requestHeader : request.GetHeaders()) { req << bn::header(requestHeader.first, requestHeader.second); } std::string body; if (request.GetContentBody()) { std::stringstream ss; ss << request.GetContentBody()->rdbuf(); body = ss.str(); } auto response = std::make_shared<Standard::StandardHttpResponse>(request); try { bn::http::client::response resp; switch (request.GetMethod()) { case Aws::Http::HttpMethod::HTTP_GET: resp = client.get(req); if (resp.status() == 301 || resp.status() == 302) { VLOG(1) << "Attempting custom redirect as cpp-netlib does not support " "redirects"; for (const auto& header : resp.headers()) { if (header.first == "Location") { req.uri(header.second); resp = client.get(req); } } } break; case Aws::Http::HttpMethod::HTTP_POST: resp = client.post(req, body, request.GetContentType()); break; case Aws::Http::HttpMethod::HTTP_PUT: resp = client.put(req, body, request.GetContentType()); break; case Aws::Http::HttpMethod::HTTP_HEAD: resp = client.head(req); break; case Aws::Http::HttpMethod::HTTP_PATCH: LOG(ERROR) << "cpp-netlib does not support HTTP PATCH"; return nullptr; break; case Aws::Http::HttpMethod::HTTP_DELETE: resp = client.delete_(req); break; default: LOG(ERROR) << "Unrecognized HTTP Method used: " << static_cast<int>(request.GetMethod()); return nullptr; break; } response->SetResponseCode( static_cast<Aws::Http::HttpResponseCode>(resp.status())); for (const auto& header : resp.headers()) { if (header.first == "content-type") { response->SetContentType(header.second); } response->AddHeader(header.first, header.second); } response->GetResponseBody() << resp.body(); } catch (const std::exception& /*e*/) { LOG(ERROR) << "Exception making HTTP request to URL: " << url; return nullptr; } return response; }
nsresult nsFileChannel::OpenContentStream(bool async, nsIInputStream **result, nsIChannel** channel) { // NOTE: the resulting file is a clone, so it is safe to pass it to the // file input stream which will be read on a background thread. nsCOMPtr<nsIFile> file; nsresult rv = GetFile(getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIFileProtocolHandler> fileHandler; rv = NS_GetFileProtocolHandler(getter_AddRefs(fileHandler)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIURI> newURI; rv = fileHandler->ReadURLFile(file, getter_AddRefs(newURI)); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIChannel> newChannel; rv = NS_NewChannel(getter_AddRefs(newChannel), newURI); if (NS_FAILED(rv)) return rv; *result = nullptr; newChannel.forget(channel); return NS_OK; } nsCOMPtr<nsIInputStream> stream; if (mUploadStream) { // Pass back a nsFileUploadContentStream instance that knows how to perform // the file copy when "read" (the resulting stream in this case does not // actually return any data). nsCOMPtr<nsIOutputStream> fileStream; rv = NS_NewLocalFileOutputStream(getter_AddRefs(fileStream), file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, PR_IRUSR | PR_IWUSR); if (NS_FAILED(rv)) return rv; nsRefPtr<nsFileUploadContentStream> uploadStream = new nsFileUploadContentStream(async, fileStream, mUploadStream, mUploadLength, this); if (!uploadStream || !uploadStream->IsInitialized()) { return NS_ERROR_OUT_OF_MEMORY; } stream = uploadStream.forget(); mContentLength = 0; // Since there isn't any content to speak of we just set the content-type // to something other than "unknown" to avoid triggering the content-type // sniffer code in nsBaseChannel. // However, don't override explicitly set types. if (!HasContentTypeHint()) SetContentType(NS_LITERAL_CSTRING(APPLICATION_OCTET_STREAM)); } else { nsAutoCString contentType; rv = MakeFileInputStream(file, stream, contentType, async); if (NS_FAILED(rv)) return rv; EnableSynthesizedProgressEvents(true); // fixup content length and type if (mContentLength < 0) { int64_t size; rv = file->GetFileSize(&size); if (NS_FAILED(rv)) { if (async && (NS_ERROR_FILE_NOT_FOUND == rv || NS_ERROR_FILE_TARGET_DOES_NOT_EXIST == rv)) { size = 0; } else { return rv; } } mContentLength = size; } if (!contentType.IsEmpty()) SetContentType(contentType); } *result = nullptr; stream.swap(*result); return NS_OK; }
void GetPocketApi::handleLoadBookmarks() { emit requestFinished(true); bool ok = false; QJsonDocument doc = PreparsingReply(sender(), ok); if (!ok) { qWarning() << Q_FUNC_INFO << "Failed preparsing reply phase"; return; } QJsonObject rootObject = doc.object(); const quint64 since = rootObject["since"].toDouble(); const auto& listObject = rootObject["list"].toObject(); Bookmarks_t bookmarks; for(const auto& key : listObject.keys()) { QJsonObject bookmarkObject = listObject[key].toObject(); if (!bookmarkObject.contains("resolved_url") || !bookmarkObject.contains("item_id")) { continue; } auto bm = std::make_shared<Bookmark>(); bm->SetID(bookmarkObject["item_id"].toString()); bm->SetUrl(bookmarkObject["resolved_url"].toString()); QString title = bookmarkObject["resolved_title"].toString(); if(title.isEmpty()) { title = bookmarkObject["given_title"].toString(); } if(title.isEmpty()) { title = bm->GetUrl().toString(); } bm->SetTitle(title); bm->SetDescription(bookmarkObject["excerpt"].toString()); bm->SetIsFavorite(bookmarkObject["favorite"].toString() != "0" || bookmarkObject["time_favorited"].toString() != "0"); bm->SetIsRead(bookmarkObject["read"].toString() == "1" || bookmarkObject["time_read"].toString() != "0"); bm->SetAddTime(QDateTime::fromTime_t(bookmarkObject["time_added"] .toString().toLongLong())); bm->SetUpdateTime(QDateTime::fromTime_t(bookmarkObject["time_updated"] .toString().toLongLong())); const auto& tagsObject = bookmarkObject["tags"].toObject(); bm->SetTags(tagsObject.keys()); bm->SetImageUrl(bookmarkObject["image"].toObject()["src"].toString()); bm->SetStatus(static_cast<Bookmark::Status>(bookmarkObject["status"] .toString().toInt())); Bookmark::ContentType ct = Bookmark::CTNoType; if (bookmarkObject.contains("is_article") && bookmarkObject["is_article"].toString().toInt() == 1) { ct = Bookmark::CTArticle; } else if (bookmarkObject.contains("has_image") && bookmarkObject["has_image"].toString().toInt() == 2) { ct = Bookmark::CTImage; } else if (bookmarkObject.contains("has_video") && bookmarkObject["has_video"].toString().toInt() == 2) { ct = Bookmark::CTVideo; } bm->SetContentType(ct); if (bookmarkObject.contains("images")) { const auto& imagesObject = bookmarkObject["images"].toObject(); QList<QUrl> images; for(const auto& imageKey : imagesObject.keys()) { QJsonObject imageObject = imagesObject[imageKey].toObject(); if (imageObject.contains("src")) { images << QUrl(imagesObject["src"].toString()); } } bm->SetImages(images); } if (bookmarkObject.contains("videos")) { const auto& videosObject = bookmarkObject["videos"].toObject(); QList<QUrl> videos; for(const auto& videoKey : videosObject.keys()) { QJsonObject videoObject = videosObject[videoKey].toObject(); if (videoObject.contains("src")) { videos << QUrl(videoObject["src"].toString()); } } } bookmarks << bm; } emit gotBookmarks(bookmarks, since); }