diff options
author | George Hazan <george.hazan@gmail.com> | 2013-09-28 14:52:02 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-09-28 14:52:02 +0000 |
commit | c1a1fb853547a1e9d50c95c8183d349b45e347ee (patch) | |
tree | 8c172e0d2dc2b2bfe17a4a40d158d83038568363 /protocols/JabberG/src | |
parent | 30bd869d78ea7d67904e6fa46c205e3a8697c6fc (diff) |
more plain & less crazy implementation of IJabberInterface
git-svn-id: http://svn.miranda-ng.org/main/trunk@6257 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/JabberG/src')
-rw-r--r-- | protocols/JabberG/src/jabber_api.cpp | 370 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_caps.cpp | 2 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_menu.cpp | 2 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_proto.cpp | 5 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_proto.h | 99 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_svc.cpp | 375 |
6 files changed, 404 insertions, 449 deletions
diff --git a/protocols/JabberG/src/jabber_api.cpp b/protocols/JabberG/src/jabber_api.cpp new file mode 100644 index 0000000000..0528643c5e --- /dev/null +++ b/protocols/JabberG/src/jabber_api.cpp @@ -0,0 +1,370 @@ +/*
+
+Jabber Protocol Plugin for Miranda IM
+Copyright (C) 2002-04 Santithorn Bunchua
+Copyright (C) 2005-12 George Hazan
+Copyright (C) 2007 Maxim Mluhov
+Copyright (C) 2012-13 Miranda NG Project
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+#include "jabber.h"
+
+// Jabber API functions
+INT_PTR __cdecl CJabberProto::JabberGetApi(WPARAM wParam, LPARAM lParam)
+{
+ IJabberInterface **ji = (IJabberInterface**)lParam;
+ if ( !ji)
+ return -1;
+ *ji = this;
+ return 0;
+}
+
+DWORD CJabberProto::GetFlags() const
+{
+ return JIF_UNICODE;
+}
+
+int CJabberProto::GetVersion() const
+{
+ return 1;
+}
+
+DWORD CJabberProto::GetJabberVersion() const
+{
+ return __VERSION_DWORD;
+}
+
+int CJabberProto::CompareJIDs(LPCTSTR jid1, LPCTSTR jid2)
+{
+ if ( !jid1 || !jid2) return 0;
+ return JabberCompareJids(jid1, jid2);
+}
+
+HANDLE CJabberProto::ContactFromJID(LPCTSTR jid)
+{
+ if (jid == NULL) return NULL;
+ return HContactFromJID(jid);
+}
+
+LPTSTR CJabberProto::ContactToJID(HANDLE hContact)
+{
+ return getTStringA(hContact, isChatRoom(hContact) ? "ChatRoomID" : "jid");
+}
+
+LPTSTR CJabberProto::GetBestResourceName(LPCTSTR jid)
+{
+ if (jid == NULL)
+ return NULL;
+ LPCTSTR p = _tcschr(jid, '/');
+ if (p == NULL) {
+ mir_cslock lck(m_csLists);
+ return mir_tstrdup(ListGetBestClientResourceNamePtr(jid));
+ }
+ return mir_tstrdup(jid);
+}
+
+LPTSTR CJabberProto::GetResourceList(LPCTSTR jid)
+{
+ if (jid == NULL)
+ return NULL;
+
+ mir_cslock lck(m_csLists);
+ JABBER_LIST_ITEM *item = NULL;
+ if ((item = ListGetItemPtr(LIST_VCARD_TEMP, jid)) == NULL)
+ item = ListGetItemPtr(LIST_ROSTER, jid);
+ if (item == NULL)
+ return NULL;
+
+ if (!item->arResources.getCount())
+ return NULL;
+
+ CMString res;
+ for (int i=0; i < item->arResources.getCount(); i++) {
+ res.Append(item->arResources[i]->m_tszResourceName);
+ res.AppendChar(0);
+ }
+ res.AppendChar(0);
+
+ return mir_tstrndup(res, res.GetLength());
+}
+
+char *CJabberProto::GetModuleName() const
+{
+ return m_szModuleName;
+}
+
+int CJabberProto::SendXmlNode(HXML node)
+{
+ return m_ThreadInfo->send(node);
+}
+
+typedef struct
+{
+ JABBER_HANDLER_FUNC Func;
+ void *pUserData;
+} sHandlerData;
+
+void CJabberProto::ExternalTempIqHandler(HXML node, CJabberIqInfo *pInfo)
+{
+ sHandlerData *d = (sHandlerData*)pInfo->GetUserData();
+ d->Func(this, node, d->pUserData);
+ free(d); // free IqHandlerData allocated in CJabberProto::AddIqHandler below
+}
+
+BOOL CJabberProto::ExternalIqHandler(HXML node, CJabberIqInfo *pInfo)
+{
+ sHandlerData *d = (sHandlerData*)pInfo->GetUserData();
+ return d->Func(this, node, d->pUserData);
+}
+
+BOOL CJabberProto::ExternalMessageHandler(HXML node, ThreadData *pThreadData, CJabberMessageInfo* pInfo)
+{
+ sHandlerData *d = (sHandlerData*)pInfo->GetUserData();
+ return d->Func(this, node, d->pUserData);
+}
+
+BOOL CJabberProto::ExternalPresenceHandler(HXML node, ThreadData *pThreadData, CJabberPresenceInfo* pInfo)
+{
+ sHandlerData *d = (sHandlerData*)pInfo->GetUserData();
+ return d->Func(this, node, d->pUserData);
+}
+
+BOOL CJabberProto::ExternalSendHandler(HXML node, ThreadData *pThreadData, CJabberSendInfo* pInfo)
+{
+ sHandlerData *d = (sHandlerData*)pInfo->GetUserData();
+ return d->Func(this, node, d->pUserData);
+}
+
+HJHANDLER CJabberProto::AddPresenceHandler(JABBER_HANDLER_FUNC Func, void *pUserData, int iPriority)
+{
+ sHandlerData *d = (sHandlerData*)malloc(sizeof(sHandlerData));
+ d->Func = Func;
+ d->pUserData = pUserData;
+ return (HJHANDLER)m_presenceManager.AddPermanentHandler(&CJabberProto::ExternalPresenceHandler, d, free, iPriority);
+}
+
+HJHANDLER CJabberProto::AddMessageHandler(JABBER_HANDLER_FUNC Func, int iMsgTypes, LPCTSTR szXmlns, LPCTSTR szTag, void *pUserData, int iPriority)
+{
+ sHandlerData *d = (sHandlerData*)malloc(sizeof(sHandlerData));
+ d->Func = Func;
+ d->pUserData = pUserData;
+ return (HJHANDLER)m_messageManager.AddPermanentHandler(&CJabberProto::ExternalMessageHandler, iMsgTypes, 0, szXmlns, FALSE, szTag, d, free, iPriority);
+}
+
+HJHANDLER CJabberProto::AddIqHandler(JABBER_HANDLER_FUNC Func, int iIqTypes, LPCTSTR szXmlns, LPCTSTR szTag, void *pUserData, int iPriority)
+{
+ sHandlerData *d = (sHandlerData*)malloc(sizeof(sHandlerData));
+ d->Func = Func;
+ d->pUserData = pUserData;
+ return (HJHANDLER)m_iqManager.AddPermanentHandler(&CJabberProto::ExternalIqHandler, iIqTypes, 0, szXmlns, FALSE, szTag, d, free, iPriority);
+}
+
+HJHANDLER CJabberProto::AddTemporaryIqHandler(JABBER_HANDLER_FUNC Func, int iIqTypes, int iIqId, void *pUserData, DWORD dwTimeout, int iPriority)
+{
+ sHandlerData *d = (sHandlerData*)malloc(sizeof(sHandlerData));
+ d->Func = Func;
+ d->pUserData = pUserData;
+ CJabberIqInfo* pInfo = m_iqManager.AddHandler(&CJabberProto::ExternalTempIqHandler, iIqTypes, NULL, 0, iIqId, d, iPriority);
+ if (pInfo && dwTimeout > 0)
+ pInfo->SetTimeout(dwTimeout);
+ return (HJHANDLER)pInfo;
+}
+
+HJHANDLER CJabberProto::AddSendHandler(JABBER_HANDLER_FUNC Func, void *pUserData, int iPriority)
+{
+ sHandlerData *d = (sHandlerData*)malloc(sizeof(sHandlerData));
+ d->Func = Func;
+ d->pUserData = pUserData;
+ return (HJHANDLER)m_sendManager.AddPermanentHandler(&CJabberProto::ExternalSendHandler, d, free, iPriority);
+}
+
+int CJabberProto::RemoveHandler(HJHANDLER hHandler)
+{
+ return m_sendManager.DeletePermanentHandler((CJabberSendPermanentInfo*)hHandler) ||
+ m_presenceManager.DeletePermanentHandler((CJabberPresencePermanentInfo*)hHandler) ||
+ m_messageManager.DeletePermanentHandler((CJabberMessagePermanentInfo*)hHandler) ||
+ m_iqManager.DeletePermanentHandler((CJabberIqPermanentInfo*)hHandler) ||
+ m_iqManager.DeleteHandler((CJabberIqInfo*)hHandler);
+}
+
+JabberFeatCapPairDynamic *CJabberProto::FindFeature(LPCTSTR szFeature)
+{
+ int i;
+ for (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) {
+ 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);
+ if ( !fcp) { // if the feature is not registered yet, allocate new bit for it
+ JabberCapsBits jcb = JABBER_CAPS_OTHER_SPECIAL; // set all bits not included in g_JabberFeatCapPairs
+
+ // set all bits occupied by g_JabberFeatCapPairs
+ for (i=0; g_JabberFeatCapPairs[i].szFeature; i++)
+ jcb |= g_JabberFeatCapPairs[i].jcbCap;
+
+ // set all bits already occupied by external plugins
+ for (i=0; i < m_lstJabberFeatCapPairsDynamic.getCount(); i++)
+ jcb |= m_lstJabberFeatCapPairsDynamic[i]->jcbCap;
+
+ // Now get first zero bit. The line below is a fast way to do it. If there are no zero bits, it returns 0.
+ jcb = (~jcb) & (JabberCapsBits)(-(__int64)(~jcb));
+
+ // no more free bits
+ if ( !jcb)
+ return false;
+
+ // remove unnecessary symbols from szFeature to make the string shorter, and use it as szExt
+ LPTSTR szExt = mir_tstrdup(szFeature);
+ LPTSTR pSrc, pDst;
+ for (pSrc = szExt, pDst = szExt; *pSrc; pSrc++)
+ if (_tcschr(_T("bcdfghjklmnpqrstvwxz0123456789"), *pSrc))
+ *pDst++ = *pSrc;
+ *pDst = 0;
+ m_clientCapsManager.SetClientCaps(JABBER_CAPS_MIRANDA_NODE, szExt, jcb);
+
+ fcp = new JabberFeatCapPairDynamic();
+ fcp->szExt = szExt; // will be deallocated along with other values of JabberFeatCapPairDynamic in CJabberProto destructor
+ fcp->szFeature = mir_tstrdup(szFeature);
+ fcp->szDescription = szDescription ? mir_tstrdup(szDescription) : NULL;
+ fcp->jcbCap = jcb;
+ m_lstJabberFeatCapPairsDynamic.insert(fcp);
+ }
+ else if (szDescription) { // update description
+ if (fcp->szDescription)
+ mir_free(fcp->szDescription);
+ fcp->szDescription = mir_tstrdup(szDescription);
+ }
+ return true;
+}
+
+int CJabberProto::AddFeatures(LPCTSTR szFeatures)
+{
+ if ( !szFeatures)
+ return false;
+
+ mir_cslockfull lck(m_csLists);
+ BOOL ret = true;
+ LPCTSTR szFeat = szFeatures;
+ while (szFeat[0]) {
+ JabberFeatCapPairDynamic *fcp = FindFeature(szFeat);
+ // if someone is trying to add one of core features, RegisterFeature() will return false, so we don't have to perform this check here
+ if ( !fcp) { // if the feature is not registered yet
+ if ( !RegisterFeature(szFeat, NULL))
+ ret = false;
+ else
+ fcp = FindFeature(szFeat); // update fcp after RegisterFeature()
+ }
+ if (fcp)
+ m_uEnabledFeatCapsDynamic |= fcp->jcbCap;
+ else
+ ret = false;
+ szFeat += lstrlen(szFeat) + 1;
+ }
+ lck.unlock();
+
+ if (m_bJabberOnline)
+ SendPresence(m_iStatus, true);
+
+ return ret;
+}
+
+int CJabberProto::RemoveFeatures(LPCTSTR szFeatures)
+{
+ if ( !szFeatures)
+ return false;
+
+ mir_cslockfull lck(m_csLists);
+ BOOL ret = true;
+ LPCTSTR szFeat = szFeatures;
+ while (szFeat[0]) {
+ JabberFeatCapPairDynamic *fcp = FindFeature(szFeat);
+ if (fcp)
+ m_uEnabledFeatCapsDynamic &= ~fcp->jcbCap;
+ else
+ ret = false; // indicate that there was an error removing at least one of the specified features
+
+ szFeat += lstrlen(szFeat) + 1;
+ }
+ lck.unlock();
+
+ if (m_bJabberOnline)
+ SendPresence(m_iStatus, true);
+
+ return ret;
+}
+
+LPTSTR CJabberProto::GetResourceFeatures(LPCTSTR jid)
+{
+ JabberCapsBits jcb = GetResourceCapabilites(jid, true);
+ if (jcb & JABBER_RESOURCE_CAPS_ERROR)
+ return NULL;
+
+ mir_cslockfull lck(m_csLists);
+ int i;
+ int iLen = 1; // 1 for extra zero terminator at the end of the string
+ // calculate total necessary string length
+ for (i=0; g_JabberFeatCapPairs[i].szFeature; i++)
+ if (jcb & g_JabberFeatCapPairs[i].jcbCap)
+ iLen += lstrlen(g_JabberFeatCapPairs[i].szFeature) + 1;
+
+ for (i=0; i < m_lstJabberFeatCapPairsDynamic.getCount(); i++)
+ if (jcb & m_lstJabberFeatCapPairsDynamic[i]->jcbCap)
+ iLen += lstrlen(m_lstJabberFeatCapPairsDynamic[i]->szFeature) + 1;
+
+ // allocate memory and fill it
+ LPTSTR str = (LPTSTR)mir_alloc(iLen * sizeof(TCHAR));
+ LPTSTR p = str;
+ for (i=0; g_JabberFeatCapPairs[i].szFeature; i++)
+ if (jcb & g_JabberFeatCapPairs[i].jcbCap) {
+ lstrcpy(p, g_JabberFeatCapPairs[i].szFeature);
+ p += lstrlen(g_JabberFeatCapPairs[i].szFeature) + 1;
+ }
+
+ for (i=0; i < m_lstJabberFeatCapPairsDynamic.getCount(); i++)
+ if (jcb & m_lstJabberFeatCapPairsDynamic[i]->jcbCap) {
+ lstrcpy(p, m_lstJabberFeatCapPairsDynamic[i]->szFeature);
+ p += lstrlen(m_lstJabberFeatCapPairsDynamic[i]->szFeature) + 1;
+ }
+
+ *p = 0; // extra zero terminator
+ return str;
+}
+
+HANDLE CJabberProto::GetHandle()
+{
+ return m_hNetlibUser;
+}
diff --git a/protocols/JabberG/src/jabber_caps.cpp b/protocols/JabberG/src/jabber_caps.cpp index dd7762f1e9..87d2b4abb9 100644 --- a/protocols/JabberG/src/jabber_caps.cpp +++ b/protocols/JabberG/src/jabber_caps.cpp @@ -75,7 +75,7 @@ const JabberFeatCapPair g_JabberFeatCapPairs[] = { { JABBER_FEAT_JINGLE, JABBER_CAPS_JINGLE, LPGENT("Supports Jingle") },
{ JABBER_FEAT_ROSTER_EXCHANGE, JABBER_CAPS_ROSTER_EXCHANGE, LPGENT("Supports Roster Exchange") },
{ JABBER_FEAT_GTALK_PMUC, JABBER_CAPS_GTALK_PMUC, LPGENT("Supports GTalk private multi-user chat") },
- { NULL, 0, NULL}
+ { NULL, 0, NULL }
};
const JabberFeatCapPair g_JabberFeatCapPairsExt[] = {
diff --git a/protocols/JabberG/src/jabber_menu.cpp b/protocols/JabberG/src/jabber_menu.cpp index 2c9fef4f4e..c8b96559b2 100644 --- a/protocols/JabberG/src/jabber_menu.cpp +++ b/protocols/JabberG/src/jabber_menu.cpp @@ -813,7 +813,7 @@ void CJabberProto::MenuInit() m_pepServices.RebuildMenu();
CheckMenuItems();
- NotifyFastHook(hStatusMenuInit, (WPARAM)hJabberRoot, (LPARAM)&m_JabberApi);
+ NotifyFastHook(hStatusMenuInit, (WPARAM)hJabberRoot, (LPARAM)this);
}
//////////////////////////////////////////////////////////////////////////
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 50b2ebd176..47b84f1117 100644 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -77,11 +77,6 @@ CJabberProto::CJabberProto(const char *aProtoName, const TCHAR *aUserName) : Log("Setting protocol/module name to '%s'", m_szModuleName);
- // Initialize Jabber API
- m_JabberApi.m_psProto = this;
- m_JabberSysApi.m_psProto = this;
- m_JabberNetApi.m_psProto = this;
-
// Jabber dialog list
m_windowList = (HANDLE)CallService(MS_UTILS_ALLOCWINDOWLIST, 0, 0);
diff --git a/protocols/JabberG/src/jabber_proto.h b/protocols/JabberG/src/jabber_proto.h index d09f3bf6aa..16476a0c45 100644 --- a/protocols/JabberG/src/jabber_proto.h +++ b/protocols/JabberG/src/jabber_proto.h @@ -83,67 +83,7 @@ struct TFilterInfo TCHAR pattern[256];
};
-struct CJabberSysInterface: public IJabberSysInterface
-{
- int STDMETHODCALLTYPE GetVersion() const; // Returns version of IJabberSysInterface.
- int STDMETHODCALLTYPE CompareJIDs(LPCTSTR jid1, LPCTSTR jid2); // Strips resource names from given JIDs and returns result of comparison for these JIDs.
- HANDLE STDMETHODCALLTYPE ContactFromJID(LPCTSTR jid); // Returns contact handle for given JID.
- LPTSTR STDMETHODCALLTYPE ContactToJID(HANDLE hContact); // Returns JID of hContact. You must free the result using mir_free().
- LPTSTR STDMETHODCALLTYPE GetBestResourceName(LPCTSTR jid); // Returns best resource name for given JID. You must free the result using mir_free().
- LPTSTR STDMETHODCALLTYPE GetResourceList(LPCTSTR jid); // Returns all resource names for a given JID in format "resource1\0resource2\0resource3\0\0" (all resources are separated by \0 character and the whole string is terminated with two \0 characters). You must free the string using mir_free().
- char* STDMETHODCALLTYPE GetModuleName() const; // Returns Jabber module name.
-
- CJabberProto *m_psProto;
-};
-
-struct CJabberNetInterface: public IJabberNetInterface
-{
- int STDMETHODCALLTYPE GetVersion() const; // Returns version of IJabberNetInterface.
- UINT STDMETHODCALLTYPE SerialNext(); // Returns id that can be used for next message sent through SendXmlNode().
- int STDMETHODCALLTYPE SendXmlNode(HXML node); // Sends XML node.
-
- // In all incoming stanza handlers, return TRUE to continue processing of the stanza (Jabber plugin will then call other handlers). Return FALSE only when you're sure noone else will need to process this stanza.
- // Registers incoming <presence/> handler. Returns handler handle on success or NULL on error.
- HJHANDLER STDMETHODCALLTYPE AddPresenceHandler(JABBER_HANDLER_FUNC Func, void *pUserData, int iPriority);
- // Registers incoming <message/> handler for messages of types specified by iMsgTypes. iMsgTypes is a combination of JABBER_MESSAGE_TYPE_* flags. Returns handler handle on success or NULL on error.
- HJHANDLER STDMETHODCALLTYPE AddMessageHandler(JABBER_HANDLER_FUNC Func, int iMsgTypes, LPCTSTR szXmlns, LPCTSTR szTag, void *pUserData, int iPriority);
- // Registers incoming <iq/> handler. iIqTypes is a combination of JABBER_IQ_TYPE_* flags. Returns handler handle on success or NULL on error.
- HJHANDLER STDMETHODCALLTYPE AddIqHandler(JABBER_HANDLER_FUNC Func, int iIqTypes, LPCTSTR szXmlns, LPCTSTR szTag, void *pUserData, int iPriority);
- // Registers temporary handler for incoming <iq/> stanza of type iIqType with id iIqId. iIqTypes is a combination of JABBER_IQ_TYPE_* flags. Returns handler handle on success or NULL on error. You must free pUserData in the handler by yourself.
- HJHANDLER STDMETHODCALLTYPE AddTemporaryIqHandler(JABBER_HANDLER_FUNC Func, int iIqTypes, int iIqId, void *pUserData, DWORD dwTimeout, int iPriority);
-
- // Registers handler for outgoing nodes. The handler may modify the node if it's necessary. Return TRUE in the handler to continue, or FALSE to abort sending.
- HJHANDLER STDMETHODCALLTYPE AddSendHandler(JABBER_HANDLER_FUNC Func, void *pUserData, int iPriority);
-
- // Unregisters handler by its handle.
- int STDMETHODCALLTYPE RemoveHandler(HJHANDLER hHandler);
-
- // Registers feature so that it's displayed with proper description in other users' details. Call this function in your ME_SYSTEM_MODULESLOADED handler. Returns TRUE on success or FALSE on error.
- int STDMETHODCALLTYPE RegisterFeature(LPCTSTR szFeature, LPCTSTR szDescription);
- int STDMETHODCALLTYPE AddFeatures(LPCTSTR szFeatures); // Adds features to the list of features returned by the client.
- int STDMETHODCALLTYPE RemoveFeatures(LPCTSTR szFeatures); // Removes features from the list of features returned by the client.
- LPTSTR STDMETHODCALLTYPE GetResourceFeatures(LPCTSTR jid); // Returns all features supported by JID in format "feature1\0feature2\0...\0featureN\0\0". You must free returned string using mir_free().
- HANDLE STDMETHODCALLTYPE GetHandle(); // Returns connection handle
-
- CJabberProto *m_psProto;
-
-private:
- JabberFeatCapPairDynamic *FindFeature(LPCTSTR szFeature);
-};
-
-struct CJabberInterface: public IJabberInterface
-{
- DWORD STDMETHODCALLTYPE GetFlags() const; // Set of JIF_* flags.
- int STDMETHODCALLTYPE GetVersion() const; // Returns version of IJabberInterface.
- DWORD STDMETHODCALLTYPE GetJabberVersion() const; // Returns Jabber plugin version.
-
- IJabberSysInterface* STDMETHODCALLTYPE Sys() const; // Jabber system utilities.
- IJabberNetInterface* STDMETHODCALLTYPE Net() const; // Jabber network interface.
-
- CJabberProto *m_psProto;
-};
-
-struct CJabberProto : public PROTO<CJabberProto>
+struct CJabberProto : public PROTO<CJabberProto>, public IJabberInterface
{
CJabberProto(const char*, const TCHAR*);
~CJabberProto();
@@ -343,10 +283,6 @@ struct CJabberProto : public PROTO<CJabberProto> CNoteList m_notes;
- CJabberInterface m_JabberApi;
- CJabberSysInterface m_JabberSysApi;
- CJabberNetInterface m_JabberNetApi;
-
/*******************************************************************
* Function declarations
*******************************************************************/
@@ -853,8 +789,6 @@ struct CJabberProto : public PROTO<CJabberProto> //---- jabber_util.c -----------------------------------------------------------------
pResourceStatus ResourceInfoFromJID(const TCHAR *jid);
- int SerialNext(void);
-
HANDLE HContactFromJID(const TCHAR *jid , BOOL bStripResource = 3);
HANDLE ChatRoomHContactFromJID(const TCHAR *jid);
void Log(const char* fmt, ...);
@@ -950,6 +884,37 @@ private: int m_nMenuResourceItems;
HGENMENU *m_phMenuResourceItems;
+
+public:
+ DWORD STDMETHODCALLTYPE GetFlags() const; // Set of JIF_* flags.
+ int STDMETHODCALLTYPE GetVersion() const; // Returns version of IJabberInterface.
+ DWORD STDMETHODCALLTYPE GetJabberVersion() const; // Returns Jabber plugin version.
+
+ int STDMETHODCALLTYPE CompareJIDs(LPCTSTR jid1, LPCTSTR jid2); // Strips resource names from given JIDs and returns result of comparison for these JIDs.
+ HANDLE STDMETHODCALLTYPE ContactFromJID(LPCTSTR jid); // Returns contact handle for given JID.
+ LPTSTR STDMETHODCALLTYPE ContactToJID(HANDLE hContact); // Returns JID of hContact. You must free the result using mir_free().
+ LPTSTR STDMETHODCALLTYPE GetBestResourceName(LPCTSTR jid); // Returns best resource name for given JID. You must free the result using mir_free().
+ LPTSTR STDMETHODCALLTYPE GetResourceList(LPCTSTR jid); // Returns all resource names for a given JID in format "resource1\0resource2\0resource3\0\0" (all resources are separated by \0 character and the whole string is terminated with two \0 characters). You must free the string using mir_free().
+ char* STDMETHODCALLTYPE GetModuleName() const; // Returns Jabber module name.
+
+ int STDMETHODCALLTYPE SerialNext(); // Returns id that can be used for next message sent through SendXmlNode().
+ int STDMETHODCALLTYPE SendXmlNode(HXML node); // Sends XML node.
+
+ HJHANDLER STDMETHODCALLTYPE AddPresenceHandler(JABBER_HANDLER_FUNC Func, void *pUserData, int iPriority);
+ HJHANDLER STDMETHODCALLTYPE AddMessageHandler(JABBER_HANDLER_FUNC Func, int iMsgTypes, LPCTSTR szXmlns, LPCTSTR szTag, void *pUserData, int iPriority);
+ HJHANDLER STDMETHODCALLTYPE AddIqHandler(JABBER_HANDLER_FUNC Func, int iIqTypes, LPCTSTR szXmlns, LPCTSTR szTag, void *pUserData, int iPriority);
+ HJHANDLER STDMETHODCALLTYPE AddTemporaryIqHandler(JABBER_HANDLER_FUNC Func, int iIqTypes, int iIqId, void *pUserData, DWORD dwTimeout, int iPriority);
+ HJHANDLER STDMETHODCALLTYPE AddSendHandler(JABBER_HANDLER_FUNC Func, void *pUserData, int iPriority);
+ int STDMETHODCALLTYPE RemoveHandler(HJHANDLER hHandler);
+
+ int STDMETHODCALLTYPE RegisterFeature(LPCTSTR szFeature, LPCTSTR szDescription);
+ int STDMETHODCALLTYPE AddFeatures(LPCTSTR szFeatures); // Adds features to the list of features returned by the client.
+ int STDMETHODCALLTYPE RemoveFeatures(LPCTSTR szFeatures); // Removes features from the list of features returned by the client.
+ LPTSTR STDMETHODCALLTYPE GetResourceFeatures(LPCTSTR jid); // Returns all features supported by JID in format "feature1\0feature2\0...\0featureN\0\0". You must free returned string using mir_free().
+ HANDLE STDMETHODCALLTYPE GetHandle(); // Returns connection handle
+
+private:
+ JabberFeatCapPairDynamic *FindFeature(LPCTSTR szFeature);
};
extern LIST<CJabberProto> g_Instances;
diff --git a/protocols/JabberG/src/jabber_svc.cpp b/protocols/JabberG/src/jabber_svc.cpp index 65bc24074d..34ee8b4480 100644 --- a/protocols/JabberG/src/jabber_svc.cpp +++ b/protocols/JabberG/src/jabber_svc.cpp @@ -29,9 +29,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <sys/types.h>
#include <sys/stat.h>
-#include "jabber_list.h"
-#include "jabber_iq.h"
-#include "jabber_caps.h"
#include "m_addcontact.h"
#include "jabber_disco.h"
@@ -720,375 +717,3 @@ INT_PTR __cdecl CJabberProto::OnHttpAuthRequest(WPARAM wParam, LPARAM lParam) return 0;
}
-
-
-// Jabber API functions
-INT_PTR __cdecl CJabberProto::JabberGetApi(WPARAM wParam, LPARAM lParam)
-{
- IJabberInterface **ji = (IJabberInterface**)lParam;
- if ( !ji)
- return -1;
- *ji = &m_JabberApi;
- return 0;
-}
-
-DWORD CJabberInterface::GetFlags() const
-{
- return JIF_UNICODE;
-}
-
-int CJabberInterface::GetVersion() const
-{
- return 1;
-}
-
-DWORD CJabberInterface::GetJabberVersion() const
-{
- return __VERSION_DWORD;
-}
-
-IJabberSysInterface *CJabberInterface::Sys() const
-{
- return &m_psProto->m_JabberSysApi;
-}
-
-IJabberNetInterface *CJabberInterface::Net() const
-{
- return &m_psProto->m_JabberNetApi;
-}
-
-int CJabberSysInterface::GetVersion() const
-{
- return 1;
-}
-
-int CJabberSysInterface::CompareJIDs(LPCTSTR jid1, LPCTSTR jid2)
-{
- if ( !jid1 || !jid2) return 0;
- return JabberCompareJids(jid1, jid2);
-}
-
-HANDLE CJabberSysInterface::ContactFromJID(LPCTSTR jid)
-{
- if (jid == NULL) return NULL;
- return m_psProto->HContactFromJID(jid);
-}
-
-LPTSTR CJabberSysInterface::ContactToJID(HANDLE hContact)
-{
- return m_psProto->getTStringA(hContact, m_psProto->isChatRoom(hContact) ? "ChatRoomID" : "jid");
-}
-
-LPTSTR CJabberSysInterface::GetBestResourceName(LPCTSTR jid)
-{
- if (jid == NULL)
- return NULL;
- LPCTSTR p = _tcschr(jid, '/');
- if (p == NULL) {
- mir_cslock lck(m_psProto->m_csLists);
- return mir_tstrdup(m_psProto->ListGetBestClientResourceNamePtr(jid));
- }
- return mir_tstrdup(jid);
-}
-
-LPTSTR CJabberSysInterface::GetResourceList(LPCTSTR jid)
-{
- if (jid == NULL)
- return NULL;
-
- mir_cslock lck(m_psProto->m_csLists);
- JABBER_LIST_ITEM *item = NULL;
- if ((item = m_psProto->ListGetItemPtr(LIST_VCARD_TEMP, jid)) == NULL)
- item = m_psProto->ListGetItemPtr(LIST_ROSTER, jid);
- if (item == NULL)
- return NULL;
-
- if (!item->arResources.getCount())
- return NULL;
-
- CMString res;
- for (int i=0; i < item->arResources.getCount(); i++) {
- res.Append(item->arResources[i]->m_tszResourceName);
- res.AppendChar(0);
- }
- res.AppendChar(0);
-
- return mir_tstrndup(res, res.GetLength());
-}
-
-char *CJabberSysInterface::GetModuleName() const
-{
- return m_psProto->m_szModuleName;
-}
-
-int CJabberNetInterface::GetVersion() const
-{
- return 1;
-}
-
-unsigned int CJabberNetInterface::SerialNext()
-{
- return m_psProto->SerialNext();
-}
-
-int CJabberNetInterface::SendXmlNode(HXML node)
-{
- return m_psProto->m_ThreadInfo->send(node);
-}
-
-
-typedef struct
-{
- JABBER_HANDLER_FUNC Func;
- void *pUserData;
-} sHandlerData;
-
-void CJabberProto::ExternalTempIqHandler(HXML node, CJabberIqInfo *pInfo)
-{
- sHandlerData *d = (sHandlerData*)pInfo->GetUserData();
- d->Func(&m_JabberApi, node, d->pUserData);
- free(d); // free IqHandlerData allocated in CJabberNetInterface::AddIqHandler below
-}
-
-BOOL CJabberProto::ExternalIqHandler(HXML node, CJabberIqInfo *pInfo)
-{
- sHandlerData *d = (sHandlerData*)pInfo->GetUserData();
- return d->Func(&m_JabberApi, node, d->pUserData);
-}
-
-BOOL CJabberProto::ExternalMessageHandler(HXML node, ThreadData *pThreadData, CJabberMessageInfo* pInfo)
-{
- sHandlerData *d = (sHandlerData*)pInfo->GetUserData();
- return d->Func(&m_JabberApi, node, d->pUserData);
-}
-
-BOOL CJabberProto::ExternalPresenceHandler(HXML node, ThreadData *pThreadData, CJabberPresenceInfo* pInfo)
-{
- sHandlerData *d = (sHandlerData*)pInfo->GetUserData();
- return d->Func(&m_JabberApi, node, d->pUserData);
-}
-
-BOOL CJabberProto::ExternalSendHandler(HXML node, ThreadData *pThreadData, CJabberSendInfo* pInfo)
-{
- sHandlerData *d = (sHandlerData*)pInfo->GetUserData();
- return d->Func(&m_JabberApi, node, d->pUserData);
-}
-
-HJHANDLER CJabberNetInterface::AddPresenceHandler(JABBER_HANDLER_FUNC Func, void *pUserData, int iPriority)
-{
- sHandlerData *d = (sHandlerData*)malloc(sizeof(sHandlerData));
- d->Func = Func;
- d->pUserData = pUserData;
- return (HJHANDLER)m_psProto->m_presenceManager.AddPermanentHandler(&CJabberProto::ExternalPresenceHandler, d, free, iPriority);
-}
-
-HJHANDLER CJabberNetInterface::AddMessageHandler(JABBER_HANDLER_FUNC Func, int iMsgTypes, LPCTSTR szXmlns, LPCTSTR szTag, void *pUserData, int iPriority)
-{
- sHandlerData *d = (sHandlerData*)malloc(sizeof(sHandlerData));
- d->Func = Func;
- d->pUserData = pUserData;
- return (HJHANDLER)m_psProto->m_messageManager.AddPermanentHandler(&CJabberProto::ExternalMessageHandler, iMsgTypes, 0, szXmlns, FALSE, szTag, d, free, iPriority);
-}
-
-HJHANDLER CJabberNetInterface::AddIqHandler(JABBER_HANDLER_FUNC Func, int iIqTypes, LPCTSTR szXmlns, LPCTSTR szTag, void *pUserData, int iPriority)
-{
- sHandlerData *d = (sHandlerData*)malloc(sizeof(sHandlerData));
- d->Func = Func;
- d->pUserData = pUserData;
- return (HJHANDLER)m_psProto->m_iqManager.AddPermanentHandler(&CJabberProto::ExternalIqHandler, iIqTypes, 0, szXmlns, FALSE, szTag, d, free, iPriority);
-}
-
-HJHANDLER CJabberNetInterface::AddTemporaryIqHandler(JABBER_HANDLER_FUNC Func, int iIqTypes, int iIqId, void *pUserData, DWORD dwTimeout, int iPriority)
-{
- sHandlerData *d = (sHandlerData*)malloc(sizeof(sHandlerData));
- d->Func = Func;
- d->pUserData = pUserData;
- CJabberIqInfo* pInfo = m_psProto->m_iqManager.AddHandler(&CJabberProto::ExternalTempIqHandler, iIqTypes, NULL, 0, iIqId, d, iPriority);
- if (pInfo && dwTimeout > 0)
- pInfo->SetTimeout(dwTimeout);
- return (HJHANDLER)pInfo;
-}
-
-HJHANDLER CJabberNetInterface::AddSendHandler(JABBER_HANDLER_FUNC Func, void *pUserData, int iPriority)
-{
- sHandlerData *d = (sHandlerData*)malloc(sizeof(sHandlerData));
- d->Func = Func;
- d->pUserData = pUserData;
- return (HJHANDLER)m_psProto->m_sendManager.AddPermanentHandler(&CJabberProto::ExternalSendHandler, d, free, iPriority);
-}
-
-int CJabberNetInterface::RemoveHandler(HJHANDLER hHandler)
-{
- return m_psProto->m_sendManager.DeletePermanentHandler((CJabberSendPermanentInfo*)hHandler) ||
- m_psProto->m_presenceManager.DeletePermanentHandler((CJabberPresencePermanentInfo*)hHandler) ||
- m_psProto->m_messageManager.DeletePermanentHandler((CJabberMessagePermanentInfo*)hHandler) ||
- m_psProto->m_iqManager.DeletePermanentHandler((CJabberIqPermanentInfo*)hHandler) ||
- m_psProto->m_iqManager.DeleteHandler((CJabberIqInfo*)hHandler);
-}
-
-JabberFeatCapPairDynamic *CJabberNetInterface::FindFeature(LPCTSTR szFeature)
-{
- int i;
- for (i=0; i < m_psProto->m_lstJabberFeatCapPairsDynamic.getCount(); i++)
- if ( !lstrcmp(m_psProto->m_lstJabberFeatCapPairsDynamic[i]->szFeature, szFeature))
- return m_psProto->m_lstJabberFeatCapPairsDynamic[i];
- return NULL;
-}
-
-int CJabberNetInterface::RegisterFeature(LPCTSTR szFeature, LPCTSTR szDescription)
-{
- 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_psProto->m_csLists);
- JabberFeatCapPairDynamic *fcp = FindFeature(szFeature);
- if ( !fcp) { // if the feature is not registered yet, allocate new bit for it
- JabberCapsBits jcb = JABBER_CAPS_OTHER_SPECIAL; // set all bits not included in g_JabberFeatCapPairs
-
- // set all bits occupied by g_JabberFeatCapPairs
- for (i=0; g_JabberFeatCapPairs[i].szFeature; i++)
- jcb |= g_JabberFeatCapPairs[i].jcbCap;
-
- // set all bits already occupied by external plugins
- for (i=0; i < m_psProto->m_lstJabberFeatCapPairsDynamic.getCount(); i++)
- jcb |= m_psProto->m_lstJabberFeatCapPairsDynamic[i]->jcbCap;
-
- // Now get first zero bit. The line below is a fast way to do it. If there are no zero bits, it returns 0.
- jcb = (~jcb) & (JabberCapsBits)(-(__int64)(~jcb));
-
- // no more free bits
- if ( !jcb)
- return false;
-
- // remove unnecessary symbols from szFeature to make the string shorter, and use it as szExt
- LPTSTR szExt = mir_tstrdup(szFeature);
- LPTSTR pSrc, pDst;
- for (pSrc = szExt, pDst = szExt; *pSrc; pSrc++)
- if (_tcschr(_T("bcdfghjklmnpqrstvwxz0123456789"), *pSrc))
- *pDst++ = *pSrc;
- *pDst = 0;
- m_psProto->m_clientCapsManager.SetClientCaps(JABBER_CAPS_MIRANDA_NODE, szExt, jcb);
-
- fcp = new JabberFeatCapPairDynamic();
- fcp->szExt = szExt; // will be deallocated along with other values of JabberFeatCapPairDynamic in CJabberProto destructor
- fcp->szFeature = mir_tstrdup(szFeature);
- fcp->szDescription = szDescription ? mir_tstrdup(szDescription) : NULL;
- fcp->jcbCap = jcb;
- m_psProto->m_lstJabberFeatCapPairsDynamic.insert(fcp);
- }
- else if (szDescription) { // update description
- if (fcp->szDescription)
- mir_free(fcp->szDescription);
- fcp->szDescription = mir_tstrdup(szDescription);
- }
- return true;
-}
-
-int CJabberNetInterface::AddFeatures(LPCTSTR szFeatures)
-{
- if ( !szFeatures)
- return false;
-
- mir_cslockfull lck(m_psProto->m_csLists);
- BOOL ret = true;
- LPCTSTR szFeat = szFeatures;
- while (szFeat[0]) {
- JabberFeatCapPairDynamic *fcp = FindFeature(szFeat);
- // if someone is trying to add one of core features, RegisterFeature() will return false, so we don't have to perform this check here
- if ( !fcp) { // if the feature is not registered yet
- if ( !RegisterFeature(szFeat, NULL))
- ret = false;
- else
- fcp = FindFeature(szFeat); // update fcp after RegisterFeature()
- }
- if (fcp)
- m_psProto->m_uEnabledFeatCapsDynamic |= fcp->jcbCap;
- else
- ret = false;
- szFeat += lstrlen(szFeat) + 1;
- }
- lck.unlock();
-
- if (m_psProto->m_bJabberOnline)
- m_psProto->SendPresence(m_psProto->m_iStatus, true);
-
- return ret;
-}
-
-int CJabberNetInterface::RemoveFeatures(LPCTSTR szFeatures)
-{
- if ( !szFeatures)
- return false;
-
- mir_cslockfull lck(m_psProto->m_csLists);
- BOOL ret = true;
- LPCTSTR szFeat = szFeatures;
- while (szFeat[0]) {
- JabberFeatCapPairDynamic *fcp = FindFeature(szFeat);
- if (fcp)
- m_psProto->m_uEnabledFeatCapsDynamic &= ~fcp->jcbCap;
- else
- ret = false; // indicate that there was an error removing at least one of the specified features
-
- szFeat += lstrlen(szFeat) + 1;
- }
- lck.unlock();
-
- if (m_psProto->m_bJabberOnline)
- m_psProto->SendPresence(m_psProto->m_iStatus, true);
-
- return ret;
-}
-
-LPTSTR CJabberNetInterface::GetResourceFeatures(LPCTSTR jid)
-{
- JabberCapsBits jcb = m_psProto->GetResourceCapabilites(jid, true);
- if (jcb & JABBER_RESOURCE_CAPS_ERROR)
- return NULL;
-
- mir_cslockfull lck(m_psProto->m_csLists);
- int i;
- int iLen = 1; // 1 for extra zero terminator at the end of the string
- // calculate total necessary string length
- for (i=0; g_JabberFeatCapPairs[i].szFeature; i++)
- if (jcb & g_JabberFeatCapPairs[i].jcbCap)
- iLen += lstrlen(g_JabberFeatCapPairs[i].szFeature) + 1;
-
- for (i=0; i < m_psProto->m_lstJabberFeatCapPairsDynamic.getCount(); i++)
- if (jcb & m_psProto->m_lstJabberFeatCapPairsDynamic[i]->jcbCap)
- iLen += lstrlen(m_psProto->m_lstJabberFeatCapPairsDynamic[i]->szFeature) + 1;
-
- // allocate memory and fill it
- LPTSTR str = (LPTSTR)mir_alloc(iLen * sizeof(TCHAR));
- LPTSTR p = str;
- for (i=0; g_JabberFeatCapPairs[i].szFeature; i++)
- if (jcb & g_JabberFeatCapPairs[i].jcbCap) {
- lstrcpy(p, g_JabberFeatCapPairs[i].szFeature);
- p += lstrlen(g_JabberFeatCapPairs[i].szFeature) + 1;
- }
-
- for (i=0; i < m_psProto->m_lstJabberFeatCapPairsDynamic.getCount(); i++)
- if (jcb & m_psProto->m_lstJabberFeatCapPairsDynamic[i]->jcbCap) {
- lstrcpy(p, m_psProto->m_lstJabberFeatCapPairsDynamic[i]->szFeature);
- p += lstrlen(m_psProto->m_lstJabberFeatCapPairsDynamic[i]->szFeature) + 1;
- }
-
- *p = 0; // extra zero terminator
- return str;
-}
-
-HANDLE CJabberNetInterface::GetHandle()
-{
- return m_psProto->m_hNetlibUser;
-}
|