From 375155f8dcd69863f1b9a220c5f890596844e99d Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sun, 16 Dec 2012 19:08:08 +0000 Subject: - reworked message receiving/sending (by another instance) git-svn-id: http://svn.miranda-ng.org/main/trunk@2756 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Skype/src/skype.cpp | 2 + protocols/Skype/src/skype.h | 1 + protocols/Skype/src/skype_database.cpp | 20 ++++++++ protocols/Skype/src/skype_dialogs.cpp | 42 +++++++--------- protocols/Skype/src/skype_events.cpp | 79 ++++++++++++++++++++++++++++++- protocols/Skype/src/skype_proto.cpp | 43 ++--------------- protocols/Skype/src/skype_proto.h | 14 ++++-- protocols/Skype/src/skype_subclassing.cpp | 40 +++------------- protocols/Skype/src/skype_subclassing.h | 16 ++----- 9 files changed, 143 insertions(+), 114 deletions(-) (limited to 'protocols/Skype') diff --git a/protocols/Skype/src/skype.cpp b/protocols/Skype/src/skype.cpp index 6e953ac747..ad23c7c14e 100644 --- a/protocols/Skype/src/skype.cpp +++ b/protocols/Skype/src/skype.cpp @@ -3,6 +3,7 @@ int hLangpack; HINSTANCE g_hInstance; +XML_API xi = {0}; TIME_API tmi = {0}; CSkype* g_skype; @@ -347,6 +348,7 @@ extern "C" int __declspec(dllexport) Load(void) if (!StartSkypeRuntime()) return 1; + mir_getXI(&xi); mir_getTMI(&tmi); mir_getLP(&pluginInfo); diff --git a/protocols/Skype/src/skype.h b/protocols/Skype/src/skype.h index d2c18dadba..b47231f46e 100644 --- a/protocols/Skype/src/skype.h +++ b/protocols/Skype/src/skype.h @@ -39,6 +39,7 @@ #include #include //#include +#include //#pragma warning(pop) #include #include diff --git a/protocols/Skype/src/skype_database.cpp b/protocols/Skype/src/skype_database.cpp index 6c583374a5..887061afbe 100644 --- a/protocols/Skype/src/skype_database.cpp +++ b/protocols/Skype/src/skype_database.cpp @@ -72,4 +72,24 @@ void CSkypeProto::RaiseMessageReceivedEvent( pre.szMessage = (char *)message; ::CallService(MS_PROTO_CHAINRECV, 0, (LPARAM)&ccs); +} + +void CSkypeProto::RaiseMessageSendedEvent( + DWORD timestamp, + const char* sid, + const char* nick, + const char* message) +{ + PROTORECVEVENT pre = {0}; + + CCSDATA ccs = {0}; + ccs.szProtoService = PSR_MESSAGE; + ccs.hContact = this->AddContactBySid(sid, ::mir_a2u(nick)); + ccs.wParam = 0; + ccs.lParam = (LPARAM)⪯ + pre.flags = PREF_UTF; + pre.timestamp = timestamp; + pre.szMessage = (char *)message; + + ::CallService(MS_PROTO_CHAINSEND, 0, (LPARAM)&ccs); } \ No newline at end of file diff --git a/protocols/Skype/src/skype_dialogs.cpp b/protocols/Skype/src/skype_dialogs.cpp index 4148d30ad6..9657513d64 100644 --- a/protocols/Skype/src/skype_dialogs.cpp +++ b/protocols/Skype/src/skype_dialogs.cpp @@ -45,18 +45,15 @@ INT_PTR CALLBACK CSkypeProto::SkypeAccountProc(HWND hwnd, UINT message, WPARAM w { if (reinterpret_cast(lparam)->code == PSN_APPLY) { proto = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); - { - TCHAR data[128]; - ::mir_free(proto->login); - GetDlgItemText(hwnd, IDC_SL, data, SIZEOF(data)); - proto->SetSettingString(SKYPE_SETTINGS_LOGIN, data); - proto->login = ::mir_wstrdup(data); - } - { - char data[128]; - GetDlgItemTextA(hwnd, IDC_PW, data, sizeof(data)); - proto->SetDecodeSettingString(NULL, SKYPE_SETTINGS_PASSWORD, data); - } + + char data[128]; + ::mir_free(proto->login); + GetDlgItemTextA(hwnd, IDC_SL, data, SIZEOF(data)); + ::DBWriteContactSettingString(NULL, proto->m_szModuleName, "sid", data); + proto->login = ::mir_strdup(data); + + GetDlgItemTextA(hwnd, IDC_PW, data, sizeof(data)); + proto->SetDecodeSettingString(NULL, SKYPE_SETTINGS_PASSWORD, data); proto->SetSettingByte("RememberPassword", true); @@ -118,18 +115,15 @@ INT_PTR CALLBACK CSkypeProto::SkypeOptionsProc(HWND hwnd, UINT message, WPARAM w if (reinterpret_cast(lparam)->code == PSN_APPLY) { proto = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); - { - wchar_t data[128]; - ::mir_free(proto->login); - GetDlgItemText(hwnd, IDC_SL, data, SIZEOF(data)); - proto->SetSettingString(SKYPE_SETTINGS_LOGIN, data); - proto->login = ::mir_wstrdup(data); - } - { - char data[128]; - GetDlgItemTextA(hwnd, IDC_PW, data, sizeof(data)); - proto->SetDecodeSettingString(NULL, SKYPE_SETTINGS_PASSWORD, data); - } + + char data[128]; + ::mir_free(proto->login); + GetDlgItemTextA(hwnd, IDC_SL, data, SIZEOF(data)); + ::DBWriteContactSettingString(NULL, proto->m_szModuleName, "sid", data); + proto->login = ::mir_strdup(data); + + GetDlgItemTextA(hwnd, IDC_PW, data, sizeof(data)); + proto->SetDecodeSettingString(NULL, SKYPE_SETTINGS_PASSWORD, data); proto->SetSettingByte("RememberPassword", true); diff --git a/protocols/Skype/src/skype_events.cpp b/protocols/Skype/src/skype_events.cpp index 541b776e15..8b99ec5219 100644 --- a/protocols/Skype/src/skype_events.cpp +++ b/protocols/Skype/src/skype_events.cpp @@ -4,7 +4,7 @@ int CSkypeProto::OnModulesLoaded(WPARAM, LPARAM) { this->HookEvent(ME_OPT_INITIALISE, &CSkypeProto::OnOptionsInit); this->HookEvent(ME_USERINFO_INITIALISE, &CSkypeProto::OnUserInfoInit); - this->login = this->GetSettingString(SKYPE_SETTINGS_LOGIN); + this->login = ::DBGetString(NULL, this->m_szModuleName, "sid"); this->rememberPassword = this->GetSettingByte("RememberPassword") > 0; return 0; @@ -23,3 +23,80 @@ int CSkypeProto::OnContactDeleted(WPARAM wParam, LPARAM lParam) return 0; } + +void CSkypeProto::OnMessageSended(CConversation::Ref conversation, CMessage::Ref message) +{ + uint timestamp; + message->GetPropTimestamp(timestamp); + + SEString data; + + message->GetPropAuthor(data); + char *sid = ::mir_strdup((const char*)data); + + message->GetPropBodyXml(data); + char *text = ::mir_strdup((const char*)data); + + Participant::Refs participants; + conversation->GetParticipants(participants, CConversation::OTHER_CONSUMERS); + + for (uint i = 0; i < participants.size(); i ++) + { + participants[i]->GetPropIdentity(data); + char *contactSid = ::mir_strdup((const char *)data); + //todo: get nickname + this->RaiseMessageSendedEvent( + timestamp, + contactSid, + contactSid, + text); + } +} + +void CSkypeProto::OnMessageReceived(CConversation::Ref conversation, CMessage::Ref message) +{ + uint timestamp; + message->GetPropTimestamp(timestamp); + + SEString data; + + message->GetPropAuthor(data); + char *sid = ::mir_strdup((const char*)data); + + message->GetPropAuthorDisplayname(data); + char *nick = ::mir_strdup((const char*)data); + + message->GetPropBodyXml(data); + char *text = ::mir_strdup((const char*)data); + + this->RaiseMessageReceivedEvent( + (DWORD)timestamp, + sid, + nick, + text); + + /*const char *msg = (const char*)propValues[2]; + int len = ::strlen(msg) + 8; + wchar_t *xml = new wchar_t[len]; + ::mir_sntprintf(xml, len, L"%s", ::mir_utf8decodeW(msg)); + + int bytesProcessed = 0; + HXML hXml = xi.parseString(xml, &bytesProcessed, NULL);*/ +} + +void CSkypeProto::OnMessage(CConversation::Ref conversation, CMessage::Ref message) +{ + CMessage::TYPE messageType; + message->GetPropType(messageType); + + CMessage::SENDING_STATUS sendingStatus; + message->GetPropSendingStatus(sendingStatus); + + if (messageType == CMessage::POSTED_TEXT) + { + if (sendingStatus == CMessage::SENT) + this->OnMessageSended(conversation, message); + else if (!sendingStatus) + this->OnMessageReceived(conversation, message); + } +} \ No newline at end of file diff --git a/protocols/Skype/src/skype_proto.cpp b/protocols/Skype/src/skype_proto.cpp index 8d4515b9fc..85a91146dd 100644 --- a/protocols/Skype/src/skype_proto.cpp +++ b/protocols/Skype/src/skype_proto.cpp @@ -345,18 +345,8 @@ int __cdecl CSkypeProto::OnEvent(PROTOEVENTTYPE eventType, WPARAM wParam, LPA void __cdecl CSkypeProto::SignInAsync(void*) { - /*g_skype->GetConversationList(g_skype->inbox, CConversation::INBOX_CONVERSATIONS); - fetch(g_skype->inbox); - g_skype->SetOnConversationAddedCallback( - (CSkype::OnConversationAdded)&CSkypeProto::OnConversationAdded, - this); - for (uint i = 0 ; i < g_skype->inbox.size(); i++) - g_skype->inbox[i]->SetOnMessageReceivedCallback( - (CConversation::OnMessageReceived)&CSkypeProto::OnMessageReceived, - this);*/ - - g_skype->SetOnMessageReceivedCallback( - (CSkype::OnMessageReceived)&CSkypeProto::OnMessageReceived, + g_skype->SetOnMessageCallback( + (CSkype::OnMessaged)&CSkypeProto::OnMessage, this); this->SetStatus(this->m_iDesiredStatus); @@ -367,7 +357,7 @@ void __cdecl CSkypeProto::SignInAsync(void*) bool CSkypeProto::SignIn(bool isReadPassword) { - if (!this->login || !::lstrcmp(this->login, L"")) + if (!this->login || !::lstrcmpA(this->login, "")) { this->m_iStatus = ID_STATUS_OFFLINE; this->SendBroadcast(ACKTYPE_LOGIN, ACKRESULT_FAILED, NULL, LOGINERR_BADUSERID); @@ -377,7 +367,7 @@ bool CSkypeProto::SignIn(bool isReadPassword) _T(MODULE), MB_OK); } - else if (g_skype->GetAccount(::mir_u2a(this->login), this->account)) + else if (g_skype->GetAccount(this->login, this->account)) { if (isReadPassword) this->password = this->GetDecodeSettingString(NULL, SKYPE_SETTINGS_PASSWORD); @@ -405,29 +395,4 @@ void CSkypeProto::RequestPassword() NULL, CSkypeProto::SkypePasswordProc, LPARAM(this)); -} - -void CSkypeProto::OnMessageReceived(CMessage::Ref message) -{ - SEIntList propIds; - SEIntDict propValues; - propIds.append(CMessage::P_AUTHOR); - propIds.append(CMessage::P_AUTHOR_DISPLAYNAME); - propIds.append(CMessage::P_BODY_XML); - propValues = message->GetProps(propIds); - - uint timestamp; - message->GetPropTimestamp(timestamp); - - this->RaiseMessageReceivedEvent( - (DWORD)timestamp, - (const char*)propValues[0], - (const char*)propValues[1], - (const char*)propValues[2]); -} - -void CSkypeProto::OnConversationAdded(CConversation::Ref conversation) -{ - //conversation->SetOnMessageReceivedCallback( - // (CConversation::OnMessageReceived)&CSkypeProto::OnMessageReceived, this); } \ No newline at end of file diff --git a/protocols/Skype/src/skype_proto.h b/protocols/Skype/src/skype_proto.h index f7a057a306..8a5eae3498 100644 --- a/protocols/Skype/src/skype_proto.h +++ b/protocols/Skype/src/skype_proto.h @@ -157,8 +157,8 @@ protected: bool IsOnline(); void OnAccountChanged(int prop); - wchar_t *login; - char *password; + char *login; + char *password; bool rememberPassword; void RequestPassword(); @@ -170,8 +170,9 @@ protected: static LanguagesListEntry languages[223]; // messages - void OnMessageReceived(CMessage::Ref message); - void OnConversationAdded(CConversation::Ref conversation); + void OnMessage(CConversation::Ref conversation, CMessage::Ref message); + void OnMessageSended(CConversation::Ref conversation, CMessage::Ref message); + void OnMessageReceived(CConversation::Ref conversation, CMessage::Ref message); // contacts void UpdateContactAboutText(HANDLE hContact, CContact::Ref contact); @@ -302,6 +303,11 @@ protected: const char* sid, const char* nick, const char* message = ""); + void RaiseMessageSendedEvent( + DWORD timestamp, + const char* sid, + const char* nick, + const char* message = ""); void RaiseAuthRequestEvent( DWORD timestamp, const char* sid, diff --git a/protocols/Skype/src/skype_subclassing.cpp b/protocols/Skype/src/skype_subclassing.cpp index 4ae99d087a..adbd6a5120 100644 --- a/protocols/Skype/src/skype_subclassing.cpp +++ b/protocols/Skype/src/skype_subclassing.cpp @@ -5,8 +5,7 @@ CSkype::CSkype(int num_threads) : Skype(num_threads) { this->proto = NULL; - this->onMessageReceivedCallback = NULL; - this->onConversationAddedCallback = NULL; + this->onMessagedCallback = NULL; } CAccount* CSkype::newAccount(int oid) @@ -49,43 +48,16 @@ void CSkype::OnMessage ( skype->GetUnixTimestamp(now); conversation->SetConsumedHorizon(now);*/ - Message::TYPE messageType; - message->GetPropType(messageType); - - Message::SENDING_STATUS sendingStatus; - message->GetPropSendingStatus(sendingStatus); - - if (messageType == Message::POSTED_TEXT && !sendingStatus) - { - if (this->proto) - (proto->*onMessageReceivedCallback)(message->ref()); - } -} - -void CSkype::SetOnMessageReceivedCallback(OnMessageReceived callback, CSkypeProto* proto) -{ - this->proto = proto; - this->onMessageReceivedCallback = callback; -} + if (this->proto) + (proto->*onMessagedCallback)(conversation->ref(), message->ref()); -void CSkype::OnConversationListChange( - const ConversationRef &conversation, - const Conversation::LIST_TYPE &type, - const bool &added) -{ - if ((type == Conversation::INBOX_CONVERSATIONS) && (added) && (!inbox.contains(conversation))) - { - conversation.fetch(); - inbox.append(conversation); - if (this->proto) - (proto->*onConversationAddedCallback)(conversation->ref()); - } + } -void CSkype::SetOnConversationAddedCallback(OnConversationAdded callback, CSkypeProto* proto) +void CSkype::SetOnMessageCallback(OnMessaged callback, CSkypeProto* proto) { this->proto = proto; - this->onConversationAddedCallback = callback; + this->onMessagedCallback = callback; } // CAccount diff --git a/protocols/Skype/src/skype_subclassing.h b/protocols/Skype/src/skype_subclassing.h index 0840c57dc3..2624ba3f76 100644 --- a/protocols/Skype/src/skype_subclassing.h +++ b/protocols/Skype/src/skype_subclassing.h @@ -125,8 +125,7 @@ private: class CSkype : public Skype { public: - typedef void (CSkypeProto::* OnMessageReceived)(CMessage::Ref message); - typedef void (CSkypeProto::* OnConversationAdded)(CConversation::Ref conversation); + typedef void (CSkypeProto::* OnMessaged)(CConversation::Ref conversation, CMessage::Ref message); CAccount* newAccount(int oid); CContactGroup* newContactGroup(int oid); @@ -139,22 +138,15 @@ public: CSkype(int num_threads = 1); - void SetOnMessageReceivedCallback(OnMessageReceived callback, CSkypeProto* proto); - void SetOnConversationAddedCallback(OnConversationAdded callback, CSkypeProto* proto); + void SetOnMessageCallback(OnMessaged callback, CSkypeProto* proto); private: - CSkypeProto* proto; - OnMessageReceived onMessageReceivedCallback; - OnConversationAdded onConversationAddedCallback; + CSkypeProto* proto; + OnMessaged onMessagedCallback; void OnMessage( const MessageRef & message, const bool & changesInboxTimestamp, const MessageRef & supersedesHistoryMessage, const ConversationRef & conversation); - - void OnConversationListChange( - const ConversationRef &conversation, - const Conversation::LIST_TYPE &type, - const bool &added); }; \ No newline at end of file -- cgit v1.2.3