|
@@ -297,50 +297,63 @@ std::string ProtoParser::connectPack(std::string userName)
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
-std::string ProtoParser::publish(std::string topic, std::string payload, uint32_t &msgId)
|
|
|
+std::string ProtoParser::publish(const std::string &topic, const std::string &payload, const std::string &request, uint32_t &msgId, std::function<void(uint32_t, uint32_t, const std::string &, const std::string &, const std::string &)> cb, const std::string & par)
|
|
|
{
|
|
|
+ auto now = timestamp_now();
|
|
|
{
|
|
|
std::lock_guard<std::mutex> l(_publishLock);
|
|
|
- for (auto &it : _publishes)
|
|
|
+#ifdef DUMP
|
|
|
+ MqttLog(LOG_INFO, LOG_TYPE_MQTT, "_publishes size: %d", _publishes.size());
|
|
|
+#endif
|
|
|
+ for (auto it = _publishes.begin(); it != _publishes.end();)
|
|
|
{
|
|
|
- if (it.second.topic == topic && it.second.payload == payload)
|
|
|
+ if ((now - it->second->time) > 60 * 1000)
|
|
|
+ {
|
|
|
+ MqttLog(LOG_WARN, LOG_TYPE_FUNC, "remove too early publish, topic: %s, msgId: %d, time: %lld", it->second->topic.c_str(), it->first, it->second->time);
|
|
|
+ it = _publishes.erase(it);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (it->second->topic == topic && it->second->payload == payload)
|
|
|
{
|
|
|
- msgId = it.first;
|
|
|
+ msgId = it->first;
|
|
|
#ifdef DUMP
|
|
|
- MqttLog(LOG_WARN, LOG_TYPE_FUNC, "already send topic: %s", topic.c_str());
|
|
|
+ MqttLog(LOG_INFO, LOG_TYPE_MQTT, "already send topic: %s, msgId: %d, request: %s", topic.c_str(), msgId, request.c_str());
|
|
|
#endif
|
|
|
return "";
|
|
|
}
|
|
|
+ it++;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-#ifdef DUMP
|
|
|
- MqttLog(LOG_INFO, LOG_TYPE_MQTT, "publish topic: %s, payload size: %d", topic.c_str(), payload.size());
|
|
|
-#endif
|
|
|
MqttPublishPacket pack;
|
|
|
pack.header.byte = 0;
|
|
|
pack.header.bits.type = MqttMsgPublish;
|
|
|
pack.header.bits.qos = MqttQosExactlyOnce;
|
|
|
-
|
|
|
- pack.topic = topic;
|
|
|
+ pack.topic = topic;
|
|
|
+ pack.payload = payload;
|
|
|
{
|
|
|
- std::lock_guard<std::mutex> l(_msgIdLock);
|
|
|
+ std::lock_guard<std::mutex> l(_publishLock);
|
|
|
pack.msgId = ++_msgId;
|
|
|
if (pack.msgId == 0)
|
|
|
pack.msgId = ++_msgId;
|
|
|
msgId = pack.msgId;
|
|
|
- _topics.emplace(pack.msgId, topic);
|
|
|
+ auto info = new PublishInfo();
|
|
|
+ info->cb = cb;
|
|
|
+ info->payload = payload;
|
|
|
+ info->topic = topic;
|
|
|
+ info->time = timestamp_now();
|
|
|
+ info->par = par;
|
|
|
+ _publishes.emplace(pack.msgId, info);
|
|
|
+ #ifdef DUMP
|
|
|
+ MqttLog(LOG_INFO, LOG_TYPE_MQTT, "_publishes size: %d", _publishes.size());
|
|
|
+ #endif
|
|
|
}
|
|
|
- pack.payload = payload;
|
|
|
-
|
|
|
+#ifdef DUMP
|
|
|
+ MqttLog(LOG_INFO, LOG_TYPE_MQTT, "publish topic: %s, msgId: %d, request: %s", topic.c_str(), pack.msgId, request.c_str());
|
|
|
+#endif
|
|
|
std::string str;
|
|
|
mqttToBuffer(&pack, str);
|
|
|
//MqttLog(MQTT_LOG_INFO, "publish packet len: %d", str.length());
|
|
|
-
|
|
|
- {
|
|
|
- std::lock_guard<std::mutex> l(_publishLock);
|
|
|
- _publishes[msgId] = PublishInfo{topic, payload};
|
|
|
- }
|
|
|
return str;
|
|
|
}
|
|
|
|
|
@@ -393,7 +406,9 @@ std::string ProtoParser::searchConversation(std::string keyword, std::string typ
|
|
|
int ProtoParser::parse(std::vector<uint8_t> &data)
|
|
|
{
|
|
|
MqttHeader *header = (MqttHeader *)&data[0];
|
|
|
- // MqttLog(MQTT_LOG_INFO, "parse type: %d", header->bits.type);
|
|
|
+#ifdef DUMP
|
|
|
+ MqttLog(LOG_DEBUG, LOG_TYPE_FUNC, "parse type: %d", header->bits.type);
|
|
|
+#endif
|
|
|
switch (header->bits.type)
|
|
|
{
|
|
|
case MqttMsgConnAck:
|
|
@@ -441,11 +456,13 @@ int ProtoParser::parse(std::vector<uint8_t> &data)
|
|
|
_payload = "";
|
|
|
_topic = pack.topic;
|
|
|
#ifdef DUMP
|
|
|
- MqttLog(LOG_INFO, LOG_TYPE_MQTT, "recv publish from server topic: %s, len: %d", _topic.c_str(), pack.payload.length());
|
|
|
+ MqttLog(LOG_INFO, LOG_TYPE_FUNC, "recv publish from server topic: %s, respMsgId: %d, len: %d", _topic.c_str(), _respMsgId, pack.payload.length());
|
|
|
#endif
|
|
|
if (_topic.length() > 0 && pack.payload.length() > 0)
|
|
|
{
|
|
|
- MqttLogHex(LOG_INFO, LOG_TYPE_MQTT, pack.payload);
|
|
|
+#ifdef DUMP
|
|
|
+ MqttLogHex(LOG_DEBUG, LOG_TYPE_MQTT, pack.payload);
|
|
|
+#endif
|
|
|
parsePayload(pack.payload, true);
|
|
|
}
|
|
|
}
|
|
@@ -458,30 +475,32 @@ int ProtoParser::parse(std::vector<uint8_t> &data)
|
|
|
_rc = pack.rc;
|
|
|
_payload = "";
|
|
|
_topic = "";
|
|
|
- std::lock_guard<std::mutex> l(_msgIdLock);
|
|
|
+ PublishInfo * info=nullptr;
|
|
|
{
|
|
|
- auto it = _topics.find(pack.msgId);
|
|
|
- if (it != _topics.end())
|
|
|
+ std::lock_guard<std::mutex> l(_publishLock);
|
|
|
+ auto it = _publishes.find(pack.msgId);
|
|
|
+ if (it != _publishes.end())
|
|
|
{
|
|
|
- _topic = it->second;
|
|
|
- _topics.erase(it);
|
|
|
+ info = it->second;
|
|
|
+ _topic = info->topic;
|
|
|
+ _publishes.erase(it);
|
|
|
+ MqttLog(LOG_INFO, LOG_TYPE_MQTT, "_publishes size: %d", _publishes.size());
|
|
|
}
|
|
|
}
|
|
|
if (_topic.length() > 0 && pack.payload.length() > 0)
|
|
|
{
|
|
|
_rc = parsePayload(pack.payload, false);
|
|
|
}
|
|
|
+ if (info!=nullptr)
|
|
|
{
|
|
|
- std::lock_guard<std::mutex> l(_callbackLock);
|
|
|
- auto it = _callbacks.find(_respMsgId);
|
|
|
- if (it != _callbacks.end())
|
|
|
+ if (info->cb!=nullptr)
|
|
|
{
|
|
|
- it->second.cb(_rc, _payload);
|
|
|
- _callbacks.erase(it);
|
|
|
+ info->cb(_respMsgId, _rc, pack.payload, _payload, info->par);
|
|
|
}
|
|
|
+ delete info;
|
|
|
}
|
|
|
#ifdef DUMP
|
|
|
- MqttLog(LOG_DEBUG, LOG_TYPE_MQTT, "recv MqttMsgPubAck from server topic: %s", _topic.c_str());
|
|
|
+ MqttLog(LOG_INFO, LOG_TYPE_MQTT, "recv MqttMsgPubAck from server topic: %s, msgId: %d, rc: %d", _topic.c_str(), _respMsgId, _rc);
|
|
|
#endif
|
|
|
}
|
|
|
break;
|
|
@@ -506,7 +525,7 @@ unsigned char ProtoParser::parsePayload(std::string &payload, bool pub)
|
|
|
{
|
|
|
auto flag = payload[0];
|
|
|
#ifdef DUMP
|
|
|
- MqttLog(LOG_INFO, LOG_TYPE_MQTT, "flag: %d, len: %d", flag, payload.length());
|
|
|
+ MqttLog(LOG_DEBUG, LOG_TYPE_MQTT, "flag: %d, len: %d", flag, payload.length());
|
|
|
#endif
|
|
|
payload.erase(payload.begin());
|
|
|
if ((flag & 1) != 0)
|
|
@@ -518,25 +537,19 @@ unsigned char ProtoParser::parsePayload(std::string &payload, bool pub)
|
|
|
rc = payload[0];
|
|
|
payload.erase(payload.begin());
|
|
|
#ifdef DUMP
|
|
|
- MqttLog(LOG_INFO, LOG_TYPE_MQTT, "rc: %d", rc);
|
|
|
+ MqttLog(LOG_DEBUG, LOG_TYPE_MQTT, "rc: %d", rc);
|
|
|
#endif
|
|
|
}
|
|
|
str = dataDecrypt(payload);
|
|
|
#ifdef DUMP
|
|
|
- MqttLog(LOG_INFO, LOG_TYPE_FUNC, "decrypt size: %d, src: %d", str.length(), payload.length());
|
|
|
+ MqttLog(LOG_DEBUG, LOG_TYPE_FUNC, "decrypt size: %d, src: %d", str.length(), payload.length());
|
|
|
#endif
|
|
|
+ payload = str;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
str = payload;
|
|
|
}
|
|
|
- if (!pub)
|
|
|
- {
|
|
|
- std::lock_guard<std::mutex> l(_publishLock);
|
|
|
- auto it = _publishes.find(_respMsgId);
|
|
|
- if (it != _publishes.end())
|
|
|
- _publishes.erase(it);
|
|
|
- }
|
|
|
if (str.length() > 0)
|
|
|
{
|
|
|
if (_topic.compare("FP") == 0) // pullFriend
|
|
@@ -788,7 +801,7 @@ std::string ProtoParser::pullFriendPack(std::string requestJson, uint32_t &msgId
|
|
|
v.SerializeToString(&str);
|
|
|
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("FP", str, msgId);
|
|
|
+ return publish("FP", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::pullFriendRequestPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -800,7 +813,7 @@ std::string ProtoParser::pullFriendRequestPack(std::string requestJson, uint32_t
|
|
|
v.SerializeToString(&str);
|
|
|
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("FRP", str, msgId);
|
|
|
+ return publish("FRP", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::addFriendPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -816,7 +829,7 @@ std::string ProtoParser::addFriendPack(std::string requestJson, uint32_t &msgId)
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("FAR", str, msgId);
|
|
|
+ return publish("FAR", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::addGroupMemberPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -831,7 +844,7 @@ std::string ProtoParser::addGroupMemberPack(std::string requestJson, uint32_t &m
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GAM", str, msgId);
|
|
|
+ return publish("GAM", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::createGroupPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -847,7 +860,7 @@ std::string ProtoParser::createGroupPack(std::string requestJson, uint32_t &msgI
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GC", str, msgId);
|
|
|
+ return publish("GC", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::deleteFriendPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -863,7 +876,7 @@ std::string ProtoParser::deleteFriendPack(std::string requestJson, uint32_t &msg
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("FDL", str, msgId);
|
|
|
+ return publish("FDL", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::dismissGroupPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -879,7 +892,7 @@ std::string ProtoParser::dismissGroupPack(std::string requestJson, uint32_t &msg
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GD", str, msgId);
|
|
|
+ return publish("GD", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::getGroupInfoPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -894,7 +907,7 @@ std::string ProtoParser::getGroupInfoPack(std::string requestJson, uint32_t &msg
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GPGI", str, msgId);
|
|
|
+ return publish("GPGI", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::getGroupMemberPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -910,7 +923,7 @@ std::string ProtoParser::getGroupMemberPack(std::string requestJson, uint32_t &m
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GPGM", str, msgId);
|
|
|
+ return publish("GPGM", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::getUserInfoPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -923,13 +936,13 @@ std::string ProtoParser::getUserInfoPack(std::string requestJson, uint32_t &msgI
|
|
|
return "";
|
|
|
}
|
|
|
#ifdef DUMP
|
|
|
- MqttLog(LOG_INFO, LOG_TYPE_FUNC, "getUserInfoPack: %d, %s", par.request().size(), par.request().at(0).uid().c_str());
|
|
|
+ MqttLog(LOG_DEBUG, LOG_TYPE_FUNC, "getUserInfoPack: size: %d, first uid: %s", par.request().size(), par.request().at(0).uid().c_str());
|
|
|
#endif
|
|
|
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- auto ret = publish("UPUI", str, msgId);
|
|
|
+ auto ret = publish("UPUI", str, requestJson, msgId);
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -949,7 +962,7 @@ std::string ProtoParser::getUserSettingPack(std::string requestJson, uint32_t &m
|
|
|
v.SerializeToString(&str);
|
|
|
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("UG", str, msgId);
|
|
|
+ return publish("UG", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::handleFriendRequestPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -965,7 +978,7 @@ std::string ProtoParser::handleFriendRequestPack(std::string requestJson, uint32
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("FHR", str, msgId);
|
|
|
+ return publish("FHR", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::loadRemoteMessagesPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -981,7 +994,7 @@ std::string ProtoParser::loadRemoteMessagesPack(std::string requestJson, uint32_
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("LRM", str, msgId);
|
|
|
+ return publish("LRM", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::modifyMyInfoPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -997,7 +1010,7 @@ std::string ProtoParser::modifyMyInfoPack(std::string requestJson, uint32_t &msg
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("MMI", str, msgId);
|
|
|
+ return publish("MMI", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::pullMessagePack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1014,7 +1027,7 @@ std::string ProtoParser::pullMessagePack(std::string requestJson, uint32_t &msgI
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("MP", str, msgId);
|
|
|
+ return publish("MP", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::putUserSettingPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1030,7 +1043,7 @@ std::string ProtoParser::putUserSettingPack(std::string requestJson, uint32_t &m
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("UP", str, msgId);
|
|
|
+ return publish("UP", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::quitGroupPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1046,7 +1059,7 @@ std::string ProtoParser::quitGroupPack(std::string requestJson, uint32_t &msgId)
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GQ", str, msgId);
|
|
|
+ return publish("GQ", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::recallMessagePack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1059,12 +1072,20 @@ std::string ProtoParser::recallMessagePack(std::string requestJson, uint32_t &ms
|
|
|
msgId = 0;
|
|
|
return "";
|
|
|
}
|
|
|
- par.set_id(GetInt64(doc["id"]));
|
|
|
+ auto mid = GetInt64(doc["id"]);
|
|
|
+ par.set_id(mid);
|
|
|
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("MR", str, msgId);
|
|
|
+ std::string s = std::to_string(mid);
|
|
|
+ return publish("MR", str, requestJson, msgId, [&](auto msgId, auto rc, auto& org, auto& payload, auto& par)
|
|
|
+ {
|
|
|
+ if (rc == 0)
|
|
|
+ {
|
|
|
+ p->recallMessage(atoll(par.c_str()));
|
|
|
+ }
|
|
|
+ }, s);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::syncFriendRequestUnreadPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1080,7 +1101,7 @@ std::string ProtoParser::syncFriendRequestUnreadPack(std::string requestJson, ui
|
|
|
std::string str;
|
|
|
v.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("FRUS", str, msgId);
|
|
|
+ return publish("FRUS", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::sendMessagePack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1099,17 +1120,30 @@ std::string ProtoParser::sendMessagePack(std::string requestJson, uint32_t &msgI
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- auto ret = publish("MS", str, msgId);
|
|
|
- p->sendMessage(par, msgId);
|
|
|
-
|
|
|
- addCallback(msgId, [&](auto i, auto s) {
|
|
|
- if (s.length() == 16)
|
|
|
+ auto ret = publish("MS", str, requestJson, msgId, [&](auto msgId, auto rc, auto& org, auto& payload, auto& par) {
|
|
|
+ if (rc == 0)
|
|
|
{
|
|
|
- auto mid = htonll(*(int64_t *)s.c_str());
|
|
|
- auto ts = htonll(*((int64_t *)str.c_str()) + 1);
|
|
|
+ if (org.length() == 16)
|
|
|
+ {
|
|
|
+ int64_t *ptr = (int64_t *)org.c_str();
|
|
|
+ auto mid = htonll(*ptr);
|
|
|
+ auto ts = htonll(*(ptr + 1));
|
|
|
+#ifdef DUMP
|
|
|
+ MqttLog(LOG_INFO, LOG_TYPE_FUNC, "update message: %d, mid: %lld, ts: %lld", msgId, mid, ts);
|
|
|
+#endif
|
|
|
+ p->updateMessage(msgId, mid, ts);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MqttLog(LOG_WARN, LOG_TYPE_FUNC, "unexpect send message callback: %d", org.length());
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
+ if (ret.length() > 0)
|
|
|
+ {
|
|
|
+ MqttLog(LOG_INFO, LOG_TYPE_FUNC, "send message with msgId: %d", msgId);
|
|
|
+ p->sendMessage(par, msgId);
|
|
|
+ }
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
@@ -1134,7 +1168,7 @@ std::string ProtoParser::uploadMediaPack(std::string requestJson, uint32_t &msgI
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GMUT", str, msgId);
|
|
|
+ return publish("GMUT", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::RriendRequestUnreadSyncPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1151,7 +1185,7 @@ std::string ProtoParser::RriendRequestUnreadSyncPack(std::string requestJson, ui
|
|
|
v.SerializeToString(&str);
|
|
|
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("FRUS", str, msgId);
|
|
|
+ return publish("FRUS", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::userSearchPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1174,7 +1208,7 @@ std::string ProtoParser::userSearchPack(std::string requestJson, uint32_t &msgId
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("US", str, msgId);
|
|
|
+ return publish("US", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::kickoffGroupMemberPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1218,7 +1252,7 @@ std::string ProtoParser::kickoffGroupMemberPack(std::string requestJson, uint32_
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GKM", str, msgId);
|
|
|
+ return publish("GKM", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::modifyGroupInfoPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1256,7 +1290,7 @@ std::string ProtoParser::modifyGroupInfoPack(std::string requestJson, uint32_t &
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GMI", str, msgId);
|
|
|
+ return publish("GMI", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::modifyGroupAliasPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1295,7 +1329,7 @@ std::string ProtoParser::modifyGroupAliasPack(std::string requestJson, uint32_t
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GMA", str, msgId);
|
|
|
+ return publish("GMA", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::setFriendAliasPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1317,7 +1351,7 @@ std::string ProtoParser::setFriendAliasPack(std::string requestJson, uint32_t &m
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("FALS", str, msgId);
|
|
|
+ return publish("FALS", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::transferGroupPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1354,7 +1388,7 @@ std::string ProtoParser::transferGroupPack(std::string requestJson, uint32_t &ms
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GTG", str, msgId);
|
|
|
+ return publish("GTG", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::setGroupManagerPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1397,7 +1431,7 @@ std::string ProtoParser::setGroupManagerPack(std::string requestJson, uint32_t &
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GTG", str, msgId);
|
|
|
+ return publish("GTG", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::clearMessagesPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1418,7 +1452,7 @@ std::string ProtoParser::clearMessagesPack(std::string requestJson, uint32_t &ms
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("CMD", str, msgId);
|
|
|
+ return publish("CMD", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::modifyGroupMemberAliasPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1456,7 +1490,7 @@ std::string ProtoParser::modifyGroupMemberAliasPack(std::string requestJson, uin
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GMMA", str, msgId);
|
|
|
+ return publish("GMMA", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::modifyGroupMemberExtraPack(std::string requestJson, uint32_t &msgId)
|
|
@@ -1495,23 +1529,7 @@ std::string ProtoParser::modifyGroupMemberExtraPack(std::string requestJson, uin
|
|
|
std::string str;
|
|
|
par.SerializeToString(&str);
|
|
|
str = dataEncrypt(str);
|
|
|
- return publish("GMME", str, msgId);
|
|
|
-}
|
|
|
-
|
|
|
-void ProtoParser::addCallback(uint32_t msgId, std::function<void(uint32_t, std::string)> cb)
|
|
|
-{
|
|
|
- std::lock_guard<std::mutex> l(_callbackLock);
|
|
|
- TopicCallback tcb;
|
|
|
- tcb.cb = cb;
|
|
|
- _callbacks.emplace(std::make_pair(msgId, tcb));
|
|
|
-}
|
|
|
-
|
|
|
-void ProtoParser::removeCallback(uint32_t msgId)
|
|
|
-{
|
|
|
- std::lock_guard<std::mutex> l(_callbackLock);
|
|
|
- auto it = _callbacks.find(msgId);
|
|
|
- if (it != _callbacks.end())
|
|
|
- _callbacks.erase(it);
|
|
|
+ return publish("GMME", str, requestJson, msgId);
|
|
|
}
|
|
|
|
|
|
std::string ProtoParser::getUserInfo(std::string userId, std::string groupId)
|
|
@@ -1964,6 +1982,11 @@ EM_BOOL ProtoParser::onWebSocketError(int eventType, const EmscriptenWebSocketEr
|
|
|
EM_BOOL ProtoParser::onWebSocketOpen(int eventType, const EmscriptenWebSocketOpenEvent *websocketEvent, void *userData)
|
|
|
{
|
|
|
ProtoParser *parser = (ProtoParser *)userData;
|
|
|
+
|
|
|
+ {
|
|
|
+ std::lock_guard<std::mutex> l(parser->_publishLock);
|
|
|
+ parser->_publishes.clear();
|
|
|
+ }
|
|
|
//MqttLog(MQTT_LOG_INFO, "ProtoParser::onWebSocketOpen, uid: %s", parser->_uid.c_str());
|
|
|
auto res = parser->connectPack(parser->_uid);
|
|
|
parser->send(res);
|
|
@@ -1978,7 +2001,7 @@ EM_BOOL ProtoParser::onWebSocketOpen(int eventType, const EmscriptenWebSocketOpe
|
|
|
EM_BOOL ProtoParser::onWebSocketMessage(int eventType, const EmscriptenWebSocketMessageEvent *websocketEvent, void *userData)
|
|
|
{
|
|
|
#ifdef DUMP
|
|
|
- MqttLog(MQTT_LOG_INFO, "ProtoParser::onWebSocketMessage, bin: %d, len: %d", !websocketEvent->isText, websocketEvent->numBytes);
|
|
|
+ MqttLog(LOG_DEBUG, LOG_TYPE_FUNC, "ProtoParser::onWebSocketMessage, bin: %d, len: %d", !websocketEvent->isText, websocketEvent->numBytes);
|
|
|
#endif
|
|
|
/*if (websocketEvent->isText)
|
|
|
return EM_TRUE;*/
|