|
@@ -9,6 +9,7 @@
|
|
|
#include "uuid4.h"
|
|
|
#include "BufferOperation.h"
|
|
|
#include "modp_b64.h"
|
|
|
+#include "SpBase.h"
|
|
|
#include "SpHelper.h"
|
|
|
#include "CWSCodec.h"
|
|
|
#include "MessageType.h"
|
|
@@ -40,9 +41,6 @@ namespace Chromium {
|
|
|
|
|
|
CWSCodec::CWSCodec() :m_DeserializeCache(MAX_TRANSFER_LEN), m_SerializeCache(MAX_TRANSFER_LEN)
|
|
|
{
|
|
|
- DbgEx("CWSCodec Constuctor");
|
|
|
- m_AckCallbackList = new std::map<int, entity_def_struct>();
|
|
|
- m_EventCallbackList = new std::map<int, std::vector<CMedthodInterface>*>();
|
|
|
}
|
|
|
|
|
|
CWSCodec::~CWSCodec() {
|
|
@@ -71,7 +69,18 @@ namespace Chromium {
|
|
|
|
|
|
void CWSCodec::init(const char* xmlPath) {
|
|
|
DbgEx("CWSCodec method -> init from %s", xmlPath);
|
|
|
- mInterpreter = new CStructureInterpreter(xmlPath);
|
|
|
+ try {
|
|
|
+ mInterpreter = new CStructureInterpreter(xmlPath);
|
|
|
+ }
|
|
|
+ catch (const std::bad_alloc& e)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::init Memory allocation failed: %s", e.what());
|
|
|
+ }
|
|
|
+ catch (const std::exception& e)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::init Error: %s", e.what());
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
void CWSCodec::DeserializeBase(CMessage& msg, CTransStruct& ts, int& rpos, cJSON* ret) {
|
|
@@ -445,13 +454,12 @@ namespace Chromium {
|
|
|
|
|
|
std::string CWSCodec::BufferToJson(CMessage & msg, boost::function<void(int, int)> dealErrcodeFun, int replaceTransId) {
|
|
|
//replaceTransId==0,MessageType为8(Event),其他都应该有值
|
|
|
- //LOG_FUNCTION();
|
|
|
int rpos = 16;
|
|
|
cJSON* ret = cJSON_CreateObject();
|
|
|
int errorCode = Error_Succeed;
|
|
|
int userCode = 0;
|
|
|
CSimpleStringA errorMsg = "";
|
|
|
- receivehexdump(msg.getPayload(), msg.getLength());
|
|
|
+ //receivehexdump(msg.getPayload(), msg.getLength());
|
|
|
|
|
|
if (msg.getLength() < 12) //End session len = 12
|
|
|
return std::string(); // 丢弃消息
|
|
@@ -528,9 +536,9 @@ namespace Chromium {
|
|
|
cJSON_AddStringToObject(ret, "errorMsg", "未知消息类型");
|
|
|
break;
|
|
|
}
|
|
|
- DbgEx("BufferToJson -> messageType=%d(%s), sessionID=%d(%02X), transID=%d(%02X), replaceTransID=%d(%02X), errorCode=%d", msg.getMessageType(),
|
|
|
+ DbgEx("BufferToJson -> messageType=%d(%s), sessionID=%d(%02X), transID=%d(%02X), replaceTransID=%d(%02X), errorCode=%d(%s)", msg.getMessageType(),
|
|
|
GetMessageTypeString(msg.getMessageType()).c_str(), msg.getSessionID(), msg.getSessionID(), srcTransId, srcTransId, replaceTransId
|
|
|
- , replaceTransId, errorCode);
|
|
|
+ , replaceTransId, errorCode, SpStrError((ErrorCodeEnum)errorCode).c_str());
|
|
|
|
|
|
if (Error_Succeed != errorCode)
|
|
|
dealErrcodeFun(errorCode, srcTransId);
|
|
@@ -539,9 +547,13 @@ namespace Chromium {
|
|
|
// RequestAck 返回的有问题 要删除对应的回调list项
|
|
|
if (Error_Succeed != errorCode && RequestAck == msg.getMessageType())
|
|
|
{
|
|
|
- std::map<int, entity_def_struct>::iterator it = m_AckCallbackList->find(msg.getTransID());
|
|
|
- if (m_AckCallbackList->end() != it)
|
|
|
- m_AckCallbackList->erase(it);
|
|
|
+ std::map<int, entity_def_struct>::iterator it = m_AckCallbackList.find(msg.getTransID());
|
|
|
+ if (m_AckCallbackList.end() != it)
|
|
|
+ {
|
|
|
+ m_ackMutex.lock();
|
|
|
+ m_AckCallbackList.erase(it);
|
|
|
+ m_ackMutex.unlock();
|
|
|
+ }
|
|
|
}
|
|
|
// 有错误时直接返回 或者 不是RequestAck和Event时也可以返回
|
|
|
if (Error_Succeed != errorCode || (RequestAck != msg.getMessageType() && Event != msg.getMessageType()))
|
|
@@ -557,7 +569,11 @@ namespace Chromium {
|
|
|
if (RequestAck == msg.getMessageType())
|
|
|
{ // Request用户自定义部分反序列化
|
|
|
// 回调反序列化列表
|
|
|
- std::map<int, entity_def_struct>::iterator it = m_AckCallbackList->find(msg.getTransID());
|
|
|
+ m_ackMutex.lock();
|
|
|
+ std::shared_ptr<void> delHandleFun((void*)0, [&](void*) {
|
|
|
+ m_ackMutex.unlock();
|
|
|
+ });
|
|
|
+ std::map<int, entity_def_struct>::iterator it = m_AckCallbackList.find(msg.getTransID());
|
|
|
|
|
|
if (m_AckCallbackList->end() == it)
|
|
|
{
|
|
@@ -576,8 +592,8 @@ namespace Chromium {
|
|
|
else if (Event == msg.getMessageType())
|
|
|
{
|
|
|
// Event用户自定义部分反序列化
|
|
|
- std::map<int, std::vector<CMedthodInterface>*>::iterator iter = m_EventCallbackList->find(msg.getTransID());
|
|
|
- if (m_EventCallbackList->end() == iter)
|
|
|
+ std::map<int, std::vector<CMedthodInterface>*>::iterator iter = m_EventCallbackList.find(msg.getTransID());
|
|
|
+ if (m_EventCallbackList.end() == iter)
|
|
|
{
|
|
|
// 没有对应的register, 无法反序列化
|
|
|
cJSON_AddNumberToObject(ret, "errorCode", Error_Unexpect);
|
|
@@ -624,18 +640,30 @@ namespace Chromium {
|
|
|
st.entity_name, st.class_name, st.methodID, mi->mMethodName.c_str(), mi->mRequestInterpreter.mParamList.size()); //如出错,可对比方法名和变量数量
|
|
|
if (Request == messageType) {
|
|
|
// 维护回调列表 Request
|
|
|
- int transid = cJSON_GetObjectItem(pJson, "transId")->valueint;
|
|
|
- m_AckCallbackList->insert(std::pair<int, entity_def_struct>(transid, st));
|
|
|
+ auto transid = json_deal::getIntergerFromCjsonObj(pJson, "transId");
|
|
|
+ if (transid.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::JsonToBuffer get transId failed");
|
|
|
+ return std::make_pair(messageType, nullptr);
|
|
|
+ }
|
|
|
+ m_ackMutex.lock();
|
|
|
+ m_AckCallbackList.insert(std::pair<int, entity_def_struct>(transid.second, st));
|
|
|
+ m_ackMutex.unlock();
|
|
|
}
|
|
|
}
|
|
|
else if (Register == messageType)
|
|
|
{
|
|
|
std::vector<CMedthodInterface>* milist = NULL;
|
|
|
entity_def_struct st = { 0 };
|
|
|
- unsigned int transid = cJSON_GetObjectItem(pJson, "transId")->valueint;
|
|
|
+ auto transid = json_deal::getIntergerFromCjsonObj(pJson, "transId");
|
|
|
+ if (transid.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::JsonToBuffer get transId failed");
|
|
|
+ return std::make_pair(messageType, nullptr);
|
|
|
+ }
|
|
|
GetCJsonObjectValue(pJson, "entity", st.entity_name, errmsg);
|
|
|
milist = mInterpreter->getAllMessageInterface(st.entity_name);
|
|
|
- m_EventCallbackList->insert(std::pair<int, std::vector<CMedthodInterface>*>(transid, milist));
|
|
|
+ m_EventCallbackList.insert(std::pair<int, std::vector<CMedthodInterface>*>(transid.second, milist));
|
|
|
}
|
|
|
else if (Broadcast == messageType)
|
|
|
{
|
|
@@ -685,39 +713,9 @@ namespace Chromium {
|
|
|
WriteT(data, len, &wpos, &capacity);
|
|
|
|
|
|
//写入messageType,附带链路信息
|
|
|
-#ifdef OPEN_LINKINFO
|
|
|
int messageTypeWithControl = messageType | PKT_TYPE_CONTROL_LINKCONTEXT;
|
|
|
-#else
|
|
|
- int messageTypeWithControl = messageType;
|
|
|
-#endif
|
|
|
WriteT(data, messageTypeWithControl, &wpos, &capacity);
|
|
|
|
|
|
- auto linkContexFun = [&]() {
|
|
|
-#ifdef OPEN_LINKINFO
|
|
|
- //添加链路信息,放到原数据最后
|
|
|
- auto linkContextRet = GetLinkContex(pJson, data, errmsg);
|
|
|
- if (linkContextRet.first)
|
|
|
- {
|
|
|
- WriteT(data, std::get<0>(linkContextRet.second), &wpos, &capacity);
|
|
|
- WriteT(data, std::get<1>(linkContextRet.second), &wpos, &capacity);
|
|
|
- WriteT(data, std::get<2>(linkContextRet.second), &wpos, &capacity);
|
|
|
- WriteT(data, std::get<3>(linkContextRet.second), &wpos, &capacity);
|
|
|
- }
|
|
|
- else// 生成链路信息
|
|
|
- {
|
|
|
- CSimpleStringA bussinessId = "ChromiumAutoGen";
|
|
|
- CSimpleStringA traceId = uuid4_generate(32).c_str();
|
|
|
- CSimpleStringA spanId = uuid4_generate(16).c_str();
|
|
|
- CSimpleStringA parentSpanId = "0";
|
|
|
- WriteT(data, bussinessId, &wpos, &capacity);//为适配silverlight,默认写入就是unicode
|
|
|
- WriteT(data, traceId, &wpos, &capacity);
|
|
|
- WriteT(data, spanId, &wpos, &capacity);
|
|
|
- WriteT(data, parentSpanId, &wpos, &capacity);
|
|
|
- }
|
|
|
-#else
|
|
|
-#endif
|
|
|
-
|
|
|
- };
|
|
|
|
|
|
// 根据不同的request进行序列化
|
|
|
switch (messageType) {
|
|
@@ -730,35 +728,35 @@ namespace Chromium {
|
|
|
break;
|
|
|
case BeginSession:
|
|
|
SerializeBeginSession(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
+ SerializeLinkInfo(pJson, data, &wpos, &capacity, errmsg);
|
|
|
break;
|
|
|
case EndSession:
|
|
|
SerializeEndSession(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
+ SerializeLinkInfo(pJson, data, &wpos, &capacity, errmsg);
|
|
|
break;
|
|
|
case Register:
|
|
|
SerializeRegister(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
+ SerializeLinkInfo(pJson, data, &wpos, &capacity, errmsg);
|
|
|
break;
|
|
|
case Unregister:
|
|
|
SerializeUnregister(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
+ SerializeLinkInfo(pJson, data, &wpos, &capacity, errmsg);
|
|
|
break;
|
|
|
case LogEventMsgType:
|
|
|
SerializeLogEvent(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
+ SerializeLinkInfo(pJson, data, &wpos, &capacity, errmsg);
|
|
|
break;
|
|
|
case LogWarnMsgType:
|
|
|
SerializeLogWarn(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
+ SerializeLinkInfo(pJson, data, &wpos, &capacity, errmsg);
|
|
|
break;
|
|
|
case SetVarReq:
|
|
|
SerializeSetVarReq(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
+ SerializeLinkInfo(pJson, data, &wpos, &capacity, errmsg);
|
|
|
break;
|
|
|
case GetVarReq:
|
|
|
SerializeGetVarReq(pJson, data, &wpos, &capacity, mi, errmsg);
|
|
|
- linkContexFun();
|
|
|
+ SerializeLinkInfo(pJson, data, &wpos, &capacity, errmsg);
|
|
|
break;
|
|
|
default:
|
|
|
// warn
|
|
@@ -804,46 +802,79 @@ namespace Chromium {
|
|
|
return pStr;
|
|
|
}
|
|
|
|
|
|
+ void CWSCodec::SerializeLinkInfo(cJSON* js, char* data, int* wpos, int* capacity, char* errmsg)
|
|
|
+ {
|
|
|
+ auto linkContextRet = GetLinkContex(js, data, errmsg);
|
|
|
+ if (linkContextRet.first)
|
|
|
+ {
|
|
|
+ linkContext curLink;
|
|
|
+ curLink.bussinessId = std::get<0>(linkContextRet.second);
|
|
|
+ curLink.traceId = std::get<1>(linkContextRet.second);
|
|
|
+ curLink.spanId = std::get<2>(linkContextRet.second);
|
|
|
+ curLink.parentSpanId = std::get<3>(linkContextRet.second);
|
|
|
+ DbgToBeidou(curLink, __FUNCTION__)(); //chromium节点
|
|
|
+ auto newLink = curLink.upgradeLink();
|
|
|
+ WriteT(data, newLink.bussinessId, wpos, capacity);
|
|
|
+ WriteT(data, newLink.traceId, wpos, capacity);
|
|
|
+ WriteT(data, newLink.spanId, wpos, capacity);
|
|
|
+ WriteT(data, newLink.parentSpanId, wpos, capacity);
|
|
|
+ //DbgToBeidou(newLink, __FUNCTION__)();
|
|
|
+ }
|
|
|
+ else// 生成链路信息
|
|
|
+ {
|
|
|
+ linkContext curLink;
|
|
|
+ curLink.bussinessId = "ChromiumAutoGen";
|
|
|
+ curLink.traceId = uuid4_generate(32).c_str();
|
|
|
+ curLink.spanId = uuid4_generate(16).c_str();
|
|
|
+ curLink.parentSpanId = "0";
|
|
|
+ DbgToBeidou(curLink, __FUNCTION__)();
|
|
|
+ auto newLink = curLink.upgradeLink();
|
|
|
+ WriteT(data, newLink.bussinessId, wpos, capacity);//为适配silverlight,默认写入就是unicode
|
|
|
+ WriteT(data, newLink.traceId, wpos, capacity);
|
|
|
+ WriteT(data, newLink.spanId, wpos, capacity);
|
|
|
+ WriteT(data, newLink.parentSpanId, wpos, capacity);
|
|
|
+ //DbgToBeidou(curLink, __FUNCTION__)();
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
void CWSCodec::SerializeInfo(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
|
|
|
- int i4 = 0;
|
|
|
- i4 = cJSON_GetObjectItem(js, "sessionID")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- i4 = cJSON_GetObjectItem(js, "methodID")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- i4 = cJSON_GetObjectItem(js, "signature")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
-#ifdef OPEN_LINKINFO
|
|
|
- auto linkContextRet = GetLinkContex(js, data, errmsg);
|
|
|
- if (linkContextRet.first)
|
|
|
+ auto sessionID = json_deal::getIntergerFromCjsonObj(js, "sessionID");
|
|
|
+ if (sessionID.first == false)
|
|
|
{
|
|
|
- WriteT(data, std::get<0>(linkContextRet.second), wpos, capacity);
|
|
|
- WriteT(data, std::get<1>(linkContextRet.second), wpos, capacity);
|
|
|
- WriteT(data, std::get<2>(linkContextRet.second), wpos, capacity);
|
|
|
- WriteT(data, std::get<3>(linkContextRet.second), wpos, capacity);
|
|
|
+ DbgEx("CWSCodec::SerializeInfo get sessionId failed");
|
|
|
+ return;
|
|
|
}
|
|
|
- else// 生成链路信息
|
|
|
+
|
|
|
+ auto methodID = json_deal::getIntergerFromCjsonObj(js, "methodID");
|
|
|
+ if (methodID.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeInfo get methodID failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ auto signature = json_deal::getIntergerFromCjsonObj(js, "signature");
|
|
|
+ if (signature.first == false)
|
|
|
{
|
|
|
- CSimpleStringA bussinessId = "ChromiumAutoGen";
|
|
|
- CSimpleStringA traceId = uuid4_generate(32).c_str();
|
|
|
- CSimpleStringA spanId = uuid4_generate(16).c_str();
|
|
|
- CSimpleStringA parentSpanId = "0";
|
|
|
- WriteT(data, bussinessId, wpos, capacity);//为适配silverlight,默认写入就是unicode
|
|
|
- WriteT(data, traceId, wpos, capacity);
|
|
|
- WriteT(data, spanId, wpos, capacity);
|
|
|
- WriteT(data, parentSpanId, wpos, capacity);
|
|
|
+ DbgEx("CWSCodec::SerializeInfo get signature failed");
|
|
|
+ return;
|
|
|
}
|
|
|
-#endif
|
|
|
+
|
|
|
+ WriteT(data, sessionID.second, wpos, capacity);
|
|
|
+ WriteT(data, methodID.second, wpos, capacity);
|
|
|
+ WriteT(data, signature.second, wpos, capacity);
|
|
|
+
|
|
|
+ SerializeLinkInfo(js, data, wpos, capacity, errmsg);
|
|
|
|
|
|
if (NULL == pI)
|
|
|
{
|
|
|
- // 没有对应定义
|
|
|
- return;
|
|
|
+ DbgEx("PI = NULL, 无法找到接口定义");
|
|
|
+ return;// 没有对应定义
|
|
|
}
|
|
|
|
|
|
- auto paramJs = cJSON_GetObjectItem(js, PARAMLIST_HEAD);
|
|
|
+ auto paramJs = cJSON_GetObjectItem(js, PARAMLIST_HEAD);//不更换,因为不为获取值
|
|
|
if (paramJs == NULL)
|
|
|
{
|
|
|
//detect the same name
|
|
@@ -860,7 +891,6 @@ namespace Chromium {
|
|
|
for (auto repeatName : c_repeatParamList)
|
|
|
{
|
|
|
#endif
|
|
|
-
|
|
|
if (paramInfo.mName == repeatName)
|
|
|
DbgEx("request参数名字重复, error, %s", paramInfo.mName.c_str());
|
|
|
}
|
|
@@ -868,12 +898,11 @@ namespace Chromium {
|
|
|
//如果存在重复,可能数据已经脏了,所以也不需要作删除参数处理
|
|
|
|
|
|
paramJs = js;
|
|
|
- }
|
|
|
+ }
|
|
|
GeneralSerialize(paramJs, data, wpos, capacity, pI, errmsg);
|
|
|
|
|
|
return;
|
|
|
- }
|
|
|
-#ifdef OPEN_LINKINFO
|
|
|
+ }
|
|
|
std::pair<bool, std::tuple<CSimpleStringA, CSimpleStringA, CSimpleStringA, CSimpleStringA, CSimpleStringA, int>> CWSCodec::GetLinkContex(cJSON * js, char* data, char* errmsg)
|
|
|
{
|
|
|
/*
|
|
@@ -889,20 +918,19 @@ namespace Chromium {
|
|
|
|
|
|
CSimpleStringA BussinessId, TraceId, SpanId, ParentSpanId, Timestamp;
|
|
|
int ReservedControl;
|
|
|
- GetCJsonObjectValue(js, "BussinessId", BussinessId, errmsg);
|
|
|
+ GetCJsonObjectValue(js, "BusinessId", BussinessId, errmsg);
|
|
|
GetCJsonObjectValue(js, "TraceId", TraceId, errmsg);
|
|
|
GetCJsonObjectValue(js, "SpanId", SpanId, errmsg);
|
|
|
GetCJsonObjectValue(js, "ParentSpanId", ParentSpanId, errmsg);
|
|
|
GetCJsonObjectValue(js, "Timestamp", Timestamp, errmsg);
|
|
|
GetCJsonIntergerValue(js, "ReservedControl", ReservedControl, errmsg);
|
|
|
|
|
|
- if (BussinessId.GetLength() > 0 && BussinessId.GetLength() < 32 && TraceId.GetLength() == 32 && SpanId.GetLength() == 16 && ParentSpanId.GetLength() == 16)
|
|
|
+ if (BussinessId.GetLength() > 0 && BussinessId.GetLength() < 32 && TraceId.GetLength() == 32 && SpanId.GetLength() == 16)
|
|
|
return std::make_pair(true, std::make_tuple(BussinessId, TraceId, SpanId, ParentSpanId, Timestamp, ReservedControl));
|
|
|
else
|
|
|
return std::make_pair(false, std::make_tuple("", "", "", "", "", 0));
|
|
|
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
void CWSCodec::SerializeBeginSession(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
int i4 = 0;
|
|
@@ -918,45 +946,57 @@ namespace Chromium {
|
|
|
|
|
|
}
|
|
|
|
|
|
- void CWSCodec::SerializeEndSession(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- int i4 = 0;
|
|
|
- i4 = cJSON_GetObjectItem(js, "sessionID")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
+ void CWSCodec::SerializeEndSession(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+ {
|
|
|
+ auto sessionID = json_deal::getIntergerFromCjsonObj(js, "sessionID");
|
|
|
+ if (sessionID.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeEndSession get sessionId failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ WriteT(data, sessionID.second, wpos, capacity);
|
|
|
}
|
|
|
|
|
|
- void CWSCodec::SerializeRequest(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- unsigned int i4 = 0;
|
|
|
- GetCJsonIntergerValue(js, "transID", i4, errmsg);
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- GetCJsonIntergerValue(js, "sessionID", i4, errmsg);
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- GetCJsonIntergerValue(js, "methodID", i4, errmsg);
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- GetCJsonIntergerValue(js, "signature", i4, errmsg);
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- GetCJsonIntergerValue(js, "timeout", i4, errmsg);
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
-#ifdef OPEN_LINKINFO
|
|
|
- auto linkContextRet = GetLinkContex(js, data, errmsg);
|
|
|
- if (linkContextRet.first)
|
|
|
+ void CWSCodec::SerializeRequest(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+ {
|
|
|
+
|
|
|
+ auto transID = json_deal::getIntergerFromCjsonObj(js, "transID");
|
|
|
+ if (transID.first == false)
|
|
|
{
|
|
|
- WriteT(data, std::get<0>(linkContextRet.second), wpos, capacity);
|
|
|
- WriteT(data, std::get<1>(linkContextRet.second), wpos, capacity);
|
|
|
- WriteT(data, std::get<2>(linkContextRet.second), wpos, capacity);
|
|
|
- WriteT(data, std::get<3>(linkContextRet.second), wpos, capacity);
|
|
|
+ DbgEx("CWSCodec::SerializeRequest get transID failed");
|
|
|
+ return;
|
|
|
}
|
|
|
- else// 生成链路信息
|
|
|
+ auto sessionID = json_deal::getIntergerFromCjsonObj(js, "sessionID");
|
|
|
+ if (sessionID.first == false)
|
|
|
{
|
|
|
- CSimpleStringA bussinessId = "ChromiumAutoGen";
|
|
|
- CSimpleStringA traceId = uuid4_generate(32).c_str();
|
|
|
- CSimpleStringA spanId = uuid4_generate(16).c_str();
|
|
|
- CSimpleStringA parentSpanId = "0";
|
|
|
- WriteT(data, bussinessId, wpos, capacity);//为适配silverlight,默认写入就是unicode
|
|
|
- WriteT(data, traceId, wpos, capacity);
|
|
|
- WriteT(data, spanId, wpos, capacity);
|
|
|
- WriteT(data, parentSpanId, wpos, capacity);
|
|
|
+ DbgEx("CWSCodec::SerializeRequest get sessionID failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ auto methodID = json_deal::getIntergerFromCjsonObj(js, "methodID");
|
|
|
+ if (methodID.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeRequest get methodID failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ auto signature = json_deal::getIntergerFromCjsonObj(js, "signature");
|
|
|
+ if (signature.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeRequest get signature failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ auto timeout = json_deal::getIntergerFromCjsonObj(js, "timeout");
|
|
|
+ if (timeout.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeRequest get timeout failed");
|
|
|
+ return;
|
|
|
}
|
|
|
-#endif
|
|
|
+
|
|
|
+ WriteT(data, transID.second, wpos, capacity);
|
|
|
+ WriteT(data, sessionID.second, wpos, capacity);
|
|
|
+ WriteT(data, methodID.second, wpos, capacity);
|
|
|
+ WriteT(data, signature.second, wpos, capacity);
|
|
|
+ WriteT(data, timeout.second, wpos, capacity);
|
|
|
+ SerializeLinkInfo(js, data, wpos, capacity, errmsg);
|
|
|
|
|
|
if (NULL == pI)
|
|
|
{
|
|
@@ -965,7 +1005,7 @@ namespace Chromium {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- auto paramJs = cJSON_GetObjectItem(js, PARAMLIST_HEAD);
|
|
|
+ auto paramJs = cJSON_GetObjectItem(js, PARAMLIST_HEAD);//不改动,因为不是为了获取值
|
|
|
if (paramJs == NULL)
|
|
|
{
|
|
|
//detect the same name
|
|
@@ -993,31 +1033,61 @@ namespace Chromium {
|
|
|
}
|
|
|
|
|
|
void CWSCodec::SerializeRegister(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- unsigned int i4 = 0;
|
|
|
- GetCJsonIntergerValue(js, "transID", i4, errmsg);
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- CSimpleStringA s = "";
|
|
|
- GetCJsonObjectValue(js, "entity", s, errmsg);
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
- s = "";
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
+
|
|
|
+ auto transID = json_deal::getIntergerFromCjsonObj(js, "transID");
|
|
|
+ if (transID.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeRegister get transID failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ auto entity = json_deal::getStringFromCjsonObj(js, "entity");
|
|
|
+ if (entity.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeRegister get entity failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ WriteT(data, transID.second, wpos, capacity);
|
|
|
+ WriteT(data, entity.second, wpos, capacity);
|
|
|
+ CSimpleStringA tmp = "";
|
|
|
+ WriteT(data, tmp, wpos, capacity);//订阅实体全局,不限定方法
|
|
|
}
|
|
|
|
|
|
void CWSCodec::SerializeUnregister(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- int i4 = 0;
|
|
|
- i4 = cJSON_GetObjectItem(js, "transID")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
+ auto transID = json_deal::getIntergerFromCjsonObj(js, "transID");
|
|
|
+ if (transID.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeUnregister get transID failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ WriteT(data, transID.second, wpos, capacity);
|
|
|
}
|
|
|
|
|
|
void CWSCodec::SerializeLogEvent(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- int i4 = 0;
|
|
|
- i4 = cJSON_GetObjectItem(js, "securityLevel")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- i4 = cJSON_GetObjectItem(js, "eventCode")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- CSimpleStringA s = "";
|
|
|
- s = cJSON_GetObjectItem(js, "message")->valuestring;
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
+
|
|
|
+ auto securityLevel = json_deal::getIntergerFromCjsonObj(js, "securityLevel");
|
|
|
+ if (securityLevel.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeUnregister get securityLevel failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ auto eventCode = json_deal::getIntergerFromCjsonObj(js, "eventCode");
|
|
|
+ if (eventCode.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeUnregister get eventCode failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ auto message = json_deal::getStringFromCjsonObj(js, "message");
|
|
|
+ if (message.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeUnregister get message failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ WriteT(data, securityLevel.second, wpos, capacity);
|
|
|
+ WriteT(data, eventCode.second, wpos, capacity);
|
|
|
+ WriteT(data, message.second, wpos, capacity);
|
|
|
}
|
|
|
|
|
|
inline CSimpleStringA DWORD2Hex(DWORD cur)
|
|
@@ -1026,27 +1096,58 @@ namespace Chromium {
|
|
|
}
|
|
|
|
|
|
void CWSCodec::SerializeLogWarn(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- int securityLevel = 0, eventCode = 0;
|
|
|
- securityLevel = cJSON_GetObjectItem(js, "securityLevel")->valueint;
|
|
|
- WriteT(data, securityLevel, wpos, capacity);
|
|
|
- eventCode = cJSON_GetObjectItem(js, "eventCode")->valueint;
|
|
|
- WriteT(data, eventCode, wpos, capacity);
|
|
|
- CSimpleStringA s = "";
|
|
|
- s = cJSON_GetObjectItem(js, "message")->valuestring;
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
- DbgWithLink(securityLevel == SeverityLevelEnum::Severity_Low ? LOG_LEVEL_INFO : LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(DWORD2Hex(eventCode).GetData())
|
|
|
- ("receive warn from web, Warn: {%s}(sc=0x%X, uc=0x%X)", s.GetData(), 0, eventCode);
|
|
|
+ auto securityLevel = json_deal::getIntergerFromCjsonObj(js, "securityLevel");
|
|
|
+ if (securityLevel.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeLogWarn get securityLevel failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ auto eventCode = json_deal::getIntergerFromCjsonObj(js, "eventCode");
|
|
|
+ if (eventCode.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeLogWarn get eventCode failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ auto message = json_deal::getStringFromCjsonObj(js, "message");
|
|
|
+ if (message.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeLogWarn get message failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ WriteT(data, securityLevel.second, wpos, capacity);
|
|
|
+ WriteT(data, eventCode.second, wpos, capacity);
|
|
|
+ WriteT(data, message.second, wpos, capacity);
|
|
|
+
|
|
|
+ DbgWithLink(securityLevel.second == SeverityLevelEnum::Severity_Low ? LOG_LEVEL_INFO : LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)
|
|
|
+ .setResultCode(DWORD2Hex(eventCode.second).GetData())
|
|
|
+ ("receive warn from web, Warn: {%s}(sc=0x%X, uc=0x%X)", message.second.GetData(), 0, eventCode.second);
|
|
|
}
|
|
|
|
|
|
- void CWSCodec::SerializeSetVarReq(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- int i4 = 0;
|
|
|
- i4 = cJSON_GetObjectItem(js, "transID")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- CSimpleStringA s = "";
|
|
|
- s = cJSON_GetObjectItem(js, "name")->valuestring;
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
- s = cJSON_GetObjectItem(js, "value")->valuestring;
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
+ void CWSCodec::SerializeSetVarReq(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg)
|
|
|
+ {
|
|
|
+ auto transID = json_deal::getIntergerFromCjsonObj(js, "transID");
|
|
|
+ if (transID.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeSetVarReq get transID failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ auto name = json_deal::getStringFromCjsonObj(js, "name");
|
|
|
+ if (name.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeSetVarReq get name failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ auto value = json_deal::getStringFromCjsonObj(js, "value");
|
|
|
+ if (value.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeSetVarReq get value failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ WriteT(data, transID.second, wpos, capacity);
|
|
|
+ WriteT(data, name.second, wpos, capacity);
|
|
|
+ WriteT(data, value.second, wpos, capacity);
|
|
|
}
|
|
|
|
|
|
using namespace std;
|
|
@@ -1089,12 +1190,21 @@ namespace Chromium {
|
|
|
}
|
|
|
|
|
|
void CWSCodec::SerializeGetVarReq(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg) {
|
|
|
- int i4 = 0;
|
|
|
- i4 = cJSON_GetObjectItem(js, "transID")->valueint;
|
|
|
- WriteT(data, i4, wpos, capacity);
|
|
|
- CSimpleStringA s = "";
|
|
|
- s = cJSON_GetObjectItem(js, "name")->valuestring;
|
|
|
- WriteT(data, s, wpos, capacity);
|
|
|
+ auto transID = json_deal::getIntergerFromCjsonObj(js, "transID");
|
|
|
+ if (transID.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeGetVarReq get transID failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ auto name = json_deal::getStringFromCjsonObj(js, "name");
|
|
|
+ if (name.first == false)
|
|
|
+ {
|
|
|
+ DbgEx("CWSCodec::SerializeGetVarReq get name failed");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ WriteT(data, transID.second, wpos, capacity);
|
|
|
+ WriteT(data, name.second, wpos, capacity);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1122,7 +1232,8 @@ namespace Chromium {
|
|
|
return std::make_pair(-1, "error binlen");
|
|
|
};
|
|
|
|
|
|
- while (it != pI->mRequestInterpreter.mParamList.end()) {
|
|
|
+ while (it != pI->mRequestInterpreter.mParamList.end())
|
|
|
+ {
|
|
|
if (it->mType == "int")
|
|
|
{
|
|
|
unsigned int d = 0;
|