diff options
author | Sergey Bolhovskoy <elzorfox@ya.ru> | 2015-05-28 10:09:40 +0000 |
---|---|---|
committer | Sergey Bolhovskoy <elzorfox@ya.ru> | 2015-05-28 10:09:40 +0000 |
commit | 7b2a41081e47ef013f53145ae5d7f6395ff26833 (patch) | |
tree | 21e5da55ec137a67b76252b47f63cf7b61613249 /protocols | |
parent | 5f288f2ae11634f7470e6ab5c09f9625c12021c6 (diff) |
VKontakte:
rework code to JSONNode class
upgrade vk api to 5.33
code cleanup
version bump
git-svn-id: http://svn.miranda-ng.org/main/trunk@13868 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r-- | protocols/VKontakte/src/misc.cpp | 288 | ||||
-rw-r--r-- | protocols/VKontakte/src/stdafx.h | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/version.h | 2 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk.h | 7 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_captcha.cpp | 13 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_chats.cpp | 138 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_feed.cpp | 274 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_files.cpp | 32 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_history.cpp | 61 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_messages.cpp | 109 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_pollserver.cpp | 65 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.cpp | 8 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_proto.h | 39 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_search.cpp | 99 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_status.cpp | 20 | ||||
-rw-r--r-- | protocols/VKontakte/src/vk_thread.cpp | 117 |
16 files changed, 639 insertions, 635 deletions
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp index f8ad79efd1..1da3b4cf92 100644 --- a/protocols/VKontakte/src/misc.cpp +++ b/protocols/VKontakte/src/misc.cpp @@ -17,9 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "stdafx.h"
-static char* szImageTypes[] = { "photo_2560", "photo_1280", "photo_807", "photo_604", "photo_256", "photo_130", "photo_128", "photo_75", "photo_64" };
+static const char* szImageTypes[] = { "photo_2560", "photo_1280", "photo_807", "photo_604", "photo_256", "photo_130", "photo_128", "photo_75", "photo_64" };
-static char* szGiftTypes[] = { "thumb_256", "thumb_96", "thumb_48" };
+static const char* szGiftTypes[] = { "thumb_256", "thumb_96", "thumb_48" };
+
+JSONNode nullNode(JSON_NULL);
bool IsEmpty(TCHAR *str)
{
@@ -39,13 +41,6 @@ bool IsEmpty(char *str) return false;
}
-CMString json_as_CMString(JSONNODE* pNode)
-{
- ptrT pString(json_as_string(pNode));
- CMString tszString = pString;
- return tszString;
-}
-
LPCSTR findHeader(NETLIBHTTPREQUEST *pReq, LPCSTR szField)
{
for (int i = 0; i < pReq->headersCount; i++)
@@ -306,30 +301,32 @@ bool CVkProto::CheckMid(LIST<void> &lList, int guid) /////////////////////////////////////////////////////////////////////////////////////////
-JSONNODE* CVkProto::CheckJsonResponse(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, JSONROOT &pRoot)
+JSONNode& CVkProto::CheckJsonResponse(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, JSONNode &root)
{
- debugLogA("CVkProto::CheckJsonResponse");
- pRoot.Parse(reply->pData);
- if (pRoot == NULL)
- return NULL;
-
- if (!CheckJsonResult(pReq, pRoot))
- return NULL;
+ debugLogA("CVkProto::CheckJsonResponse JSONNode");
+ root = JSONNode::parse(reply->pData);
- return json_get(pRoot, "response");
+ if (!root)
+ return nullNode;
+ if (!CheckJsonResult(pReq, root))
+ return nullNode;
+
+ return root["response"];
}
-bool CVkProto::CheckJsonResult(AsyncHttpRequest *pReq, JSONNODE *pNode)
+bool CVkProto::CheckJsonResult(AsyncHttpRequest *pReq, JSONNode &jnNode)
{
debugLogA("CVkProto::CheckJsonResult");
- if (pNode == NULL)
+ if (!jnNode)
return false;
- JSONNODE *pError = json_get(pNode, "error"), *pErrorCode = json_get(pError, "error_code");
- if (pError == NULL || pErrorCode == NULL)
+ const JSONNode &jnError = jnNode["error"];
+ const JSONNode &jnErrorCode = jnError["error_code"];
+
+ if (!jnError || !jnErrorCode)
return true;
- int iErrorCode = json_as_int(pErrorCode);
+ int iErrorCode = jnErrorCode.as_int();
debugLogA("CVkProto::CheckJsonResult %d", iErrorCode);
CVkFileUploadParam * fup = (CVkFileUploadParam *)pReq->pUserInfo;
CVkSendMsgParam *param = (CVkSendMsgParam*)pReq->pUserInfo;
@@ -340,16 +337,16 @@ bool CVkProto::CheckJsonResult(AsyncHttpRequest *pReq, JSONNODE *pNode) case VKERR_ACCESS_DENIED:
if (time(NULL) - getDword("LastAccessTokenTime", 0) > 60 * 60 * 24) {
debugLogA("CVkProto::CheckJsonResult VKERR_ACCESS_DENIED (AccessToken fail?)");
- setDword("LastAccessTokenTime", (DWORD)time(NULL));
+ setDword("LastAccessTokenTime", (DWORD)time(NULL));
delSetting("AccessToken");
ShutdownSession();
return false;
}
- debugLogA("CVkProto::CheckJsonResult VKERR_ACCESS_DENIED");
+ debugLogA("CVkProto::CheckJsonResult VKERR_ACCESS_DENIED");
MsgPopup(NULL, TranslateT("Access denied! Data will not be sent or received."), TranslateT("Error"), true);
break;
case VKERR_CAPTCHA_NEEDED:
- ApplyCaptcha(pReq, pError);
+ ApplyCaptcha(pReq, jnError);
break;
case VKERR_COULD_NOT_SAVE_FILE:
case VKERR_INVALID_ALBUM_ID:
@@ -399,10 +396,9 @@ bool CVkProto::CheckJsonResult(AsyncHttpRequest *pReq, JSONNODE *pNode) void CVkProto::OnReceiveSmth(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq)
{
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- ptrT ptszLog(json_as_string(pResponse));
- debugLog(_T("CVkProto::OnReceiveSmth %s"), ptszLog);
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ debugLogA("CVkProto::OnReceiveSmth %d", jnResponse.as_int());
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -845,48 +841,49 @@ CMString CVkProto::SpanVKNotificationType(CMString& tszType, VKObjType& vkFeedba return tszRes;
}
-CMString CVkProto::GetVkPhotoItem(JSONNODE *pPhoto, BBCSupport iBBC)
+CMString CVkProto::GetVkPhotoItem(const JSONNode &jnPhoto, BBCSupport iBBC)
{
CMString tszRes;
- if (pPhoto == NULL)
+ if (!jnPhoto)
return tszRes;
- ptrT ptszLink, ptszPreviewLink;
+ CMString tszLink, tszPreviewLink;
for (int i = 0; i < SIZEOF(szImageTypes); i++) {
- JSONNODE *n = json_get(pPhoto, szImageTypes[i]);
- if (n != NULL) {
- ptszLink = json_as_string(n);
+ const JSONNode &n = jnPhoto[szImageTypes[i]];
+ if (!n.isnull()) {
+ tszLink = n.as_mstring();
break;
}
}
switch (m_iIMGBBCSupport) {
case imgNo:
- ptszPreviewLink = NULL;
+ tszPreviewLink = _T("");
break;
case imgFullSize:
- ptszPreviewLink = ptszLink;
+ tszPreviewLink = tszLink;
break;
case imgPreview130:
case imgPreview604:
- ptszPreviewLink = json_as_string(json_get(pPhoto, m_iIMGBBCSupport == imgPreview130 ? "photo_130" : "photo_604"));
+ tszPreviewLink = jnPhoto[ m_iIMGBBCSupport == imgPreview130 ? "photo_130" : "photo_604"].as_mstring();
break;
}
- int iWidth = json_as_int(json_get(pPhoto, "width"));
- int iHeight = json_as_int(json_get(pPhoto, "height"));
+ int iWidth = jnPhoto["width"].as_int();
+ int iHeight = jnPhoto["height"].as_int();
- tszRes.AppendFormat(_T("%s (%dx%d)"), SetBBCString(TranslateT("Photo"), iBBC, vkbbcUrl, ptszLink).GetBuffer(), iWidth, iHeight);
+ tszRes.AppendFormat(_T("%s (%dx%d)"), SetBBCString(TranslateT("Photo"), iBBC, vkbbcUrl, tszLink.GetBuffer()).GetBuffer(), iWidth, iHeight);
if (m_iIMGBBCSupport)
- tszRes.AppendFormat(_T("\n\t[img]%s[/img]"), ptszPreviewLink ? ptszPreviewLink : (ptszLink ? ptszLink : _T("")));
- CMString tszText = json_as_CMString(json_get(pPhoto, "text"));
+ tszRes.AppendFormat(_T("\n\t[img]%s[/img]"), !tszPreviewLink.IsEmpty() ? tszPreviewLink.GetBuffer() : (!tszLink.IsEmpty() ? tszLink.GetBuffer() : _T("")));
+ CMString tszText(jnPhoto["text"].as_mstring());
if (!tszText.IsEmpty())
tszRes += _T("\n") + tszText;
return tszRes;
}
+
CMString CVkProto::SetBBCString(TCHAR *ptszString, BBCSupport iBBC, VKBBCType bbcType, TCHAR *tszAddString)
{
CVKBBCItem bbcItem[] = {
@@ -955,160 +952,162 @@ CMString& CVkProto::ClearFormatNick(CMString& tszText) /////////////////////////////////////////////////////////////////////////////////////////
-CMString CVkProto::GetAttachmentDescr(JSONNODE *pAttachments, BBCSupport iBBC)
+CMString CVkProto::GetAttachmentDescr(const JSONNode jnAttachments, BBCSupport iBBC)
{
debugLogA("CVkProto::GetAttachmentDescr");
CMString res;
- if (pAttachments == NULL) {
+ if (!jnAttachments) {
debugLogA("CVkProto::GetAttachmentDescr pAttachments == NULL");
return res;
}
res += SetBBCString(TranslateT("Attachments:"), iBBC, vkbbcB);
res.AppendChar('\n');
- JSONNODE *pAttach;
- for (int k = 0; (pAttach = json_at(pAttachments, k)) != NULL; k++) {
+
+ for (auto it = jnAttachments.begin(); it != jnAttachments.end(); ++it) {
+ const JSONNode jnAttach = (*it);
+
res.AppendChar('\t');
- ptrT ptszType(json_as_string(json_get(pAttach, "type")));
- if (!mir_tstrcmp(ptszType, _T("photo"))) {
- JSONNODE *pPhoto = json_get(pAttach, "photo");
- if (pPhoto == NULL)
+ CMString tszType(jnAttach["type"].as_mstring());
+ if (tszType == _T("photo")) {
+ const JSONNode &jnPhoto = jnAttach["photo"];
+ if (!jnPhoto)
continue;
- res += GetVkPhotoItem(pPhoto, iBBC);
+ res += GetVkPhotoItem(jnPhoto, iBBC);
}
- else if (!mir_tstrcmp(ptszType, _T("audio"))) {
- JSONNODE *pAudio = json_get(pAttach, "audio");
- if (pAudio == NULL)
+ else if (tszType ==_T("audio")) {
+ const JSONNode &jnAudio = jnAttach["audio"];
+ if (!jnAudio)
continue;
- ptrT ptszArtist(json_as_string(json_get(pAudio, "artist")));
- ptrT ptszTitle(json_as_string(json_get(pAudio, "title")));
- ptrT ptszUrl(json_as_string(json_get(pAudio, "url")));
+ CMString tszArtist(jnAudio["artist"].as_mstring());
+ CMString tszTitle(jnAudio["title"].as_mstring());
+ CMString tszUrl(jnAudio["url"].as_mstring());
CMString tszAudio;
- tszAudio.AppendFormat(_T("%s - %s"), ptszArtist, ptszTitle);
+ tszAudio.AppendFormat(_T("%s - %s"), tszArtist.GetBuffer(), tszTitle.GetBuffer());
res.AppendFormat(_T("%s: %s"),
- SetBBCString(TranslateT("Audio"), iBBC, vkbbcB).GetBuffer(),
- SetBBCString(tszAudio.GetBuffer(), iBBC, vkbbcUrl, ptszUrl).GetBuffer());
+ SetBBCString(TranslateT("Audio"), iBBC, vkbbcB).GetBuffer(),
+ SetBBCString(tszAudio.GetBuffer(), iBBC, vkbbcUrl, tszUrl.GetBuffer()).GetBuffer());
}
- else if (!mir_tstrcmp(ptszType, _T("video"))) {
- JSONNODE *pVideo = json_get(pAttach, "video");
- if (pVideo == NULL)
+ else if (tszType ==_T("video")) {
+ const JSONNode &jnVideo = jnAttach["video"];
+ if (jnVideo)
continue;
- ptrT ptszTitle(json_as_string(json_get(pVideo, "title")));
- int vid = json_as_int(json_get(pVideo, "id"));
- int ownerID = json_as_int(json_get(pVideo, "owner_id"));
+ CMString tszTitle(jnVideo["title"].as_mstring());
+ int vid = jnVideo["id"].as_int();
+ int ownerID = jnVideo["owner_id"].as_int();
CMString tszUrl;
tszUrl.AppendFormat(_T("http://vk.com/video%d_%d"), ownerID, vid);
- res.AppendFormat(_T("%s: %s"),
- SetBBCString(TranslateT("Video"), iBBC, vkbbcB).GetBuffer(),
- SetBBCString(ptszTitle, iBBC, vkbbcUrl, tszUrl.GetBuffer()).GetBuffer());
+ res.AppendFormat(_T("%s: %s"),
+ SetBBCString(TranslateT("Video"), iBBC, vkbbcB).GetBuffer(),
+ SetBBCString(tszTitle.GetBuffer(), iBBC, vkbbcUrl, tszUrl.GetBuffer()).GetBuffer());
}
- else if (!mir_tstrcmp(ptszType, _T("doc"))) {
- JSONNODE *pDoc = json_get(pAttach, "doc");
- if (pDoc == NULL)
+ else if (tszType == _T("doc")) {
+ const JSONNode &jnDoc = jnAttach["doc"];
+ if (!jnDoc)
continue;
- ptrT ptszTitle(json_as_string(json_get(pDoc, "title")));
- ptrT ptszUrl(json_as_string(json_get(pDoc, "url")));
- res.AppendFormat(_T("%s: %s"),
- SetBBCString(TranslateT("Document"), iBBC, vkbbcB).GetBuffer(),
- SetBBCString(ptszTitle, iBBC, vkbbcUrl, ptszUrl).GetBuffer());
+ CMString tszTitle(jnDoc["title"].as_mstring());
+ CMString tszUrl(jnDoc["url"].as_mstring());
+ res.AppendFormat(_T("%s: %s"),
+ SetBBCString(TranslateT("Document"), iBBC, vkbbcB).GetBuffer(),
+ SetBBCString(tszTitle.GetBuffer(), iBBC, vkbbcUrl, tszUrl.GetBuffer()).GetBuffer());
}
- else if (!mir_tstrcmp(ptszType, _T("wall"))) {
- JSONNODE *pWall = json_get(pAttach, "wall");
- if (pWall == NULL)
+ else if (tszType == _T("wall")) {
+ const JSONNode &jnWall = jnAttach["wall"];
+ if (!jnWall)
continue;
- ptrT ptszText(json_as_string(json_get(pWall, "text")));
- int id = json_as_int(json_get(pWall, "id"));
- int fromID = json_as_int(json_get(pWall, "from_id"));
+ CMString tszText(jnWall["text"].as_mstring());
+ int id = jnWall["id"].as_int();
+ int fromID = jnWall["from_id"].as_int();
CMString tszUrl;
tszUrl.AppendFormat(_T("http://vk.com/wall%d_%d"), fromID, id);
- res.AppendFormat(_T("%s: %s"),
- SetBBCString(TranslateT("Wall post"), iBBC, vkbbcUrl, tszUrl.GetBuffer()).GetBuffer(),
- ptszText ? ptszText : _T(" "));
+ res.AppendFormat(_T("%s: %s"),
+ SetBBCString(TranslateT("Wall post"), iBBC, vkbbcUrl, tszUrl.GetBuffer()).GetBuffer(),
+ tszText.IsEmpty() ? _T(" ") : tszText.GetBuffer());
- JSONNODE *pSubAttachments = json_get(pWall, "attachments");
- if (pSubAttachments != NULL) {
+ const JSONNode &jnSubAttachments = jnWall["attachments"];
+ if (!jnSubAttachments.isnull()) {
debugLogA("CVkProto::GetAttachmentDescr SubAttachments");
- CMString tszAttachmentDescr = GetAttachmentDescr(pSubAttachments, m_iBBCForAttachments);
+ CMString tszAttachmentDescr = GetAttachmentDescr(jnSubAttachments, m_iBBCForAttachments);
tszAttachmentDescr.Replace(_T("\n"), _T("\n\t"));
res += _T("\n\t") + tszAttachmentDescr;
}
}
- else if (!mir_tstrcmp(ptszType, _T("sticker"))) {
- JSONNODE *pSticker = json_get(pAttach, "sticker");
- if (pSticker == NULL)
+ else if (tszType == _T("sticker")) {
+ const JSONNode &jnSticker = jnAttach["sticker"];
+ if (!jnSticker)
continue;
res.Empty(); // sticker is not really an attachment, so we don't want all that heading info
if (m_bStikersAsSmyles) {
- int id = json_as_int(json_get(pSticker, "id"));
+ int id = jnSticker["id"].as_int();
res.AppendFormat(_T("[sticker:%d]"), id);
}
else {
- ptrT ptszLink;
+ CMString tszLink;
for (int i = 0; i < SIZEOF(szImageTypes); i++) {
- JSONNODE *n = json_get(pSticker, szImageTypes[i]);
- if (n != NULL) {
- ptszLink = json_as_string(n);
+ const JSONNode &n = jnSticker[szImageTypes[i]];
+ if (!n.isnull()) {
+ tszLink = n.as_mstring();
break;
}
}
- res.AppendFormat(_T("%s"), ptszLink);
+ res.AppendFormat(_T("%s"), tszLink);
if (m_iIMGBBCSupport)
- res.AppendFormat(_T("[img]%s[/img]"), ptszLink);
+ res.AppendFormat(_T("[img]%s[/img]"), tszLink.GetBuffer());
}
}
- else if (!mir_tstrcmp(ptszType, _T("link"))) {
- JSONNODE *pLink = json_get(pAttach, "link");
- if (pLink == NULL)
+ else if (tszType == _T("link")) {
+ const JSONNode &jnLink = jnAttach["link"];
+ if (!jnLink)
continue;
- ptrT ptszUrl(json_as_string(json_get(pLink, "url")));
- ptrT ptszTitle(json_as_string(json_get(pLink, "title")));
- ptrT ptszDescription(json_as_string(json_get(pLink, "description")));
- ptrT ptszImage(json_as_string(json_get(pLink, "image_src")));
+ CMString tszUrl(jnLink["url"].as_mstring());
+ CMString tszTitle(jnLink["title"].as_mstring());
+ CMString tszDescription(jnLink["description"].as_mstring());
+ CMString tszImage(jnLink["image_src"].as_mstring());
- res.AppendFormat(_T("%s: %s"),
- SetBBCString(TranslateT("Link"), iBBC, vkbbcB).GetBuffer(),
- SetBBCString(ptszTitle, iBBC, vkbbcUrl, ptszUrl).GetBuffer());
- if (!IsEmpty(ptszImage))
+ res.AppendFormat(_T("%s: %s"),
+ SetBBCString(TranslateT("Link"), iBBC, vkbbcB).GetBuffer(),
+ SetBBCString(tszTitle.GetBuffer(), iBBC, vkbbcUrl, tszUrl.GetBuffer()).GetBuffer());
+ if (!tszImage.IsEmpty())
if (m_iIMGBBCSupport)
- res.AppendFormat(_T("\n\t%s: [img]%s[/img]"), TranslateT("Image"), ptszImage);
+ res.AppendFormat(_T("\n\t%s: [img]%s[/img]"), TranslateT("Image"), tszImage.GetBuffer());
else
- res.AppendFormat(_T("\n\t%s: %s"), TranslateT("Image"), ptszImage);
+ res.AppendFormat(_T("\n\t%s: %s"), TranslateT("Image"), tszImage.GetBuffer());
- if (ptszDescription)
- res.AppendFormat(_T("\n\t%s"), ptszDescription);
+ if (tszDescription)
+ res.AppendFormat(_T("\n\t%s"), tszDescription.GetBuffer());
}
- else if (!mir_tstrcmp(ptszType, _T("gift"))) {
- JSONNODE *pGift = json_get(pAttach, "gift");
- if (pGift == NULL)
+ else if (tszType == _T("gift")) {
+ const JSONNode &jnGift = jnAttach["gift"];
+ if (!jnGift)
continue;
- ptrT ptszLink;
+ CMString tszLink;
for (int i = 0; i < SIZEOF(szGiftTypes); i++) {
- JSONNODE *n = json_get(pGift, szGiftTypes[i]);
- if (n != NULL) {
- ptszLink = json_as_string(n);
+ const JSONNode &n = jnGift[szGiftTypes[i]];
+ if (!n.isnull()) {
+ tszLink = n.as_mstring();
break;
}
}
- if (IsEmpty(ptszLink))
+ if (tszLink.IsEmpty())
continue;
- res += SetBBCString(TranslateT("Gift"), iBBC, vkbbcUrl, ptszLink);
+ res += SetBBCString(TranslateT("Gift"), iBBC, vkbbcUrl, tszLink.GetBuffer());
if (m_iIMGBBCSupport)
- res.AppendFormat(_T("\n\t[img]%s[/img]"), ptszLink);
+ res.AppendFormat(_T("\n\t[img]%s[/img]"), tszLink.GetBuffer());
}
- else
- res.AppendFormat(TranslateT("Unsupported or unknown attachment type: %s"), SetBBCString(ptszType, iBBC, vkbbcB).GetBuffer());
+ else
+ res.AppendFormat(TranslateT("Unsupported or unknown attachment type: %s"), SetBBCString(tszType.GetBuffer(), iBBC, vkbbcB).GetBuffer());
res.AppendChar('\n');
}
@@ -1116,50 +1115,51 @@ CMString CVkProto::GetAttachmentDescr(JSONNODE *pAttachments, BBCSupport iBBC) return res;
}
-CMString CVkProto::GetFwdMessages(JSONNODE *pMessages, BBCSupport iBBC)
+CMString CVkProto::GetFwdMessages(const JSONNode &jnMessages, BBCSupport iBBC)
{
CMString res;
debugLogA("CVkProto::GetFwdMessages");
- if (pMessages == NULL) {
+ if (!jnMessages) {
debugLogA("CVkProto::GetFwdMessages pMessages == NULL");
return res;
}
+
+ for (auto it = jnMessages.begin(); it != jnMessages.end(); --it) {
+ const JSONNode &jnMsg = (*it);
- JSONNODE *pMsg;
- for (int i = 0; (pMsg = json_at(pMessages, i)) != NULL; i++) {
- int uid = json_as_int(json_get(pMsg, "user_id"));
+ int uid = jnMsg["user_id"].as_int();
MCONTACT hContact = FindUser(uid);
CMString tszNick;
if (hContact)
tszNick = ptrT(db_get_tsa(hContact, m_szModuleName, "Nick"));
if (tszNick.IsEmpty())
tszNick = TranslateT("(Unknown contact)");
-
+
CMString tszUrl = _T("https://vk.com/id");
tszUrl.AppendFormat(_T("%d"), uid);
- time_t datetime = (time_t)json_as_int(json_get(pMsg, "date"));
+ time_t datetime = (time_t)jnMsg["date"].as_int();
TCHAR ttime[64];
_locale_t locale = _create_locale(LC_ALL, "");
_tcsftime_l(ttime, SIZEOF(ttime), _T("%x %X"), localtime(&datetime), locale);
_free_locale(locale);
- CMString tszBody = json_as_CMString(json_get(pMsg, "body"));
+ CMString tszBody(jnMsg["body"].as_mstring());
- JSONNODE *pFwdMessages = json_get(pMsg, "fwd_messages");
- if (pFwdMessages != NULL) {
- CMString tszFwdMessages = GetFwdMessages(pFwdMessages, m_iBBCForAttachments);
+ const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
+ if (!jnFwdMessages) {
+ CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, m_iBBCForAttachments);
if (!tszBody.IsEmpty())
tszFwdMessages = _T("\n") + tszFwdMessages;
tszBody += tszFwdMessages;
}
-
- JSONNODE *pAttachments = json_get(pMsg, "attachments");
- if (pAttachments != NULL) {
- CMString tszAttachmentDescr = GetAttachmentDescr(pAttachments, m_iBBCForAttachments);
+
+ const JSONNode &jnAttachments = jnMsg["attachments"];
+ if (!jnAttachments) {
+ CMString tszAttachmentDescr = GetAttachmentDescr(jnAttachments, m_iBBCForAttachments);
if (!tszBody.IsEmpty())
tszAttachmentDescr = _T("\n") + tszAttachmentDescr;
- tszBody += tszAttachmentDescr;
+ tszBody += tszAttachmentDescr;
}
tszBody.Replace(_T("\n"), _T("\n\t"));
diff --git a/protocols/VKontakte/src/stdafx.h b/protocols/VKontakte/src/stdafx.h index 71153bf2b0..0748199a1d 100644 --- a/protocols/VKontakte/src/stdafx.h +++ b/protocols/VKontakte/src/stdafx.h @@ -43,6 +43,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <m_icolib.h>
#include <m_idle.h>
#include <m_imgsrvc.h>
+#include <m_string.h>
#include <m_json.h>
#include <m_langpack.h>
#include <m_message.h>
@@ -52,7 +53,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include <m_protosvc.h>
#include <m_protoint.h>
#include <m_skin.h>
-#include <m_string.h>
#include <m_timezones.h>
#include <m_toptoolbar.h>
#include <m_userinfo.h>
diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h index beb50fbf72..bf21fdd8f2 100644 --- a/protocols/VKontakte/src/version.h +++ b/protocols/VKontakte/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 1
#define __RELEASE_NUM 1
-#define __BUILD_NUM 2
+#define __BUILD_NUM 3
#include <stdver.h>
diff --git a/protocols/VKontakte/src/vk.h b/protocols/VKontakte/src/vk.h index 4f38eb6716..47bcf11039 100644 --- a/protocols/VKontakte/src/vk.h +++ b/protocols/VKontakte/src/vk.h @@ -67,7 +67,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #define VKERR_INVALID_FILENAME 301 // Invalid filename
#define VKERR_INVALID_FILESIZE 302 // Invalid filesize
-#define VK_API_VER "5.31"
+#define VK_API_VER "5.33"
#define VER_API CHAR_PARAM("v", VK_API_VER)
#define VK_FEED_USER 2147483647L
@@ -82,8 +82,6 @@ struct CVkProto; extern LIST<CVkProto> vk_Instances;
extern HINSTANCE hInst;
-CMString json_as_CMString(JSONNODE* pNode);
-
LPCSTR findHeader(NETLIBHTTPREQUEST *hdr, LPCSTR szField);
bool tlstrstr(TCHAR* _s1, TCHAR* _s2);
@@ -91,5 +89,6 @@ void InitIcons(void); HANDLE GetIconHandle(int iCommand);
char* ExpUrlEncode(const char *szUrl, bool strict = false);
+
bool IsEmpty(TCHAR *str);
-bool IsEmpty(char *str);
\ No newline at end of file +bool IsEmpty(char *str);
diff --git a/protocols/VKontakte/src/vk_captcha.cpp b/protocols/VKontakte/src/vk_captcha.cpp index 9c9de02d55..8064a3ea89 100644 --- a/protocols/VKontakte/src/vk_captcha.cpp +++ b/protocols/VKontakte/src/vk_captcha.cpp @@ -141,22 +141,23 @@ bool CVkProto::RunCaptchaForm(LPCSTR szUrl, CMStringA &result) /////////////////////////////////////////////////////////////////////////////////////////
// fill a request from JSON
-bool CVkProto::ApplyCaptcha(AsyncHttpRequest *pReq, JSONNODE *pErrorNode)
+bool CVkProto::ApplyCaptcha(AsyncHttpRequest *pReq, const JSONNode &jnErrorNode)
{
debugLogA("CVkProto::ApplyCaptcha");
if (!IsOnline())
return false;
- char *szUrl = NEWSTR_ALLOCA(_T2A(json_as_string(json_get(pErrorNode, "captcha_img"))));
- char *szSid = NEWSTR_ALLOCA(_T2A(json_as_string(json_get(pErrorNode, "captcha_sid"))));
- if (szUrl == NULL || szSid == NULL)
+ CMStringA szUrl(jnErrorNode["captcha_img"].as_mstring());
+ CMStringA szSid(jnErrorNode["captcha_sid"].as_mstring());
+
+ if (szUrl.IsEmpty() || szSid.IsEmpty())
return false;
CMStringA userReply;
- if (!RunCaptchaForm(szUrl, userReply))
+ if (!RunCaptchaForm(szUrl.GetBuffer(), userReply))
return false;
pReq << CHAR_PARAM("captcha_sid", szSid) << CHAR_PARAM("captcha_key", userReply.GetString());
pReq->bNeedsRestart = true;
return true;
-}
+}
\ No newline at end of file diff --git a/protocols/VKontakte/src/vk_chats.cpp b/protocols/VKontakte/src/vk_chats.cpp index b2c7fd4060..c3e6514008 100644 --- a/protocols/VKontakte/src/vk_chats.cpp +++ b/protocols/VKontakte/src/vk_chats.cpp @@ -26,7 +26,9 @@ enum static LPCTSTR sttStatuses[] = { LPGENT("Participants"), LPGENT("Owners") };
-CVkChatInfo* CVkProto::AppendChat(int id, JSONNODE *pDlg)
+extern JSONNode nullNode;
+
+CVkChatInfo* CVkProto::AppendChat(int id, const JSONNode &jnDlg)
{
debugLog(_T("CVkProto::AppendChat"));
if (id == 0)
@@ -41,11 +43,11 @@ CVkChatInfo* CVkProto::AppendChat(int id, JSONNODE *pDlg) if (c != NULL)
return c;
- ptrT ptszTitle;
+ CMString tszTitle;
c = new CVkChatInfo(id);
- if (pDlg != NULL) {
- ptszTitle = json_as_string(json_get(pDlg, "title"));
- c->m_tszTopic = mir_tstrdup((ptszTitle != NULL) ? ptszTitle : _T(""));
+ if (!jnDlg.isnull()) {
+ tszTitle = jnDlg["title"].as_mstring();
+ c->m_tszTopic = mir_tstrdup(!tszTitle.IsEmpty() ? tszTitle.GetBuffer() : _T(""));
}
CMString sid;
@@ -55,7 +57,7 @@ CVkChatInfo* CVkProto::AppendChat(int id, JSONNODE *pDlg) GCSESSION gcw = { sizeof(gcw) };
gcw.iType = GCW_CHATROOM;
gcw.pszModule = m_szModuleName;
- gcw.ptszName = ptszTitle;
+ gcw.ptszName = tszTitle.GetBuffer();
gcw.ptszID = sid;
CallServiceSync(MS_GC_NEWSESSION, NULL, (LPARAM)&gcw);
@@ -66,7 +68,7 @@ CVkChatInfo* CVkProto::AppendChat(int id, JSONNODE *pDlg) CallServiceSync(MS_GC_GETINFO, 0, (LPARAM)&gci);
c->m_hContact = gci.hContact;
- setTString(gci.hContact, "Nick", ptszTitle);
+ setTString(gci.hContact, "Nick", tszTitle);
m_chats.insert(c);
GCDEST gcd = { m_szModuleName, sid, GC_EVENT_ADDGROUP };
@@ -79,7 +81,7 @@ CVkChatInfo* CVkProto::AppendChat(int id, JSONNODE *pDlg) setDword(gci.hContact, "vk_chat_id", id);
db_unset(gci.hContact, m_szModuleName, "off");
- if (json_as_int(json_get(pDlg, "left")) == 1) {
+ if (jnDlg["left"].as_int() == 1) {
setByte(gci.hContact, "off", 1);
m_chats.remove(c);
return NULL;
@@ -124,20 +126,20 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (reply->resultCode != 200)
return;
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
CVkChatInfo *cc = (CVkChatInfo*)pReq->pUserInfo;
if (m_chats.indexOf(cc) == -1)
return;
- JSONNODE *info = json_get(pResponse, "info");
- if (info != NULL) {
- ptrT tszTitle(json_as_string(json_get(info, "title")));
- if (mir_tstrcmp(tszTitle, cc->m_tszTopic)) {
- cc->m_tszTopic = mir_tstrdup(tszTitle);
+ const JSONNode &jnInfo = jnResponse["info"];
+ if (!jnInfo.isnull()) {
+ CMString tszTitle(jnInfo["title"].as_mstring());
+ if (tszTitle == cc->m_tszTopic) {
+ cc->m_tszTopic = mir_tstrdup(tszTitle.GetBuffer());
setTString(cc->m_hContact, "Nick", tszTitle);
GCDEST gcd = { m_szModuleName, cc->m_tszId, GC_EVENT_CHANGESESSIONAME };
@@ -145,25 +147,25 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe gce.ptszText = tszTitle;
CallServiceSync(MS_GC_EVENT, 0, (LPARAM)&gce);
}
- if ((json_as_int(json_get(info, "left")) == 1) || (json_as_int(json_get(info, "kicked")) == 1)) {
+ if (jnInfo["left"].as_int() == 1 || jnInfo["kicked"].as_int() == 1) {
setByte(cc->m_hContact, "kicked", (int)true);
LeaveChat(cc->m_chatid);
return;
}
- cc->m_admin_id = json_as_int(json_get(info, "admin_id"));
+ cc->m_admin_id = jnInfo["admin_id"].as_int();
}
- JSONNODE *users = json_get(pResponse, "users");
- if (users != NULL) {
+ const JSONNode &jnUsers = jnResponse["users"];
+ if (!jnUsers.isnull()) {
for (int i = 0; i < cc->m_users.getCount(); i++)
cc->m_users[i].m_bDel = true;
- for (int i = 0;; i++) {
- JSONNODE *pUser = json_at(users, i);
- if (pUser == NULL)
+ for (auto it = jnUsers.begin(); it != jnUsers.end(); ++it) {
+ const JSONNode &jnUser = (*it);
+ if (!jnUser)
break;
- int uid = json_as_int(json_get(pUser, "id"));
+ int uid = jnUser["id"].as_int();
TCHAR tszId[20];
_itot(uid, tszId, 10);
@@ -173,13 +175,14 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe cc->m_users.insert(cu = new CVkChatUser(uid));
bNew = true;
}
- else bNew = cu->m_bUnknown;
+ else
+ bNew = cu->m_bUnknown;
cu->m_bDel = false;
- ptrT fName(json_as_string(json_get(pUser, "first_name")));
- ptrT lName(json_as_string(json_get(pUser, "last_name")));
- CMString tszNick = CMString(fName).Trim() + _T(" ") + CMString(lName).Trim();
- cu->m_tszNick = mir_tstrdup(tszNick);
+ CMString fName(jnUser["first_name"].as_mstring());
+ CMString lName(jnUser["last_name"].as_mstring());
+ CMString tszNick = fName.Trim() + _T(" ") + lName.Trim();
+ cu->m_tszNick = mir_tstrdup(tszNick.GetBuffer());
cu->m_bUnknown = false;
if (bNew) {
@@ -211,17 +214,17 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe }
}
- JSONNODE *msgs = json_get(pResponse, "msgs");
- if (msgs != NULL) {
- int numMessages = json_as_int(json_get(msgs, "count"));
- msgs = json_get(msgs, "items");
- if (msgs != NULL) {
- for (int i = 0; i < numMessages; i++) {
- JSONNODE *pMsg = json_at(msgs, i);
- if (pMsg == NULL)
+ const JSONNode &jnMsgs = jnResponse["msgs"];
+ if (!jnMsgs.isnull()) {
+
+ const JSONNode &jnItems = jnMsgs["items"];
+ if (!jnItems.isnull()) {
+ for (auto it = jnItems.begin(); it != jnItems.end(); ++it) {
+ const JSONNode &jnMsg = (*it);
+ if (!jnMsg)
break;
- AppendChatMessage(cc->m_chatid, pMsg, true);
+ AppendChatMessage(cc->m_chatid, jnMsg, true);
}
cc->m_bHistoryRead = true;
}
@@ -236,41 +239,41 @@ void CVkProto::OnReceiveChatInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe /////////////////////////////////////////////////////////////////////////////////////////
-void CVkProto::AppendChatMessage(int id, JSONNODE *pMsg, bool bIsHistory)
+void CVkProto::AppendChatMessage(int id, const JSONNode &jnMsg, bool bIsHistory)
{
debugLogA("CVkProto::AppendChatMessage");
- CVkChatInfo *cc = AppendChat(id, NULL);
+ CVkChatInfo *cc = AppendChat(id, nullNode);
if (cc == NULL)
return;
- int mid = json_as_int(json_get(pMsg, "id"));
- int uid = json_as_int(json_get(pMsg, "user_id"));
+ int mid = jnMsg["id"].as_int();
+ int uid = jnMsg["user_id"].as_int();
- int msgTime = json_as_int(json_get(pMsg, "date"));
+ int msgTime = jnMsg["date"].as_int();
time_t now = time(NULL);
if (!msgTime || msgTime > now)
msgTime = now;
- ptrT ptszBody(json_as_string(json_get(pMsg, "body")));
+ CMString tszBody(jnMsg["body"].as_mstring());
- JSONNODE *pFwdMessages = json_get(pMsg, "fwd_messages");
- if (pFwdMessages != NULL){
- CMString tszFwdMessages = GetFwdMessages(pFwdMessages, m_iBBCForAttachments);
- if (!IsEmpty(ptszBody))
+ const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
+ if (!jnFwdMessages.isnull()){
+ CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, m_iBBCForAttachments);
+ if (!tszBody.IsEmpty())
tszFwdMessages = _T("\n") + tszFwdMessages;
- ptszBody = mir_tstrdup(CMString(ptszBody) + tszFwdMessages);
+ tszBody += tszFwdMessages;
}
- JSONNODE *pAttachments = json_get(pMsg, "attachments");
- if (pAttachments != NULL){
- CMString tszAttachmentDescr = GetAttachmentDescr(pAttachments, m_iBBCForAttachments);
- if (!IsEmpty(ptszBody))
+ const JSONNode &jnAttachments = jnMsg["attachments"];
+ if (!jnAttachments.isnull()){
+ CMString tszAttachmentDescr = GetAttachmentDescr(jnAttachments, m_iBBCForAttachments);
+ if (!tszBody.IsEmpty())
tszAttachmentDescr = _T("\n") + tszAttachmentDescr;
- ptszBody = mir_tstrdup(CMString(ptszBody) + tszAttachmentDescr);
+ tszBody += tszAttachmentDescr;
}
if (cc->m_bHistoryRead)
- AppendChatMessage(cc, uid, msgTime, ptszBody, bIsHistory);
+ AppendChatMessage(cc, uid, msgTime, tszBody.GetBuffer(), bIsHistory);
else {
CVkChatMessage *cm = cc->m_msgs.find((CVkChatMessage *)&mid);
if (cm == NULL)
@@ -278,7 +281,7 @@ void CVkProto::AppendChatMessage(int id, JSONNODE *pMsg, bool bIsHistory) cm->m_uid = uid;
cm->m_date = msgTime;
- cm->m_tszBody = ptszBody.detouch();
+ cm->m_tszBody = mir_tstrdup(tszBody.GetBuffer());
cm->m_bHistory = bIsHistory;
}
}
@@ -411,8 +414,8 @@ void CVkProto::OnSendChatMsg(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) {
debugLogA("CVkProto::OnSendChatMsg %d", reply->resultCode);
if (reply->resultCode == 200) {
- JSONROOT pRoot;
- CheckJsonResponse(pReq, reply, pRoot);
+ JSONNode jnRoot;
+ CheckJsonResponse(pReq, reply, jnRoot);
}
}
@@ -579,7 +582,7 @@ void CVkProto::LeaveChat(int chat_id, bool close_window, bool delete_chat) m_chats.remove(cc);
}
-void CVkProto::KickFromChat(int chat_id, int user_id, JSONNODE* pMsg)
+void CVkProto::KickFromChat(int chat_id, int user_id, const JSONNode &jnMsg)
{
debugLogA("CVkProto::KickFromChat (%d)", user_id);
@@ -596,7 +599,7 @@ void CVkProto::KickFromChat(int chat_id, int user_id, JSONNODE* pMsg) return;
MCONTACT hContact = FindUser(user_id, false);
- CMString msg = json_as_CMString(json_get(pMsg, "body"));
+ CMString msg(jnMsg["body"].as_mstring());
if (msg.IsEmpty()) {
msg = TranslateT("You've been kicked by ");
if (hContact != NULL)
@@ -604,7 +607,8 @@ void CVkProto::KickFromChat(int chat_id, int user_id, JSONNODE* pMsg) else
msg += TranslateT("(Unknown contact)");
}
- else AppendChatMessage(chat_id, pMsg, false);
+ else
+ AppendChatMessage(chat_id, jnMsg, false);
MsgPopup(hContact, msg, TranslateT("Chat"));
setByte(cc->m_hContact, "kicked", 1);
@@ -839,12 +843,12 @@ void CVkProto::OnCreateNewChat(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) if (reply->resultCode != 200)
return;
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
- int chat_id = json_as_int(pResponse);
- if (chat_id != NULL)
- AppendChat(chat_id, NULL);
+ int chat_id = jnResponse.as_int();
+ if (chat_id != 0)
+ AppendChat(chat_id, nullNode);
}
\ No newline at end of file diff --git a/protocols/VKontakte/src/vk_feed.cpp b/protocols/VKontakte/src/vk_feed.cpp index 966d1ccaee..ade52f1382 100644 --- a/protocols/VKontakte/src/vk_feed.cpp +++ b/protocols/VKontakte/src/vk_feed.cpp @@ -90,25 +90,26 @@ CVkUserInfo* CVkProto::GetVkUserInfo(LONG iUserId, OBJLIST<CVkUserInfo> &vkUsers return vkUser;
}
-void CVkProto::CreateVkUserInfoList(OBJLIST<CVkUserInfo> &vkUsers, JSONNODE *pResponse)
+void CVkProto::CreateVkUserInfoList(OBJLIST<CVkUserInfo> &vkUsers, const JSONNode &jnResponse)
{
debugLogA("CVkProto::CreateVkUserInfoList");
- if (pResponse == NULL)
+ if (!jnResponse)
return;
- JSONNODE *pProfiles = json_get(pResponse, "profiles");
- JSONNODE *pProfile;
- if (pProfiles != NULL)
- for (size_t i = 0; (pProfile = json_at(pProfiles, i)) != NULL; i++) {
- LONG UserId = json_as_int(json_get(pProfile, "id"));
- if (!UserId)
+ const JSONNode &jnProfiles = jnResponse["profiles"];
+
+ if (!jnProfiles.isnull())
+ for (auto it = jnProfiles.begin(); it != jnProfiles.end(); ++it) {
+ const JSONNode &jnProfile = (*it);
+ if (!jnProfile["id"])
continue;
+ LONG UserId = jnProfile["id"].as_int();
- CMString tszNick = json_as_CMString(json_get(pProfile, "first_name"));
+ CMString tszNick(jnProfile["first_name"].as_mstring());
tszNick.AppendChar(' ');
- tszNick += json_as_CMString(json_get(pProfile, "last_name"));
+ tszNick += jnProfile["last_name"].as_mstring();
CMString tszLink = _T("https://vk.com/");
- CMString tszScreenName = json_as_CMString(json_get(pProfile, "screen_name"));
+ CMString tszScreenName(jnProfile["screen_name"].as_mstring());
if (tszScreenName.IsEmpty())
tszScreenName.AppendFormat(_T("id%d"), UserId);
tszLink += tszScreenName;
@@ -116,16 +117,17 @@ void CVkProto::CreateVkUserInfoList(OBJLIST<CVkUserInfo> &vkUsers, JSONNODE *pRe vkUsers.insert(vkUser);
}
- JSONNODE *pGroups = json_get(pResponse, "groups");
- if (pGroups != NULL)
- for (size_t i = 0; (pProfile = json_at(pGroups, i)) != NULL; i++) {
- LONG UserId = -json_as_int(json_get(pProfile, "id"));
- if (!UserId)
+ const JSONNode &jnGroups = jnResponse["groups"];
+ if (!jnGroups.isnull())
+ for (auto it = jnGroups.begin(); it != jnGroups.end(); ++it) {
+ const JSONNode &jnProfile = (*it);
+ if (!jnProfile["id"])
continue;
+ LONG UserId = - jnProfile["id"].as_int();
- CMString tszNick = json_as_CMString(json_get(pProfile, "name"));
+ CMString tszNick(jnProfile["name"].as_mstring());
CMString tszLink = _T("https://vk.com/");
- tszLink += json_as_CMString(json_get(pProfile, "screen_name"));
+ tszLink += jnProfile["screen_name"].as_mstring();
CVkUserInfo * vkUser = new CVkUserInfo(UserId, true, tszNick, tszLink);
vkUsers.insert(vkUser);
}
@@ -133,22 +135,21 @@ void CVkProto::CreateVkUserInfoList(OBJLIST<CVkUserInfo> &vkUsers, JSONNODE *pRe //////////////////////////////////////////////////////////////////////////////////////////////////////////
-CVKNewsItem* CVkProto::GetVkNewsItem(JSONNODE *pItem, OBJLIST<CVkUserInfo> &vkUsers, bool isRepost)
+CVKNewsItem* CVkProto::GetVkNewsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers, bool isRepost)
{
bool bPostLink = true;
CVKNewsItem *vkNewsItem = new CVKNewsItem();
- if (pItem == NULL)
+ if (!jnItem)
return vkNewsItem;
- LONG iSourceId = json_as_int(json_get(pItem, "source_id"));
- iSourceId = iSourceId ? iSourceId : json_as_int(json_get(pItem, "owner_id"));
- LONG iPostId = json_as_int(json_get(pItem, "post_id"));
- CMString tszText = json_as_CMString(json_get(pItem, "text"));
+ LONG iSourceId = jnItem["source_id"].isnull() ? jnItem["owner_id"].as_int() : jnItem["source_id"].as_int();
+ LONG iPostId = jnItem["post_id"].as_int();
+ CMString tszText(jnItem["text"].as_mstring());
- vkNewsItem->tszType = json_as_CMString(json_get(pItem, "type"));
+ vkNewsItem->tszType = jnItem["type"].as_mstring();
vkNewsItem->vkUser = GetVkUserInfo(iSourceId, vkUsers);
vkNewsItem->bIsGroup = vkNewsItem->vkUser->m_bIsGroup;
- vkNewsItem->tDate = json_as_int(json_get(pItem, "date"));
+ vkNewsItem->tDate = jnItem["date"].as_int();
if (!tszText.IsEmpty())
tszText += _T("\n");
@@ -157,41 +158,42 @@ CVKNewsItem* CVkProto::GetVkNewsItem(JSONNODE *pItem, OBJLIST<CVkUserInfo> &vkUs if (vkNewsItem->tszType == _T("photo_tag")) {
bPostLink = false;
- JSONNODE *pPhotos = json_get(pItem, "photo_tags");
- if (pPhotos) {
- JSONNODE *pPhotoItems = json_get(pPhotos, "items");
- if (pPhotoItems) {
- JSONNODE *pPhotoItem;
+ const JSONNode &jnPhotos = jnItem["photo_tags"];
+ if (!jnPhotos.isnull()) {
+ const JSONNode &jnPhotoItems = jnPhotos["items"];
+ if (!jnPhotoItems.isnull()) {
tszText = TranslateT("User was tagged in these photos:");
- for (size_t i = 0; (pPhotoItem = json_at(pPhotoItems, i)) != NULL; i++)
- tszText += _T("\n") + GetVkPhotoItem(pPhotoItem, m_iBBCForNews);
+ for (auto it = jnPhotoItems.begin(); it != jnPhotoItems.end(); ++it)
+ tszText += _T("\n") + GetVkPhotoItem((*it), m_iBBCForNews);
}
}
}
else if (vkNewsItem->tszType == _T("photo") || vkNewsItem->tszType == _T("wall_photo")) {
bPostLink = false;
- JSONNODE *pPhotos = json_get(pItem, "photos");
- if (pPhotos) {
- JSONNODE *pPhotoItems = json_get(pPhotos, "items"), *pPhotoItem;
- if (pPhotoItems)
- for (size_t i = 0; (pPhotoItem = json_at(pPhotoItems, i)) != NULL; i++) {
- tszText += GetVkPhotoItem(pPhotoItem, m_iBBCForNews) + _T("\n");
- if (i == 0 && vkNewsItem->tszType == _T("wall_photo")) {
- LONG iPhotoPostId = json_as_int(json_get(pPhotoItem, "post_id"));
- if (iPhotoPostId) {
+ const JSONNode &jnPhotos = jnItem["photos"];
+ int i = 0;
+ if (!jnPhotos.isnull()) {
+ const JSONNode &jnPhotoItems = jnPhotos["items"];
+ if (!jnPhotoItems.isnull())
+ for (auto it = jnPhotoItems.begin(); it != jnPhotoItems.end(); ++it) {
+ const JSONNode &jnPhotoItem = (*it);
+ tszText += GetVkPhotoItem(jnPhotoItem, m_iBBCForNews) + _T("\n");
+ if (i == 0 && vkNewsItem->tszType == _T("wall_photo")) {
+ if (!jnPhotoItem["post_id"].isnull()) {
bPostLink = true;
- iPostId = iPhotoPostId;
+ iPostId = jnPhotoItem["post_id"].as_int();
break; // max 1 wall_photo when photo post_id !=0
}
}
+ i++;
}
}
}
else if (vkNewsItem->tszType == _T("post") || vkNewsItem->tszType.IsEmpty()) {
bPostLink = true;
- JSONNODE * pRepost = json_get(pItem, "copy_history");
- if (pRepost) {
- CVKNewsItem *vkRepost = GetVkNewsItem(json_at(pRepost, 0), vkUsers, true);
+ const JSONNode &jnRepost = jnItem["copy_history"];
+ if (!jnRepost.isnull()) {
+ CVKNewsItem *vkRepost = GetVkNewsItem((*jnRepost.begin()), vkUsers, true);
vkRepost->tszText.Replace(_T("\n"), _T("\n\t"));
tszText += vkRepost->tszText;
tszText += _T("\n");
@@ -199,11 +201,11 @@ CVKNewsItem* CVkProto::GetVkNewsItem(JSONNODE *pItem, OBJLIST<CVkUserInfo> &vkUs delete vkRepost;
}
- JSONNODE *pAttachments = json_get(pItem, "attachments");
- if (pAttachments){
+ const JSONNode &jnAttachments = jnItem["attachments"];
+ if (!jnAttachments.isnull()){
if (!tszText.IsEmpty())
tszText.AppendChar(_T('\n'));
- tszText += GetAttachmentDescr(pAttachments, m_bUseBBCOnAttacmentsAsNews ? m_iBBCForNews : m_iBBCForAttachments);
+ tszText += GetAttachmentDescr(jnAttachments, m_bUseBBCOnAttacmentsAsNews ? m_iBBCForNews : m_iBBCForAttachments);
}
}
@@ -234,32 +236,33 @@ CVKNewsItem* CVkProto::GetVkNewsItem(JSONNODE *pItem, OBJLIST<CVkUserInfo> &vkUs //////////////////////////////////////////////////////////////////////////////////////////////////////////
-CMString CVkProto::GetVkFeedback(JSONNODE *pFeedback, VKObjType vkFeedbackType, OBJLIST<CVkUserInfo> &vkUsers, CVkUserInfo *vkUser)
+CMString CVkProto::GetVkFeedback(const JSONNode &jnFeedback, VKObjType vkFeedbackType, OBJLIST<CVkUserInfo> &vkUsers, CVkUserInfo *vkUser)
{
debugLogA("CVkProto::GetVkFeedback");
CMString tszRes;
- if (!pFeedback || !vkFeedbackType)
+ if (!jnFeedback || !vkFeedbackType)
return tszRes;
CMString tszFormat;
LONG iUserId = 0;
if (vkFeedbackType == vkComment) {
- iUserId = json_as_int(json_get(pFeedback, "from_id"));
+ iUserId = jnFeedback["from_id"].as_int();
tszFormat = _T("%s %%s %%s\n%s");
}
else if (vkFeedbackType == vkPost) {
- iUserId = json_as_int(json_get(pFeedback, "owner_id "));
+ iUserId = jnFeedback["owner_id "].as_int();
tszFormat = _T("%s %%s %%s\n%s");
}
else if (vkFeedbackType == VKObjType::vkUsers || vkFeedbackType == vkCopy) {
- JSONNODE *pUsers = json_get(pFeedback, "items"), *pUserItem;
+ const JSONNode &jnUsers = jnFeedback["items"];
CMString tszUsers;
- for (int i = 0; (pUserItem = json_at(pUsers, i)) != NULL; i++) {
- iUserId = json_as_int(json_get(pUserItem, "from_id"));
- if (iUserId == 0)
+ for (auto it = jnUsers.begin(); it != jnUsers.end(); ++it) {
+ const JSONNode &jnUserItem = (*it);
+ if (!jnUserItem["from_id"])
continue;
+ iUserId = jnUserItem["from_id"].as_int();
vkUser = GetVkUserInfo(iUserId, vkUsers);
if (!tszUsers.IsEmpty())
tszUsers += _T(", ");
@@ -272,7 +275,7 @@ CMString CVkProto::GetVkFeedback(JSONNODE *pFeedback, VKObjType vkFeedbackType, if (iUserId) {
vkUser = GetVkUserInfo(iUserId, vkUsers);
- CMString tszText = json_as_CMString(json_get(pFeedback, "text"));
+ CMString tszText(jnFeedback["text"].as_mstring());
tszText.Replace(_T("%"), _T("%%"));
tszRes.AppendFormat(tszFormat, SetBBCString(vkUser->m_tszUserNick.GetBuffer(), m_iBBCForNews, vkbbcUrl, vkUser->m_tszLink.GetBuffer()), ClearFormatNick(tszText).GetBuffer());
}
@@ -280,19 +283,19 @@ CMString CVkProto::GetVkFeedback(JSONNODE *pFeedback, VKObjType vkFeedbackType, return tszRes;
}
-CVKNewsItem* CVkProto::GetVkParent(JSONNODE *pParent, VKObjType vkParentType, TCHAR *ptszReplyText, TCHAR *ptszReplyLink)
+CVKNewsItem* CVkProto::GetVkParent(const JSONNode &jnParent, VKObjType vkParentType, TCHAR *ptszReplyText, TCHAR *ptszReplyLink)
{
debugLogA("CVkProto::GetVkParent");
CMString tszRes;
- if (!pParent || !vkParentType)
+ if (!jnParent || !vkParentType)
return NULL;
CVKNewsItem * vkNotificationItem = new CVKNewsItem();
if (vkParentType == vkPhoto) {
- CMString tszPhoto = GetVkPhotoItem(pParent, m_iBBCForNews);
- LONG iOwnerId = json_as_int(json_get(pParent, "owner_id"));
- LONG iId = json_as_int(json_get(pParent, "id"));
+ CMString tszPhoto = GetVkPhotoItem(jnParent, m_iBBCForNews);
+ LONG iOwnerId = jnParent["owner_id"].as_int();
+ LONG iId = jnParent["id"].as_int();
vkNotificationItem->tszId.AppendFormat(_T("%d_%d"), iOwnerId, iId);
vkNotificationItem->tszLink.AppendFormat(_T("https://vk.com/photo%s"), vkNotificationItem->tszId.GetBuffer());
vkNotificationItem->tszText.AppendFormat(_T("\n%s"), tszPhoto.GetBuffer());
@@ -303,13 +306,13 @@ CVKNewsItem* CVkProto::GetVkParent(JSONNODE *pParent, VKObjType vkParentType, TC vkNotificationItem->tszText.AppendFormat(_T("\n%s"), SetBBCString(TranslateT("Link"), m_iBBCForNews, vkbbcUrl, vkNotificationItem->tszLink.GetBuffer()).GetBuffer());
}
else if (vkParentType == vkVideo) {
- LONG iOwnerId = json_as_int(json_get(pParent, "owner_id"));
- LONG iId = json_as_int(json_get(pParent, "id"));
- CMString tszTitle = json_as_CMString(json_get(pParent, "title"));
+ LONG iOwnerId = jnParent["owner_id"].as_int();
+ LONG iId = jnParent["id"].as_int();
+ CMString tszTitle(jnParent["title"].as_mstring());
vkNotificationItem->tszId.AppendFormat(_T("%d_%d"), iOwnerId, iId);
vkNotificationItem->tszLink.AppendFormat(_T("https://vk.com/video%s"), vkNotificationItem->tszId.GetBuffer());
- CMString tszText = json_as_CMString(json_get(pParent, "text"));
+ CMString tszText(jnParent["text"].as_mstring());
ClearFormatNick(tszText);
if (!tszText.IsEmpty())
@@ -321,12 +324,12 @@ CVKNewsItem* CVkProto::GetVkParent(JSONNODE *pParent, VKObjType vkParentType, TC vkNotificationItem->tszText.AppendFormat(_T("\n%s"), SetBBCString(tszTitle.GetBuffer(), m_iBBCForNews, vkbbcUrl, vkNotificationItem->tszLink.GetBuffer()).GetBuffer());
}
else if (vkParentType == vkPost) {
- LONG iOwnerId = json_as_int(json_get(pParent, "from_id"));
- LONG iId = json_as_int(json_get(pParent, "id"));
+ LONG iOwnerId = jnParent["from_id"].as_int();
+ LONG iId = jnParent["id"].as_int();
vkNotificationItem->tszId.AppendFormat(_T("%d_%d"), iOwnerId, iId);
vkNotificationItem->tszLink.AppendFormat(_T("https://vk.com/wall%s%s"), vkNotificationItem->tszId.GetBuffer(), ptszReplyLink ? ptszReplyLink : _T(""));
- CMString tszText = json_as_CMString(json_get(pParent, "text"));
+ CMString tszText(jnParent["text"].as_mstring());
ClearFormatNick(tszText);
if (!tszText.IsEmpty())
@@ -338,14 +341,14 @@ CVKNewsItem* CVkProto::GetVkParent(JSONNODE *pParent, VKObjType vkParentType, TC vkNotificationItem->tszText.AppendFormat(_T("\n%s"), SetBBCString(TranslateT("Link"), m_iBBCForNews, vkbbcUrl, vkNotificationItem->tszLink.GetBuffer()).GetBuffer());
}
else if (vkParentType == vkTopic) {
- LONG iOwnerId = json_as_int(json_get(pParent, "owner_id"));
- LONG iId = json_as_int(json_get(pParent, "id"));
- CMString tszTitle = json_as_CMString(json_get(pParent, "title"));
+ LONG iOwnerId = jnParent["owner_id"].as_int();
+ LONG iId = jnParent["id"].as_int();
+ CMString tszTitle(jnParent["title"].as_mstring());
vkNotificationItem->tszId.AppendFormat(_T("%d_%d"), iOwnerId, iId);
vkNotificationItem->tszLink.AppendFormat(_T("https://vk.com/topic%s%s"),
vkNotificationItem->tszId.GetBuffer(), ptszReplyLink ? ptszReplyLink : _T(""));
- CMString tszText = json_as_CMString(json_get(pParent, "text"));
+ CMString tszText(jnParent["text"].as_mstring());
ClearFormatNick(tszText);
if (!tszText.IsEmpty())
@@ -357,64 +360,65 @@ CVKNewsItem* CVkProto::GetVkParent(JSONNODE *pParent, VKObjType vkParentType, TC vkNotificationItem->tszText.AppendFormat(_T("\n%s"), SetBBCString(tszTitle.GetBuffer(), m_iBBCForNews, vkbbcUrl, vkNotificationItem->tszLink.GetBuffer()).GetBuffer());
}
else if (vkParentType == vkComment) {
- CMString tszText = json_as_CMString(json_get(pParent, "text"));
+ CMString tszText(jnParent["text"].as_mstring());
ClearFormatNick(tszText);
- JSONNODE *pNode = json_get(pParent, "photo");
- if (pNode) {
+ const JSONNode &jnPhoto = jnParent["photo"];
+ if (!jnPhoto.isnull()) {
delete vkNotificationItem;
- return GetVkParent(pNode, vkPhoto, tszText.IsEmpty() ? NULL : tszText.GetBuffer());
+ return GetVkParent(jnPhoto, vkPhoto, tszText.IsEmpty() ? NULL : tszText.GetBuffer());
}
- pNode = json_get(pParent, "video");
- if (pNode) {
+ const JSONNode &jnVideo = jnParent["video"];
+ if (!jnVideo.isnull()) {
delete vkNotificationItem;
- return GetVkParent(pNode, vkVideo, tszText.IsEmpty() ? NULL : tszText.GetBuffer());
+ return GetVkParent(jnVideo, vkVideo, tszText.IsEmpty() ? NULL : tszText.GetBuffer());
}
- LONG iId = json_as_int(json_get(pParent, "id"));
+ LONG iId = jnParent["id"].as_int();
- pNode = json_get(pParent, "post");
- if (pNode) {
+ const JSONNode &jnPost = jnParent["post"];
+ if (!jnPost.isnull()) {
CMString tszRepl;
tszRepl.AppendFormat(_T("?reply=%d"), iId);
delete vkNotificationItem;
- return GetVkParent(pNode, vkPost, tszText.IsEmpty() ? NULL : tszText.GetBuffer(), tszRepl.GetBuffer());
+ return GetVkParent(jnPost, vkPost, tszText.IsEmpty() ? NULL : tszText.GetBuffer(), tszRepl.GetBuffer());
}
- pNode = json_get(pParent, "topic");
- if (pNode) {
+ const JSONNode &jnTopic = jnParent["topic"];
+ if (!jnTopic.isnull()) {
CMString tszRepl;
tszRepl.AppendFormat(_T("?reply=%d"), iId);
delete vkNotificationItem;
- return GetVkParent(pNode, vkTopic, tszText.IsEmpty() ? NULL : tszText.GetBuffer(), tszRepl.GetBuffer());
+ return GetVkParent(jnTopic, vkTopic, tszText.IsEmpty() ? NULL : tszText.GetBuffer(), tszRepl.GetBuffer());
}
}
return vkNotificationItem;
}
-CVKNewsItem* CVkProto::GetVkNotificationsItem(JSONNODE *pItem, OBJLIST<CVkUserInfo> &vkUsers)
+CVKNewsItem* CVkProto::GetVkNotificationsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers)
{
debugLogA("CVkProto::GetVkNotificationsItem");
- if (pItem == NULL)
+ if (!jnItem)
return NULL;
- CMString tszType = json_as_CMString(json_get(pItem, "type"));
+ CMString tszType(jnItem["type"].as_mstring());
VKObjType vkFeedbackType = vkNull, vkParentType = vkNull;
CMString tszNotificationTranslate = SpanVKNotificationType(tszType, vkFeedbackType, vkParentType);
- JSONNODE *pFeedback = json_get(pItem, "feedback");
- if (!pFeedback)
+ const JSONNode &jnFeedback = jnItem["feedback"];
+ if (!jnFeedback)
return NULL;
+
CVkUserInfo *vkUser = NULL;
- CMString tszFeedback = GetVkFeedback(pFeedback, vkFeedbackType, vkUsers, vkUser);
+ CMString tszFeedback = GetVkFeedback(jnFeedback, vkFeedbackType, vkUsers, vkUser);
- JSONNODE *pParent = json_get(pItem, "parent");
- if (!pParent)
+ const JSONNode &jnParent = jnItem["parent"];
+ if (!jnParent)
return NULL;
- CVKNewsItem* vkNotification = GetVkParent(pParent, vkParentType);
+ CVKNewsItem* vkNotification = GetVkParent(jnParent, vkParentType);
if (!vkNotification)
return NULL;
@@ -423,7 +427,7 @@ CVKNewsItem* CVkProto::GetVkNotificationsItem(JSONNODE *pItem, OBJLIST<CVkUserIn tszNotificaton.AppendFormat(tszFeedback, tszNotificationTranslate.GetBuffer(), vkNotification->tszText.GetBuffer());
vkNotification->tszText = tszNotificaton;
vkNotification->tszType = tszType;
- vkNotification->tDate = json_as_int(json_get(pItem, "date"));
+ vkNotification->tDate = jnItem["date"].as_int();
vkNotification->vkFeedbackType = vkFeedbackType;
vkNotification->vkParentType = vkParentType;
vkNotification->vkUser = vkUser;
@@ -434,20 +438,20 @@ CVKNewsItem* CVkProto::GetVkNotificationsItem(JSONNODE *pItem, OBJLIST<CVkUserIn return NULL;
}
-CVKNewsItem* CVkProto::GetVkGroupInvates(JSONNODE *pItem, OBJLIST<CVkUserInfo> &vkUsers)
+CVKNewsItem* CVkProto::GetVkGroupInvates(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers)
{
debugLogA("CVkProto::GetVkGroupInvates");
- if (pItem == NULL)
+ if (!jnItem)
return NULL;
- CMString tszType = json_as_CMString(json_get(pItem, "type"));
+ CMString tszType(jnItem["type"].as_mstring());
VKObjType vkFeedbackType = vkNull, vkParentType = vkNull;
CMString tszNotificationTranslate = SpanVKNotificationType(tszType, vkFeedbackType, vkParentType);
- LONG iGroupId = json_as_int(json_get(pItem, "id"));
-
- if (iGroupId == 0)
+
+ if (!jnItem["id"])
return NULL;
+ LONG iGroupId = jnItem["id"].as_int();
CMString tszId;
tszId.AppendFormat(_T("%d,"), iGroupId);
CMString tszIds = ptrT(db_get_tsa(NULL, m_szModuleName, "InviteGroupIds"));
@@ -455,7 +459,7 @@ CVKNewsItem* CVkProto::GetVkGroupInvates(JSONNODE *pItem, OBJLIST<CVkUserInfo> & if (tszIds.Find(tszId, 0) != -1)
return NULL;
- LONG iUserId = json_as_int(json_get(pItem, "invited_by"));
+ LONG iUserId = jnItem["invited_by"] ? 0 : jnItem["invited_by"].as_int();
CVKNewsItem *vkNotification = new CVKNewsItem();
vkNotification->tDate = time(NULL);
vkNotification->vkUser = GetVkUserInfo(iUserId, vkUsers);
@@ -464,9 +468,9 @@ CVKNewsItem* CVkProto::GetVkGroupInvates(JSONNODE *pItem, OBJLIST<CVkUserInfo> & vkNotification->vkFeedbackType = vkFeedbackType;
vkNotification->vkParentType = vkParentType;
- CMString tszGroupName, tszGName, tszGLink;
- tszGName = json_as_CMString(json_get(pItem, "name"));
- tszGLink.AppendFormat(_T("https://vk.com/%s"), json_as_CMString(json_get(pItem, "screen_name")).GetBuffer());
+ CMString tszGroupName, tszGLink;
+ CMString tszGName = jnItem["name"].as_mstring();
+ tszGLink.AppendFormat(_T("https://vk.com/%s"), jnItem["screen_name"].as_mstring().GetBuffer());
tszGroupName = SetBBCString(tszGName.GetBuffer(), m_iBBCForNews, vkbbcUrl, tszGLink.GetBuffer());
CMString tszUsers = SetBBCString(vkNotification->vkUser->m_tszUserNick.GetBuffer(), m_iBBCForNews, vkbbcUrl, vkNotification->vkUser->m_tszLink.GetBuffer());
@@ -542,21 +546,20 @@ void CVkProto::OnReceiveUnreadNews(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *p if (reply->resultCode != 200)
return;
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
OBJLIST<CVkUserInfo> vkUsers(5, NumericKeySortT);
- CreateVkUserInfoList(vkUsers, pResponse);
+ CreateVkUserInfoList(vkUsers, jnResponse);
- JSONNODE *pItems = json_get(pResponse, "items");
- JSONNODE *pItem;
+ const JSONNode &jnItems = jnResponse["items"];
OBJLIST<CVKNewsItem> vkNews(5, sttCompareVKNewsItems);
- if (pItems != NULL)
- for (int i = 0; (pItem = json_at(pItems, i)) != NULL; i++) {
- CVKNewsItem *vkNewsItem = GetVkNewsItem(pItem, vkUsers);
+ if (!jnItems.isnull())
+ for (auto it = jnItems.begin(); it != jnItems.end(); ++it) {
+ CVKNewsItem *vkNewsItem = GetVkNewsItem((*it), vkUsers);
if (!vkNewsItem)
continue;
if (vkNews.find(vkNewsItem) == NULL)
@@ -632,29 +635,28 @@ void CVkProto::OnReceiveUnreadNotifications(NETLIBHTTPREQUEST *reply, AsyncHttpR if (reply->resultCode != 200)
return;
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
- JSONNODE *pNotifications = json_get(pResponse, "notifications");
- JSONNODE *pGroupInvates = json_get(pResponse, "groupinvates");
+ const JSONNode &jnNotifications = jnResponse["notifications"];
+ const JSONNode &jnGroupInvates = jnResponse["groupinvates"];
OBJLIST<CVkUserInfo> vkUsers(5, NumericKeySortT);
OBJLIST<CVKNewsItem> vkNotification(5, sttCompareVKNewsItems);
- CreateVkUserInfoList(vkUsers, pNotifications);
- CreateVkUserInfoList(vkUsers, pGroupInvates);
+ CreateVkUserInfoList(vkUsers, jnNotifications);
+ CreateVkUserInfoList(vkUsers, jnGroupInvates);
- JSONNODE *pItems, *pItem;
+
- if (pNotifications != NULL) {
-
- pItems = json_get(pNotifications, "items");
+ if (!jnNotifications.isnull()) {
+ const JSONNode &jnItems = jnNotifications["items"];
- if (pItems != NULL)
- for (int i = 0; (pItem = json_at(pItems, i)) != NULL; i++) {
- CVKNewsItem *vkNotificationItem = GetVkNotificationsItem(pItem, vkUsers);
+ if (!jnItems.isnull())
+ for (auto it = jnItems.begin(); it != jnItems.end(); ++it) {
+ CVKNewsItem *vkNotificationItem = GetVkNotificationsItem((*it), vkUsers);
if (!vkNotificationItem)
continue;
if (vkNotification.find(vkNotificationItem) == NULL)
@@ -665,12 +667,12 @@ void CVkProto::OnReceiveUnreadNotifications(NETLIBHTTPREQUEST *reply, AsyncHttpR }
- if (pGroupInvates != NULL) {
- pItems = json_get(pGroupInvates, "items");
+ if (!jnGroupInvates.isnull()) {
+ const JSONNode &jnItems = jnGroupInvates["items"];
- if (pItems != NULL)
- for (int i = 0; (pItem = json_at(pItems, i)) != NULL; i++) {
- CVKNewsItem *vkNotificationItem = GetVkGroupInvates(pItem, vkUsers);
+ if (!jnItems.isnull())
+ for (auto it = jnItems.begin(); it != jnItems.end(); ++it) {
+ CVKNewsItem *vkNotificationItem = GetVkGroupInvates((*it), vkUsers);
if (!vkNotificationItem)
continue;
if (vkNotification.find(vkNotificationItem) == NULL)
diff --git a/protocols/VKontakte/src/vk_files.cpp b/protocols/VKontakte/src/vk_files.cpp index bcc509c3e4..3cfbf27894 100644 --- a/protocols/VKontakte/src/vk_files.cpp +++ b/protocols/VKontakte/src/vk_files.cpp @@ -165,14 +165,14 @@ void CVkProto::OnReciveUploadServer(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * return;
}
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL) {
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse) {
SendFileFiled(fup);
return;
}
- CMStringA uri = json_as_CMString(json_get(pResponse, "upload_url"));
+ CMStringA uri = jnResponse["upload_url"].as_mstring();
if (uri.IsEmpty()) {
SendFileFiled(fup);
return;
@@ -261,18 +261,18 @@ void CVkProto::OnReciveUpload(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) return;
}
- JSONROOT pRoot;
- CheckJsonResponse(pReq, reply, pRoot);
+ JSONNode jnRoot;
+ CheckJsonResponse(pReq, reply, jnRoot);
- ptrT server(json_as_string(json_get(pRoot, "server")));
- ptrT hash(json_as_string(json_get(pRoot, "hash")));
+ CMString server(jnRoot["server"].as_mstring());
+ CMString hash(jnRoot["hash"].as_mstring());
CMString upload;
AsyncHttpRequest *pUploadReq;
switch (fup->GetType()) {
case CVkFileUploadParam::typeImg:
- upload = json_as_CMString(json_get(pRoot, "photo"));
+ upload = jnRoot["photo"].as_mstring();
if (upload == _T("[]")) {
SendFileFiled(fup, _T("NotUpload Photo"));
return;
@@ -284,7 +284,7 @@ void CVkProto::OnReciveUpload(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) << VER_API;
break;
case CVkFileUploadParam::typeAudio:
- upload = json_as_CMString(json_get(pRoot, "audio"));
+ upload = jnRoot["audio"].as_mstring();
if (upload == _T("[]")) {
SendFileFiled(fup, _T("NotUpload Audio"));
return;
@@ -296,7 +296,7 @@ void CVkProto::OnReciveUpload(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) << VER_API;
break;
case CVkFileUploadParam::typeDoc:
- upload = json_as_CMString(json_get(pRoot, "file"));
+ upload = jnRoot["file"].as_mstring();
if (upload.IsEmpty()) {
SendFileFiled(fup, _T("NotUpload Doc"));
return;
@@ -329,15 +329,15 @@ void CVkProto::OnReciveUploadFile(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pR return;
}
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL) {
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse) {
SendFileFiled(fup);
return;
}
- int id = json_as_int(json_get(fup->GetType() == CVkFileUploadParam::typeAudio ? pResponse : json_at(pResponse, 0), "id"));
- int owner_id = json_as_int(json_get(fup->GetType() == CVkFileUploadParam::typeAudio ? pResponse : json_at(pResponse, 0), "owner_id"));
+ int id = fup->GetType() == CVkFileUploadParam::typeAudio ? jnResponse["id"].as_int() : (*jnResponse.begin())["id"].as_int();
+ int owner_id = fup->GetType() == CVkFileUploadParam::typeAudio ? jnResponse["owner_id"].as_int() : (*jnResponse.begin())["owner_id"].as_int();
if ((id == 0) || (owner_id == 0)) {
SendFileFiled(fup);
return;
diff --git a/protocols/VKontakte/src/vk_history.cpp b/protocols/VKontakte/src/vk_history.cpp index a07b003730..7d0726d27a 100644 --- a/protocols/VKontakte/src/vk_history.cpp +++ b/protocols/VKontakte/src/vk_history.cpp @@ -169,54 +169,51 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque if (reply->resultCode != 200)
return;
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
CVkSendMsgParam *param = (CVkSendMsgParam*)pReq->pUserInfo;
- int iCount = json_as_int(json_get(pResponse, "count"));
- int iTime = json_as_int(json_get(pResponse, "datetime"));
- JSONNODE *pMsgs = json_get(pResponse, "items");
+ int iTime = jnResponse["datetime"].as_int();
+ const JSONNode &jnMsgs = jnResponse["items"];
+
int iLastMsgId = getDword(param->hContact, "lastmsgid", -1);
- int iIndex = iCount;
int count = 0;
- for (iIndex = (iCount - 1); iIndex >= 0; iIndex--) {
- JSONNODE *pMsg = json_at(pMsgs, iIndex);
- if (pMsg == NULL)
- continue;
+ for (auto it = jnMsgs.rbegin(); it != jnMsgs.rend(); ++it) {
+ const JSONNode &jnMsg = (*it);
- int mid = json_as_int(json_get(pMsg, "id"));
+ int mid = jnMsg["id"].as_int();
if (iLastMsgId < mid)
iLastMsgId = mid;
char szMid[40];
_itoa(mid, szMid, 10);
- ptrT ptszBody(json_as_string(json_get(pMsg, "body")));
- int datetime = json_as_int(json_get(pMsg, "date"));
- int isOut = json_as_int(json_get(pMsg, "out"));
- int isRead = json_as_int(json_get(pMsg, "read_state"));
- int uid = json_as_int(json_get(pMsg, "user_id"));
-
- JSONNODE *pFwdMessages = json_get(pMsg, "fwd_messages");
- if (pFwdMessages != NULL){
- CMString tszFwdMessages = GetFwdMessages(pFwdMessages, m_iBBCForAttachments);
- if (!IsEmpty(ptszBody))
+ CMString tszBody(jnMsg["body"].as_mstring());
+ int datetime = jnMsg["date"].as_int();
+ int isOut = jnMsg["out"].as_int();
+ int isRead = jnMsg["read_state"].as_int();
+ int uid = jnMsg["user_id"].as_int();
+
+ const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
+ if (!jnFwdMessages.isnull()){
+ CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, m_iBBCForAttachments);
+ if (!tszBody.IsEmpty())
tszFwdMessages = _T("\n") + tszFwdMessages;
- ptszBody = mir_tstrdup(CMString(ptszBody) + tszFwdMessages);
+ tszBody += tszFwdMessages;
}
-
- JSONNODE *pAttachments = json_get(pMsg, "attachments");
- if (pAttachments != NULL){
- CMString tszAttachmentDescr = GetAttachmentDescr(pAttachments, m_iBBCForAttachments);
- if (!IsEmpty(ptszBody))
+
+ const JSONNode &jnAttachments = jnMsg["attachments"];
+ if (!jnAttachments.isnull()){
+ CMString tszAttachmentDescr = GetAttachmentDescr(jnAttachments, m_iBBCForAttachments);
+ if (!tszBody.IsEmpty())
tszAttachmentDescr = _T("\n") + tszAttachmentDescr;
- ptszBody = mir_tstrdup(CMString(ptszBody) + tszAttachmentDescr);
+ tszBody += tszAttachmentDescr;
}
- T2Utf pszBody(ptszBody);
+ T2Utf pszBody(tszBody.GetBuffer());
MCONTACT hContact = FindUser(uid, true);
PROTORECVEVENT recv = { 0 };
if (isRead)
@@ -234,8 +231,8 @@ void CVkProto::OnReceiveHistoryMessages(NETLIBHTTPREQUEST *reply, AsyncHttpReque }
setDword(param->hContact, "lastmsgid", iLastMsgId);
- int once = json_as_int(json_get(pResponse, "once"));
- int iRCount = json_as_int(json_get(pResponse, "rcount"));
+ int once = jnResponse["once"].as_int();
+ int iRCount = jnResponse["rcount"].as_int();
if (count == iRCount && once == 0)
GetServerHistory(param->hContact, param->iCount + count, iRCount, iTime, param->iMsgID);
diff --git a/protocols/VKontakte/src/vk_messages.cpp b/protocols/VKontakte/src/vk_messages.cpp index 1c24dc30e5..3020907d3a 100644 --- a/protocols/VKontakte/src/vk_messages.cpp +++ b/protocols/VKontakte/src/vk_messages.cpp @@ -86,10 +86,10 @@ void CVkProto::OnSendMessage(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) debugLogA("CVkProto::OnSendMessage %d", reply->resultCode);
if (reply->resultCode == 200) {
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse != NULL) {
- UINT mid = json_as_int(pResponse);
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse.isnull()) {
+ UINT mid = jnResponse.as_int();
if (param->iMsgID != -1)
m_sendIds.insert((HANDLE)mid);
if (mid > getDword(param->hContact, "lastmsgid", 0))
@@ -180,49 +180,49 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (reply->resultCode != 200)
return;
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
CMStringA mids;
- int numMessages = json_as_int(json_get(pResponse, "count"));
- JSONNODE *pMsgs = json_get(pResponse, "items");
+ int numMessages = jnResponse["count"].as_int();
+ const JSONNode &jnMsgs = jnResponse["items"];
debugLogA("CVkProto::OnReceiveMessages numMessages = %d", numMessages);
- for (int i = 0; i < numMessages; i++) {
- JSONNODE *pMsg = json_at(pMsgs, i);
- if (pMsg == NULL) {
+ for (auto it = jnMsgs.begin(); it != jnMsgs.end(); ++it) {
+ const JSONNode &jnMsg = (*it);
+ if (!jnMsg) {
debugLogA("CVkProto::OnReceiveMessages pMsg == NULL");
break;
}
- UINT mid = json_as_int(json_get(pMsg, "id"));
- ptrT ptszBody(json_as_string(json_get(pMsg, "body")));
- int datetime = json_as_int(json_get(pMsg, "date"));
- int isOut = json_as_int(json_get(pMsg, "out"));
- int isRead = json_as_int(json_get(pMsg, "read_state"));
- int uid = json_as_int(json_get(pMsg, "user_id"));
-
- JSONNODE *pFwdMessages = json_get(pMsg, "fwd_messages");
- if (pFwdMessages != NULL){
- CMString tszFwdMessages = GetFwdMessages(pFwdMessages, m_iBBCForAttachments);
- if (!IsEmpty(ptszBody))
+ UINT mid = jnMsg["id"].as_int();
+ CMString tszBody(jnMsg["body"].as_mstring());
+ int datetime = jnMsg["date"].as_int();
+ int isOut = jnMsg["out"].as_int();
+ int isRead = jnMsg["read_state"].as_int();
+ int uid = jnMsg["user_id"].as_int();
+
+ const JSONNode &jnFwdMessages = jnMsg["fwd_messages"];
+ if (!jnFwdMessages.isnull()){
+ CMString tszFwdMessages = GetFwdMessages(jnFwdMessages, m_iBBCForAttachments);
+ if (!tszBody.IsEmpty())
tszFwdMessages = _T("\n") + tszFwdMessages;
- ptszBody = mir_tstrdup(CMString(ptszBody) + tszFwdMessages);
+ tszBody += tszFwdMessages;
}
- JSONNODE *pAttachments = json_get(pMsg, "attachments");
- if (pAttachments != NULL){
- CMString tszAttachmentDescr = GetAttachmentDescr(pAttachments, m_iBBCForAttachments);
- if (!IsEmpty(ptszBody))
+ const JSONNode &jnAttachments = jnMsg["attachments"];
+ if (!jnAttachments.isnull()){
+ CMString tszAttachmentDescr = GetAttachmentDescr(jnAttachments, m_iBBCForAttachments);
+ if (!tszBody.IsEmpty())
tszAttachmentDescr = _T("\n") + tszAttachmentDescr;
- ptszBody = mir_tstrdup(CMString(ptszBody) + tszAttachmentDescr);
+ tszBody += tszAttachmentDescr;
}
MCONTACT hContact = NULL;
- int chat_id = json_as_int(json_get(pMsg, "chat_id"));
+ int chat_id = jnMsg["chat_id"].as_int();
if (chat_id == 0)
hContact = FindUser(uid, true);
@@ -236,12 +236,12 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (chat_id != 0) {
debugLogA("CVkProto::OnReceiveMessages chat_id != 0");
- CMString action_chat = json_as_CMString(json_get(pMsg, "action"));
- int action_mid = _ttoi(json_as_CMString(json_get(pMsg, "action_mid")));
+ CMString action_chat = jnMsg["action"].as_mstring();
+ int action_mid = _ttoi(jnMsg["action_mid"].as_mstring().GetBuffer());
if ((action_chat == "chat_kick_user") && (action_mid == m_myUserId))
- KickFromChat(chat_id, uid, pMsg);
+ KickFromChat(chat_id, uid, jnMsg);
else
- AppendChatMessage(chat_id, pMsg, false);
+ AppendChatMessage(chat_id, jnMsg, false);
continue;
}
@@ -253,7 +253,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe else if (m_bUserForceOnlineOnActivity)
SetInvisible(hContact);
- T2Utf pszBody(ptszBody);
+ T2Utf pszBody(tszBody.GetBuffer());
recv.timestamp = m_bUseLocalTime ? time(NULL) : datetime;
recv.szMessage = pszBody;
recv.lParam = isOut;
@@ -261,7 +261,7 @@ void CVkProto::OnReceiveMessages(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe recv.cbCustomDataSize = (int)mir_strlen(szMid);
Sleep(100);
- debugLogA("CVkProto::OnReceiveMessages i = %d, mid = %d, datetime = %d, isOut = %d, isRead = %d, uid = %d", i, mid, datetime, isOut, isRead, uid);
+ debugLogA("CVkProto::OnReceiveMessages mid = %d, datetime = %d, isOut = %d, isRead = %d, uid = %d", mid, datetime, isOut, isRead, uid);
if (!CheckMid(m_sendIds, mid)) {
debugLogA("CVkProto::OnReceiveMessages ProtoChainRecvMsg");
@@ -283,37 +283,32 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) if (reply->resultCode != 200)
return;
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
-
- int numDlgs = json_as_int(json_get(pResponse, "count"));
- JSONNODE *pDlgs = json_get(pResponse, "items");
-
- if (pDlgs == NULL)
+
+ const JSONNode &jnDlgs = jnResponse["items"];
+ if (!jnDlgs)
return;
- for (int i = 0; i < numDlgs; i++) {
- JSONNODE *pDlg = json_at(pDlgs, i);
- if (pDlg == NULL)
+ for (auto it = jnDlgs.begin(); it != jnDlgs.end(); ++it) {
+ if (!(*it))
break;
-
- int numUnread = json_as_int(json_get(pDlg, "unread"));
-
- pDlg = json_get(pDlg, "message");
- if (pDlg == NULL)
+ int numUnread = (*it)["unread"].as_int();
+ const JSONNode &jnDlg = (*it)["message"];
+ if (jnDlg == NULL)
break;
- int chatid = json_as_int(json_get(pDlg, "chat_id"));
+ int chatid = jnDlg["chat_id"].as_int();
if (chatid != 0) {
debugLogA("CVkProto::OnReceiveDlgs chatid = %d", chatid);
if (m_chats.find((CVkChatInfo*)&chatid) == NULL)
- AppendChat(chatid, pDlg);
+ AppendChat(chatid, jnDlg);
}
else if (m_iSyncHistoryMetod) {
- int mid = json_as_int(json_get(pDlg, "id"));
- int uid = json_as_int(json_get(pDlg, "user_id"));
+ int mid = jnDlg["id"].as_int();
+ int uid = jnDlg["user_id"].as_int();
MCONTACT hContact = FindUser(uid, true);
if (getDword(hContact, "lastmsgid", -1) == -1 && numUnread)
@@ -325,7 +320,7 @@ void CVkProto::OnReceiveDlgs(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) MarkMessagesRead(hContact);
}
else if (numUnread) {
- int uid = json_as_int(json_get(pDlg, "user_id"));
+ int uid = jnDlg["user_id"].as_int();
MCONTACT hContact = FindUser(uid, true);
GetServerHistory(hContact, 0, numUnread, 0, 0, true);
diff --git a/protocols/VKontakte/src/vk_pollserver.cpp b/protocols/VKontakte/src/vk_pollserver.cpp index 72c23b2e09..3a66e994ac 100644 --- a/protocols/VKontakte/src/vk_pollserver.cpp +++ b/protocols/VKontakte/src/vk_pollserver.cpp @@ -33,14 +33,18 @@ void CVkProto::OnReceivePollingInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * if (reply->resultCode != 200)
return;
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ JSONNode jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
- m_pollingTs = mir_t2a(ptrT(json_as_string(json_get(pResponse, "ts"))));
- m_pollingKey = mir_t2a(ptrT(json_as_string(json_get(pResponse, "key"))));
- m_pollingServer = mir_t2a(ptrT(json_as_string(json_get(pResponse, "server"))));
+ char ts[32];
+ itoa(jnResponse["ts"].as_int(), ts, 10);
+
+ m_pollingTs = mir_strdup(ts);
+ m_pollingKey = mir_t2a(jnResponse["key"].as_mstring().GetBuffer());
+ m_pollingServer = mir_t2a(jnResponse["server"].as_mstring().GetBuffer());
+
if (!m_hPollingThread) {
debugLogA("CVkProto::OnReceivePollingInfo m_hPollingThread is NULL");
debugLogA("CVkProto::OnReceivePollingInfo m_pollingTs = \'%s' m_pollingKey = \'%s\' m_pollingServer = \'%s\'",
@@ -62,20 +66,21 @@ void CVkProto::OnReceivePollingInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * debugLogA("CVkProto::OnReceivePollingInfo m_hPollingThread is not NULL");
}
-void CVkProto::PollUpdates(JSONNODE *pUpdates)
+void CVkProto::PollUpdates(const JSONNode &jnUpdates)
{
debugLogA("CVkProto::PollUpdates");
CMStringA mids;
int msgid, uid, flags, platform;
MCONTACT hContact;
- JSONNODE *pChild;
- for (int i = 0; (pChild = json_at(pUpdates, i)) != NULL; i++) {
- switch (json_as_int(json_at(pChild, 0))) {
+
+ for (auto it = jnUpdates.begin(); it != jnUpdates.end(); ++it) {
+ const JSONNode &jnChild = (*it).as_array();
+ switch (jnChild[json_index_t(0)].as_int()) {
case VKPOLL_MSG_DELFLAGS:
- msgid = json_as_int(json_at(pChild, 1));
- flags = json_as_int(json_at(pChild, 2));
- uid = json_as_int(json_at(pChild, 3));
+ msgid = jnChild[1].as_int();
+ flags = jnChild[2].as_int();
+ uid = jnChild[3].as_int();
hContact = FindUser(uid);
if (hContact != NULL && (flags & VKFLAG_MSGUNREAD) && !CheckMid(m_incIds, msgid)) {
@@ -87,10 +92,10 @@ void CVkProto::PollUpdates(JSONNODE *pUpdates) break;
case VKPOLL_MSG_ADDED: // new message
- msgid = json_as_int(json_at(pChild, 1));
+ msgid = jnChild[1].as_int();
// skip outgoing messages sent from a client
- flags = json_as_int(json_at(pChild, 2));
+ flags = jnChild[2].as_int();
if (flags & VKFLAG_MSGOUTBOX && !(flags & VKFLAG_MSGCHAT))
if (CheckMid(m_sendIds, msgid))
break;
@@ -101,7 +106,7 @@ void CVkProto::PollUpdates(JSONNODE *pUpdates) break;
case VKPOLL_READ_ALL_OUT:
- uid = json_as_int(json_at(pChild, 1));
+ uid = jnChild[1].as_int();
hContact = FindUser(uid);
if (hContact != NULL) {
setDword(hContact, "LastMsgReadTime", time(NULL));
@@ -112,16 +117,16 @@ void CVkProto::PollUpdates(JSONNODE *pUpdates) break;
case VKPOLL_USR_ONLINE:
- uid = -json_as_int(json_at(pChild, 1));
+ uid = -jnChild[1].as_int();
if ((hContact = FindUser(uid)) != NULL) {
setWord(hContact, "Status", ID_STATUS_ONLINE);
- platform = json_as_int(json_at(pChild, 2));
+ platform = jnChild[2].as_int();
SetMirVer(hContact, platform);
}
break;
case VKPOLL_USR_OFFLINE:
- uid = -json_as_int(json_at(pChild, 1));
+ uid = -jnChild[1].as_int();
if ((hContact = FindUser(uid)) != NULL) {
setWord(hContact, "Status", ID_STATUS_OFFLINE);
db_unset(hContact, m_szModuleName, "ListeningTo");
@@ -130,7 +135,7 @@ void CVkProto::PollUpdates(JSONNODE *pUpdates) break;
case VKPOLL_USR_UTN:
- uid = json_as_int(json_at(pChild, 1));
+ uid = jnChild[1].as_int();
hContact = FindUser(uid);
if (hContact != NULL) {
ForkThread(&CVkProto::ContactTypingThread, (void *)hContact);
@@ -140,7 +145,7 @@ void CVkProto::PollUpdates(JSONNODE *pUpdates) break;
case VKPOLL_CHAT_CHANGED:
- int chat_id = json_as_int(json_at(pChild, 1));
+ int chat_id = jnChild[1].as_int();
CVkChatInfo *cc = m_chats.find((CVkChatInfo*)&chat_id);
if (cc)
RetrieveChatInfo(cc);
@@ -194,18 +199,20 @@ int CVkProto::PollServer() int retVal = 0;
if (reply->resultCode == 200) {
- JSONROOT pRoot(reply->pData);
- JSONNODE *pFailed = json_get(pRoot, "failed");
- if (pFailed != NULL && json_as_int(pFailed) > 1) {
+ JSONNode jnRoot = JSONNode::parse(reply->pData);
+ const JSONNode &jnFailed = jnRoot["failed"];
+ if (!jnFailed.isnull() && jnFailed.as_int() > 1) {
RetrievePollingInfo();
retVal = -1;
debugLogA("Polling key expired, restarting polling thread");
}
- else if (CheckJsonResult(NULL, pRoot)) {
- m_pollingTs = mir_t2a(ptrT(json_as_string(json_get(pRoot, "ts"))));
- JSONNODE *pUpdates = json_get(pRoot, "updates");
- if (pUpdates != NULL)
- PollUpdates(pUpdates);
+ else if (CheckJsonResult(NULL, jnRoot)) {
+ char ts[32];
+ itoa(jnRoot["ts"].as_int(), ts, 10);
+ m_pollingTs = mir_strdup(ts);
+ const JSONNode &jnUpdates = jnRoot["updates"];
+ if (!jnUpdates.isnull())
+ PollUpdates(jnUpdates);
retVal = 1;
}
}
diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index bc6198c5b5..c8b4b5ed45 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -538,10 +538,10 @@ void CVkProto::OnReceiveAuthRequest(NETLIBHTTPREQUEST *reply, AsyncHttpRequest * debugLogA("CVkProto::OnReceiveAuthRequest %d", reply->resultCode);
CVkSendMsgParam *param = (CVkSendMsgParam*)pReq->pUserInfo;
if (reply->resultCode == 200) {
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse != NULL) {
- int iRet = json_as_int(pResponse);
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse.isnull()) {
+ int iRet = jnResponse.as_int();
setByte(param->hContact, "Auth", 0);
if (iRet == 2) {
CMString msg,
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 0468fd7802..f947cb197c 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -352,14 +352,14 @@ struct CVkProto : public PROTO<CVkProto> void AddFeedEvent(CMString& tszBody, time_t tTime);
CVkUserInfo* GetVkUserInfo(LONG iUserId, OBJLIST<CVkUserInfo> &vkUsers);
- void CreateVkUserInfoList(OBJLIST<CVkUserInfo> &vkUsers, JSONNODE *pResponse);
+ void CreateVkUserInfoList(OBJLIST<CVkUserInfo> &vkUsers, const JSONNode &jnResponse);
- CVKNewsItem* GetVkNewsItem(JSONNODE *pItem, OBJLIST<CVkUserInfo> &vkUsers, bool isRepost = false);
+ CVKNewsItem* GetVkNewsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers, bool isRepost = false);
- CVKNewsItem* GetVkGroupInvates(JSONNODE *pItem, OBJLIST<CVkUserInfo> &vkUsers);
- CVKNewsItem* GetVkNotificationsItem(JSONNODE *pItem, OBJLIST<CVkUserInfo> &vkUsers);
- CMString GetVkFeedback(JSONNODE *pFeedback, VKObjType vkFeedbackType, OBJLIST<CVkUserInfo> &vkUsers, CVkUserInfo *vkUser);
- CVKNewsItem* GetVkParent(JSONNODE *pParent, VKObjType vkParentType, TCHAR *ptszReplyText = NULL, TCHAR *ptszReplyLink = NULL);
+ CVKNewsItem* GetVkGroupInvates(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers);
+ CVKNewsItem* GetVkNotificationsItem(const JSONNode &jnItem, OBJLIST<CVkUserInfo> &vkUsers);
+ CMString GetVkFeedback(const JSONNode &jnFeedback, VKObjType vkFeedbackType, OBJLIST<CVkUserInfo> &vkUsers, CVkUserInfo *vkUser);
+ CVKNewsItem* GetVkParent(const JSONNode &jnParent, VKObjType vkParentType, TCHAR *ptszReplyText = NULL, TCHAR *ptszReplyLink = NULL);
void RetrieveUnreadNews(time_t tLastNewsTime);
void OnReceiveUnreadNews(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
@@ -382,9 +382,10 @@ struct CVkProto : public PROTO<CVkProto> MCONTACT FindChat(LONG dwUserid);
bool CheckMid(LIST<void> &lList, int guid);
+
+ JSONNode& CheckJsonResponse(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, JSONNode &root);
+ bool CheckJsonResult(AsyncHttpRequest *pReq, JSONNode &Node);
- JSONNODE* CheckJsonResponse(AsyncHttpRequest *pReq, NETLIBHTTPREQUEST *reply, JSONROOT&);
- bool CheckJsonResult(AsyncHttpRequest *pReq, JSONNODE*);
void OnReceiveSmth(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
bool AutoFillForm(char*, CMStringA&, CMStringA&);
@@ -405,12 +406,12 @@ struct CVkProto : public PROTO<CVkProto> char* GetStickerId(const char* Msg, int& stickerid);
CMString SpanVKNotificationType(CMString& tszType, VKObjType& vkFeedback, VKObjType& vkParent);
- CMString GetVkPhotoItem(JSONNODE *pPhotoItem, BBCSupport iBBC);
+ CMString GetVkPhotoItem(const JSONNode &jnPhoto, BBCSupport iBBC);
CMString SetBBCString(TCHAR *tszString, BBCSupport iBBC, VKBBCType bbcType, TCHAR *tszAddString = NULL);
CMString& ClearFormatNick(CMString& tszText);
- CMString GetAttachmentDescr(JSONNODE*, BBCSupport iBBC = bbcNo);
- CMString GetFwdMessages(JSONNODE *pMessages, BBCSupport iBBC = bbcNo);
+ CMString GetAttachmentDescr(const JSONNode jnAttachments, BBCSupport iBBC = bbcNo);
+ CMString GetFwdMessages(const JSONNode &jnMessages, BBCSupport iBBC = bbcNo);
void SetInvisible(MCONTACT hContact);
@@ -421,7 +422,7 @@ struct CVkProto : public PROTO<CVkProto> void OnReceiveStatus(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveStatusMsg(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
- MCONTACT SetContactInfo(JSONNODE* Item, bool flag = false, bool self = false);
+ MCONTACT SetContactInfo(const JSONNode &jnItem, bool flag = false, bool self = false);
void RetrieveMyInfo(void);
void OnReceiveMyInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void RetrieveUserInfo(LONG userId);
@@ -450,7 +451,7 @@ struct CVkProto : public PROTO<CVkProto> void OnReceivePollingInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void __cdecl PollingThread(void*);
int PollServer();
- void PollUpdates(JSONNODE*);
+ void PollUpdates(const JSONNode&);
void OnReceivePolling(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
void OnReceiveAuthRequest(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
@@ -535,7 +536,7 @@ private: AsyncHttpRequest* Push(AsyncHttpRequest*, int iTimeout = 10000);
bool RunCaptchaForm(LPCSTR szUrl, CMStringA&);
- bool ApplyCaptcha(AsyncHttpRequest *pReq, JSONNODE*);
+ bool ApplyCaptcha(AsyncHttpRequest *pReq, const JSONNode&);
void ConnectionFailed(int iReason);
void OnLoggedIn();
@@ -613,8 +614,8 @@ private: ptrT m_defaultGroup;
ptrA
- m_pollingServer,
- m_pollingKey,
+ m_pollingServer,
+ m_pollingKey,
m_pollingTs,
m_szAccessToken;
@@ -635,8 +636,8 @@ private: static INT_PTR CALLBACK OptionsViewProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
OBJLIST<CVkChatInfo> m_chats;
- CVkChatInfo* AppendChat(int id, JSONNODE *pNode);
- void AppendChatMessage(int id, JSONNODE *pMsg, bool bIsHistory);
+ CVkChatInfo* AppendChat(int id, const JSONNode &jnNode);
+ void AppendChatMessage(int id, const JSONNode &jnMsg, bool bIsHistory);
void AppendChatMessage(CVkChatInfo *cc, int uid, int msgTime, LPCTSTR ptszBody, bool bIsHistory);
void RetrieveChatInfo(CVkChatInfo*);
void OnReceiveChatInfo(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
@@ -645,7 +646,7 @@ private: void OnChatDestroy(NETLIBHTTPREQUEST*, AsyncHttpRequest*);
int __cdecl OnChatEvent(WPARAM, LPARAM);
int __cdecl OnGcMenuHook(WPARAM, LPARAM);
- void KickFromChat(int chat_id, int user_id, JSONNODE* pMsg);
+ void KickFromChat(int chat_id, int user_id, const JSONNode &jnMsg);
void LeaveChat(int chat_id, bool close_window = true, bool delete_chat = false);
INT_PTR __cdecl OnLeaveChat(WPARAM, LPARAM);
INT_PTR __cdecl OnJoinChat(WPARAM, LPARAM);
diff --git a/protocols/VKontakte/src/vk_search.cpp b/protocols/VKontakte/src/vk_search.cpp index 924a6f593c..212881b2dc 100644 --- a/protocols/VKontakte/src/vk_search.cpp +++ b/protocols/VKontakte/src/vk_search.cpp @@ -33,9 +33,9 @@ HANDLE CVkProto::SearchByName(const PROTOCHAR* nick, const PROTOCHAR* firstName, {
PROTOSEARCHBYNAME * psr = new (PROTOSEARCHBYNAME);
- psr->pszFirstName = mir_wstrdup(firstName);
- psr->pszLastName = mir_wstrdup(lastName);
- psr->pszNick = mir_wstrdup(nick);
+ psr->pszFirstName = mir_tstrdup(firstName);
+ psr->pszLastName = mir_tstrdup(lastName);
+ psr->pszNick = mir_tstrdup(nick);
ForkThread(&CVkProto::SearchThread, (void *)psr);
return (HANDLE)1;
@@ -100,9 +100,9 @@ void CVkProto::OnSearch(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) return;
}
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL) {
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse) {
if (pParam) {
mir_free(pParam->pszFirstName);
mir_free(pParam->pszLastName);
@@ -113,41 +113,34 @@ void CVkProto::OnSearch(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) return;
}
- int iCount = json_as_int(json_get(pResponse, "count"));
- JSONNODE *pItems = json_get(pResponse, "items");
- if (!pItems) {
- pItems = pResponse;
- iCount = 1;
- }
-
- for (int i = 0; i<iCount; i++) {
- JSONNODE *pRecord = json_at(pItems, i);
- if (pRecord == NULL)
+ const JSONNode jnItems = jnResponse["items"].isnull() ? jnResponse : jnResponse["items"];
+ for (auto it = jnItems.begin(); it != jnItems.end(); ++it) {
+ const JSONNode &jnRecord = (*it);
+ if (!jnRecord)
break;
PROTOSEARCHRESULT psr = { sizeof(psr) };
psr.flags = PSR_TCHAR;
- ptrT pId(json_as_string(json_get(pRecord, "id")));
- ptrT pFirstName(json_as_string(json_get(pRecord, "first_name")));
- ptrT pLastName(json_as_string(json_get(pRecord, "last_name")));
- ptrT pNick(json_as_string(json_get(pRecord, "nickname")));
- ptrT pDomain(json_as_string(json_get(pRecord, "domain")));
-
- psr.id = mir_wstrdup(pId);
- psr.firstName = mir_wstrdup(pFirstName);
- psr.lastName = mir_wstrdup(pLastName);
- psr.nick = mir_wstrdup(pNick);
- if (!psr.nick || !psr.nick[0])
- psr.nick = mir_wstrdup(pDomain);
+ CMString Id;
+ Id.AppendFormat(_T("%d"), jnRecord["id"].as_int());
+ CMString FirstName(jnRecord["first_name"].as_mstring());
+ CMString LastName(jnRecord["last_name"].as_mstring());
+ CMString Nick(jnRecord["nickname"].as_mstring());
+ CMString Domain(jnRecord["domain"].as_mstring());
+
+ psr.id = mir_tstrdup(Id.GetBuffer());
+ psr.firstName = mir_tstrdup(FirstName.GetBuffer());
+ psr.lastName = mir_tstrdup(LastName.GetBuffer());
+ psr.nick = Nick.IsEmpty() ? mir_tstrdup(Domain.GetBuffer()) : mir_tstrdup(Nick.GetBuffer());
bool filter = true;
if (pParam) {
- if (psr.firstName&&pParam->pszFirstName)
+ if (psr.firstName && pParam->pszFirstName)
filter = tlstrstr(psr.firstName, pParam->pszFirstName) && filter;
- if (psr.lastName&&pParam->pszLastName)
+ if (psr.lastName && pParam->pszLastName)
filter = tlstrstr(psr.lastName, pParam->pszLastName) && filter;
- if (psr.nick&&pParam->pszNick)
+ if (psr.nick && pParam->pszNick)
filter = tlstrstr(psr.nick, pParam->pszNick) && filter;
}
@@ -172,40 +165,40 @@ void CVkProto::OnSearchByMail(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) return;
}
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL) {
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse) {
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
return;
}
- JSONNODE *pItems = json_get(pResponse, "found");
- if (!pItems) {
+ const JSONNode &jnItems = jnResponse["found"];
+ if (!jnItems) {
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0);
return;
}
- for (int i = 0;; i++) {
- JSONNODE *pRecord = json_at(pItems, i);
- if (pRecord == NULL)
+ for (auto it = jnItems.begin(); it != jnItems.end(); ++it) {
+ const JSONNode &jnRecord = (*it);
+ if (!jnRecord)
break;
PROTOSEARCHRESULT psr = { sizeof(psr) };
psr.flags = PSR_TCHAR;
-
- ptrT pId(json_as_string(json_get(pRecord, "id")));
- ptrT pFirstName(json_as_string(json_get(pRecord, "first_name")));
- ptrT pLastName(json_as_string(json_get(pRecord, "last_name")));
- ptrT pNick(json_as_string(json_get(pRecord, "nickname")));
- ptrT pEmail(json_as_string(json_get(pRecord, "contact")));
-
- psr.id = mir_wstrdup(pId);
- psr.firstName = mir_wstrdup(pFirstName);
- psr.lastName = mir_wstrdup(pLastName);
- psr.nick = mir_wstrdup(pNick);
- psr.email = mir_wstrdup(pEmail);
- if (!psr.nick || !psr.nick[0])
- psr.nick = psr.email;
+
+ CMString Id;
+ Id.AppendFormat(_T("%d"), jnRecord["id"].as_int());
+ CMString FirstName(jnRecord["first_name"].as_mstring());
+ CMString LastName(jnRecord["last_name"].as_mstring());
+ CMString Nick(jnRecord["nickname"].as_mstring());
+ CMString Email(jnRecord["contact"].as_mstring());
+
+
+ psr.id = mir_tstrdup(Id.GetBuffer());
+ psr.firstName = mir_tstrdup(FirstName.GetBuffer());
+ psr.lastName = mir_tstrdup(LastName.GetBuffer());
+ psr.nick = Nick.IsEmpty() ? mir_tstrdup(Email.GetBuffer()) : mir_tstrdup(Nick.GetBuffer());
+ psr.email = mir_tstrdup(Email.GetBuffer());
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr);
}
diff --git a/protocols/VKontakte/src/vk_status.cpp b/protocols/VKontakte/src/vk_status.cpp index e7d6ee7cc6..1c4490b324 100644 --- a/protocols/VKontakte/src/vk_status.cpp +++ b/protocols/VKontakte/src/vk_status.cpp @@ -153,16 +153,16 @@ void CVkProto::OnReceiveStatus(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) debugLogA("CVkProto::OnReceiveStatus %d", reply->resultCode);
if (reply->resultCode != 200)
return;
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
- JSONNODE *pAudio = json_get(pResponse, "audio");
- if (pAudio == NULL) {
- ptrT ptszStatusText(json_as_string(json_get(pResponse, "text")));
- if (ptszStatusText[0] != TCHAR(9835))
- setTString("OldStatusMsg", ptszStatusText);
+ const JSONNode &jnAudio = jnResponse["audio"];
+ if (jnAudio.isnull()) {
+ CMString tszStatusText(jnResponse["text"].as_mstring());
+ if (tszStatusText.GetBuffer()[0] != TCHAR(9835))
+ setTString("OldStatusMsg", tszStatusText);
}
}
@@ -184,13 +184,13 @@ void CVkProto::RetrieveStatusMusic(const CMString &StatusMsg) return;
CMString code;
- ptrT ptszOldStatusMsg(db_get_tsa(0, m_szModuleName, "OldStatusMsg"));
+ CMString tszOldStatusMsg(db_get_tsa(0, m_szModuleName, "OldStatusMsg"));
if (StatusMsg.IsEmpty()) {
if (m_iMusicSendMetod == sendBroadcastOnly)
code = "API.audio.setBroadcast();return null;";
else {
CMString codeformat("API.status.set({text:\"%s\"});return null;");
- code.AppendFormat(codeformat, ptszOldStatusMsg);
+ code.AppendFormat(codeformat, tszOldStatusMsg);
}
m_bSetBroadcast = false;
}
diff --git a/protocols/VKontakte/src/vk_thread.cpp b/protocols/VKontakte/src/vk_thread.cpp index 977f00bea3..5713f570e3 100644 --- a/protocols/VKontakte/src/vk_thread.cpp +++ b/protocols/VKontakte/src/vk_thread.cpp @@ -211,12 +211,15 @@ void CVkProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) return;
}
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
- m_myUserId = json_as_int(json_get(json_at(pResponse, 0), "id"));
+ const JSONNode &jnUser = *(jnResponse.begin());
+
+
+ m_myUserId = jnUser["id"].as_int();
setDword("ID", m_myUserId);
OnLoggedIn();
@@ -226,14 +229,14 @@ void CVkProto::OnReceiveMyInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) RetrievePollingInfo();
}
-MCONTACT CVkProto::SetContactInfo(JSONNODE* pItem, bool flag, bool self)
+MCONTACT CVkProto::SetContactInfo(const JSONNode &jnItem, bool flag, bool self)
{
- if (pItem == NULL) {
+ if (!jnItem) {
debugLogA("CVkProto::SetContactInfo pItem == NULL");
return INVALID_CONTACT_ID;
}
- LONG userid = json_as_int(json_get(pItem, "id"));
+ LONG userid = jnItem["id"].as_int();
debugLogA("CVkProto::SetContactInfo %d", userid);
if (userid == 0 || userid == VK_FEED_USER)
return NULL;
@@ -245,7 +248,7 @@ MCONTACT CVkProto::SetContactInfo(JSONNODE* pItem, bool flag, bool self) if (self)
hContact = NULL;
else
- SetContactInfo(pItem, flag, true);
+ SetContactInfo(jnItem, flag, true);
}
else if (hContact == NULL)
return NULL;
@@ -253,14 +256,14 @@ MCONTACT CVkProto::SetContactInfo(JSONNODE* pItem, bool flag, bool self) CMString tszNick, tszValue;
int iValue;
- tszValue = json_as_CMString(json_get(pItem, "first_name"));
+ tszValue = jnItem["first_name"].as_mstring();
if (!tszValue.IsEmpty()) {
setTString(hContact, "FirstName", tszValue.GetBuffer());
tszNick.Append(tszValue);
tszNick.AppendChar(' ');
}
- tszValue = json_as_CMString(json_get(pItem, "last_name"));
+ tszValue = jnItem["last_name"].as_mstring();
if (!tszValue.IsEmpty()) {
setTString(hContact, "LastName", tszValue.GetBuffer());
tszNick.Append(tszValue);
@@ -269,11 +272,11 @@ MCONTACT CVkProto::SetContactInfo(JSONNODE* pItem, bool flag, bool self) if (!tszNick.IsEmpty())
setTString(hContact, "Nick", tszNick);
- int sex = json_as_int(json_get(pItem, "sex"));
+ int sex = jnItem["sex"].as_int();
if (sex)
setByte(hContact, "Gender", sex == 2 ? 'M' : 'F');
- tszValue = json_as_CMString(json_get(pItem, "bdate"));
+ tszValue = jnItem["bdate"].as_mstring();
if (!tszValue.IsEmpty()) {
int d, m, y, iReadCount;
iReadCount = _stscanf(tszValue.GetBuffer(), _T("%d.%d.%d"), &d, &m, &y);
@@ -285,19 +288,19 @@ MCONTACT CVkProto::SetContactInfo(JSONNODE* pItem, bool flag, bool self) }
}
- tszValue = json_as_CMString(json_get(pItem, "photo_100"));
+ tszValue = jnItem["photo_100"].as_mstring();
if (!tszValue.IsEmpty()) {
SetAvatarUrl(hContact, tszValue);
ReloadAvatarInfo(hContact);
}
- int iNewStatus = (json_as_int(json_get(pItem, "online")) == 0) ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE;
+ int iNewStatus = (jnItem["online"] == 0) ? ID_STATUS_OFFLINE : ID_STATUS_ONLINE;
if (getWord(hContact, "Status", ID_STATUS_OFFLINE) != iNewStatus)
setWord(hContact, "Status", iNewStatus);
if (iNewStatus == ID_STATUS_ONLINE) {
- int online_app = _ttoi(json_as_CMString(json_get(pItem, "online_app")));
- int online_mobile = json_as_int(json_get(pItem, "online_mobile"));
+ int online_app = _ttoi(jnItem["online_app"].as_mstring());
+ int online_mobile = jnItem["online_mobile"].as_int();
if (online_app == 0 && online_mobile == 0)
SetMirVer(hContact, 7); // vk.com
@@ -309,26 +312,26 @@ MCONTACT CVkProto::SetContactInfo(JSONNODE* pItem, bool flag, bool self) else
SetMirVer(hContact, -1); // unset MinVer
- if ((iValue = json_as_int(json_get(pItem, "timezone"))) != 0)
+ if ((iValue = jnItem["timezone"].as_int()) != 0)
setByte(hContact, "Timezone", iValue * -2);
- tszValue = json_as_CMString(json_get(pItem, "mobile_phone"));
+ tszValue = jnItem["mobile_phone"].as_mstring();
if (!tszValue.IsEmpty())
setTString(hContact, "Cellular", tszValue.GetBuffer());
- tszValue = json_as_CMString(json_get(pItem, "home_phone"));
+ tszValue = jnItem["home_phone"].as_mstring();
if (!tszValue.IsEmpty())
setTString(hContact, "Phone", tszValue.GetBuffer());
- tszValue = json_as_CMString(json_get(pItem, "status"));
+ tszValue = jnItem["status"].as_mstring();
CMString tszOldStatus(ptrT(db_get_tsa(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg")));
if (tszValue != tszOldStatus) {
db_set_ts(hContact, hContact ? "CList" : m_szModuleName, "StatusMsg", tszValue.GetBuffer());
db_unset(hContact, m_szModuleName, "AudioUrl");
- JSONNODE* pAudio = json_get(pItem, "status_audio");
- if (pAudio != NULL) {
+ const JSONNode &jnAudio = jnItem["status_audio"];
+ if (!jnAudio.isnull()) {
db_set_ts(hContact, m_szModuleName, "ListeningTo", tszValue.GetBuffer());
- tszValue = json_as_CMString(json_get(pAudio, "url"));
+ tszValue = jnAudio["url"].as_mstring();
db_set_ts(hContact, m_szModuleName, "AudioUrl", tszValue.GetBuffer());
}
else if (tszValue.GetBuffer()[0] == TCHAR(9835) && tszValue.GetLength() > 2)
@@ -337,12 +340,12 @@ MCONTACT CVkProto::SetContactInfo(JSONNODE* pItem, bool flag, bool self) db_unset(hContact, m_szModuleName, "ListeningTo");
}
- tszValue = json_as_CMString(json_get(pItem, "about"));
-
+ tszValue = jnItem["about"].as_mstring();
+
if (!tszValue.IsEmpty())
setTString(hContact, "About", tszValue.GetBuffer());
- tszValue = json_as_CMString(json_get(pItem, "domain"));
+ tszValue = jnItem["domain"].as_mstring();
if (!tszValue.IsEmpty()) {
setTString(hContact, "domain", tszValue.GetBuffer());
CMString tszUrl("https://vk.com/");
@@ -411,13 +414,13 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (reply->resultCode != 200 || !IsOnline())
return;
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
- JSONNODE *pUsers = json_get(pResponse, "users");
- if (pUsers == NULL)
+ const JSONNode &jnUsers = jnResponse["users"];
+ if (!jnUsers)
return;
LIST<void> arContacts(10, PtrKeySortT);
@@ -427,11 +430,13 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe if (!isChatRoom(hContact))
arContacts.insert((HANDLE)hContact);
- for (size_t i = 0; (hContact = SetContactInfo(json_at(pUsers, i))) != INVALID_CONTACT_ID; i++)
+ for (auto it = jnUsers.begin(); it != jnUsers.end(); ++it){
+ hContact = SetContactInfo((*it));
if (hContact)
arContacts.remove((HANDLE)hContact);
+ }
- if (json_as_int(json_get(pResponse, "freeoffline")))
+ if (jnResponse["freeoffline"].as_bool())
for (int i = 0; i < arContacts.getCount(); i++) {
hContact = (MCONTACT)arContacts[i];
LONG userID = getDword(hContact, "ID", -1);
@@ -451,18 +456,18 @@ void CVkProto::OnReceiveUserInfo(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pRe arContacts.destroy();
AddFeedSpecialUser();
- JSONNODE *pRequests = json_get(pResponse, "requests");
- if (pRequests == NULL)
+ const JSONNode &jnRequests = jnResponse["requests"];
+ if (!jnRequests)
return;
- int iCount = json_as_int(json_get(pRequests, "count"));
- JSONNODE *pItems = json_get(pRequests, "items"), *pInfo;
- if (!iCount || pItems == NULL)
+ int iCount = jnRequests["count"].as_int();
+ const JSONNode &jnItems = jnRequests["items"];
+ if (!iCount || !jnItems)
return;
debugLogA("CVkProto::OnReceiveUserInfo AuthRequests");
- for (int i = 0; (pInfo = json_at(pItems, i)) != NULL; i++) {
- LONG userid = json_as_int(pInfo);
+ for (auto it = jnItems.begin(); it != jnItems.end(); ++it) {
+ LONG userid = (*it).as_int();
if (userid == 0)
break;
hContact = FindUser(userid, true);
@@ -491,9 +496,9 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq if (reply->resultCode != 200 || !IsOnline())
return;
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse == NULL)
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse)
return;
bool bCleanContacts = getBool("AutoClean", false);
@@ -508,12 +513,12 @@ void CVkProto::OnReceiveFriends(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq arContacts.insert((HANDLE)hContact);
}
- int iCount = json_as_int(json_get(pResponse, "count"));
- JSONNODE *pItems = json_get(pResponse, "items");
- if (pItems)
- for (int i = 0; i < iCount; i++) {
- MCONTACT hContact = SetContactInfo(json_at(pItems, i), true);
+ const JSONNode &jnItems = jnResponse["items"];
+
+ if (!jnItems.isnull())
+ for (auto it = jnItems.begin(); it != jnItems.end(); ++it) {
+ MCONTACT hContact = SetContactInfo((*it), true);
if (hContact == NULL || hContact == INVALID_CONTACT_ID)
continue;
@@ -573,22 +578,22 @@ void CVkProto::OnReceiveDeleteFriend(NETLIBHTTPREQUEST* reply, AsyncHttpRequest* debugLogA("CVkProto::OnReceiveDeleteFriend %d", reply->resultCode);
CVkSendMsgParam *param = (CVkSendMsgParam*)pReq->pUserInfo;
if (reply->resultCode == 200) {
- JSONROOT pRoot;
- JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot);
- if (pResponse != NULL) {
+ JSONNode jnRoot;
+ const JSONNode &jnResponse = CheckJsonResponse(pReq, reply, jnRoot);
+ if (!jnResponse.isnull()) {
CMString tszNick = ptrT(db_get_tsa(param->hContact, m_szModuleName, "Nick"));
if (tszNick.IsEmpty())
tszNick = TranslateT("(Unknown contact)");
CMString msgformat, msg;
- if (json_as_int(json_get(pResponse, "success"))) {
- if (json_as_int(json_get(pResponse, "friend_deleted")))
+ if (jnResponse["success"].as_bool()) {
+ if (jnResponse["friend_deleted"].as_bool())
msgformat = TranslateT("User %s was deleted from your friend list");
- else if (json_as_int(json_get(pResponse, "out_request_deleted")))
+ else if (jnResponse["out_request_deleted"].as_bool())
msgformat = TranslateT("Your request to the user %s was deleted");
- else if (json_as_int(json_get(pResponse, "in_request_deleted")))
+ else if (jnResponse["in_request_deleted"].as_bool())
msgformat = TranslateT("Friend request from the user %s declined");
- else if (json_as_int(json_get(pResponse, "suggestion_deleted")))
+ else if (jnResponse["suggestion_deleted"].as_bool())
msgformat = TranslateT("Friend request suggestion for the user %s deleted");
msg.AppendFormat(msgformat, tszNick);
|