summaryrefslogtreecommitdiff
path: root/protocols/MSN
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-07-24 14:30:13 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-07-24 14:30:13 +0300
commit103de9c164934b2393dfcba7011625f90c8a2097 (patch)
treef7a4a09afe29398f3b7605d7d0db264638a18150 /protocols/MSN
parent541eab20530165d10592a9fda590f435c6a8b4be (diff)
NLHR_PTR - smart pointers make better code
Diffstat (limited to 'protocols/MSN')
-rw-r--r--protocols/MSN/src/msn_auth.cpp11
-rw-r--r--protocols/MSN/src/msn_avatar.cpp12
-rw-r--r--protocols/MSN/src/msn_commands.cpp6
-rw-r--r--protocols/MSN/src/msn_proto.cpp24
-rw-r--r--protocols/MSN/src/msn_skypeab.cpp86
-rw-r--r--protocols/MSN/src/msn_soapab.cpp3
-rw-r--r--protocols/MSN/src/msn_ssl.cpp25
7 files changed, 67 insertions, 100 deletions
diff --git a/protocols/MSN/src/msn_auth.cpp b/protocols/MSN/src/msn_auth.cpp
index 176c42f1f9..c2956d09af 100644
--- a/protocols/MSN/src/msn_auth.cpp
+++ b/protocols/MSN/src/msn_auth.cpp
@@ -287,10 +287,9 @@ bool SkypeToken::Refresh(bool bForce)
nlhr.pData = szPOST.GetBuffer();
m_proto->mHttpsTS = clock();
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_proto->m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_proto->m_hNetlibUser, &nlhr));
m_proto->mHttpsTS = clock();
- bool bRet = false;
if (nlhrReply) {
m_proto->hHttpsConnection = nlhrReply->nlc;
@@ -303,14 +302,13 @@ bool SkypeToken::Refresh(bool bForce)
if (tExpires == 0)
tExpires = 86400;
SetToken("skype_token " + szToken, time(0) + tExpires);
- bRet = true;
+ return true;
}
}
}
- Netlib_FreeHttpRequest(nlhrReply);
}
else m_proto->hHttpsConnection = nullptr;
- return bRet;
+ return false;
}
const char* SkypeToken::XSkypetoken()
@@ -698,7 +696,7 @@ bool CMsnProto::RefreshOAuth(const char *pszRefreshToken, const char *pszService
// Query
mHttpsTS = clock();
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
mHttpsTS = clock();
if (nlhrReply) {
hHttpsConnection = nlhrReply->nlc;
@@ -728,7 +726,6 @@ bool CMsnProto::RefreshOAuth(const char *pszRefreshToken, const char *pszService
}
}
}
- Netlib_FreeHttpRequest(nlhrReply);
}
else hHttpsConnection = nullptr;
return bRet;
diff --git a/protocols/MSN/src/msn_avatar.cpp b/protocols/MSN/src/msn_avatar.cpp
index 7d148dd5ca..91122e32c5 100644
--- a/protocols/MSN/src/msn_avatar.cpp
+++ b/protocols/MSN/src/msn_avatar.cpp
@@ -61,20 +61,17 @@ bool CMsnProto::loadHttpAvatar(AvatarQueueEntry *p)
nlhr.headers = (NETLIBHTTPHEADER*)&nlbhHeaders;
nlhr.headersCount = 1;
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
if (nlhrReply == nullptr)
return false;
- if (nlhrReply->resultCode != 200 || nlhrReply->dataLength == 0) {
-LBL_Error:
- Netlib_FreeHttpRequest(nlhrReply);
+ if (nlhrReply->resultCode != 200 || nlhrReply->dataLength == 0)
return false;
- }
const wchar_t *szExt;
int fmt = ProtoGetBufferFormat(nlhrReply->pData, &szExt);
if (fmt == PA_FORMAT_UNKNOWN)
- goto LBL_Error;
+ return false;
PROTO_AVATAR_INFORMATION ai = { 0 };
ai.format = fmt;
@@ -84,13 +81,12 @@ LBL_Error:
int fileId = _wopen(ai.filename, _O_CREAT | _O_TRUNC | _O_WRONLY | O_BINARY, _S_IREAD | _S_IWRITE);
if (fileId == -1)
- goto LBL_Error;
+ return false;
_write(fileId, nlhrReply->pData, (unsigned)nlhrReply->dataLength);
_close(fileId);
ProtoBroadcastAck(p->hContact, ACKTYPE_AVATAR, ACKRESULT_SUCCESS, &ai);
- Netlib_FreeHttpRequest(nlhrReply);
return true;
}
diff --git a/protocols/MSN/src/msn_commands.cpp b/protocols/MSN/src/msn_commands.cpp
index 0a4fa74562..e4e3beca97 100644
--- a/protocols/MSN/src/msn_commands.cpp
+++ b/protocols/MSN/src/msn_commands.cpp
@@ -392,7 +392,7 @@ void CMsnProto::MSN_ProcessURIObject(MCONTACT hContact, ezxml_t xmli)
nlbhHeaders[0].szName = "User-Agent"; nlbhHeaders[0].szValue = (LPSTR)MSN_USER_AGENT;
nlbhHeaders[1].szName = "Authorization"; nlbhHeaders[1].szValue = (char*)pszSkypeToken;
- NETLIBHTTPREQUEST nlhr = { 0 }, *nlhrReply;
+ NETLIBHTTPREQUEST nlhr = {};
nlhr.cbSize = sizeof(nlhr);
nlhr.requestType = REQUEST_GET;
nlhr.flags = NLHRF_PERSISTENT;
@@ -402,7 +402,7 @@ void CMsnProto::MSN_ProcessURIObject(MCONTACT hContact, ezxml_t xmli)
nlhr.nlc = hHttpsConnection;
mHttpsTS = clock();
- nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
mHttpsTS = clock();
if (nlhrReply) {
hHttpsConnection = nlhrReply->nlc;
@@ -416,8 +416,6 @@ void CMsnProto::MSN_ProcessURIObject(MCONTACT hContact, ezxml_t xmli)
fileSize = _atoi64(pLength);
}
}
-
- Netlib_FreeHttpRequest(nlhrReply);
}
else hHttpsConnection = nullptr;
diff --git a/protocols/MSN/src/msn_proto.cpp b/protocols/MSN/src/msn_proto.cpp
index e26d2828f0..24bd25f121 100644
--- a/protocols/MSN/src/msn_proto.cpp
+++ b/protocols/MSN/src/msn_proto.cpp
@@ -796,22 +796,14 @@ int CMsnProto::SendMsg(MCONTACT hContact, int flags, const char* pszSrc)
ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
}
else {
- // MSNP24 doesn't have a switchboard anymore
- bool isOffline = true;
- ThreadData *thread = nullptr;
-
- if (thread == nullptr) {
- if (isOffline) {
- if (netId != NETID_LCS) {
- seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag | MSG_OFFLINE);
- ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, nullptr, this));
- }
- else {
- seq = 999993;
- errMsg = Translate("Offline messaging is not allowed for LCS contacts");
- ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
- }
- }
+ if (netId != NETID_LCS) {
+ seq = msnNsThread->sendMessage('1', tEmail, netId, msg, rtlFlag | MSG_OFFLINE);
+ ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, nullptr, this));
+ }
+ else {
+ seq = 999993;
+ errMsg = Translate("Offline messaging is not allowed for LCS contacts");
+ ForkThread(&CMsnProto::MsnFakeAck, new TFakeAckParams(hContact, seq, errMsg, this));
}
}
break;
diff --git a/protocols/MSN/src/msn_skypeab.cpp b/protocols/MSN/src/msn_skypeab.cpp
index c759604fba..eb5fa20886 100644
--- a/protocols/MSN/src/msn_skypeab.cpp
+++ b/protocols/MSN/src/msn_skypeab.cpp
@@ -68,7 +68,7 @@ bool CMsnProto::MSN_SKYABRefreshClist(void)
// Query addressbook
mHttpsTS = clock();
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
mHttpsTS = clock();
if (nlhrReply) {
hHttpsConnection = nlhrReply->nlc;
@@ -107,9 +107,7 @@ bool CMsnProto::MSN_SKYABRefreshClist(void)
}
}
bRet = true;
- //MSN_SKYABGetProfiles((const char*)post);
}
- Netlib_FreeHttpRequest(nlhrReply);
}
else hHttpsConnection = nullptr;
return bRet;
@@ -130,7 +128,7 @@ bool CMsnProto::MSN_SKYABGetProfiles(const char *pszPOST)
nlhr.pData = (char*)pszPOST;
mHttpsTS = clock();
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
mHttpsTS = clock();
if (nlhrReply) {
hHttpsConnection = nlhrReply->nlc;
@@ -163,7 +161,6 @@ bool CMsnProto::MSN_SKYABGetProfiles(const char *pszPOST)
json_delete(items);
bRet = true;
}
- Netlib_FreeHttpRequest(nlhrReply);
}
else hHttpsConnection = nullptr;
return bRet;
@@ -183,7 +180,7 @@ bool CMsnProto::MSN_SKYABGetProfile(const char *wlid)
nlhr.szUrl = szURL;
mHttpsTS = clock();
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
mHttpsTS = clock();
if (nlhrReply) {
hHttpsConnection = nlhrReply->nlc;
@@ -235,7 +232,6 @@ bool CMsnProto::MSN_SKYABGetProfile(const char *wlid)
}
bRet = true;
}
- Netlib_FreeHttpRequest(nlhrReply);
}
else hHttpsConnection = nullptr;
return bRet;
@@ -246,13 +242,14 @@ bool CMsnProto::MSN_SKYABBlockContact(const char *wlid, const char *pszAction)
{
NETLIBHTTPREQUEST nlhr = { 0 };
NETLIBHTTPHEADER headers[4];
- bool bRet = false;
+ // initialize the netlib request
+ if (!APISkypeComRequest(&nlhr, headers))
+ return false;
+
char szURL[256], szPOST[128];
+ mir_snprintf(szURL, sizeof(szURL), "https://api.skype.com/users/self/contacts/%s/%s", wlid, pszAction);
- // initialize the netlib request
- if (!APISkypeComRequest(&nlhr, headers)) return false;
nlhr.requestType = REQUEST_PUT;
- mir_snprintf(szURL, sizeof(szURL), "https://api.skype.com/users/self/contacts/%s/%s", wlid, pszAction);
nlhr.szUrl = szURL;
nlhr.headers[3].szName = "Content-type";
nlhr.headers[3].szValue = "application/x-www-form-urlencoded";
@@ -261,69 +258,68 @@ bool CMsnProto::MSN_SKYABBlockContact(const char *wlid, const char *pszAction)
nlhr.pData = szPOST;
mHttpsTS = clock();
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
mHttpsTS = clock();
- if (nlhrReply) {
- hHttpsConnection = nlhrReply->nlc;
- Netlib_FreeHttpRequest(nlhrReply);
- bRet = true;
+ if (!nlhrReply) {
+ hHttpsConnection = nullptr;
+ return false;
}
- else hHttpsConnection = nullptr;
- return bRet;
+
+ hHttpsConnection = nlhrReply->nlc;
+ return true;
}
bool CMsnProto::MSN_SKYABDeleteContact(const char *wlid)
{
+ // initialize the netlib request
NETLIBHTTPREQUEST nlhr = { 0 };
NETLIBHTTPHEADER headers[4];
- bool bRet = false;
- char szURL[256];
+ if (!APISkypeComRequest(&nlhr, headers))
+ return false;
- // initialize the netlib request
- if (!APISkypeComRequest(&nlhr, headers)) return false;
- nlhr.requestType = REQUEST_DELETE;
+ char szURL[256];
mir_snprintf(szURL, sizeof(szURL), "https://contacts.skype.com/contacts/v2/users/SELF/contacts/%s", wlid);
+ nlhr.requestType = REQUEST_DELETE;
nlhr.szUrl = szURL;
nlhr.headers[3].szName = "Content-type";
nlhr.headers[3].szValue = "application/x-www-form-urlencoded";
nlhr.headersCount++;
mHttpsTS = clock();
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
mHttpsTS = clock();
- if (nlhrReply) {
- hHttpsConnection = nlhrReply->nlc;
- Netlib_FreeHttpRequest(nlhrReply);
- bRet = true;
+ if (!nlhrReply) {
+ hHttpsConnection = nullptr;
+ return false;
}
- else hHttpsConnection = nullptr;
- return bRet;
+
+ hHttpsConnection = nlhrReply->nlc;
+ return true;
}
// pszAction: "accept" or "decline"
bool CMsnProto::MSN_SKYABAuthRsp(const char *wlid, const char *pszAction)
{
+ // initialize the netlib request
NETLIBHTTPREQUEST nlhr = { 0 };
NETLIBHTTPHEADER headers[3];
- bool bRet = false;
- char szURL[256];
+ if (!APISkypeComRequest(&nlhr, headers))
+ return false;
- // initialize the netlib request
- if (!APISkypeComRequest(&nlhr, headers)) return false;
+ char szURL[256];
+ mir_snprintf(szURL, sizeof(szURL), "https://contacts.skype.com/contacts/v2/users/SELF/invites/%s/%s", wlid, pszAction);
nlhr.requestType = REQUEST_PUT;
- mir_snprintf(szURL, sizeof(szURL), "https://contacts.skype.com/contacts/v2/users/SELF/invites/%s/%s", wlid, pszAction);
nlhr.szUrl = szURL;
mHttpsTS = clock();
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
mHttpsTS = clock();
- if (nlhrReply) {
- hHttpsConnection = nlhrReply->nlc;
- Netlib_FreeHttpRequest(nlhrReply);
- bRet = true;
+ if (!nlhrReply) {
+ hHttpsConnection = nullptr;
+ return false;
}
- else hHttpsConnection = nullptr;
- return bRet;
+ hHttpsConnection = nlhrReply->nlc;
+ return true;
}
bool CMsnProto::MSN_SKYABAuthRq(const char *wlid, const char *pszGreeting)
@@ -349,11 +345,10 @@ bool CMsnProto::MSN_SKYABAuthRq(const char *wlid, const char *pszGreeting)
nlhr.pData = (char*)(const char*)post;
mHttpsTS = clock();
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
mHttpsTS = clock();
if (nlhrReply) {
hHttpsConnection = nlhrReply->nlc;
- Netlib_FreeHttpRequest(nlhrReply);
return true;
}
@@ -383,7 +378,7 @@ bool CMsnProto::MSN_SKYABSearch(const char *keyWord, HANDLE hSearch)
nlhr.headersCount++;
mHttpsTS = clock();
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
mHttpsTS = clock();
if (nlhrReply) {
hHttpsConnection = nlhrReply->nlc;
@@ -413,7 +408,6 @@ bool CMsnProto::MSN_SKYABSearch(const char *keyWord, HANDLE hSearch)
ProtoBroadcastAck(0, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, hSearch);
bRet = true;
}
- Netlib_FreeHttpRequest(nlhrReply);
}
else hHttpsConnection = nullptr;
return bRet;
diff --git a/protocols/MSN/src/msn_soapab.cpp b/protocols/MSN/src/msn_soapab.cpp
index d9f4194f81..6a98c797de 100644
--- a/protocols/MSN/src/msn_soapab.cpp
+++ b/protocols/MSN/src/msn_soapab.cpp
@@ -862,7 +862,7 @@ bool CMsnProto::MSN_ABRefreshClist(unsigned int nTry)
// Query addressbook
mHttpsTS = clock();
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
mHttpsTS = clock();
if (nlhrReply) {
hHttpsConnection = nlhrReply->nlc;
@@ -947,7 +947,6 @@ bool CMsnProto::MSN_ABRefreshClist(unsigned int nTry)
authSkypeComToken.Clear();
if (MSN_AuthOAuth() > 0) return MSN_ABRefreshClist(1);
}
- Netlib_FreeHttpRequest(nlhrReply);
}
else hHttpsConnection = nullptr;
return bRet;
diff --git a/protocols/MSN/src/msn_ssl.cpp b/protocols/MSN/src/msn_ssl.cpp
index dbd9d2f7db..bdf32d5647 100644
--- a/protocols/MSN/src/msn_ssl.cpp
+++ b/protocols/MSN/src/msn_ssl.cpp
@@ -76,8 +76,7 @@ char* CMsnProto::getSslResult(char** parUrl, const char* parAuthInfo, const char
}
// download the page
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
-
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
if (nlhrReply) {
hHttpsConnection = nlhrReply->nlc;
status = nlhrReply->resultCode;
@@ -92,11 +91,8 @@ char* CMsnProto::getSslResult(char** parUrl, const char* parAuthInfo, const char
nlhrReply->dataLength = 0;
nlhrReply->pData = nullptr;
-
- Netlib_FreeHttpRequest(nlhrReply);
}
- else
- hHttpsConnection = nullptr;
+ else hHttpsConnection = nullptr;
mHttpsTS = clock();
@@ -105,29 +101,24 @@ char* CMsnProto::getSslResult(char** parUrl, const char* parAuthInfo, const char
bool CMsnProto::getMyAvatarFile(char *url, wchar_t *fname)
{
- NETLIBHTTPREQUEST nlhr = { 0 };
- bool result = true;
-
// initialize the netlib request
+ NETLIBHTTPREQUEST nlhr = {};
nlhr.cbSize = sizeof(nlhr);
nlhr.requestType = REQUEST_GET;
nlhr.flags = NLHRF_HTTP11 | NLHRF_REDIRECT;
nlhr.szUrl = url;
-
nlhr.headersCount = 1;
nlhr.headers = (NETLIBHTTPHEADER*)alloca(sizeof(NETLIBHTTPHEADER) * nlhr.headersCount);
nlhr.headers[0].szName = "User-Agent";
nlhr.headers[0].szValue = (char*)MSN_USER_AGENT;
// download the page
- NETLIBHTTPREQUEST *nlhrReply = Netlib_HttpTransaction(m_hNetlibUser, &nlhr);
+ NLHR_PTR nlhrReply(Netlib_HttpTransaction(m_hNetlibUser, &nlhr));
if (nlhrReply) {
- if (nlhrReply->resultCode == 200 && nlhrReply->dataLength)
+ if (nlhrReply->resultCode == 200 && nlhrReply->dataLength) {
MSN_SetMyAvatar(fname, nlhrReply->pData, nlhrReply->dataLength);
- else
- result = false;
-
- Netlib_FreeHttpRequest(nlhrReply);
+ return true;
+ }
}
- return result;
+ return false;
}