⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httputils.cpp

📁 一个Symbian平台上的serverclient模型的简单示例
💻 CPP
字号:
// httputils.cpp
//

#include "httputils.h"

#include <apmfndr.h>

_LIT8(KCRLF, "\r\n");
_LIT8(KSpace, " ");
_LIT8(KFullStop, ".");
_LIT8(KHTTPPrefix, "HTTP/");
_LIT8(KColonSpace, ": ");


_LIT8(KHeadContentLength, "Content-Length");
_LIT8(KHeadContentType, "Content-Type");
_LIT8(KMimeTextPlain, "text/plain");

_LIT8(KMethodOptions, "OPTIONS");
_LIT8(KMethodGet, "GET");
_LIT8(KMethodHead, "HEAD");
_LIT8(KMethodPost, "POST");
_LIT8(KMethodPut, "PUT");
_LIT8(KMethodDelete, "DELETE");
_LIT8(KMethodTrace, "TRACE");
_LIT8(KMethodConnect, "CONNECT");


void HTTP::WriteStatusLine(TDes8& aBuffer, const TVersion aVer, TInt response)
	{
	aBuffer.Append(KHTTPPrefix);
	aBuffer.AppendNum(aVer.iMajor);
	aBuffer.Append(KFullStop);
	aBuffer.AppendNum(aVer.iMinor);
	aBuffer.Append(KSpace);
	aBuffer.AppendNum(response);
	aBuffer.Append(KSpace);
	// clearly, this hard coded message should be replaced with a lookup of the correct message
	aBuffer.Append(_L8("Not Found"));
	aBuffer.Append(KCRLF);
	}

void HTTP::AppendFieldName(TDes8& aBuffer, const TDesC8& aName)
	{
	aBuffer.Append(aName);
	aBuffer.Append(KColonSpace);
	}

void HTTP::AppendField(TDes8& aBuffer, const TDesC8& aName, TInt aVal)
	{
	AppendFieldName(aBuffer, aName);
	aBuffer.AppendNum(aVal);
	aBuffer.Append(KCRLF);
	}

void HTTP::AppendField(TDes8& aBuffer, const TDesC8& aName, const TDesC16& aVal)
	{
	AppendFieldName(aBuffer, aName);
	aBuffer.Append(aVal);
	aBuffer.Append(KCRLF);
	}

void HTTP::AppendField(TDes8& aBuffer, const TDesC8& aName, const TDesC8& aVal)
	{
	AppendFieldName(aBuffer, aName);
	aBuffer.Append(aVal);
	aBuffer.Append(KCRLF);
	}

HBufC8* HTTP::SystemMimeTypeL(const TDesC& aPath, RFs& aFs)
	{
	CApaScanningDataRecognizer* recog = CApaScanningDataRecognizer::NewL(aFs);
	CleanupStack::PushL(recog);

	recog->ScanForRecognizersL();
	TDataRecognitionResult result = recog->RecognizeL(aPath, KNullDesC8);

	HBufC8* result_type = result.iDataType.Des8().AllocL();
	CleanupStack::PopAndDestroy();

	return result_type;
	}

//
// WriteMessageL
//
// Currently only writes 404 not found...
void HTTP::WriteMessageL(TDes8& aBuffer, HTTP::TMessages)
	{
	TVersion request_version(1, 1, 0);
	HTTP::WriteStatusLine(aBuffer, request_version, 404);
	HTTP::AppendField(aBuffer, KHeadContentLength, 0);
	HTTP::AppendField(aBuffer, KHeadContentType, KMimeTextPlain);
	aBuffer.Append(KCRLF);
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -