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 | |
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
-rw-r--r-- | include/m_jabber.h | 96 | ||||
-rw-r--r-- | plugins/BossKeyPlus/src/BossKey.cpp | 2 | ||||
-rw-r--r-- | protocols/GTalkExt/src/handlers.cpp | 39 | ||||
-rw-r--r-- | protocols/GTalkExt/src/inbox.cpp | 2 | ||||
-rw-r--r-- | protocols/JabberG/jabber_10.vcxproj | 1 | ||||
-rw-r--r-- | protocols/JabberG/jabber_10.vcxproj.filters | 6 | ||||
-rw-r--r-- | protocols/JabberG/jabber_11.vcxproj | 1 | ||||
-rw-r--r-- | protocols/JabberG/jabber_11.vcxproj.filters | 3 | ||||
-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 |
14 files changed, 471 insertions, 532 deletions
diff --git a/include/m_jabber.h b/include/m_jabber.h index 0e1fe707eb..05a94e5de9 100644 --- a/include/m_jabber.h +++ b/include/m_jabber.h @@ -29,32 +29,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <m_xml.h>
-struct IJabberInterface;
-
-struct IJabberSysInterface
-{
- // Returns version of IJabberSysInterface.
- virtual int STDMETHODCALLTYPE GetVersion() const = 0;
-
- // Compares JIDs by their node@domain part (without resource name).
- virtual int STDMETHODCALLTYPE CompareJIDs(LPCTSTR jid1, LPCTSTR jid2) = 0;
-
- // Returns contact handle for given JID, or NULL on error.
- virtual HANDLE STDMETHODCALLTYPE ContactFromJID(LPCTSTR jid) = 0;
-
- // Returns JID of hContact, or NULL on error. You must free the result using mir_free().
- virtual LPTSTR STDMETHODCALLTYPE ContactToJID(HANDLE hContact) = 0;
-
- // Returns best resource name for given JID, or NULL on error. You must free the result using mir_free().
- virtual LPTSTR STDMETHODCALLTYPE GetBestResourceName(LPCTSTR jid) = 0;
-
- // 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), or NULL on error. You must free returned string using mir_free().
- virtual LPTSTR STDMETHODCALLTYPE GetResourceList(LPCTSTR jid) = 0;
-
- // Returns Jabber module name. DO NOT free the returned string.
- virtual char* STDMETHODCALLTYPE GetModuleName() const = 0;
-};
-
// Iq type flags
enum
{
@@ -100,15 +74,46 @@ enum typedef void* HJHANDLER;
-typedef BOOL (*JABBER_HANDLER_FUNC)(IJabberInterface *ji, HXML node, void *pUserData);
+typedef BOOL (*JABBER_HANDLER_FUNC)(struct IJabberInterface *ji, HXML node, void *pUserData);
+
+// IJabberInterface::dwFlags values
+enum
+{
+ JIF_UNICODE = 1
+};
-struct IJabberNetInterface
+// Overall Jabber interface
+struct IJabberInterface
{
- // Returns version of IJabberNetInterface.
+ // Set of JIF_* flags.
+ virtual DWORD STDMETHODCALLTYPE GetFlags() const = 0;
+
+ // Returns version of IJabberInterface.
virtual int STDMETHODCALLTYPE GetVersion() const = 0;
+ // Returns Jabber plugin version.
+ virtual DWORD STDMETHODCALLTYPE GetJabberVersion() const = 0;
+
+ // Compares JIDs by their node@domain part (without resource name).
+ virtual int STDMETHODCALLTYPE CompareJIDs(LPCTSTR jid1, LPCTSTR jid2) = 0;
+
+ // Returns contact handle for given JID, or NULL on error.
+ virtual HANDLE STDMETHODCALLTYPE ContactFromJID(LPCTSTR jid) = 0;
+
+ // Returns JID of hContact, or NULL on error. You must free the result using mir_free().
+ virtual LPTSTR STDMETHODCALLTYPE ContactToJID(HANDLE hContact) = 0;
+
+ // Returns best resource name for given JID, or NULL on error. You must free the result using mir_free().
+ virtual LPTSTR STDMETHODCALLTYPE GetBestResourceName(LPCTSTR jid) = 0;
+
+ // 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), or NULL on error. You must free returned string using mir_free().
+ virtual LPTSTR STDMETHODCALLTYPE GetResourceList(LPCTSTR jid) = 0;
+
+ // Returns Jabber module name. DO NOT free the returned string.
+ virtual char* STDMETHODCALLTYPE GetModuleName() const = 0;
+
// Returns id that can be used for next message sent through SendXmlNode().
- virtual unsigned int STDMETHODCALLTYPE SerialNext() = 0;
+ virtual int STDMETHODCALLTYPE SerialNext() = 0;
// Sends XML node.
virtual int STDMETHODCALLTYPE SendXmlNode(HXML node) = 0;
@@ -134,7 +139,6 @@ struct IJabberNetInterface // Unregisters handler by its handle.
virtual int STDMETHODCALLTYPE RemoveHandler(HJHANDLER hHandler) = 0;
-
// Entity capabilities support (see xep-0115)
// 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.
virtual int STDMETHODCALLTYPE RegisterFeature(LPCTSTR szFeature, LPCTSTR szDescription) = 0;
@@ -152,31 +156,6 @@ struct IJabberNetInterface virtual HANDLE STDMETHODCALLTYPE GetHandle(void) = 0;
};
-// IJabberInterface::dwFlags values
-enum
-{
- JIF_UNICODE = 1
-};
-
-// Overall Jabber interface
-struct IJabberInterface
-{
- // Set of JIF_* flags.
- virtual DWORD STDMETHODCALLTYPE GetFlags() const = 0;
-
- // Returns version of IJabberInterface.
- virtual int STDMETHODCALLTYPE GetVersion() const = 0;
-
- // Returns Jabber plugin version.
- virtual DWORD STDMETHODCALLTYPE GetJabberVersion() const = 0;
-
- // Jabber system utilities.
- virtual IJabberSysInterface* STDMETHODCALLTYPE Sys() const = 0;
-
- // Jabber network interface.
- virtual IJabberNetInterface* STDMETHODCALLTYPE Net() const = 0;
-};
-
/*
A service to obtain Jabber API for a given account.
If you store the pointer to the interface for later use, you must also hook ME_PROTO_ACCLISTCHANGED and update the pointer to prevent calling API for a removed account.
@@ -186,15 +165,14 @@ lParam = (LPARAM)(IJabberInterface**). Returns FALSE if all is Ok, and TRUE otherwise.
*/
-#define JS_GETJABBERAPI "/GetJabberApi"
+#define JS_GETJABBERAPI "/GetJabberApi"
__forceinline IJabberInterface *getJabberApi(const char *szAccount)
{
IJabberInterface *ji;
if (!CallProtoService(szAccount, JS_GETJABBERAPI, 0, (LPARAM)&ji))
- {
return ji;
- }
+
return NULL;
}
diff --git a/plugins/BossKeyPlus/src/BossKey.cpp b/plugins/BossKeyPlus/src/BossKey.cpp index 98d8068c78..a208c2e40f 100644 --- a/plugins/BossKeyPlus/src/BossKey.cpp +++ b/plugins/BossKeyPlus/src/BossKey.cpp @@ -721,9 +721,7 @@ int MirandaLoaded(WPARAM,LPARAM) {
hDwmApi = LoadLibrary(_T("dwmapi.dll"));
if (hDwmApi)
- {
dwmIsCompositionEnabled = (PFNDwmIsCompositionEnabled)GetProcAddress(hDwmApi,"DwmIsCompositionEnabled");
- }
}
if (g_wMaskAdv & OPT_MENUITEM)
BossKeyMenuItemInit();
diff --git a/protocols/GTalkExt/src/handlers.cpp b/protocols/GTalkExt/src/handlers.cpp index 4f47f3b1d5..f5bd3bc212 100644 --- a/protocols/GTalkExt/src/handlers.cpp +++ b/protocols/GTalkExt/src/handlers.cpp @@ -204,7 +204,7 @@ BOOL MailListHandler(IJabberInterface *ji, HXML node, void *pUserData) }
__finally {
if (jidWithRes)
- ji->Net()->AddTemporaryIqHandler(TimerHandler, JABBER_IQ_TYPE_RESULT, 0,
+ ji->AddTemporaryIqHandler(TimerHandler, JABBER_IQ_TYPE_RESULT, 0,
(PVOID)_tcsdup(jidWithRes), TIMER_INTERVAL);
// Never get a real result stanza. Results elapsed request after WAIT_TIMER_INTERVAL ms
}
@@ -217,7 +217,7 @@ void RequestMail(LPCTSTR jidWithRes, IJabberInterface *ji) xi.addAttr(node, ATTRNAME_TYPE, IQTYPE_GET);
xi.addAttr(node, ATTRNAME_FROM, jidWithRes);
- UINT uID = ji->Net()->SerialNext();
+ UINT uID = ji->SerialNext();
ptrT jid( ExtractJid(jidWithRes));
xi.addAttr(node, ATTRNAME_TO, jid);
@@ -234,10 +234,8 @@ void RequestMail(LPCTSTR jidWithRes, IJabberInterface *ji) xi.addAttr(child, ATTRNAME_NEWER_THAN_TIME, lastMailTime);
xi.addAttr(child, ATTRNAME_NEWER_THAN_TID, lastThreadId);
- IJabberNetInterface* piNet = ji->Net();
- if ( piNet )
- if (piNet->SendXmlNode(node))
- piNet->AddTemporaryIqHandler(MailListHandler, JABBER_IQ_TYPE_RESULT, (int)uID, NULL, RESPONSE_TIMEOUT);
+ if (ji->SendXmlNode(node))
+ ji->AddTemporaryIqHandler(MailListHandler, JABBER_IQ_TYPE_RESULT, (int)uID, NULL, RESPONSE_TIMEOUT);
if (child) xi.destroyNode(child);
if (node) xi.destroyNode(node);
@@ -267,7 +265,7 @@ BOOL NewMailHandler(IJabberInterface *ji, HXML node, void *pUserData) if (!attr) return FALSE;
xi.addAttr(response, ATTRNAME_FROM, attr);
- int bytesSent = ji->Net()->SendXmlNode(response);
+ int bytesSent = ji->SendXmlNode(response);
RequestMail(attr, ji);
return bytesSent > 0;
}
@@ -288,7 +286,7 @@ void SetNotificationSetting(LPCTSTR jidWithResource, IJabberInterface *ji) xi.addAttr(node, ATTRNAME_TO, jid);
TCHAR id[30];
- mir_sntprintf(id, SIZEOF(id), JABBER_IQID_FORMAT, ji->Net()->SerialNext());
+ mir_sntprintf(id, SIZEOF(id), JABBER_IQID_FORMAT, ji->SerialNext());
xi.addAttr(node, ATTRNAME_ID, id);
child = xi.addChild(node, NODENAME_USERSETTING, NULL);
@@ -297,7 +295,7 @@ void SetNotificationSetting(LPCTSTR jidWithResource, IJabberInterface *ji) child = xi.addChild(child, NODENAME_MAILNOTIFICATIONS, NULL);
xi.addAttr(child, ATTRNAME_VALUE, SETTING_TRUE);
- ji->Net()->SendXmlNode(node);
+ ji->SendXmlNode(node);
if (child) xi.destroyNode(child);
if (node) xi.destroyNode(node);
@@ -317,7 +315,7 @@ BOOL DiscoverHandler(IJabberInterface *ji, HXML node, void *pUserData) child = xi.getChildByAttrValue(node, NODENAME_FEATURE, ATTRNAME_VAR, NOTIFY_FEATURE_XMLNS);
if (child) {
- ji->Net()->AddIqHandler(NewMailHandler, JABBER_IQ_TYPE_SET, NOTIFY_FEATURE_XMLNS, NODENAME_NEW_MAIL);
+ ji->AddIqHandler(NewMailHandler, JABBER_IQ_TYPE_SET, NOTIFY_FEATURE_XMLNS, NODENAME_NEW_MAIL);
RequestMail(jid, ji);
}
@@ -338,7 +336,7 @@ BOOL SendHandler(IJabberInterface *ji, HXML node, void *pUserData) TlsSetValue(itlsRecursion, (PVOID)TRUE);
- UINT id = ji->Net()->SerialNext();
+ UINT id = ji->SerialNext();
HXML newNode = xi.createNode(NODENAME_IQ, NULL, FALSE);
xi.addAttr(newNode, ATTRNAME_TYPE, IQTYPE_GET);
xi.addAttr(newNode, ATTRNAME_TO, xi.getAttrValue(node, ATTRNAME_TO));
@@ -348,11 +346,11 @@ BOOL SendHandler(IJabberInterface *ji, HXML node, void *pUserData) xi.addAttr(newNode, ATTRNAME_ID, idAttr);
xi.addAttr(xi.addChild(newNode, NODENAME_QUERY, NULL), ATTRNAME_XMLNS, DISCOVERY_XMLNS);
- ji->Net()->SendXmlNode(newNode);
+ ji->SendXmlNode(newNode);
xi.destroyNode(newNode);
- ji->Net()->AddTemporaryIqHandler(DiscoverHandler, JABBER_IQ_TYPE_RESULT, id, NULL, RESPONSE_TIMEOUT);
+ ji->AddTemporaryIqHandler(DiscoverHandler, JABBER_IQ_TYPE_RESULT, id, NULL, RESPONSE_TIMEOUT);
TlsSetValue(itlsRecursion, (PVOID)FALSE);
return FALSE;
}
@@ -375,15 +373,14 @@ int OnFilterPopup(WPARAM wParam, LPARAM lParam) IJabberInterface* IsGoogleAccount(LPCSTR szModuleName)
{
IJabberInterface *japi = getJabberApi(szModuleName);
- if (!japi) return NULL;
+ if (!japi)
+ return NULL;
- DBVARIANT dbv;
- if ( db_get_s(NULL, szModuleName, "ManualHost", &dbv))
+ ptrA host( db_get_sa(NULL, szModuleName, "ManualHost"));
+ if (host == NULL)
return NULL;
- bool res = !strcmp(dbv.pszVal, "talk.google.com");
- db_free(&dbv);
- return (res) ? japi : NULL;
+ return ( !strcmp(host, "talk.google.com")) ? japi : NULL;
}
int AccListChanged(WPARAM wParam, LPARAM lParam)
@@ -391,7 +388,7 @@ int AccListChanged(WPARAM wParam, LPARAM lParam) if (wParam == PRAC_ADDED) {
IJabberInterface *ji = getJabberApi(((PROTOACCOUNT*)lParam)->szModuleName);
if (ji)
- ji->Net()->AddSendHandler(SendHandler);
+ ji->AddSendHandler(SendHandler);
}
return 0;
}
@@ -406,7 +403,7 @@ int ModulesLoaded(WPARAM wParam, LPARAM lParam) for (int i=0; i < count; i++) {
IJabberInterface *ji = IsGoogleAccount(protos[i]->szModuleName);
if (ji)
- ji->Net()->AddSendHandler(SendHandler);
+ ji->AddSendHandler(SendHandler);
}
HookEvent(ME_POPUP_FILTER, OnFilterPopup);
diff --git a/protocols/GTalkExt/src/inbox.cpp b/protocols/GTalkExt/src/inbox.cpp index 9fd82a5aec..2271972fbb 100644 --- a/protocols/GTalkExt/src/inbox.cpp +++ b/protocols/GTalkExt/src/inbox.cpp @@ -155,7 +155,7 @@ HANDLE FindNetUserHandle(LPCSTR acc) if (!ji)
return NULL;
- return ji->Net()->GetHandle();
+ return ji->GetHandle();
}
void OpenUrlThread(void *param)
diff --git a/protocols/JabberG/jabber_10.vcxproj b/protocols/JabberG/jabber_10.vcxproj index 8f99e8ab51..ad09ddb768 100644 --- a/protocols/JabberG/jabber_10.vcxproj +++ b/protocols/JabberG/jabber_10.vcxproj @@ -201,6 +201,7 @@ </Link>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClCompile Include="src\jabber_api.cpp" />
<ClCompile Include="src\jabber_archive.cpp" />
<ClCompile Include="src\stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
diff --git a/protocols/JabberG/jabber_10.vcxproj.filters b/protocols/JabberG/jabber_10.vcxproj.filters index ef8e13988c..427cd51797 100644 --- a/protocols/JabberG/jabber_10.vcxproj.filters +++ b/protocols/JabberG/jabber_10.vcxproj.filters @@ -177,6 +177,9 @@ <ClCompile Include="src\jabber_archive.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\jabber_api.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\jabber.h">
@@ -254,6 +257,9 @@ <ClInclude Include="src\jabber_xstatus.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\include\m_jabber.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="res\jabber.rc">
diff --git a/protocols/JabberG/jabber_11.vcxproj b/protocols/JabberG/jabber_11.vcxproj index e75dcc9bf5..3adfd81a56 100644 --- a/protocols/JabberG/jabber_11.vcxproj +++ b/protocols/JabberG/jabber_11.vcxproj @@ -204,6 +204,7 @@ </Link>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClCompile Include="src\jabber_api.cpp" />
<ClCompile Include="src\jabber_archive.cpp" />
<ClCompile Include="src\stdafx.cpp">
<PrecompiledHeader>Create</PrecompiledHeader>
diff --git a/protocols/JabberG/jabber_11.vcxproj.filters b/protocols/JabberG/jabber_11.vcxproj.filters index 48cac088a0..427cd51797 100644 --- a/protocols/JabberG/jabber_11.vcxproj.filters +++ b/protocols/JabberG/jabber_11.vcxproj.filters @@ -177,6 +177,9 @@ <ClCompile Include="src\jabber_archive.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\jabber_api.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\jabber.h">
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;
-}
|