diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2015-04-08 20:34:40 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2015-04-08 20:34:40 +0000 |
commit | 97cdf4cf1a9bdf132477708c0cb150ce1b6e118f (patch) | |
tree | 283f998d6a7212c6d48872aa049e4a420c03f1d2 | |
parent | 6148761669741440a617e27f03c9eaf0e9038818 (diff) |
SkypeWeb: cleanup
git-svn-id: http://svn.miranda-ng.org/main/trunk@12683 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r-- | protocols/SkypeWeb/src/common.h | 11 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/capabilities.h | 9 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/contacts.h | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/endpoint.h | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/login.h | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/messages.h | 8 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/poll.h | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/status.h | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/requests/subscriptions.h | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_avatars.cpp | 6 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_dialogs.h | 12 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_login.cpp | 96 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_messages.cpp | 53 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_options.cpp | 15 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_options.h | 2 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_polling.cpp | 12 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.cpp | 25 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_proto.h | 4 | ||||
-rw-r--r-- | protocols/SkypeWeb/src/skype_utils.cpp | 84 |
19 files changed, 161 insertions, 192 deletions
diff --git a/protocols/SkypeWeb/src/common.h b/protocols/SkypeWeb/src/common.h index b4a870c207..47ada92684 100644 --- a/protocols/SkypeWeb/src/common.h +++ b/protocols/SkypeWeb/src/common.h @@ -41,6 +41,8 @@ struct CSkypeProto;
+#define SKYPE_ENDPOINTS_HOST "client-s.gateway.messenger.live.com"
+
#include "version.h"
#include "resource.h"
#include "skype_icons.h"
@@ -66,12 +68,17 @@ extern HINSTANCE g_hInstance; #define MODULE "SKYPE"
+#define SKYPE_MAX_CONNECT_RETRIES 10
+
+enum SKYPE_LOGIN_ERROR
+{
+ LOGIN_ERROR_UNKNOWN = 1001
+};
+
#define SKYPE_SETTINGS_ID "Skypename"
#define SKYPE_SETTINGS_PASSWORD "Password"
#define SKYPE_SETTINGS_GROUP "DefaultGroup"
#define SKYPE_DB_EVENT_TYPE_ACTION 10001
-#define SKYPE_ENDPOINTS_HOST "client-s.gateway.messenger.live.com"
-
#endif //_COMMON_H_
\ No newline at end of file diff --git a/protocols/SkypeWeb/src/requests/capabilities.h b/protocols/SkypeWeb/src/requests/capabilities.h index 3c2894ac91..80f7e93bfb 100644 --- a/protocols/SkypeWeb/src/requests/capabilities.h +++ b/protocols/SkypeWeb/src/requests/capabilities.h @@ -4,20 +4,21 @@ class SendCapabilitiesRequest : public HttpRequest
{
public:
- SendCapabilitiesRequest(const char *regToken, const char *endpointID, const char *server = "client-s.gateway.messenger.live.com") :
+ SendCapabilitiesRequest(const char *regToken, const char *endpointID, const char *server = SKYPE_ENDPOINTS_HOST) :
HttpRequest(REQUEST_PUT, FORMAT, "%s/v1/users/ME/endpoints/%s/presenceDocs/messagingService", server, ptrA(mir_urlEncode(endpointID)))
{
Headers
<< CHAR_VALUE("Accept", "application/json, text/javascript")
- << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken)
- << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8");
- CMStringA data;
+ << CHAR_VALUE("Content-Type", "application/json; charset=UTF-8")
+ << FORMAT_VALUE("RegistrationToken", "registrationToken=%s", regToken);
+ CMStringA data;
int bitness = 32;
#ifdef _WIN64
bitness = 64;
#endif
data.AppendFormat("{\"id\":\"messagingService\",\"type\":\"EndpointPresenceDoc\",\"selfLink\":\"uri\",\"privateInfo\":{\"epname\":\"Miranda\"},\"publicInfo\":{\"capabilities\":\"\",\"typ\":125,\"skypeNameVersion\":\"Miranda NG Skype\",\"nodeInfo\":\"xx\",\"version\":\"%s x%d\"}}", MIRANDA_VERSION_STRING, bitness);
+
Body <<
VALUE(data);
}
diff --git a/protocols/SkypeWeb/src/requests/contacts.h b/protocols/SkypeWeb/src/requests/contacts.h index 9c6a9a309c..f362f02284 100644 --- a/protocols/SkypeWeb/src/requests/contacts.h +++ b/protocols/SkypeWeb/src/requests/contacts.h @@ -33,7 +33,7 @@ public: class GetContactStatusRequest : public HttpRequest
{
public:
- GetContactStatusRequest(const char *regToken, const char *skypename, const char *server = "client-s.gateway.messenger.live.com") :
+ GetContactStatusRequest(const char *regToken, const char *skypename, const char *server = SKYPE_ENDPOINTS_HOST) :
HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/contacts/8:%s/presenceDocs/messagingService", server, skypename)
{
Headers
@@ -45,7 +45,7 @@ public: class CreateContactsRequest : public HttpRequest
{
public:
- CreateContactsRequest(const char *regToken, const LIST<char> &skypenames, const char *server = "client-s.gateway.messenger.live.com") :
+ CreateContactsRequest(const char *regToken, const LIST<char> &skypenames, const char *server = SKYPE_ENDPOINTS_HOST) :
HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/contacts", server)
{
Headers
diff --git a/protocols/SkypeWeb/src/requests/endpoint.h b/protocols/SkypeWeb/src/requests/endpoint.h index be4a5d9ce7..729c2180d8 100644 --- a/protocols/SkypeWeb/src/requests/endpoint.h +++ b/protocols/SkypeWeb/src/requests/endpoint.h @@ -4,7 +4,7 @@ class CreateEndpointRequest : public HttpRequest
{
public:
- CreateEndpointRequest(const char *token, const char *server = "client-s.gateway.messenger.live.com") :
+ CreateEndpointRequest(const char *token, const char *server = SKYPE_ENDPOINTS_HOST) :
HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/endpoints", server)
{
Headers
diff --git a/protocols/SkypeWeb/src/requests/login.h b/protocols/SkypeWeb/src/requests/login.h index e972852d07..eaa37f7831 100644 --- a/protocols/SkypeWeb/src/requests/login.h +++ b/protocols/SkypeWeb/src/requests/login.h @@ -7,8 +7,6 @@ public: LoginRequest() :
HttpRequest(REQUEST_POST, "login.skype.com/login")
{
- //flags = NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
-
Url
<< INT_VALUE("client_id", 578134)
<< CHAR_VALUE("redirect_uri", "https%3A%2F%2Fweb.skype.com");
@@ -17,8 +15,6 @@ public: LoginRequest(const char *skypename, const char *password, const char *pie, const char *etm) :
HttpRequest(REQUEST_POST, "login.skype.com/login")
{
- //flags = NLHRF_SSL | NLHRF_NODUMPSEND | NLHRF_DUMPASTEXT;
-
Url
<< INT_VALUE("client_id", 578134)
<< CHAR_VALUE("redirect_uri", "https%3A%2F%2Fweb.skype.com");
diff --git a/protocols/SkypeWeb/src/requests/messages.h b/protocols/SkypeWeb/src/requests/messages.h index c7aa5347c8..afb541edbc 100644 --- a/protocols/SkypeWeb/src/requests/messages.h +++ b/protocols/SkypeWeb/src/requests/messages.h @@ -4,7 +4,7 @@ class SendMessageRequest : public HttpRequest
{
public:
- SendMessageRequest(const char *regToken, const char *username, time_t timestamp, const char *message, const char *server = "client-s.gateway.messenger.live.com") :
+ SendMessageRequest(const char *regToken, const char *username, time_t timestamp, const char *message, const char *server = SKYPE_ENDPOINTS_HOST) :
HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages", server, username)
{
Headers
@@ -22,7 +22,7 @@ public: class SendActionRequest : public HttpRequest
{
public:
- SendActionRequest(const char *regToken, const char *username, time_t timestamp, const char *message, const char *server = "client-s.gateway.messenger.live.com") :
+ SendActionRequest(const char *regToken, const char *username, time_t timestamp, const char *message, const char *server = SKYPE_ENDPOINTS_HOST) :
HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages", server, username)
{
Headers
@@ -40,7 +40,7 @@ public: class SendTypingRequest : public HttpRequest
{
public:
- SendTypingRequest(const char *regToken, const char *username, bool bstate, const char *server = "client-s.gateway.messenger.live.com") :
+ SendTypingRequest(const char *regToken, const char *username, bool bstate, const char *server = SKYPE_ENDPOINTS_HOST) :
HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages", server, mir_urlEncode(username))
{
Headers
@@ -60,7 +60,7 @@ public: class GetHistoryRequest : public HttpRequest
{
public:
- GetHistoryRequest(const char *regToken, const char *username/* int time*/, const char *server = "client-s.gateway.messenger.live.com") :
+ GetHistoryRequest(const char *regToken, const char *username/* int time*/, const char *server = SKYPE_ENDPOINTS_HOST) :
HttpRequest(REQUEST_GET, FORMAT, "%s/v1/users/ME/conversations/8:%s/messages?startTime=0&pageSize=100&view=msnp24Equivalent&targetType=Passport|Skype|Lync|Thread", server, mir_urlEncode(username)/*, time*/)
{
Headers
diff --git a/protocols/SkypeWeb/src/requests/poll.h b/protocols/SkypeWeb/src/requests/poll.h index 8e04ef0842..e00394eeaf 100644 --- a/protocols/SkypeWeb/src/requests/poll.h +++ b/protocols/SkypeWeb/src/requests/poll.h @@ -4,7 +4,7 @@ class PollRequest : public HttpRequest
{
public:
- PollRequest(const char *regToken, const char *server = "client-s.gateway.messenger.live.com") :
+ PollRequest(const char *regToken, const char *server = SKYPE_ENDPOINTS_HOST) :
HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/endpoints/SELF/subscriptions/0/poll", server)
{
timeout = INFINITE;
diff --git a/protocols/SkypeWeb/src/requests/status.h b/protocols/SkypeWeb/src/requests/status.h index 6d61af48d5..39561c0a64 100644 --- a/protocols/SkypeWeb/src/requests/status.h +++ b/protocols/SkypeWeb/src/requests/status.h @@ -4,7 +4,7 @@ class SetStatusRequest : public HttpRequest
{
public:
- SetStatusRequest(const char *regToken, const char *status, const char *server = "client-s.gateway.messenger.live.com") :
+ SetStatusRequest(const char *regToken, const char *status, const char *server = SKYPE_ENDPOINTS_HOST) :
HttpRequest(REQUEST_PUT, FORMAT, "%s/v1/users/ME/presenceDocs/messagingService", server)
{
Headers
diff --git a/protocols/SkypeWeb/src/requests/subscriptions.h b/protocols/SkypeWeb/src/requests/subscriptions.h index bff30fdb2e..bad20855cc 100644 --- a/protocols/SkypeWeb/src/requests/subscriptions.h +++ b/protocols/SkypeWeb/src/requests/subscriptions.h @@ -4,7 +4,7 @@ class CreateSubscriptionsRequest : public HttpRequest
{
public:
- CreateSubscriptionsRequest(const char *regToken, const char *server = "client-s.gateway.messenger.live.com") :
+ CreateSubscriptionsRequest(const char *regToken, const char *server = SKYPE_ENDPOINTS_HOST) :
HttpRequest(REQUEST_POST, FORMAT, "%s/v1/users/ME/endpoints/SELF/subscriptions", server)
{
Headers
diff --git a/protocols/SkypeWeb/src/skype_avatars.cpp b/protocols/SkypeWeb/src/skype_avatars.cpp index a62d936abf..8fd2c6a727 100644 --- a/protocols/SkypeWeb/src/skype_avatars.cpp +++ b/protocols/SkypeWeb/src/skype_avatars.cpp @@ -2,7 +2,8 @@ INT_PTR CSkypeProto::SvcGetAvatarCaps(WPARAM wParam, LPARAM lParam)
{
- switch (wParam) {
+ switch (wParam)
+ {
case AF_MAXSIZE:
((POINT*)lParam)->x = 96;
((POINT*)lParam)->y = 96;
@@ -24,7 +25,8 @@ INT_PTR CSkypeProto::SvcGetAvatarCaps(WPARAM wParam, LPARAM lParam) void CSkypeProto::ReloadAvatarInfo(MCONTACT hContact)
{
- if (!hContact) {
+ if (hContact == NULL)
+ {
CallService(MS_AV_REPORTMYAVATARCHANGED, (WPARAM)m_szModuleName, 0);
return;
}
diff --git a/protocols/SkypeWeb/src/skype_dialogs.h b/protocols/SkypeWeb/src/skype_dialogs.h index ee834bcd35..80a62fd4a2 100644 --- a/protocols/SkypeWeb/src/skype_dialogs.h +++ b/protocols/SkypeWeb/src/skype_dialogs.h @@ -1,15 +1,7 @@ #ifndef _SKYPE_DIALOGS_H_
#define _SKYPE_DIALOGS_H_
-class CSkypeDlgBase : public CProtoDlgBase<CSkypeProto>
-{
-private:
- typedef CProtoDlgBase<CSkypeProto> CSuper;
-
-protected:
- __inline CSkypeDlgBase(CSkypeProto *proto, int idDialog, HWND parent, bool show_label = true) :
- CSuper(proto, idDialog, parent, show_label) { }
-};
+typedef CProtoDlgBase<CSkypeProto> CSkypeDlgBase;
class CSkypePasswordEditor : public CSkypeDlgBase
{
@@ -40,7 +32,7 @@ protected: public:
CSkypePasswordEditor(CSkypeProto *proto) :
- CSuper(proto, IDD_PASSWORD_EDITOR, NULL, false), m_ok(this, IDOK),
+ CSkypeDlgBase(proto, IDD_PASSWORD_EDITOR, NULL, false), m_ok(this, IDOK),
m_password(this, IDC_PASSWORD), m_savePermanently(this, IDC_SAVEPERMANENTLY)
{
m_ok.OnClick = Callback(this, &CSkypePasswordEditor::OnOk);
diff --git a/protocols/SkypeWeb/src/skype_login.cpp b/protocols/SkypeWeb/src/skype_login.cpp index b783508b58..913d23f46a 100644 --- a/protocols/SkypeWeb/src/skype_login.cpp +++ b/protocols/SkypeWeb/src/skype_login.cpp @@ -9,7 +9,8 @@ void CSkypeProto::OnLoginFirst(const NETLIBHTTPREQUEST *response) {
if (response == NULL)
{
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, 1001);
+ debugLogA(__FUNCTION__ ": failed to get login page");
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
return;
}
@@ -17,36 +18,39 @@ void CSkypeProto::OnLoginFirst(const NETLIBHTTPREQUEST *response) std::regex regex;
std::smatch match;
- const std::string content = response->pData;
-
+ std::string content = response->pData;
regex = "<input type=\"hidden\" name=\"pie\" id=\"pie\" value=\"(.+?)\"/>";
if (!std::regex_search(content, match, regex))
{
+ debugLogA(__FUNCTION__ ": failed to get pie");
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
- return;
}
std::string pie = match[1];
regex = "<input type=\"hidden\" name=\"etm\" id=\"etm\" value=\"(.+?)\"/>";
if (!std::regex_search(content, match, regex))
{
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, 1001);
+ debugLogA(__FUNCTION__ ": failed to get etm");
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
return;
}
std::string etm = match[1];
- ptrA skypename(mir_utf8encodeT(ptrT(getTStringA(SKYPE_SETTINGS_ID))));
- ptrA password(mir_utf8encodeT(ptrT(getTStringA(SKYPE_SETTINGS_PASSWORD))));
-
+ ptrA skypename(getStringA(SKYPE_SETTINGS_ID));
+ ptrA password(getStringA(SKYPE_SETTINGS_PASSWORD));
PushRequest(new LoginRequest(skypename, password, pie.c_str(), etm.c_str()), &CSkypeProto::OnLoginSecond);
}
void CSkypeProto::OnLoginSecond(const NETLIBHTTPREQUEST *response)
{
+ m_iStatus++;
+
if (response == NULL)
{
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, 1001);
+ debugLogA(__FUNCTION__ ": failed to login");
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
return;
}
@@ -55,27 +59,24 @@ void CSkypeProto::OnLoginSecond(const NETLIBHTTPREQUEST *response) std::smatch match;
std::string content = response->pData;
-
regex = "<input type=\"hidden\" name=\"skypetoken\" value=\"(.+?)\"/>";
if (!std::regex_search(content, match, regex))
{
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, 1001);
+ debugLogA(__FUNCTION__ ": failed to get skype token");
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
return;
}
std::string token = match[1];
setString("TokenSecret", token.c_str());
- regex = "<input type=\"hidden\" name=\"expires_in\" value=\"(.+?)\"/>";
- if (!std::regex_search(content, match, regex))
+ /*regex = "<input type=\"hidden\" name=\"expires_in\" value=\"(.+?)\"/>";
+ if (std::regex_search(content, match, regex))
{
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, 1001);
- SetStatus(ID_STATUS_OFFLINE);
- return;
- }
- std::string expiresIn = match[1];
- int seconds = atoi(expiresIn.c_str());
- setDword("TokenExpiresIn", time(NULL) + seconds);
+ std::string expiresIn = match[1];
+ int seconds = atoi(expiresIn.c_str());
+ setDword("TokenExpiresIn", time(NULL) + seconds);
+ }*/
for (int i = 0; i < response->headersCount; i++)
{
@@ -84,7 +85,6 @@ void CSkypeProto::OnLoginSecond(const NETLIBHTTPREQUEST *response) regex = "^(.+?)=(.+?);";
content = response->headers[i].szValue;
-
if (std::regex_search(content, match, regex))
cookies[match[1]] = match[2];
}
@@ -97,11 +97,16 @@ void CSkypeProto::OnLoginSecond(const NETLIBHTTPREQUEST *response) void CSkypeProto::OnEndpointCreated(const NETLIBHTTPREQUEST *response)
{
+ m_iStatus++;
+
if (response == NULL)
+ {
+ debugLogA(__FUNCTION__ ": failed to get create endpoint");
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
return;
+ }
- std::regex regex;
- std::smatch match;
for (int i = 0; i < response->headersCount; i++)
{
if (!mir_strcmpi(response->headers[i].szName, "Set-RegistrationToken"))
@@ -127,8 +132,15 @@ void CSkypeProto::OnEndpointCreated(const NETLIBHTTPREQUEST *response) }
- ptrA server(getStringA("Server"));
+ if (m_iStatus++ > SKYPE_MAX_CONNECT_RETRIES)
+ {
+ debugLogA(__FUNCTION__ ": failed to get create endpoint");
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+ ptrA server(getStringA("Server"));
if (response->resultCode != 201)
{
ptrA token(getStringA("TokenSecret"));
@@ -137,15 +149,20 @@ void CSkypeProto::OnEndpointCreated(const NETLIBHTTPREQUEST *response) }
ptrA regToken(getStringA("registrationToken"));
-
-
PushRequest(new CreateSubscriptionsRequest(regToken, server), &CSkypeProto::OnSubscriptionsCreated);
}
void CSkypeProto::OnSubscriptionsCreated(const NETLIBHTTPREQUEST *response)
{
+ m_iStatus++;
+
if (response == NULL)
+ {
+ debugLogA(__FUNCTION__ ": failed to create subscription");
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
return;
+ }
ptrA regToken(getStringA("registrationToken"));
ptrA skypename(getStringA(SKYPE_SETTINGS_ID));
@@ -153,7 +170,6 @@ void CSkypeProto::OnSubscriptionsCreated(const NETLIBHTTPREQUEST *response) ptrA server(getStringA("Server"));
PushRequest(new SendCapabilitiesRequest(regToken, endpoint, server));
PushRequest(new SetStatusRequest(regToken, MirandaToSkypeStatus(m_iDesiredStatus), server), &CSkypeProto::OnStatusChanged);
- //PushRequest(new GetContactStatusRequest(regToken, skypename), &CSkypeProto::OnStatusChanged);
LIST<char> skypenames(1);
for (MCONTACT hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName))
@@ -168,21 +184,27 @@ void CSkypeProto::OnSubscriptionsCreated(const NETLIBHTTPREQUEST *response) void CSkypeProto::OnStatusChanged(const NETLIBHTTPREQUEST *response)
{
- if (response == NULL)
- return;
-
- JSONROOT root(response->pData);
+ m_iStatus++;
- if (root == NULL)
- return;
-
- JSONNODE *status_json = json_get(root, "status");
- ptrT status(json_as_string(status_json));
+ if (response == NULL || response->pData)
+ {
+ debugLogA(__FUNCTION__ ": failed to change status");
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
+ SetStatus(ID_STATUS_OFFLINE);
+ }
+
+ JSONROOT json(response->pData);
+ ptrT status(json_as_string(json_get(json, "status")));
int iNewStatus = SkypeToMirandaStatus(_T2A(status));
-
if (iNewStatus == ID_STATUS_OFFLINE)
+ {
+ debugLogA(__FUNCTION__ ": failed to change status");
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGIN_ERROR_UNKNOWN);
SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
m_iStatus = m_iDesiredStatus = iNewStatus;
ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus);
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_SUCCESS, NULL, 0);
}
\ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_messages.cpp b/protocols/SkypeWeb/src/skype_messages.cpp index 05b6c7b35d..65c444f369 100644 --- a/protocols/SkypeWeb/src/skype_messages.cpp +++ b/protocols/SkypeWeb/src/skype_messages.cpp @@ -1,6 +1,6 @@ #include "common.h"
-MEVENT CSkypeProto::GetMessageFromDB(MCONTACT hContact, DWORD timestamp, const char *messageId)
+MEVENT CSkypeProto::GetMessageFromDB(MCONTACT hContact, const char *messageId, LONGLONG timestamp)
{
mir_cslock lock(messageSyncLock);
@@ -9,6 +9,7 @@ MEVENT CSkypeProto::GetMessageFromDB(MCONTACT hContact, DWORD timestamp, const c {
DBEVENTINFO dbei = { sizeof(dbei) };
dbei.cbBlob = db_event_getBlobSize(hDbEvent);
+
if (dbei.cbBlob < messageIdLength)
continue;
@@ -19,9 +20,11 @@ MEVENT CSkypeProto::GetMessageFromDB(MCONTACT hContact, DWORD timestamp, const c if (dbei.timestamp < timestamp)
break;
- if ((dbei.eventType == EVENTTYPE_MESSAGE || dbei.eventType == SKYPE_DB_EVENT_TYPE_ACTION))
- if (memcmp(&dbei.pBlob[dbei.cbBlob - messageIdLength], messageId, messageIdLength) == 0)
- return hDbEvent;
+ if (dbei.eventType != EVENTTYPE_MESSAGE && dbei.eventType != SKYPE_DB_EVENT_TYPE_ACTION)
+ continue;
+
+ if (memcmp(&dbei.pBlob[dbei.cbBlob - messageIdLength], messageId, messageIdLength) == 0)
+ return hDbEvent;
}
return NULL;
@@ -29,7 +32,7 @@ MEVENT CSkypeProto::GetMessageFromDB(MCONTACT hContact, DWORD timestamp, const c MEVENT CSkypeProto::AddMessageToDb(MCONTACT hContact, DWORD timestamp, DWORD flags, const char *messageId, char *content, int emoteOffset)
{
- if (MEVENT hDbEvent = GetMessageFromDB(hContact, timestamp, messageId))
+ if (MEVENT hDbEvent = GetMessageFromDB(hContact, messageId, timestamp))
return hDbEvent;
size_t messageLength = mir_strlen(&content[emoteOffset]) + 1;
@@ -84,7 +87,7 @@ int CSkypeProto::SaveMessageToDb(MCONTACT hContact, PROTORECVEVENT *pre) struct SendMessageParam
{
MCONTACT hContact;
- HANDLE hMessage;
+ LONGLONG hMessage;
};
// outcoming message flow
@@ -96,11 +99,9 @@ int CSkypeProto::OnSendMessage(MCONTACT hContact, int flags, const char *szMessa return 0;
}
- time_t timestamp = time(NULL); //InterlockedIncrement(&hMessageProcess);
-
SendMessageParam *param = new SendMessageParam();
param->hContact = hContact;
- param->hMessage = (HANDLE)timestamp;
+ param->hMessage = time(NULL);
ptrA message;
if (flags & PREF_UNICODE)
@@ -114,25 +115,20 @@ int CSkypeProto::OnSendMessage(MCONTACT hContact, int flags, const char *szMessa ptrA token(getStringA("registrationToken"));
ptrA username(getStringA(hContact, "Skypename"));
if (strncmp(message, "/me ", 4) == 0)
- {
- PushRequest(new SendActionRequest(token, username, timestamp, &message[4], server), &CSkypeProto::OnMessageSent, param);
- return timestamp;
- }
- PushRequest(new SendMessageRequest(token, username, timestamp, message, server), &CSkypeProto::OnMessageSent, param);
- return timestamp;
+ PushRequest(new SendActionRequest(token, username, param->hMessage, &message[4], server), &CSkypeProto::OnMessageSent, param);
+ else
+ PushRequest(new SendMessageRequest(token, username, param->hMessage, message, server), &CSkypeProto::OnMessageSent, param);
+
+ return param->hMessage;
}
void CSkypeProto::OnMessageSent(const NETLIBHTTPREQUEST *response, void *arg)
{
SendMessageParam *param = (SendMessageParam*)arg;
MCONTACT hContact = param->hContact;
- HANDLE hMessage = param->hMessage;
+ HANDLE hMessage = (HANDLE)param->hMessage;
delete param;
- if (response == NULL)
- {
- ProtoBroadcastAck(hContact, ACKTYPE_MESSAGE, ACKRESULT_FAILED, hMessage, (LPARAM)"Response = NULL");
- return;
- }
+
if (response->resultCode != 200 && response->resultCode != 201)
{
CMStringA error = "Unknown error";
@@ -163,14 +159,13 @@ int CSkypeProto::OnPreCreateMessage(WPARAM, LPARAM lParam) memmove(evt->dbei->pBlob, &evt->dbei->pBlob[4], evt->dbei->cbBlob);
evt->dbei->eventType = SKYPE_DB_EVENT_TYPE_ACTION;
}
- char messageId[20];
- itoa(evt->seq, messageId, 10);
- int messageIdLength = mir_strlen(messageId);
- evt->dbei->pBlob = (PBYTE)mir_realloc(evt->dbei->pBlob, evt->dbei->cbBlob + messageIdLength);
- memcpy(&evt->dbei->pBlob[evt->dbei->cbBlob], messageId, messageIdLength);
- evt->dbei->cbBlob += messageIdLength;
-
- return 1;
+
+ CMStringA messageId(FORMAT, "%d", evt->seq);
+ evt->dbei->pBlob = (PBYTE)mir_realloc(evt->dbei->pBlob, evt->dbei->cbBlob + messageId.GetLength());
+ memcpy(&evt->dbei->pBlob[evt->dbei->cbBlob], messageId, messageId.GetLength());
+ evt->dbei->cbBlob += messageId.GetLength();
+
+ return 0;
}
/* HISTORY SYNC */
diff --git a/protocols/SkypeWeb/src/skype_options.cpp b/protocols/SkypeWeb/src/skype_options.cpp index d2a07137c6..d20b1d360b 100644 --- a/protocols/SkypeWeb/src/skype_options.cpp +++ b/protocols/SkypeWeb/src/skype_options.cpp @@ -1,18 +1,19 @@ #include "common.h"
CSkypeOptionsMain::CSkypeOptionsMain(CSkypeProto *proto, int idDialog, HWND hwndParent)
- : CSuper(proto, idDialog, hwndParent, false),
- m_skypename(this, IDC_SKYPENAME), m_password(this, IDC_PASSWORD),
+ : CSkypeDlgBase(proto, idDialog, hwndParent, false),
+ m_skypename(this, IDC_SKYPENAME),
+ m_password(this, IDC_PASSWORD),
m_group(this, IDC_GROUP)
{
- CreateLink(m_skypename, SKYPE_SETTINGS_ID, _T(""));
- CreateLink(m_password, "Password", _T(""));
+ //CreateLink(m_skypename, SKYPE_SETTINGS_ID, _T(""));
+ //CreateLink(m_password, "Password", _T(""));
CreateLink(m_group, SKYPE_SETTINGS_GROUP, _T("Skype"));
}
void CSkypeOptionsMain::OnInitDialog()
{
- CSuper::OnInitDialog();
+ CSkypeDlgBase::OnInitDialog();
SendMessage(m_skypename.GetHwnd(), EM_LIMITTEXT, 32, 0);
SendMessage(m_password.GetHwnd(), EM_LIMITTEXT, 20, 0);
@@ -22,6 +23,9 @@ void CSkypeOptionsMain::OnInitDialog() void CSkypeOptionsMain::OnApply()
{
+ m_proto->setString(SKYPE_SETTINGS_ID, m_skypename.GetTextA());
+ m_proto->setString("Password", m_password.GetTextA());
+
TCHAR *group = m_group.GetText();
if (mir_tstrlen(group) > 0 && !Clist_GroupExists(group))
Clist_CreateGroup(0, group);
@@ -34,7 +38,6 @@ int CSkypeProto::OnOptionsInit(WPARAM wParam, LPARAM) OPTIONSDIALOGPAGE odp = { sizeof(odp) };
odp.hInstance = g_hInstance;
odp.pszTitle = title;
- //odp.dwInitParam = (LPARAM)this;
odp.flags = ODPF_BOLDGROUPS | ODPF_DONTTRANSLATE;
odp.pszGroup = LPGEN("Network");
diff --git a/protocols/SkypeWeb/src/skype_options.h b/protocols/SkypeWeb/src/skype_options.h index 56d08aedd8..67f889b727 100644 --- a/protocols/SkypeWeb/src/skype_options.h +++ b/protocols/SkypeWeb/src/skype_options.h @@ -4,8 +4,6 @@ class CSkypeOptionsMain : public CSkypeDlgBase
{
private:
- typedef CSkypeDlgBase CSuper;
-
CCtrlEdit m_skypename;
CCtrlEdit m_password;
CCtrlEdit m_group;
diff --git a/protocols/SkypeWeb/src/skype_polling.cpp b/protocols/SkypeWeb/src/skype_polling.cpp index 0a1905ff13..b40a84ccd4 100644 --- a/protocols/SkypeWeb/src/skype_polling.cpp +++ b/protocols/SkypeWeb/src/skype_polling.cpp @@ -48,9 +48,8 @@ void CSkypeProto::PollingThread(void*) ptrA server(getStringA("Server"));
int errors = 0;
- bool breaked = false;
isTerminated = false;
- while (!isTerminated && !breaked && errors < POLLING_ERRORS_LIMIT)
+ while (!isTerminated && errors < POLLING_ERRORS_LIMIT)
{
PollRequest *request = new PollRequest(regToken, server);
request->nlc = m_pollingConnection;
@@ -74,13 +73,14 @@ void CSkypeProto::PollingThread(void*) delete request;
}
- m_hPollingThread = NULL;
- m_pollingConnection = NULL;
- debugLogA(__FUNCTION__": leaving");
-
+
if (!isTerminated)
{
debugLogA(__FUNCTION__": unexpected termination; switching protocol to offline");
SetStatus(ID_STATUS_OFFLINE);
}
+
+ m_hPollingThread = NULL;
+ m_pollingConnection = NULL;
+ debugLogA(__FUNCTION__": leaving");
}
\ No newline at end of file diff --git a/protocols/SkypeWeb/src/skype_proto.cpp b/protocols/SkypeWeb/src/skype_proto.cpp index 91ab87bc78..2ff641a103 100644 --- a/protocols/SkypeWeb/src/skype_proto.cpp +++ b/protocols/SkypeWeb/src/skype_proto.cpp @@ -160,19 +160,21 @@ int CSkypeProto::SetStatus(int iNewStatus) {
// logout
isTerminated = true;
+ if (m_pollingConnection)
+ CallService(MS_NETLIB_SHUTDOWN, (WPARAM)m_pollingConnection, 0);
- //if (m_pollingConnection)
- // CallService(MS_NETLIB_SHUTDOWN, (WPARAM)m_pollingConnection, 0);
-
- LogoutRequest *logoutRequest = new LogoutRequest();
- if (!cookies.empty())
+ if (m_iStatus > ID_STATUS_CONNECTING + 1)
{
- CMStringA allCookies;
- for (std::map<std::string, std::string>::iterator cookie = cookies.begin(); cookie != cookies.end(); ++cookie)
- allCookies.AppendFormat("%s=%s; ", cookie->first.c_str(), cookie->second.c_str());
- logoutRequest->Headers << CHAR_VALUE("Set-Cookie", allCookies);
+ LogoutRequest *logoutRequest = new LogoutRequest();
+ if (!cookies.empty())
+ {
+ CMStringA allCookies;
+ for (std::map<std::string, std::string>::iterator cookie = cookies.begin(); cookie != cookies.end(); ++cookie)
+ allCookies.AppendFormat("%s=%s; ", cookie->first.c_str(), cookie->second.c_str());
+ logoutRequest->Headers << CHAR_VALUE("Set-Cookie", allCookies);
+ }
+ PushRequest(logoutRequest);
}
- PushRequest(logoutRequest);
requestQueue->Stop();
if (!Miranda_Terminated())
@@ -184,7 +186,8 @@ int CSkypeProto::SetStatus(int iNewStatus) {
if (old_status == ID_STATUS_CONNECTING)
return 0;
- else if (old_status == ID_STATUS_OFFLINE && m_iStatus == ID_STATUS_OFFLINE)
+
+ if (old_status == ID_STATUS_OFFLINE && m_iStatus == ID_STATUS_OFFLINE)
{
// login
m_iStatus = ID_STATUS_CONNECTING;
diff --git a/protocols/SkypeWeb/src/skype_proto.h b/protocols/SkypeWeb/src/skype_proto.h index 5c45aa1840..b294e1bd37 100644 --- a/protocols/SkypeWeb/src/skype_proto.h +++ b/protocols/SkypeWeb/src/skype_proto.h @@ -90,7 +90,7 @@ private: std::map<std::string, std::string> RegInfo;
HANDLE m_pollingConnection, m_hPollingThread;
static std::map<std::tstring, std::tstring> languages;
- ULONG hMessageProcess;
+
static INT_PTR CALLBACK PasswordEditorProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// accounts
@@ -193,7 +193,7 @@ private: // messages
mir_cs messageSyncLock;
- MEVENT GetMessageFromDB(MCONTACT hContact, DWORD timestamp, const char *messageId);
+ MEVENT GetMessageFromDB(MCONTACT hContact, const char *messageId, LONGLONG timestamp = 0);
MEVENT AddMessageToDb(MCONTACT hContact, DWORD timestamp, DWORD flags, const char *messageId, char *content, int emoteOffset = 0);
int OnReceiveMessage(const char *messageId, const char *url, time_t timestamp, char *content, int emoteOffset = 0, bool isRead = false);
diff --git a/protocols/SkypeWeb/src/skype_utils.cpp b/protocols/SkypeWeb/src/skype_utils.cpp index d7e119874c..38ca985b24 100644 --- a/protocols/SkypeWeb/src/skype_utils.cpp +++ b/protocols/SkypeWeb/src/skype_utils.cpp @@ -153,86 +153,36 @@ bool CSkypeProto::IsFileExists(std::tstring path) return _taccess(path.c_str(), 0) == 0;
}
-char *CSkypeProto::ContactUrlToName(const char *url)
-{
- char *tempname = NULL;
- const char *start, *end;
- start = strstr(url, "/8:");
+// url parsing
- if (!start)
+char *ParseUrl(const char *url, const char *token)
+{
+ const char *start = strstr(url, token);
+ if (start == NULL)
return NULL;
- start = start + 3;
- if ((end = strchr(start, '/')))
- {
- mir_free(tempname);
- tempname = mir_strndup(start, end - start);
- return tempname;
- }
- mir_free(tempname);
- tempname = mir_strdup(start);
+ start = start + mir_strlen(token);
+ const char *end = strchr(start, '/');
+ if (start == NULL)
+ return mir_strdup(start);
+ return mir_strndup(start, end - start);
+}
- return tempname;
+char *CSkypeProto::ContactUrlToName(const char *url)
+{
+ return ParseUrl(url, "/8:");
}
char *CSkypeProto::SelfUrlToName(const char *url)
{
- char *tempname = NULL;
- const char *start, *end;
- start = strstr(url, "/1:");
-
- if (!start)
- return NULL;
- start = start + 3;
- if ((end = strchr(start, '/')))
- {
- mir_free(tempname);
- tempname = mir_strndup(start, end - start);
- return tempname;
- }
- mir_free(tempname);
- tempname = mir_strdup(start);
-
- return tempname;
+ return ParseUrl(url, "/1:");
}
char *CSkypeProto::ChatUrlToName(const char *url)
{
- char *tempname = NULL;
- const char *start, *end;
- start = strstr(url, "/19:");
-
- if (!start)
- return NULL;
- start = start + 4;
- if ((end = strchr(start, '/')))
- {
- mir_free(tempname);
- tempname = mir_strndup(start, end - start);
- return tempname;
- }
- mir_free(tempname);
- tempname = mir_strdup(start);
-
- return tempname;
+ return ParseUrl(url, "/19:");
}
char *CSkypeProto::GetServerFromUrl(const char *url)
{
- char *tempname = NULL;
- const char *start, *end;
- start = strstr(url, "://");
-
- if (!start)
- return NULL;
- start = start + 3;
- if ((end = strchr(start, '/')))
- {
- mir_free(tempname);
- tempname = mir_strndup(start, end - start);
- return tempname;
- }
- mir_free(tempname);
- tempname = mir_strdup(start);
-
- return tempname;
+ return ParseUrl(url, "://");
}
\ No newline at end of file |