コード例 #1
0
XBOX::VError DecompressStream (XBOX::VStream& ioStream)
{
	XBOX::VError error = VE_COMP_LIBRARY_NOT_FOUND;

	if (XBOX::VComponentManager::IsComponentAvailable ((XBOX::CType)CZipComponent::Component_Type))
	{
		CZipComponent *zipComponent = (CZipComponent *)VComponentManager::RetainComponent ((CType)CZipComponent::Component_Type);

		if (zipComponent)
		{
			XBOX::VPtrStream decompressedStream;

			if ((XBOX::VE_OK == (error = ioStream.OpenReading())) && !decompressedStream.OpenWriting())
			{
				error = zipComponent->ExpandStream (&ioStream, &decompressedStream);
				ioStream.CloseReading();
				decompressedStream.CloseWriting();

				if ((XBOX::VE_OK == error) && (!decompressedStream.IsEmpty()))
				{
					if (XBOX::VE_OK == (error = ioStream.OpenWriting()))
					{
						ioStream.SetSize (0);
						ioStream.PutData (decompressedStream.GetDataPtr(), decompressedStream.GetDataSize());
						error = ioStream.CloseWriting();
					}
				}
			}

			zipComponent->Release();
		}
	}

	return error;
}
コード例 #2
0
void VMIMEMessage::_AddTextPart (const XBOX::VString& inName, bool inIsInline, const XBOX::VString& inContentType, const XBOX::VString& inContentID, XBOX::VPtrStream& inStream)
{
	VMIMEMessagePart *partSource = new VMIMEMessagePart();
	if (NULL != partSource)
	{
		partSource->SetName (inName);
		partSource->SetIsInline(inIsInline);
		partSource->SetMediaType (inContentType);
		partSource->SetContentID(inContentID);
		if (XBOX::VE_OK == inStream.OpenReading())
			partSource->PutData (inStream.GetDataPtr(), inStream.GetDataSize());
		inStream.CloseReading();

		fMIMEParts.push_back (partSource);
		partSource->Release();
	}
}
コード例 #3
0
XBOX::VError CompressStream (XBOX::VStream& ioStream, HTTPCompressionMethod inMethod)
{
	if ((inMethod == COMPRESSION_NONE) || (inMethod > COMPRESSION_LAST_SUPPORTED_METHOD))
		return VE_INVALID_PARAMETER;

	XBOX::VError error = VE_COMP_LIBRARY_NOT_FOUND;

	if (VHTTPServer::GetZipComponentAvailable())
	{
		CZipComponent *zipComponent = VHTTPServer::RetainZipComponent();

		if (NULL != zipComponent)
		{
			XBOX::VPtrStream		compressedStream;
			EZipCompressionLevel	compressionLevel = ((inMethod == COMPRESSION_GZIP) || (inMethod == COMPRESSION_X_GZIP)) ? eCompressionLevel_GZip_BestSpeed : eCompressionLevel_BestSpeed;

			if ((XBOX::VE_OK == (error = ioStream.OpenReading())) && !compressedStream.OpenWriting())
			{
				error = zipComponent->CompressStream (&ioStream, compressionLevel, &compressedStream);
				ioStream.CloseReading();
				compressedStream.CloseWriting();

				if ((XBOX::VE_OK == error) && (!compressedStream.IsEmpty()))
				{
					if (XBOX::VE_OK == (error = ioStream.OpenWriting()))
					{
						ioStream.SetSize (0);
						ioStream.PutData (compressedStream.GetDataPtr(), compressedStream.GetDataSize());
						ioStream.CloseWriting();
					}
				}
			}

			XBOX::QuickReleaseRefCountable (zipComponent);
		}
	}

	return error;
}
コード例 #4
0
void VMIMEMessage::_ReadMultiPartMail (const XBOX::VStream &inStream)
{
	XBOX::VStream	&stream	= const_cast<XBOX::VStream&>(inStream);
	VMIMEReader		reader(fBoundary, stream);

	while (reader.HasNextPart()) {
		
		XBOX::VHTTPMessage	message;

		reader.GetNextPart(message);

		// Parse header of part.

		XBOX::VHTTPHeader							header		= message.GetHeaders();
		const XBOX::VNameValueCollection			&headerList	= header.GetHeaderList();
		XBOX::VNameValueCollection::ConstIterator	it;

		XBOX::VString	name, fileName, contentType, contentID;
		bool			isInline, isBase64, isQuotedPrintable;

		isInline = isBase64 = isQuotedPrintable = false;
		for (it = headerList.begin(); it != headerList.end(); it++) {

			XBOX::VString				value;
			XBOX::VNameValueCollection	params;			

			if (HTTPTools::EqualASCIIVString(it->first, "Content-Type", false)) {

				header.GetHeaderValue(it->first, contentType);
				VHTTPHeader::SplitParameters(contentType, value, params);

				if (params.Has("name")) {

					name = params.Get("name");
					_UnQuote(&name, '"', '"');
				
				}

			} else if (HTTPTools::EqualASCIIVString(it->first, "Content-Disposition", false)) {

				XBOX::VString	disposition;

				header.GetHeaderValue(it->first, value);
				VHTTPHeader::SplitParameters(value, disposition, params);

				isInline = HTTPTools::EqualASCIIVString(disposition, "inline");

				if (params.Has("filename")) {

					fileName = params.Get("filename");
					_UnQuote(&fileName, '"', '"');
				
				}

			} else if (HTTPTools::EqualASCIIVString(it->first, "Content-Transfer-Encoding", false)) {

				XBOX::VString	encoding;

				header.GetHeaderValue(it->first, value);
				VHTTPHeader::SplitParameters(value, encoding, params);

				if (!(isBase64 = HTTPTools::EqualASCIIVString(encoding, "base64")))

					isQuotedPrintable = HTTPTools::EqualASCIIVString(encoding, "quoted-printable");

			} else if (HTTPTools::EqualASCIIVString(it->first, "Content-ID", false)) {

				header.GetHeaderValue(it->first, value);
				VHTTPHeader::SplitParameters(value, contentID, params);

				_UnQuote(&contentID, '<', '>');

			} else {

				// Ignore unknown fields.

			}

		}

		//  Get body of part, decode it if need.

		XBOX::VMemoryBuffer<>	decodedData;
		XBOX::VPtrStream		decodedBody;
		
		XBOX::VPtrStream		*body	= message.GetBodyPtr();

		if (isBase64) {

			XBOX::Base64Coder::Decode(body->GetDataPtr(), body->GetDataSize(), decodedData);

			decodedBody.SetDataPtr(decodedData.GetDataPtr(), decodedData.GetDataSize());
			decodedData.ForgetData();

			body = &decodedBody;

		} else if (isQuotedPrintable) {

			VMIMEReader::DecodeQuotedPrintable (body->GetDataPtr(), body->GetDataSize(), &decodedData);

			decodedBody.SetDataPtr(decodedData.GetDataPtr(), decodedData.GetDataSize());
			decodedData.ForgetData();

			body = &decodedBody;

		}

		if (fileName.IsEmpty()) 

			_AddTextPart(name, isInline, contentType, contentID, *body);

		else

			_AddFilePart(name, fileName, isInline, contentType, contentID, *body);

		decodedBody.Clear();

	}
}