From 56ac6b6b49cd5785ce5fb14dc63e776b4b3da07a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 28 Sep 2013 18:22:40 +0000 Subject: - Google specific functionality got moved to GTalkExt, part I; - new event for extensions list creation, ME_JABBER_EXTLISTINIT git-svn-id: http://svn.miranda-ng.org/main/trunk@6260 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- include/m_jabber.h | 13 ++++-- protocols/GTalkExt/src/GTalkExt.cpp | 3 ++ protocols/GTalkExt/src/db.h | 2 - protocols/GTalkExt/src/handlers.cpp | 44 ++++++++++++++----- protocols/GTalkExt/src/options.cpp | 63 ++++++++++++--------------- protocols/GTalkExt/src/stdafx.h | 2 + protocols/JabberG/src/jabber.cpp | 4 ++ protocols/JabberG/src/jabber_api.cpp | 11 ++--- protocols/JabberG/src/jabber_caps.h | 1 - protocols/JabberG/src/jabber_iqid.cpp | 80 +++++++++++++++++------------------ protocols/JabberG/src/jabber_menu.cpp | 8 ++-- protocols/JabberG/src/jabber_proto.h | 1 - protocols/JabberG/src/jabber_util.cpp | 7 ++- 13 files changed, 130 insertions(+), 109 deletions(-) diff --git a/include/m_jabber.h b/include/m_jabber.h index 05a94e5de9..26635b24a4 100644 --- a/include/m_jabber.h +++ b/include/m_jabber.h @@ -180,13 +180,20 @@ __forceinline IJabberInterface *getJabberApi(const char *szAccount) /* A menu hook to be called during Jabber protocol menu initialization. +wParam = (HGENMENU)m_hMenuRoot; +lParam = (LPARAM)(IJabberInterface*). +Returns FALSE if all is Ok, and TRUE otherwise. +*/ -wParam = 0; -lParam = (LPARAM)(IJabberInterface**). +#define ME_JABBER_MENUINIT "Jabber/ProtoMenuInit" +/* +A hook to be called during extensions list's creation +wParam = (WPARAM)(LIST*) - extensions list to be populated; +lParam = (LPARAM)(IJabberInterface*). Returns FALSE if all is Ok, and TRUE otherwise. */ -#define ME_JABBER_MENUINIT "Jabber/ProtoMenuInit" +#define ME_JABBER_EXTLISTINIT "Jabber/ExtListInit" #endif // M_JABBER_H__ diff --git a/protocols/GTalkExt/src/GTalkExt.cpp b/protocols/GTalkExt/src/GTalkExt.cpp index 64d860f77d..85374a3883 100644 --- a/protocols/GTalkExt/src/GTalkExt.cpp +++ b/protocols/GTalkExt/src/GTalkExt.cpp @@ -32,6 +32,8 @@ int hLangpack; HICON g_hPopupIcon = 0; +LIST g_accs(1, PtrKeySortT); + PLUGININFOEX pluginInfo = { sizeof(PLUGININFOEX), @@ -101,6 +103,7 @@ extern "C" int __declspec(dllexport) Load(void) extern "C" int __declspec(dllexport) Unload(void) { + g_accs.destroy(); InitAvaUnit(FALSE); InitMenus(FALSE); return 0; diff --git a/protocols/GTalkExt/src/db.h b/protocols/GTalkExt/src/db.h index 92a01c6500..6cecd89a1d 100644 --- a/protocols/GTalkExt/src/db.h +++ b/protocols/GTalkExt/src/db.h @@ -28,6 +28,4 @@ static const LPSTR LAST_THREAD_ID_FROM_JID = SHORT_PLUGIN_NAME ".LastThreadIdFro LPTSTR ReadJidSetting(LPCSTR name, LPCTSTR jid); void WriteJidSetting(LPCSTR name, LPCTSTR jid, LPCTSTR setting); -IJabberInterface* IsGoogleAccount(LPCSTR szModuleName); - void RenewPseudocontactHandles(); diff --git a/protocols/GTalkExt/src/handlers.cpp b/protocols/GTalkExt/src/handlers.cpp index f5bd3bc212..a08c68c21a 100644 --- a/protocols/GTalkExt/src/handlers.cpp +++ b/protocols/GTalkExt/src/handlers.cpp @@ -26,6 +26,8 @@ #include "notifications.h" #include "options.h" +#define JABBER_EXT_GTALK_PMUC _T("pmuc-v1") + static const LPCTSTR JABBER_IQID = _T("mir_"); static const LPCTSTR JABBER_IQID_FORMAT = _T("mir_%d"); @@ -355,6 +357,19 @@ BOOL SendHandler(IJabberInterface *ji, HXML node, void *pUserData) return FALSE; } +///////////////////////////////////////////////////////////////////////////////////////// +// adds Google extensions into the caps list + +int OnExtListInit(WPARAM wParam, LPARAM lParam) +{ + IJabberInterface *japi = (IJabberInterface*)lParam; + if (g_accs.indexOf(japi) != -1) { + LIST *pList = (LIST*)wParam; + pList->insert(JABBER_EXT_GTALK_PMUC); + } + return 0; +} + ///////////////////////////////////////////////////////////////////////////////////////// // for our pseudo contact only our own popups are allowed // 0 = allowed, 1 = disallowed @@ -370,6 +385,20 @@ int OnFilterPopup(WPARAM wParam, LPARAM lParam) ///////////////////////////////////////////////////////////////////////////////////////// +int AccListChanged(WPARAM wParam, LPARAM lParam) +{ + if (wParam == PRAC_ADDED) { + IJabberInterface *ji = getJabberApi(((PROTOACCOUNT*)lParam)->szModuleName); + if (ji) { + g_accs.insert(ji); + ji->AddSendHandler(SendHandler); + } + } + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + IJabberInterface* IsGoogleAccount(LPCSTR szModuleName) { IJabberInterface *japi = getJabberApi(szModuleName); @@ -383,16 +412,6 @@ IJabberInterface* IsGoogleAccount(LPCSTR szModuleName) return ( !strcmp(host, "talk.google.com")) ? japi : NULL; } -int AccListChanged(WPARAM wParam, LPARAM lParam) -{ - if (wParam == PRAC_ADDED) { - IJabberInterface *ji = getJabberApi(((PROTOACCOUNT*)lParam)->szModuleName); - if (ji) - ji->AddSendHandler(SendHandler); - } - return 0; -} - int ModulesLoaded(WPARAM wParam, LPARAM lParam) { RenewPseudocontactHandles(); @@ -402,11 +421,14 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) ProtoEnumAccounts(&count, &protos); for (int i=0; i < count; i++) { IJabberInterface *ji = IsGoogleAccount(protos[i]->szModuleName); - if (ji) + if (ji) { + g_accs.insert(ji); ji->AddSendHandler(SendHandler); + } } HookEvent(ME_POPUP_FILTER, OnFilterPopup); + HookEvent(ME_JABBER_EXTLISTINIT, OnExtListInit); HookOptionsInitialization(); return 0; } diff --git a/protocols/GTalkExt/src/options.cpp b/protocols/GTalkExt/src/options.cpp index 0d5fdc25ee..1f032c108e 100644 --- a/protocols/GTalkExt/src/options.cpp +++ b/protocols/GTalkExt/src/options.cpp @@ -233,46 +233,37 @@ INT_PTR CALLBACK PopupsOptionsDlgProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM return 0; } -void AddPopupsPage(WPARAM wParam) -{ - OPTIONSDIALOGPAGE odp = { sizeof(odp) }; - odp.ptszTitle = MAIL_NOTIFICATIONS; - odp.pfnDlgProc = PopupsOptionsDlgProc; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_POPUPSETTINGS); - odp.hInstance = g_hInst; - odp.ptszGroup = POPUPS_OPTIONS_GROUP; - odp.flags = ODPF_UNICODE | ODPF_USERINFOTAB; - Options_AddPage(wParam, &odp); -} - -void AddAccPage(LPTSTR acc, LPCSTR mod, WPARAM wParam) -{ - OPTIONSDIALOGPAGE odp = { sizeof(odp) }; - odp.ptszTitle = acc; - odp.pfnDlgProc = AccOptionsDlgProc; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_MAILSETTINGS); - odp.hInstance = g_hInst; - odp.ptszGroup = NETWORK_OPTIONS_GROUP; - odp.flags = ODPF_UNICODE | ODPF_USERINFOTAB | ODPF_DONTTRANSLATE; - odp.ptszTab = MAIL_NOTIFICATIONS; - odp.dwInitParam = (LPARAM)mod; - Options_AddPage(wParam, &odp); -} - int OptionsInitialization(WPARAM wParam, LPARAM lParam) { - int count; - PROTOACCOUNT **accs; - ProtoEnumAccounts(&count, &accs); - for (int i = 0; i < count; i++) { - IJabberInterface *ji = IsGoogleAccount(accs[i]->szModuleName); - if (ji) - AddAccPage(accs[i]->tszAccountName, accs[i]->szModuleName, wParam); + if (ServiceExists(MS_POPUP_ADDPOPUPT)) { + OPTIONSDIALOGPAGE odp = { sizeof(odp) }; + odp.ptszTitle = MAIL_NOTIFICATIONS; + odp.pfnDlgProc = PopupsOptionsDlgProc; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_POPUPSETTINGS); + odp.hInstance = g_hInst; + odp.ptszGroup = POPUPS_OPTIONS_GROUP; + odp.flags = ODPF_UNICODE | ODPF_USERINFOTAB; + Options_AddPage(wParam, &odp); } - if (ServiceExists(MS_POPUP_ADDPOPUPT)) - AddPopupsPage(wParam); - return FALSE; + for (int i=0; i < g_accs.getCount(); i++) { + LPCSTR szProto = g_accs[i]->GetModuleName(); + PROTOACCOUNT *pa = ProtoGetAccount(szProto); + if (pa == 0) + continue; + + OPTIONSDIALOGPAGE odp = { sizeof(odp) }; + odp.ptszTitle = pa->tszAccountName; + odp.pfnDlgProc = AccOptionsDlgProc; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_MAILSETTINGS); + odp.hInstance = g_hInst; + odp.ptszGroup = NETWORK_OPTIONS_GROUP; + odp.flags = ODPF_UNICODE | ODPF_USERINFOTAB | ODPF_DONTTRANSLATE; + odp.ptszTab = MAIL_NOTIFICATIONS; + odp.dwInitParam = (LPARAM)szProto; + Options_AddPage(wParam, &odp); + } + return 0; } void HookOptionsInitialization() diff --git a/protocols/GTalkExt/src/stdafx.h b/protocols/GTalkExt/src/stdafx.h index 0a4dd456ee..c65c0ddd99 100644 --- a/protocols/GTalkExt/src/stdafx.h +++ b/protocols/GTalkExt/src/stdafx.h @@ -51,6 +51,7 @@ #pragma warning(disable:4996) #include +#include #include #include #include @@ -65,6 +66,7 @@ #pragma warning(pop) extern HINSTANCE g_hInst; +extern LIST g_accs; void SetAvatar(HANDLE hContact); BOOL InitAvaUnit(BOOL init); diff --git a/protocols/JabberG/src/jabber.cpp b/protocols/JabberG/src/jabber.cpp index 83b90a0e95..d72f1b99c3 100644 --- a/protocols/JabberG/src/jabber.cpp +++ b/protocols/JabberG/src/jabber.cpp @@ -63,6 +63,7 @@ BOOL jabberChatDllPresent = FALSE; HANDLE hExtraActivity = NULL; HANDLE hExtraMood = NULL; +HANDLE hExtListInit; void JabberUserInfoInit(void); @@ -202,6 +203,8 @@ extern "C" int __declspec(dllexport) Load() setlocale(LC_ALL, ""); + hExtListInit = CreateHookableEvent(ME_JABBER_EXTLISTINIT); + // Register protocol module PROTOCOLDESCRIPTOR pd = { sizeof(pd) }; pd.szName = "JABBER"; @@ -224,6 +227,7 @@ extern "C" int __declspec(dllexport) Load() extern "C" int __declspec(dllexport) Unload(void) { + DestroyHookableEvent(hExtListInit); g_MenuUninit(); g_Instances.destroy(); diff --git a/protocols/JabberG/src/jabber_api.cpp b/protocols/JabberG/src/jabber_api.cpp index 0528643c5e..03dbf8b276 100644 --- a/protocols/JabberG/src/jabber_api.cpp +++ b/protocols/JabberG/src/jabber_api.cpp @@ -204,28 +204,23 @@ int CJabberProto::RemoveHandler(HJHANDLER hHandler) JabberFeatCapPairDynamic *CJabberProto::FindFeature(LPCTSTR szFeature) { - int i; - for (i=0; i < m_lstJabberFeatCapPairsDynamic.getCount(); i++) + for (int i=0; i < m_lstJabberFeatCapPairsDynamic.getCount(); i++) if ( !lstrcmp(m_lstJabberFeatCapPairsDynamic[i]->szFeature, szFeature)) return m_lstJabberFeatCapPairsDynamic[i]; + return NULL; } int CJabberProto::RegisterFeature(LPCTSTR szFeature, LPCTSTR szDescription) { - if ( !szFeature) { + if ( !szFeature) return false; - } // check for this feature in core features, and return false if it's present, to prevent re-registering a core feature int i; for (i=0; g_JabberFeatCapPairs[i].szFeature; i++) - { if ( !lstrcmp(g_JabberFeatCapPairs[i].szFeature, szFeature)) - { return false; - } - } mir_cslock lck(m_csLists); JabberFeatCapPairDynamic *fcp = FindFeature(szFeature); diff --git a/protocols/JabberG/src/jabber_caps.h b/protocols/JabberG/src/jabber_caps.h index 6322fd4170..5c5bc8199b 100644 --- a/protocols/JabberG/src/jabber_caps.h +++ b/protocols/JabberG/src/jabber_caps.h @@ -166,7 +166,6 @@ typedef unsigned __int64 JabberCapsBits; #define JABBER_EXT_USER_MOOD "mood" #define JABBER_EXT_USER_TUNE "tune" #define JABBER_EXT_USER_ACTIVITY "activity" -#define JABBER_EXT_GTALK_PMUC "pmuc-v1" #define JABBER_EXT_MIR_NOTES "mir_notes" #define JABBER_EXT_PLATFORMX86 "x86" #define JABBER_EXT_PLATFORMX64 "x64" diff --git a/protocols/JabberG/src/jabber_iqid.cpp b/protocols/JabberG/src/jabber_iqid.cpp index 567c762869..f226f5b7af 100644 --- a/protocols/JabberG/src/jabber_iqid.cpp +++ b/protocols/JabberG/src/jabber_iqid.cpp @@ -34,55 +34,55 @@ void CJabberProto::OnIqResultServerDiscoInfo(HXML iqNode) return; const TCHAR *type = xmlGetAttrValue(iqNode, _T("type")); - int i; + if ( _tcscmp(type, _T("result"))) + return; - if ( !_tcscmp(type, _T("result"))) { - HXML query = xmlGetChildByTag(iqNode, "query", "xmlns", JABBER_FEAT_DISCO_INFO); - if ( !query) - return; + HXML query = xmlGetChildByTag(iqNode, "query", "xmlns", JABBER_FEAT_DISCO_INFO); + if ( !query) + return; - HXML identity; - for (i = 1; (identity = xmlGetNthChild(query, _T("identity"), i)) != NULL; i++) { - const TCHAR *identityCategory = xmlGetAttrValue(identity, _T("category")); - const TCHAR *identityType = xmlGetAttrValue(identity, _T("type")); - const TCHAR *identityName = xmlGetAttrValue(identity, _T("name")); - if (identityCategory && identityType && !_tcscmp(identityCategory, _T("pubsub")) && !_tcscmp(identityType, _T("pep"))) { - m_bPepSupported = TRUE; + HXML identity; + for (int i = 1; (identity = xmlGetNthChild(query, _T("identity"), i)) != NULL; i++) { + const TCHAR *identityCategory = xmlGetAttrValue(identity, _T("category")); + const TCHAR *identityType = xmlGetAttrValue(identity, _T("type")); + const TCHAR *identityName = xmlGetAttrValue(identity, _T("name")); + if (identityCategory && identityType && !_tcscmp(identityCategory, _T("pubsub")) && !_tcscmp(identityType, _T("pep"))) { + m_bPepSupported = TRUE; - EnableMenuItems(TRUE); - RebuildInfoFrame(); - } - else if (identityCategory && identityType && identityName && - !_tcscmp(identityCategory, _T("server")) && - !_tcscmp(identityType, _T("im")) && - !_tcscmp(identityName, _T("Google Talk"))) { - m_ThreadInfo->jabberServerCaps |= JABBER_CAPS_PING; - m_bGoogleTalk = true; - - // Google Shared Status - m_ThreadInfo->send( - XmlNodeIq(m_iqManager.AddHandler(&CJabberProto::OnIqResultGoogleSharedStatus, JABBER_IQ_TYPE_GET)) - << XQUERY(JABBER_FEAT_GTALK_SHARED_STATUS) << XATTR(_T("version"), _T("2"))); - } + EnableMenuItems(TRUE); + RebuildInfoFrame(); } + else if (identityCategory && identityType && identityName && + !_tcscmp(identityCategory, _T("server")) && + !_tcscmp(identityType, _T("im")) && + !_tcscmp(identityName, _T("Google Talk"))) { + m_ThreadInfo->jabberServerCaps |= JABBER_CAPS_PING; + + // Google Shared Status + m_ThreadInfo->send( + XmlNodeIq(m_iqManager.AddHandler(&CJabberProto::OnIqResultGoogleSharedStatus, JABBER_IQ_TYPE_GET)) + << XQUERY(JABBER_FEAT_GTALK_SHARED_STATUS) << XATTR(_T("version"), _T("2"))); + } + } - if (m_ThreadInfo) { - HXML feature; - for (i = 1; (feature = xmlGetNthChild(query, _T("feature"), i)) != NULL; i++) { - const TCHAR *featureName = xmlGetAttrValue(feature, _T("var")); - if (!featureName) - continue; + if (m_ThreadInfo) { + HXML feature; + for (int i = 1; (feature = xmlGetNthChild(query, _T("feature"), i)) != NULL; i++) { + const TCHAR *featureName = xmlGetAttrValue(feature, _T("var")); + if (!featureName) + continue; - for (int j = 0; g_JabberFeatCapPairs[j].szFeature; j++) - if ( !_tcscmp(g_JabberFeatCapPairs[j].szFeature, featureName)) { - m_ThreadInfo->jabberServerCaps |= g_JabberFeatCapPairs[j].jcbCap; - break; - } + for (int j = 0; g_JabberFeatCapPairs[j].szFeature; j++) { + if ( !_tcscmp(g_JabberFeatCapPairs[j].szFeature, featureName)) { + m_ThreadInfo->jabberServerCaps |= g_JabberFeatCapPairs[j].jcbCap; + break; + } } } + } - OnProcessLoginRq(m_ThreadInfo, JABBER_LOGIN_SERVERINFO); -} } + OnProcessLoginRq(m_ThreadInfo, JABBER_LOGIN_SERVERINFO); +} void CJabberProto::OnIqResultNestedRosterGroups(HXML iqNode, CJabberIqInfo* pInfo) { diff --git a/protocols/JabberG/src/jabber_menu.cpp b/protocols/JabberG/src/jabber_menu.cpp index c8b96559b2..4c27ddf361 100644 --- a/protocols/JabberG/src/jabber_menu.cpp +++ b/protocols/JabberG/src/jabber_menu.cpp @@ -49,11 +49,12 @@ static HGENMENU g_hMenuResourcesRoot; static HGENMENU g_hMenuResourcesActive; static HGENMENU g_hMenuResourcesServer; -static struct +struct { int icon; int mode; -} PresenceModeArray[] = +} +static PresenceModeArray[] = { { SKINICON_STATUS_ONLINE, ID_STATUS_ONLINE }, { SKINICON_STATUS_AWAY, ID_STATUS_AWAY }, @@ -813,7 +814,7 @@ void CJabberProto::MenuInit() m_pepServices.RebuildMenu(); CheckMenuItems(); - NotifyFastHook(hStatusMenuInit, (WPARAM)hJabberRoot, (LPARAM)this); + NotifyFastHook(hStatusMenuInit, (WPARAM)hJabberRoot, (LPARAM)(IJabberInterface*)this); } ////////////////////////////////////////////////////////////////////////// @@ -1194,6 +1195,7 @@ INT_PTR __cdecl CJabberProto::OnMenuHandleDirectPresence(WPARAM wParam, LPARAM l //////////////////////////////////////////////////////////////////////// // Choose protocol instance + CJabberProto *JabberChooseInstance(bool bIsLink) { if (g_Instances.getCount() == 0) diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index 16476a0c45..b1cc88bc0a 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -195,7 +195,6 @@ struct CJabberProto : public PROTO, public IJabberInterface BOOL m_bChangeStatusMessageOnly; BOOL m_bSendKeepAlive; BOOL m_bPepSupported; - BOOL m_bGoogleTalk; HWND m_hwndAgentRegInput; HWND m_hwndRegProgress; diff --git a/protocols/JabberG/src/jabber_util.cpp b/protocols/JabberG/src/jabber_util.cpp index 65a5f059f6..132395ddd6 100644 --- a/protocols/JabberG/src/jabber_util.cpp +++ b/protocols/JabberG/src/jabber_util.cpp @@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "jabber_caps.h" extern CRITICAL_SECTION mutex; - +extern HANDLE hExtListInit; extern int bSecureIM, bMirOTR, bNewGPG, bPlatform; int CJabberProto::SerialNext(void) @@ -620,9 +620,6 @@ void CJabberProto::SendPresenceTo(int status, TCHAR* to, HXML extra, const TCHAR << XATTR(_T("ver"), szCoreVersion); LIST arrExtCaps(5); - if (m_bGoogleTalk) - arrExtCaps.insert( _T(JABBER_EXT_GTALK_PMUC)); - if (bSecureIM) arrExtCaps.insert( _T(JABBER_EXT_SECUREIM)); @@ -652,6 +649,8 @@ void CJabberProto::SendPresenceTo(int status, TCHAR* to, HXML extra, const TCHAR if (m_options.AcceptNotes) arrExtCaps.insert( _T(JABBER_EXT_MIR_NOTES)); + NotifyFastHook(hExtListInit, (WPARAM)&arrExtCaps, (LPARAM)(IJabberInterface*)this); + // add features enabled through IJabberNetInterface::AddFeatures() for (int i=0; i < m_lstJabberFeatCapPairsDynamic.getCount(); i++) if (m_uEnabledFeatCapsDynamic & m_lstJabberFeatCapPairsDynamic[i]->jcbCap) -- cgit v1.2.3