summaryrefslogtreecommitdiff
path: root/protocols/Tox/src
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-01-05 15:54:03 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-01-05 15:54:03 +0300
commit14c4e44a0a91e1ad701d4ae3c58185d25118e64e (patch)
tree50f36035466f355c74373e757bc00b6610ce6267 /protocols/Tox/src
parent94667140aeb3886d22e4c1301423fe99aaf3fba4 (diff)
Netlib:
- NETLIBHTTPHEADER & NETLIBHTTPREQUEST obsoleted; - NETLIBHTTPREQUEST divided into MHttpRequest & MHttpResponse; - MHttpHeaders now manager headers both for MHttpRequest & MHttpResponse;
Diffstat (limited to 'protocols/Tox/src')
-rw-r--r--protocols/Tox/src/http_request.h41
-rw-r--r--protocols/Tox/src/tox_bootstrap.cpp6
2 files changed, 5 insertions, 42 deletions
diff --git a/protocols/Tox/src/http_request.h b/protocols/Tox/src/http_request.h
index bba9f0591c..1e140b2ef0 100644
--- a/protocols/Tox/src/http_request.h
+++ b/protocols/Tox/src/http_request.h
@@ -17,22 +17,12 @@ public:
}
};
-class HttpRequest : protected NETLIBHTTPREQUEST
+class HttpRequest : public MHttpRequest
{
-private:
- CMStringA m_szUrl;
-
void Init(int type)
{
requestType = type;
flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
- szUrl = nullptr;
- headers = nullptr;
- headersCount = 0;
- pData = nullptr;
- dataLength = 0;
- resultCode = 0;
- szResultDescr = nullptr;
nlc = nullptr;
timeout = 0;
}
@@ -60,22 +50,6 @@ public:
~HttpRequest()
{
- for (int i = 0; i < headersCount; i++)
- {
- mir_free(headers[i].szName);
- mir_free(headers[i].szValue);
- }
- mir_free(headers);
- if (pData)
- mir_free(pData);
- }
-
- void AddHeader(LPCSTR szName, LPCSTR szValue)
- {
- headers = (NETLIBHTTPHEADER*)mir_realloc(headers, sizeof(NETLIBHTTPHEADER) * (headersCount + 1));
- headers[headersCount].szName = mir_strdup(szName);
- headers[headersCount].szValue = mir_strdup(szValue);
- headersCount++;
}
void AddUrlParameter(const char *urlFormat, ...)
@@ -87,20 +61,9 @@ public:
va_end(urlArgs);
}
- void SetData(const char *data, size_t size)
- {
- if (pData != nullptr)
- mir_free(pData);
-
- dataLength = (int)size;
- pData = (char*)mir_alloc(size);
- memcpy(pData, data, size);
- }
-
- NETLIBHTTPREQUEST* Send(HNETLIBUSER hNetlibConnection)
+ MHttpResponse* Send(HNETLIBUSER hNetlibConnection)
{
m_szUrl.Replace('\\', '/');
- szUrl = m_szUrl.GetBuffer();
return Netlib_HttpTransaction(hNetlibConnection, this);
}
};
diff --git a/protocols/Tox/src/tox_bootstrap.cpp b/protocols/Tox/src/tox_bootstrap.cpp
index 663e46a8ab..6e8a5d774e 100644
--- a/protocols/Tox/src/tox_bootstrap.cpp
+++ b/protocols/Tox/src/tox_bootstrap.cpp
@@ -121,12 +121,12 @@ void CToxProto::UpdateNodes()
debugLogA(__FUNCTION__": updating nodes");
HttpRequest request(REQUEST_GET, "https://nodes.tox.chat/json");
NLHR_PTR response(request.Send(m_hNetlibUser));
- if (!response || response->resultCode != HTTP_CODE_OK || !response->pData) {
+ if (!response || response->resultCode != HTTP_CODE_OK || response->body.IsEmpty()) {
debugLogA(__FUNCTION__": failed to dowload tox.json");
return;
}
- JSONNode root = JSONNode::parse(response->pData);
+ JSONNode root = JSONNode::parse(response->body);
if (root.empty()) {
debugLogA(__FUNCTION__": failed to dowload tox.json");
return;
@@ -142,7 +142,7 @@ void CToxProto::UpdateNodes()
return;
}
- if (fwrite(response->pData, sizeof(char), response->dataLength, hFile) != (size_t)response->dataLength)
+ if (fwrite(response->body, sizeof(char), response->body.GetLength(), hFile) != (size_t)response->body.GetLength())
debugLogA(__FUNCTION__": failed to write tox.json");
fclose(hFile);