summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2025-03-30 11:35:03 +0300
committerGeorge Hazan <george.hazan@gmail.com>2025-03-30 11:35:03 +0300
commit7d95e67308ee0abcce5c7bd66265146d3dfefd74 (patch)
tree9c377087518bb53a429151edb6a947fc47e89242 /src
parent66821b916cc298111f9e5ddd2684d15ff7909f02 (diff)
useful helper JsonReply moved to the core
Diffstat (limited to 'src')
-rw-r--r--src/mir_app/src/MHttpResponse.cpp27
-rw-r--r--src/mir_app/src/mir_app.def5
-rw-r--r--src/mir_app/src/mir_app64.def5
3 files changed, 37 insertions, 0 deletions
diff --git a/src/mir_app/src/MHttpResponse.cpp b/src/mir_app/src/MHttpResponse.cpp
index ccfd81e34c..4a27d794df 100644
--- a/src/mir_app/src/MHttpResponse.cpp
+++ b/src/mir_app/src/MHttpResponse.cpp
@@ -34,6 +34,33 @@ MHttpResponse::~MHttpResponse()
}
/////////////////////////////////////////////////////////////////////////////////////////
+
+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);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
// MHttpResponse helpers for Pascal
// declared only in m_netlib.inc
diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def
index 1dd24ecab3..045183f86f 100644
--- a/src/mir_app/src/mir_app.def
+++ b/src/mir_app/src/mir_app.def
@@ -998,3 +998,8 @@ Proto_CanDeleteHistory @1118 NONAME
?getConn@MWebSocket@@QBEPAXXZ @1129 NONAME
?Chat_GetStatus@@YGPAUSTATUSINFO@@PAUSESSION_INFO@@PBUUSERINFO@@@Z @1130 NONAME
?SetBirthday@Contact@@YGXIHHH@Z @1131 NONAME
+??0JsonReply@@QAE@PAUMHttpResponse@@@Z @1132 NONAME
+??1JsonReply@@QAE@XZ @1133 NONAME
+?data@JsonReply@@QBEAAVJSONNode@@XZ @1134 NONAME
+?error@JsonReply@@QBEHXZ @1135 NONAME
+??BJsonReply@@QBE_NXZ @1136 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def
index 5e7b681246..097f6a94fa 100644
--- a/src/mir_app/src/mir_app64.def
+++ b/src/mir_app/src/mir_app64.def
@@ -998,3 +998,8 @@ Proto_CanDeleteHistory @1118 NONAME
?getConn@MWebSocket@@QEBAPEAXXZ @1129 NONAME
?Chat_GetStatus@@YAPEAUSTATUSINFO@@PEAUSESSION_INFO@@PEBUUSERINFO@@@Z @1130 NONAME
?SetBirthday@Contact@@YAXIHHH@Z @1131 NONAME
+??0JsonReply@@QEAA@PEAUMHttpResponse@@@Z @1132 NONAME
+??1JsonReply@@QEAA@XZ @1133 NONAME
+?data@JsonReply@@QEBAAEAVJSONNode@@XZ @1134 NONAME
+?error@JsonReply@@QEBAHXZ @1135 NONAME
+??BJsonReply@@QEBA_NXZ @1136 NONAME