void CRTConnHttp::SendResponse(int code, const std::string&params, const char*pData, int nDataLen)
{
	http_message *httpMsg = http_generator_create(HTTP_RESPONSE);
	httpMsg->status_code = (http_status)code;

	//
	http_generator_add_header(httpMsg, HPR_ACCESS_CONTROL_ALLOW_ORIGIN, "*", 1);

	if(params.length() > 0)
	{
		http_generator_add_header(httpMsg, HPR_PRAGMA, params.c_str(), (int)params.length());
	}

	if(pData != NULL && nDataLen > 0)
	{
		http_generator_set_content(httpMsg, pData, nDataLen, "text/json");
	}

	int nLen = 0;
	char* pMsg = http_generator_tostring(httpMsg, &nLen);

	OnResponse(pMsg, nLen);

	free(pMsg);
	http_generator_destroy(httpMsg);
	httpMsg = NULL;
}
void MessageQueue::OnReceive(const TCHAR *buf, int len)
{
	if (len == 0)
		return;
	CharString str(buf, len);
	if (OnResponse != 0)
		if (OnResponse(&str)) return;
	extQueue->Enqueue(&str);	
}
ZQ_Error	ApsApnsAdvanceClient::OnProcessRecvMsg(char* pBuffer, UInt32& nLen)
{
	ApsApnsAdvanceResponseMessage advanceResponseMessage;
	if(pBuffer[0] != 8)
	{
		return ZQ_BadIndex;
	}
	advanceResponseMessage.SetCommand(pBuffer[0]);
	advanceResponseMessage.SetStatus(pBuffer[1]);
	advanceResponseMessage.SetId(ntohl(*((uint32_t *)&pBuffer[2])));
	nLen -= 6;
	OnResponse(advanceResponseMessage);
	return OS_NoErr;
}
void CRTConnHttp::SendResponse(int code, const std::string&strContent)
{
	http_message *httpMsg = http_generator_create(HTTP_RESPONSE);
	httpMsg->status_code = (http_status)code;

	//
	http_generator_add_header(httpMsg, HPR_ACCESS_CONTROL_ALLOW_ORIGIN, "*", 1);

	if(strContent.length() > 0)
	{
		http_generator_set_content(httpMsg, strContent.c_str(), (int)strContent.length(), "text/json");
	}

	int nLen = 0;
	char* pMsg = http_generator_tostring(httpMsg, &nLen);

	OnResponse(pMsg, nLen);

	free(pMsg);
	http_generator_destroy(httpMsg);
	httpMsg = NULL;
}
void RTConnHttp::OnHttpMessage(http_message* httpMsg)
{
    //if (httpMsg->type == HTTP_RESPONSE) {
        OnResponse(httpMsg->body, httpMsg->body_size);
    //}
}