summaryrefslogtreecommitdiff
path: root/protocols/SkypeWeb/src/skype_login.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/SkypeWeb/src/skype_login.cpp')
-rw-r--r--protocols/SkypeWeb/src/skype_login.cpp96
1 files changed, 59 insertions, 37 deletions
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