summaryrefslogtreecommitdiff
path: root/protocols/SkypeWeb/src/skype_events.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/SkypeWeb/src/skype_events.cpp')
-rw-r--r--protocols/SkypeWeb/src/skype_events.cpp93
1 files changed, 93 insertions, 0 deletions
diff --git a/protocols/SkypeWeb/src/skype_events.cpp b/protocols/SkypeWeb/src/skype_events.cpp
new file mode 100644
index 0000000000..c4655bd310
--- /dev/null
+++ b/protocols/SkypeWeb/src/skype_events.cpp
@@ -0,0 +1,93 @@
+#include "common.h"
+
+int CSkypeProto::OnModulesLoaded(WPARAM, LPARAM)
+{
+ return 0;
+}
+
+void CSkypeProto::OnLoginFirst(const NETLIBHTTPREQUEST *response)
+{
+ if (response == NULL)
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, 1001);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ std::regex regex;
+ std::smatch match;
+
+ const std::string content = response->pData;
+
+ regex = "<input type=\"hidden\" name=\"pie\" id=\"pie\" value=\"(.+?)\"/>";
+ if (!std::regex_search(content, match, regex))
+ {
+ 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);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+ std::string etm = match[1];
+
+ ptrA login(mir_utf8encodeT(ptrT(getTStringA(SKYPE_SETTINGS_ID))));
+ ptrA password(mir_utf8encodeT(ptrT(getTStringA(SKYPE_SETTINGS_PASSWORD))));
+
+ requestQueue->Push(new LoginRequest(login, password, pie.c_str(), etm.c_str()), HttpResponse<&CSkypeProto::OnLoginSecond>, this);
+}
+
+void CSkypeProto::OnLoginSecond(const NETLIBHTTPREQUEST *response)
+{
+ if (response == NULL)
+ {
+ ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, (HANDLE)NULL, 1001);
+ SetStatus(ID_STATUS_OFFLINE);
+ return;
+ }
+
+ std::regex regex;
+ 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);
+ 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))
+ {
+ 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);
+
+ for (int i = 0; i < response->headersCount; i++)
+ {
+ if (mir_strcmpi(response->headers[i].szName, "Set-Cookie"))
+ continue;
+
+ regex = "^(.+?)=(.+?);";
+ content = response->headers[i].szValue;
+
+ if (std::regex_search(content, match, regex))
+ cookies[match[1]] = match[2];
+ }
+
+ ProtoBroadcastAck(NULL, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)ID_STATUS_CONNECTING, m_iStatus = m_iDesiredStatus);
+} \ No newline at end of file