From 7d95e67308ee0abcce5c7bd66265146d3dfefd74 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 30 Mar 2025 11:35:03 +0300 Subject: useful helper JsonReply moved to the core --- protocols/Discord/src/http.cpp | 19 --------------- protocols/Discord/src/proto.h | 14 ----------- protocols/Facebook/src/http.cpp | 27 --------------------- protocols/Facebook/src/proto.h | 13 ----------- protocols/SkypeWeb/src/skype_utils.cpp | 27 --------------------- protocols/SkypeWeb/src/skype_utils.h | 13 ----------- protocols/Weather/src/stdafx.h | 17 -------------- protocols/Weather/src/weather_utils.cpp | 39 ------------------------------- protocols/Weather/weather.vcxproj | 1 - protocols/Weather/weather.vcxproj.filters | 3 --- 10 files changed, 173 deletions(-) delete mode 100644 protocols/Weather/src/weather_utils.cpp (limited to 'protocols') diff --git a/protocols/Discord/src/http.cpp b/protocols/Discord/src/http.cpp index 32976d39cf..f6a912e9e4 100644 --- a/protocols/Discord/src/http.cpp +++ b/protocols/Discord/src/http.cpp @@ -74,25 +74,6 @@ AsyncHttpRequest::AsyncHttpRequest(CDiscordProto *ppro, int iRequestType, LPCSTR m_iReqNum = ::InterlockedIncrement(&g_reqNum); } -JsonReply::JsonReply(MHttpResponse *pReply) -{ - if (pReply == nullptr) { - m_errorCode = 500; - return; - } - - m_errorCode = pReply->resultCode; - - m_root = json_parse(pReply->body); - if (m_root == nullptr) - m_errorCode = 500; -} - -JsonReply::~JsonReply() -{ - json_delete(m_root); -} - ///////////////////////////////////////////////////////////////////////////////////////// void CDiscordProto::ServerThread(void*) diff --git a/protocols/Discord/src/proto.h b/protocols/Discord/src/proto.h index a147124a43..04fe34110b 100644 --- a/protocols/Discord/src/proto.h +++ b/protocols/Discord/src/proto.h @@ -71,20 +71,6 @@ struct AsyncHttpRequest : public MTHttpRequest MCONTACT hContact; }; -class JsonReply -{ - JSONNode *m_root = nullptr; - int m_errorCode = 0; - -public: - JsonReply(MHttpResponse *); - ~JsonReply(); - - __forceinline int error() const { return m_errorCode; } - __forceinline JSONNode& data() const { return *m_root; } - __forceinline operator bool() const { return m_errorCode == 200; } -}; - ///////////////////////////////////////////////////////////////////////////////////////// struct CDiscordRole : public MZeroedObject diff --git a/protocols/Facebook/src/http.cpp b/protocols/Facebook/src/http.cpp index eaa91d8aff..033fc47b80 100644 --- a/protocols/Facebook/src/http.cpp +++ b/protocols/Facebook/src/http.cpp @@ -69,33 +69,6 @@ AsyncHttpRequest* operator<<(AsyncHttpRequest *pReq, const INT_PARAM ¶m) ///////////////////////////////////////////////////////////////////////////////////////// -JsonReply::JsonReply(MHttpResponse *pReply) -{ - if (pReply == nullptr) { - m_errorCode = 500; - return; - } - - m_errorCode = pReply->resultCode; - if (m_errorCode != 200) - return; - - m_root = json_parse(pReply->body); - if (m_root == nullptr) { - m_errorCode = 500; - return; - } - - m_errorCode = (*m_root)["error_code"].as_int(); -} - -JsonReply::~JsonReply() -{ - json_delete(m_root); -} - -///////////////////////////////////////////////////////////////////////////////////////// - AsyncHttpRequest* FacebookProto::CreateRequest(const char *url, const char *szName, const char *szMethod) { AsyncHttpRequest *pReq = new AsyncHttpRequest(); diff --git a/protocols/Facebook/src/proto.h b/protocols/Facebook/src/proto.h index 00a436b524..87e31351f7 100644 --- a/protocols/Facebook/src/proto.h +++ b/protocols/Facebook/src/proto.h @@ -326,19 +326,6 @@ struct AsyncHttpRequest : public MTHttpRequest AsyncHttpRequest *operator<<(AsyncHttpRequest *, const CHAR_PARAM &); AsyncHttpRequest *operator<<(AsyncHttpRequest *, const INT_PARAM &); -class JsonReply -{ - JSONNode *m_root = nullptr; - int m_errorCode = 0; - -public: - JsonReply(MHttpResponse *); - ~JsonReply(); - - __forceinline JSONNode &data() const { return *m_root; } - __forceinline int error() const { return m_errorCode; } -}; - ///////////////////////////////////////////////////////////////////////////////////////// struct FacebookUser diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index 26cf39e7bb..87a0863a4d 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -883,30 +883,3 @@ INT_PTR CSkypeProto::GlobalParseSkypeUriService(WPARAM wParam, LPARAM lParam) return 1; } - -///////////////////////////////////////////////////////////////////////////////////////// - -JsonReply::JsonReply(MHttpResponse *pReply) -{ - if (pReply == nullptr) { - m_errorCode = 500; - return; - } - - m_errorCode = pReply->resultCode; - if (m_errorCode != 200) - return; - - m_root = json_parse(pReply->body); - if (m_root == nullptr) { - m_errorCode = 500; - return; - } - - m_errorCode = (*m_root)["status"]["code"].as_int(); -} - -JsonReply::~JsonReply() -{ - json_delete(m_root); -} diff --git a/protocols/SkypeWeb/src/skype_utils.h b/protocols/SkypeWeb/src/skype_utils.h index 64b72124b3..aecb8f66fe 100644 --- a/protocols/SkypeWeb/src/skype_utils.h +++ b/protocols/SkypeWeb/src/skype_utils.h @@ -60,17 +60,4 @@ struct CFileUploadParam : public MZeroedObject } }; -class JsonReply -{ - JSONNode *m_root = nullptr; - int m_errorCode = 0; - -public: - JsonReply(MHttpResponse *response); - ~JsonReply(); - - __forceinline JSONNode &data() const { return *m_root; } - __forceinline int error() const { return m_errorCode; } -}; - #endif //_UTILS_H_ diff --git a/protocols/Weather/src/stdafx.h b/protocols/Weather/src/stdafx.h index 956ce498b9..96e5410c71 100644 --- a/protocols/Weather/src/stdafx.h +++ b/protocols/Weather/src/stdafx.h @@ -150,20 +150,3 @@ const wchar_t *GetDefaultText(int c); // function from multiwin module void UpdateMwinData(MCONTACT hContact); - -///////////////////////////////////////////////////////////////////////////////////////// -// utils - -class JsonReply -{ - JSONNode *m_root = nullptr; - int m_errorCode = 0; - -public: - JsonReply(MHttpResponse *); - ~JsonReply(); - - __forceinline int error() const { return m_errorCode; } - __forceinline JSONNode &data() const { return *m_root; } - __forceinline operator bool() const { return m_errorCode == 200; } -}; diff --git a/protocols/Weather/src/weather_utils.cpp b/protocols/Weather/src/weather_utils.cpp deleted file mode 100644 index b37b6bbe9a..0000000000 --- a/protocols/Weather/src/weather_utils.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright (C) 2012-25 Miranda NG team (https://miranda-ng.org) - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation version 2 -of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "stdafx.h" - -JsonReply::JsonReply(MHttpResponse *pReply) -{ - if (pReply == nullptr) { - m_errorCode = 500; - return; - } - - m_errorCode = pReply->resultCode; - - m_root = json_parse(pReply->body); - if (m_root == nullptr) - m_errorCode = 500; - - delete pReply; -} - -JsonReply::~JsonReply() -{ - json_delete(m_root); -} diff --git a/protocols/Weather/weather.vcxproj b/protocols/Weather/weather.vcxproj index 8b18056c59..56a2b52edd 100644 --- a/protocols/Weather/weather.vcxproj +++ b/protocols/Weather/weather.vcxproj @@ -41,7 +41,6 @@ - diff --git a/protocols/Weather/weather.vcxproj.filters b/protocols/Weather/weather.vcxproj.filters index 50c35cce0e..92a72a4653 100644 --- a/protocols/Weather/weather.vcxproj.filters +++ b/protocols/Weather/weather.vcxproj.filters @@ -41,9 +41,6 @@ Source Files - - Source Files - -- cgit v1.2.3