summaryrefslogtreecommitdiff
path: root/protocols/JabberG
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/JabberG')
-rw-r--r--protocols/JabberG/src/jabber_file.cpp26
-rw-r--r--protocols/JabberG/src/jabber_ft.cpp26
-rw-r--r--protocols/JabberG/src/jabber_util.cpp12
3 files changed, 28 insertions, 36 deletions
diff --git a/protocols/JabberG/src/jabber_file.cpp b/protocols/JabberG/src/jabber_file.cpp
index ebd33b3d93..c35069a294 100644
--- a/protocols/JabberG/src/jabber_file.cpp
+++ b/protocols/JabberG/src/jabber_file.cpp
@@ -49,10 +49,10 @@ void __cdecl CJabberProto::OfflineFileThread(OFDTHREAD *ofd)
}
// initialize the netlib request
- NETLIBHTTPREQUEST nlhr = {};
+ MHttpRequest nlhr;
nlhr.requestType = REQUEST_GET;
nlhr.flags = NLHRF_HTTP11 | NLHRF_DUMPASTEXT | NLHRF_REDIRECT;
- nlhr.szUrl = (char *)url;
+ nlhr.m_szUrl = url;
// download the page
NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
@@ -61,18 +61,18 @@ void __cdecl CJabberProto::OfflineFileThread(OFDTHREAD *ofd)
size_t written = 0;
if (f) {
if (encrypted) {
- int payload_len = nlhrReply->dataLength - 16;
+ int payload_len = nlhrReply->body.GetLength() - 16;
if (payload_len > 0) {
uint8_t ivkey[44];
hex2bin(hexkey, ivkey, 44);
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, 12, NULL);
EVP_DecryptInit(ctx, EVP_aes_256_gcm(), ivkey + 12, ivkey);
- EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, 16, nlhrReply->pData + payload_len);
+ EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, 16, (uint8_t *)nlhrReply->body.c_str() + payload_len);
int outl = 0, round_len = 0;
uint8_t *out = (uint8_t *)mir_alloc(payload_len);
- EVP_DecryptUpdate(ctx, out, &outl, (uint8_t *)nlhrReply->pData, (int)payload_len);
+ EVP_DecryptUpdate(ctx, out, &outl, (uint8_t *)nlhrReply->body.c_str(), (int)payload_len);
int dec_success = EVP_DecryptFinal(ctx, out + outl, &round_len);
outl += round_len;
EVP_CIPHER_CTX_free(ctx);
@@ -82,8 +82,8 @@ void __cdecl CJabberProto::OfflineFileThread(OFDTHREAD *ofd)
mir_free(out);
}
}
- else if (fwrite(nlhrReply->pData, 1, nlhrReply->dataLength, f) == size_t(nlhrReply->dataLength))
- written = nlhrReply->dataLength;
+ else if (fwrite(nlhrReply->body, 1, nlhrReply->body.GetLength(), f) == size_t(nlhrReply->body.GetLength()))
+ written = nlhrReply->body.GetLength();
fclose(f);
}
@@ -127,16 +127,16 @@ void CJabberProto::OnReceiveOfflineFile(DB::FILE_BLOB &blob, void *pHandle)
void __cdecl CJabberProto::FileReceiveHttpThread(filetransfer *ft)
{
- NETLIBHTTPREQUEST req = {};
+ MHttpRequest req;
req.requestType = REQUEST_GET;
- req.szUrl = ft->httpPath;
+ req.m_szUrl = ft->httpPath;
NLHR_PTR pResp(Netlib_HttpTransaction(m_hNetlibUser, &req));
if (pResp && pResp->resultCode == 200) {
- ft->std.currentFileSize = pResp->dataLength;
+ ft->std.currentFileSize = pResp->body.GetLength();
ProtoBroadcastAck(ft->std.hContact, ACKTYPE_FILE, ACKRESULT_INITIALISING, ft);
- FtReceive(ft, pResp->pData, pResp->dataLength);
+ FtReceive(ft, pResp->body.GetBuffer(), pResp->body.GetLength());
ft->complete();
}
@@ -154,9 +154,9 @@ void CJabberProto::FileProcessHttpDownload(MCONTACT hContact, const char *jid, c
szName.AppendChar(*b++);
auto *pszName = szName.c_str();
- NETLIBHTTPREQUEST req = {};
+ MHttpRequest req;
req.requestType = REQUEST_HEAD;
- req.szUrl = (char*)pszUrl;
+ req.m_szUrl = pszUrl;
filetransfer *ft = new filetransfer(this, 0);
ft->jid = mir_strdup(jid);
diff --git a/protocols/JabberG/src/jabber_ft.cpp b/protocols/JabberG/src/jabber_ft.cpp
index 9ca292ca71..a489aa696c 100644
--- a/protocols/JabberG/src/jabber_ft.cpp
+++ b/protocols/JabberG/src/jabber_ft.cpp
@@ -691,22 +691,16 @@ LBL_Fail:
if (!szUrl)
goto LBL_Fail;
- NETLIBHTTPHEADER hdr[10];
-
- NETLIBHTTPREQUEST nlhr = {};
+ MHttpRequest nlhr;
nlhr.requestType = REQUEST_PUT;
nlhr.flags = NLHRF_NODUMPSEND | NLHRF_SSL | NLHRF_REDIRECT;
- nlhr.szUrl = (char *)szUrl;
+ nlhr.m_szUrl = szUrl;
for (auto *it : TiXmlFilter(putNode, "header")) {
auto *szName = it->Attribute("name");
auto *szValue = it->GetText();
- if (szName && szValue && nlhr.headersCount < _countof(hdr)) {
- nlhr.headers = hdr;
- hdr[nlhr.headersCount].szName = (char *)szName;
- hdr[nlhr.headersCount].szValue = (char *)szValue;
- nlhr.headersCount++;
- }
+ if (szName && szValue)
+ nlhr.AddHeader(szName, szValue);
}
const wchar_t *pwszFileName = ft->std.pszFiles.w[ft->std.currentFileNumber];
@@ -728,8 +722,8 @@ LBL_Fail:
EVP_EncryptInit(ctx, EVP_aes_256_gcm(), key, iv);
int tmp_len = 0, outl;
- //EVP_EncryptUpdate(ctx, nullptr, &outl, aad, _countof(aad));
- unsigned char *out = (unsigned char *)mir_alloc(_filelength(fileId) + _countof(key) - 1 + _countof(tag));
+ nlhr.m_szParam.Truncate(_filelength(fileId) + _countof(key) - 1 + _countof(tag));
+ unsigned char *out = (unsigned char *)nlhr.m_szParam.GetBuffer();
unsigned char *in = (unsigned char *)mir_alloc(128 * 1024);
for (;;) {
int inl = _read(fileId, in, 128 * 1024);
@@ -746,13 +740,11 @@ LBL_Fail:
EVP_CIPHER_CTX_free(ctx);
memcpy(out + tmp_len, tag, _countof(tag));
- nlhr.dataLength = tmp_len + _countof(tag);
- nlhr.pData = (char *)out;
}
else {
- nlhr.dataLength = _filelength(fileId);
- nlhr.pData = new char[nlhr.dataLength];
- _read(fileId, nlhr.pData, nlhr.dataLength);
+ int iLength = _filelength(fileId);
+ nlhr.m_szParam.Truncate(iLength);
+ _read(fileId, nlhr.m_szParam.GetBuffer(), iLength);
}
_close(fileId);
diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp
index e018c39b40..441b5de49c 100644
--- a/protocols/JabberG/src/jabber_util.cpp
+++ b/protocols/JabberG/src/jabber_util.cpp
@@ -881,17 +881,17 @@ void __cdecl CJabberProto::LoadHttpAvatars(void* param)
OBJLIST<JABBER_HTTP_AVATARS> &avs = *(OBJLIST<JABBER_HTTP_AVATARS>*)param;
HNETLIBCONN hHttpCon = nullptr;
for (auto &it : avs) {
- NETLIBHTTPREQUEST nlhr = { 0 };
+ MHttpRequest nlhr;
nlhr.requestType = REQUEST_GET;
nlhr.flags = NLHRF_HTTP11 | NLHRF_REDIRECT | NLHRF_PERSISTENT;
- nlhr.szUrl = it->Url;
+ nlhr.m_szUrl = it->Url;
nlhr.nlc = hHttpCon;
NLHR_PTR res(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
if (res) {
hHttpCon = res->nlc;
- if (res->resultCode == 200 && res->dataLength) {
- int pictureType = ProtoGetBufferFormat(res->pData);
+ if (res->resultCode == 200 && !res->body.IsEmpty()) {
+ int pictureType = ProtoGetBufferFormat(res->body);
if (pictureType != PA_FORMAT_UNKNOWN) {
PROTO_AVATAR_INFORMATION ai;
ai.format = pictureType;
@@ -909,7 +909,7 @@ void __cdecl CJabberProto::LoadHttpAvatars(void* param)
uint8_t digest[MIR_SHA1_HASH_SIZE];
mir_sha1_ctx sha;
mir_sha1_init(&sha);
- mir_sha1_append(&sha, (uint8_t*)res->pData, res->dataLength);
+ mir_sha1_append(&sha, (uint8_t*)res->body.c_str(), res->body.GetLength());
mir_sha1_finish(&sha, digest);
bin2hex(digest, sizeof(digest), buffer);
@@ -920,7 +920,7 @@ void __cdecl CJabberProto::LoadHttpAvatars(void* param)
wcsncpy_s(ai.filename, tszFileName, _TRUNCATE);
FILE* out = _wfopen(tszFileName, L"wb");
if (out != nullptr) {
- fwrite(res->pData, res->dataLength, 1, out);
+ fwrite(res->body, res->body.GetLength(), 1, out);
fclose(out);
setString(ai.hContact, "AvatarHash", buffer);
ProtoBroadcastAck(ai.hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &ai);