diff options
author | George Hazan <george.hazan@gmail.com> | 2014-09-06 12:19:24 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2014-09-06 12:19:24 +0000 |
commit | eb61560d6fa9ab5e7bf895805dcedfd7870f482d (patch) | |
tree | 60fd612a969d560fe7e9613bd45f2b8ce56f02eb /protocols/JabberG/src | |
parent | e157bfe1e82eb3c6086fdd92d6c7604347d18d3f (diff) |
Jabber: manual lists partially removed
git-svn-id: http://svn.miranda-ng.org/main/trunk@10382 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/JabberG/src')
-rw-r--r-- | protocols/JabberG/src/jabber_iq.cpp | 165 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_iq.h | 28 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_message_handlers.cpp | 1 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_message_manager.cpp | 87 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_message_manager.h | 6 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_presence_manager.cpp | 47 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_presence_manager.h | 93 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_proto.cpp | 5 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_send_manager.cpp | 43 | ||||
-rw-r--r-- | protocols/JabberG/src/jabber_send_manager.h | 89 |
10 files changed, 198 insertions, 366 deletions
diff --git a/protocols/JabberG/src/jabber_iq.cpp b/protocols/JabberG/src/jabber_iq.cpp index 45e335e053..5adc5c3116 100644 --- a/protocols/JabberG/src/jabber_iq.cpp +++ b/protocols/JabberG/src/jabber_iq.cpp @@ -30,60 +30,53 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "jabber_ibb.h"
#include "jabber_rc.h"
+static int CompareItems(const CJabberIqPermanentInfo *p1, const CJabberIqPermanentInfo *p2)
+{
+ return p1->getPriority() - p2->getPriority();
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
// CJabberIqManager class
-CJabberIqManager::CJabberIqManager(CJabberProto* proto)
+CJabberIqManager::CJabberIqManager(CJabberProto *proto) :
+ m_arHandlers(10, &CompareItems)
{
m_dwLastUsedHandle = 0;
m_pIqs = NULL;
m_hExpirerThread = NULL;
- m_pPermanentHandlers = NULL;
ppro = proto;
}
CJabberIqManager::~CJabberIqManager()
{
ExpireAll();
- {
- mir_cslock lck(m_cs);
- CJabberIqPermanentInfo *pInfo = m_pPermanentHandlers;
- while (pInfo) {
- CJabberIqPermanentInfo *pTmp = pInfo->m_pNext;
- delete pInfo;
- pInfo = pTmp;
- }
- m_pPermanentHandlers = NULL;
- }
}
-BOOL CJabberIqManager::Start()
+bool CJabberIqManager::Start()
{
if (m_hExpirerThread || m_bExpirerThreadShutdownRequest)
- return FALSE;
+ return false;
m_hExpirerThread = ppro->ForkThreadEx(&CJabberProto::ExpirerThread, this, 0);
if (!m_hExpirerThread)
- return FALSE;
+ return false;
- return TRUE;
+ return true;
}
-BOOL CJabberIqManager::Shutdown()
+void CJabberIqManager::Shutdown()
{
if (m_bExpirerThreadShutdownRequest || !m_hExpirerThread)
- return TRUE;
+ return;
m_bExpirerThreadShutdownRequest = TRUE;
WaitForSingleObject(m_hExpirerThread, INFINITE);
CloseHandle(m_hExpirerThread);
m_hExpirerThread = NULL;
-
- return TRUE;
}
-BOOL CJabberIqManager::FillPermanentHandlers()
+void CJabberIqManager::FillPermanentHandlers()
{
// version requests (XEP-0092)
AddPermanentHandler(&CJabberProto::OnIqRequestVersion, JABBER_IQ_TYPE_GET, JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_ID_STR, JABBER_FEAT_VERSION, FALSE, _T("query"));
@@ -132,8 +125,6 @@ BOOL CJabberIqManager::FillPermanentHandlers() // http auth (XEP-0070)
AddPermanentHandler(&CJabberProto::OnIqHttpAuth, JABBER_IQ_TYPE_GET, JABBER_IQ_PARSE_FROM | JABBER_IQ_PARSE_ID_STR | JABBER_IQ_PARSE_CHILD_TAG_NODE, JABBER_FEAT_HTTP_AUTH, FALSE, _T("confirm"));
-
- return TRUE;
}
void __cdecl CJabberProto::ExpirerThread(void* pParam)
@@ -180,34 +171,34 @@ void CJabberIqManager::ExpireInfo(CJabberIqInfo *pInfo, void*) (ppro->*(pInfo->m_pHandler))(NULL, pInfo);
}
-BOOL CJabberIqManager::ExpireIq(int nIqId)
+bool CJabberIqManager::ExpireIq(int nIqId)
{
CJabberIqInfo *pInfo = DetachInfo(nIqId);
- if (pInfo) {
- do {
- ExpireInfo(pInfo);
- delete pInfo;
- }
- while ((pInfo = DetachInfo(nIqId)) != NULL);
- return TRUE;
+ if (pInfo == NULL)
+ return false;
+
+ do {
+ ExpireInfo(pInfo);
+ delete pInfo;
}
- return FALSE;
+ while ((pInfo = DetachInfo(nIqId)) != NULL);
+ return true;
}
-BOOL CJabberIqManager::ExpireByUserData(void *pUserData)
+bool CJabberIqManager::ExpireByUserData(void *pUserData)
{
while (true) {
CJabberIqInfo *pInfo = DetachInfo(pUserData);
if (!pInfo)
- return FALSE;
+ return false;
ExpireInfo(pInfo, NULL);
delete pInfo;
- return TRUE;
+ return true;
}
}
-BOOL CJabberIqManager::ExpireAll(void *pUserData)
+bool CJabberIqManager::ExpireAll(void *pUserData)
{
while (true) {
CJabberIqInfo *pInfo;
@@ -223,7 +214,7 @@ BOOL CJabberIqManager::ExpireAll(void *pUserData) ExpireInfo(pInfo, pUserData);
delete pInfo;
}
- return TRUE;
+ return true;
}
CJabberIqInfo* CJabberIqManager::AddHandler(JABBER_IQ_HANDLER pHandler, int nIqType, const TCHAR *szReceiver, DWORD dwParamsToParse, int nIqId, void *pUserData, int iPriority)
@@ -247,14 +238,14 @@ CJabberIqInfo* CJabberIqManager::AddHandler(JABBER_IQ_HANDLER pHandler, int nIqT return pInfo;
}
-BOOL CJabberIqManager::HandleIq(int nIqId, HXML pNode)
+bool CJabberIqManager::HandleIq(int nIqId, HXML pNode)
{
if (nIqId == -1 || pNode == NULL)
- return FALSE;
+ return false;
const TCHAR *szType = xmlGetAttrValue(pNode, _T("type"));
if (!szType)
- return FALSE;
+ return false;
int nIqType = JABBER_IQ_TYPE_FAIL;
if (!_tcsicmp(szType, _T("result")))
@@ -262,11 +253,11 @@ BOOL CJabberIqManager::HandleIq(int nIqId, HXML pNode) else if (!_tcsicmp(szType, _T("error")))
nIqType = JABBER_IQ_TYPE_ERROR;
else
- return FALSE;
+ return false;
CJabberIqInfo *pInfo = DetachInfo(nIqId);
if (pInfo == NULL)
- return FALSE;
+ return false;
do {
pInfo->m_nIqType = nIqType;
@@ -295,14 +286,13 @@ BOOL CJabberIqManager::HandleIq(int nIqId, HXML pNode) delete pInfo;
}
while ((pInfo = DetachInfo(nIqId)) != NULL);
- return TRUE;
+ return true;
}
-BOOL CJabberIqManager::HandleIqPermanent(HXML pNode)
+bool CJabberIqManager::HandleIqPermanent(HXML pNode)
{
- mir_cslock lck(m_cs);
- CJabberIqPermanentInfo *pInfo = m_pPermanentHandlers;
- while (pInfo) {
+ for (int i = 0; i < m_arHandlers.getCount(); i++) {
+ CJabberIqPermanentInfo &pInfo = m_arHandlers[i];
// have to get all data here, in the loop, because there's always possibility that previous handler modified it
const TCHAR *szType = xmlGetAttrValue(pNode, _T("type"));
if (!szType)
@@ -317,7 +307,7 @@ BOOL CJabberIqManager::HandleIqPermanent(HXML pNode) else
return FALSE;
- if (pInfo->m_nIqTypes & iqInfo.m_nIqType) {
+ if (pInfo.m_nIqTypes & iqInfo.m_nIqType) {
HXML pFirstChild = xmlGetChild(pNode , 0);
if (!pFirstChild || !xmlGetName(pFirstChild))
return FALSE;
@@ -325,35 +315,33 @@ BOOL CJabberIqManager::HandleIqPermanent(HXML pNode) const TCHAR *szTagName = xmlGetName(pFirstChild);
const TCHAR *szXmlns = xmlGetAttrValue(pFirstChild, _T("xmlns"));
- if ((!pInfo->m_szXmlns || (szXmlns && !_tcscmp(pInfo->m_szXmlns, szXmlns))) &&
- (!pInfo->m_szTag || !_tcscmp(pInfo->m_szTag, szTagName)))
+ if ((!pInfo.m_szXmlns || (szXmlns && !_tcscmp(pInfo.m_szXmlns, szXmlns))) &&
+ (!pInfo.m_szTag || !_tcscmp(pInfo.m_szTag, szTagName)))
{
// node suits handler criteria, call the handler
iqInfo.m_pChildNode = pFirstChild;
iqInfo.m_szChildTagName = (TCHAR*)szTagName;
iqInfo.m_szChildTagXmlns = (TCHAR*)szXmlns;
iqInfo.m_szId = (TCHAR*)xmlGetAttrValue(pNode, _T("id"));
- iqInfo.m_pUserData = pInfo->m_pUserData;
+ iqInfo.m_pUserData = pInfo.m_pUserData;
- if (pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_TO)
+ if (pInfo.m_dwParamsToParse & JABBER_IQ_PARSE_TO)
iqInfo.m_szTo = (TCHAR*)xmlGetAttrValue(pNode, _T("to"));
- if (pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_FROM)
+ if (pInfo.m_dwParamsToParse & JABBER_IQ_PARSE_FROM)
iqInfo.m_szFrom = (TCHAR*)xmlGetAttrValue(pNode, _T("from"));
- if ((pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_HCONTACT) && (iqInfo.m_szFrom))
+ if ((pInfo.m_dwParamsToParse & JABBER_IQ_PARSE_HCONTACT) && (iqInfo.m_szFrom))
iqInfo.m_hContact = ppro->HContactFromJID(iqInfo.m_szFrom, 3);
ppro->debugLog(_T("Handling iq id %s, type %s, from %s"), iqInfo.m_szId, szType, iqInfo.m_szFrom);
- if ((ppro->*(pInfo->m_pHandler))(pNode, &iqInfo))
- return TRUE;
+ if ((ppro->*(pInfo.m_pHandler))(pNode, &iqInfo))
+ return true;
}
}
-
- pInfo = pInfo->m_pNext;
}
- return FALSE;
+ return false;
}
CJabberIqInfo* CJabberIqManager::DetachInfo(int nIqId)
@@ -434,7 +422,7 @@ CJabberIqInfo* CJabberIqManager::DetachExpired() }
// inserts pInfo at a place determined by pInfo->m_iPriority
-BOOL CJabberIqManager::InsertIq(CJabberIqInfo *pInfo)
+bool CJabberIqManager::InsertIq(CJabberIqInfo *pInfo)
{
mir_cslock lck(m_cs);
if (!m_pIqs)
@@ -452,7 +440,7 @@ BOOL CJabberIqManager::InsertIq(CJabberIqInfo *pInfo) pTmp->m_pNext = pInfo;
}
}
- return TRUE;
+ return true;
}
// fucking params, maybe just return CJabberIqRequestInfo pointer ?
@@ -468,76 +456,41 @@ CJabberIqPermanentInfo* CJabberIqManager::AddPermanentHandler( int iPriority)
{
CJabberIqPermanentInfo *pInfo = new CJabberIqPermanentInfo();
- if (!pInfo)
- return NULL;
-
pInfo->m_pHandler = pHandler;
pInfo->m_nIqTypes = nIqTypes ? nIqTypes : JABBER_IQ_TYPE_ANY;
- replaceStrT(pInfo->m_szXmlns, szXmlns);
+ pInfo->m_szXmlns = mir_tstrdup(szXmlns);
pInfo->m_bAllowPartialNs = bAllowPartialNs;
- replaceStrT(pInfo->m_szTag, szTag);
+ pInfo->m_szTag = mir_tstrdup(szTag);
pInfo->m_dwParamsToParse = dwParamsToParse;
pInfo->m_pUserData = pUserData;
pInfo->m_pUserDataFree = pUserDataFree;
pInfo->m_iPriority = iPriority;
mir_cslock lck(m_cs);
- if (!m_pPermanentHandlers)
- m_pPermanentHandlers = pInfo;
- else {
- if (m_pPermanentHandlers->m_iPriority > pInfo->m_iPriority) {
- pInfo->m_pNext = m_pPermanentHandlers;
- m_pPermanentHandlers = pInfo;
- }
- else {
- CJabberIqPermanentInfo* pTmp = m_pPermanentHandlers;
- while (pTmp->m_pNext && pTmp->m_pNext->m_iPriority <= pInfo->m_iPriority)
- pTmp = pTmp->m_pNext;
- pInfo->m_pNext = pTmp->m_pNext;
- pTmp->m_pNext = pInfo;
- }
- }
+ m_arHandlers.insert(pInfo);
return pInfo;
}
// returns TRUE when pInfo found, or FALSE otherwise
-BOOL CJabberIqManager::DeletePermanentHandler(CJabberIqPermanentInfo *pInfo)
+bool CJabberIqManager::DeletePermanentHandler(CJabberIqPermanentInfo *pInfo)
{
mir_cslock lck(m_cs);
- if (!m_pPermanentHandlers)
- return FALSE;
-
- if (m_pPermanentHandlers == pInfo) { // check first item
- m_pPermanentHandlers = m_pPermanentHandlers->m_pNext;
- delete pInfo;
- return TRUE;
- }
-
- CJabberIqPermanentInfo* pTmp = m_pPermanentHandlers;
- while (pTmp->m_pNext) {
- if (pTmp->m_pNext == pInfo) {
- pTmp->m_pNext = pTmp->m_pNext->m_pNext;
- delete pInfo;
- return TRUE;
- }
- pTmp = pTmp->m_pNext;
- }
- return FALSE;
+ return m_arHandlers.remove(pInfo) == 1;
}
-BOOL CJabberIqManager::DeleteHandler(CJabberIqInfo *pInfo)
+bool CJabberIqManager::DeleteHandler(CJabberIqInfo *pInfo)
{
// returns TRUE when pInfo found, or FALSE otherwise
mir_cslockfull lck(m_cs);
if (!m_pIqs)
- return FALSE;
+ return false;
if (m_pIqs == pInfo) { // check first item
m_pIqs = m_pIqs->m_pNext;
lck.unlock();
ExpireInfo(pInfo); // must expire it to allow the handler to free m_pUserData if necessary
delete pInfo;
- return TRUE;
+ return true;
}
CJabberIqInfo *pTmp = m_pIqs;
@@ -547,9 +500,9 @@ BOOL CJabberIqManager::DeleteHandler(CJabberIqInfo *pInfo) lck.unlock();
ExpireInfo(pInfo); // must expire it to allow the handler to free m_pUserData if necessary
delete pInfo;
- return TRUE;
+ return true;
}
pTmp = pTmp->m_pNext;
}
- return FALSE;
+ return false;
}
diff --git a/protocols/JabberG/src/jabber_iq.h b/protocols/JabberG/src/jabber_iq.h index b1e0f786e8..89c28039d7 100644 --- a/protocols/JabberG/src/jabber_iq.h +++ b/protocols/JabberG/src/jabber_iq.h @@ -143,8 +143,6 @@ class CJabberIqPermanentInfo : public MZeroedObject {
friend class CJabberIqManager;
- CJabberIqPermanentInfo *m_pNext;
-
JABBER_PERMANENT_IQ_HANDLER m_pHandler;
DWORD m_dwParamsToParse;
int m_nIqTypes;
@@ -163,6 +161,8 @@ public: mir_free(m_szXmlns);
mir_free(m_szTag);
}
+
+ __forceinline int getPriority() const { return m_iPriority; }
};
class CJabberIqManager
@@ -175,7 +175,7 @@ protected: HANDLE m_hExpirerThread;
BOOL m_bExpirerThreadShutdownRequest;
- CJabberIqPermanentInfo* m_pPermanentHandlers;
+ OBJLIST<CJabberIqPermanentInfo> m_arHandlers;
CJabberIqInfo* DetachInfo(int nIqId);
CJabberIqInfo* DetachInfo(void *pUserData);
@@ -184,31 +184,31 @@ protected: void ExpireInfo(CJabberIqInfo *pInfo, void *pUserData = NULL);
// inserts pInfo at a place determined by pInfo->m_iPriority
- BOOL InsertIq(CJabberIqInfo *pInfo);
+ bool InsertIq(CJabberIqInfo *pInfo);
public:
CJabberIqManager(CJabberProto* proto);
~CJabberIqManager();
- BOOL Start();
- BOOL Shutdown();
+ bool Start();
+ void Shutdown();
// fucking params, maybe just return CJabberIqRequestInfo pointer ?
CJabberIqInfo* AddHandler(JABBER_IQ_HANDLER pHandler, int nIqType, const TCHAR *szReceiver, DWORD dwParamsToParse, int nIqId, void *pUserData, int iPriority);
CJabberIqPermanentInfo* AddPermanentHandler(JABBER_PERMANENT_IQ_HANDLER pHandler, int nIqTypes, DWORD dwParamsToParse, const TCHAR *szXmlns, BOOL bAllowPartialNs, const TCHAR *szTag, void *pUserData = NULL, IQ_USER_DATA_FREE_FUNC pUserDataFree = NULL, int iPriority = JH_PRIORITY_DEFAULT);
// returns TRUE when pInfo found, or FALSE otherwise
- BOOL DeletePermanentHandler(CJabberIqPermanentInfo *pInfo);
- BOOL DeleteHandler(CJabberIqInfo *pInfo);
+ bool DeletePermanentHandler(CJabberIqPermanentInfo *pInfo);
+ bool DeleteHandler(CJabberIqInfo *pInfo);
- BOOL HandleIq(int nIqId, HXML pNode);
- BOOL HandleIqPermanent(HXML pNode);
+ bool HandleIq(int nIqId, HXML pNode);
+ bool HandleIqPermanent(HXML pNode);
- BOOL ExpireIq(int nIqId);
+ bool ExpireIq(int nIqId);
void ExpirerThread(void);
- BOOL ExpireByUserData(void *pUserData);
- BOOL ExpireAll(void *pUserData = NULL);
- BOOL FillPermanentHandlers();
+ bool ExpireByUserData(void *pUserData);
+ bool ExpireAll(void *pUserData = NULL);
+ void FillPermanentHandlers();
};
#endif
diff --git a/protocols/JabberG/src/jabber_message_handlers.cpp b/protocols/JabberG/src/jabber_message_handlers.cpp index cda431a346..1362e3d9a2 100644 --- a/protocols/JabberG/src/jabber_message_handlers.cpp +++ b/protocols/JabberG/src/jabber_message_handlers.cpp @@ -25,7 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "jabber.h"
-#include "jabber_message_manager.h"
BOOL CJabberProto::OnMessageError(HXML node, ThreadData *pThreadData, CJabberMessageInfo* pInfo)
{
diff --git a/protocols/JabberG/src/jabber_message_manager.cpp b/protocols/JabberG/src/jabber_message_manager.cpp index bea0d98def..cea9943c42 100644 --- a/protocols/JabberG/src/jabber_message_manager.cpp +++ b/protocols/JabberG/src/jabber_message_manager.cpp @@ -25,22 +25,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "jabber.h"
-#include "jabber_message_manager.h"
-CJabberMessageManager::CJabberMessageManager(CJabberProto *proto)
+static int CompareItems(const CJabberMessagePermanentInfo *p1, const CJabberMessagePermanentInfo *p2)
+{
+ return p1->getPriority() - p2->getPriority();
+}
+
+CJabberMessageManager::CJabberMessageManager(CJabberProto *proto) :
+ m_arHandlers(1, &CompareItems)
{
- m_pPermanentHandlers = NULL;
ppro = proto;
}
+
CJabberMessageManager::~CJabberMessageManager()
{
- CJabberMessagePermanentInfo *pInfo = m_pPermanentHandlers;
- while (pInfo) {
- CJabberMessagePermanentInfo *pTmp = pInfo->m_pNext;
- delete pInfo;
- pInfo = pTmp;
- }
- m_pPermanentHandlers = NULL;
}
void CJabberMessageManager::FillPermanentHandlers()
@@ -53,10 +51,9 @@ void CJabberMessageManager::FillPermanentHandlers() bool CJabberMessageManager::HandleMessagePermanent(HXML node, ThreadData *pThreadData)
{
- mir_cslock lck(m_cs);
+ for (int k = 0; k < m_arHandlers.getCount(); k++) {
+ CJabberMessagePermanentInfo &pInfo = m_arHandlers[k];
- CJabberMessagePermanentInfo *pInfo = m_pPermanentHandlers;
- while (pInfo) {
// have to get all data here, in the loop, because there's always possibility that previous handler modified it
CJabberMessageInfo messageInfo;
@@ -73,11 +70,11 @@ bool CJabberMessageManager::HandleMessagePermanent(HXML node, ThreadData *pThrea else if (!_tcsicmp(szType, _T("headline")))
messageInfo.m_nMessageType = JABBER_MESSAGE_TYPE_HEADLINE;
else
- return FALSE;
+ return false;
}
else messageInfo.m_nMessageType = JABBER_MESSAGE_TYPE_NORMAL;
- if (pInfo->m_nMessageTypes & messageInfo.m_nMessageType) {
+ if (pInfo.m_nMessageTypes & messageInfo.m_nMessageType) {
for (int i = xmlGetChildCount(node) - 1; i >= 0; i--) {
// enumerate all children and see whether this node suits handler criteria
HXML child = xmlGetChild(node, i);
@@ -85,34 +82,33 @@ bool CJabberMessageManager::HandleMessagePermanent(HXML node, ThreadData *pThrea LPCTSTR szTagName = xmlGetName(child);
LPCTSTR szXmlns = xmlGetAttrValue(child, _T("xmlns"));
- if ((!pInfo->m_szXmlns || (szXmlns && !_tcscmp(pInfo->m_szXmlns, szXmlns))) && (!pInfo->m_szTag || !_tcscmp(pInfo->m_szTag, szTagName))) {
+ if ((!pInfo.m_szXmlns || (szXmlns && !_tcscmp(pInfo.m_szXmlns, szXmlns))) && (!pInfo.m_szTag || !_tcscmp(pInfo.m_szTag, szTagName))) {
// node suits handler criteria, call the handler
messageInfo.m_hChildNode = child;
messageInfo.m_szChildTagName = szTagName;
messageInfo.m_szChildTagXmlns = szXmlns;
- messageInfo.m_pUserData = pInfo->m_pUserData;
+ messageInfo.m_pUserData = pInfo.m_pUserData;
messageInfo.m_szFrom = xmlGetAttrValue(node, _T("from")); // is necessary for ppro->debugLogA() below, that's why we must parse it even if JABBER_MESSAGE_PARSE_FROM flag is not set
- if (pInfo->m_dwParamsToParse & JABBER_MESSAGE_PARSE_ID_STR)
+ if (pInfo.m_dwParamsToParse & JABBER_MESSAGE_PARSE_ID_STR)
messageInfo.m_szId = xmlGetAttrValue(node, _T("id"));
- if (pInfo->m_dwParamsToParse & JABBER_IQ_PARSE_TO)
+ if (pInfo.m_dwParamsToParse & JABBER_IQ_PARSE_TO)
messageInfo.m_szTo = xmlGetAttrValue(node, _T("to"));
- if (pInfo->m_dwParamsToParse & JABBER_MESSAGE_PARSE_HCONTACT)
+ if (pInfo.m_dwParamsToParse & JABBER_MESSAGE_PARSE_HCONTACT)
messageInfo.m_hContact = ppro->HContactFromJID(messageInfo.m_szFrom, 3);
if (messageInfo.m_szFrom)
ppro->debugLog(_T("Handling message from %s"), messageInfo.m_szFrom);
- if ((ppro->*(pInfo->m_pHandler))(node, pThreadData, &messageInfo))
- return TRUE;
+ if ((ppro->*(pInfo.m_pHandler))(node, pThreadData, &messageInfo))
+ return true;
}
}
}
- pInfo = pInfo->m_pNext;
}
- return FALSE;
+ return false;
}
CJabberMessagePermanentInfo* CJabberMessageManager::AddPermanentHandler(
@@ -127,58 +123,23 @@ CJabberMessagePermanentInfo* CJabberMessageManager::AddPermanentHandler( int iPriority)
{
CJabberMessagePermanentInfo* pInfo = new CJabberMessagePermanentInfo();
- if (pInfo == NULL)
- return NULL;
-
pInfo->m_pHandler = pHandler;
pInfo->m_nMessageTypes = nMessageTypes ? nMessageTypes : JABBER_MESSAGE_TYPE_ANY;
- replaceStrT(pInfo->m_szXmlns, szXmlns);
+ pInfo->m_szXmlns = mir_tstrdup(szXmlns);
pInfo->m_bAllowPartialNs = bAllowPartialNs;
- replaceStrT(pInfo->m_szTag, szTag);
+ pInfo->m_szTag = mir_tstrdup(szTag);
pInfo->m_dwParamsToParse = dwParamsToParse;
pInfo->m_pUserData = pUserData;
pInfo->m_pUserDataFree = pUserDataFree;
pInfo->m_iPriority = iPriority;
mir_cslock lck(m_cs);
- if (!m_pPermanentHandlers)
- m_pPermanentHandlers = pInfo;
- else {
- if (m_pPermanentHandlers->m_iPriority > pInfo->m_iPriority) {
- pInfo->m_pNext = m_pPermanentHandlers;
- m_pPermanentHandlers = pInfo;
- }
- else {
- CJabberMessagePermanentInfo *pTmp = m_pPermanentHandlers;
- while (pTmp->m_pNext && pTmp->m_pNext->m_iPriority <= pInfo->m_iPriority)
- pTmp = pTmp->m_pNext;
- pInfo->m_pNext = pTmp->m_pNext;
- pTmp->m_pNext = pInfo;
- }
- }
+ m_arHandlers.insert(pInfo);
return pInfo;
}
bool CJabberMessageManager::DeletePermanentHandler(CJabberMessagePermanentInfo *pInfo)
{
mir_cslock lck(m_cs);
- if (!m_pPermanentHandlers)
- return FALSE;
-
- if (m_pPermanentHandlers == pInfo) { // check first item
- m_pPermanentHandlers = m_pPermanentHandlers->m_pNext;
- delete pInfo;
- return TRUE;
- }
-
- CJabberMessagePermanentInfo *pTmp = m_pPermanentHandlers;
- while (pTmp->m_pNext) {
- if (pTmp->m_pNext == pInfo) {
- pTmp->m_pNext = pTmp->m_pNext->m_pNext;
- delete pInfo;
- return TRUE;
- }
- pTmp = pTmp->m_pNext;
- }
- return FALSE;
+ return m_arHandlers.remove(pInfo) == 1;
}
diff --git a/protocols/JabberG/src/jabber_message_manager.h b/protocols/JabberG/src/jabber_message_manager.h index 41bd6cdc80..f7ac98253f 100644 --- a/protocols/JabberG/src/jabber_message_manager.h +++ b/protocols/JabberG/src/jabber_message_manager.h @@ -92,8 +92,6 @@ class CJabberMessagePermanentInfo : public MZeroedObject {
friend class CJabberMessageManager;
- CJabberMessagePermanentInfo* m_pNext;
-
JABBER_PERMANENT_MESSAGE_HANDLER m_pHandler;
DWORD m_dwParamsToParse;
int m_nMessageTypes;
@@ -112,6 +110,8 @@ public: mir_free(m_szXmlns);
mir_free(m_szTag);
}
+
+ __forceinline int getPriority() const { return m_iPriority; }
};
class CJabberMessageManager
@@ -119,7 +119,7 @@ class CJabberMessageManager protected:
CJabberProto *ppro;
mir_cs m_cs;
- CJabberMessagePermanentInfo* m_pPermanentHandlers;
+ OBJLIST<CJabberMessagePermanentInfo> m_arHandlers;
public:
CJabberMessageManager(CJabberProto* proto);
diff --git a/protocols/JabberG/src/jabber_presence_manager.cpp b/protocols/JabberG/src/jabber_presence_manager.cpp index 680f852532..31cd8d5e26 100644 --- a/protocols/JabberG/src/jabber_presence_manager.cpp +++ b/protocols/JabberG/src/jabber_presence_manager.cpp @@ -25,20 +25,53 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "jabber.h"
-#include "jabber_presence_manager.h"
-BOOL CJabberPresenceManager::FillPermanentHandlers()
+static int CompareItems(const CJabberPresencePermanentInfo *p1, const CJabberPresencePermanentInfo *p2)
{
- return TRUE;
+ return p1->getPriority() - p2->getPriority();
}
-BOOL CJabberPresenceManager::HandlePresencePermanent(HXML node, ThreadData *pThreadData)
+CJabberPresenceManager::CJabberPresenceManager(CJabberProto *proto) :
+ m_arHandlers(1, &CompareItems)
{
+ ppro = proto;
+}
+
+CJabberPresenceManager::~CJabberPresenceManager()
+{
+}
+
+CJabberPresencePermanentInfo* CJabberPresenceManager::AddPermanentHandler(
+ JABBER_PRESENCE_HANDLER pHandler,
+ void *pUserData,
+ PRESENCE_USER_DATA_FREE_FUNC pUserDataFree,
+ int iPriority)
+{
+ CJabberPresencePermanentInfo* pInfo = new CJabberPresencePermanentInfo();
+ pInfo->m_pHandler = pHandler;
+ pInfo->m_pUserData = pUserData;
+ pInfo->m_pUserDataFree = pUserDataFree;
+ pInfo->m_iPriority = iPriority;
+
mir_cslock lck(m_cs);
- for (CJabberPresencePermanentInfo *pInfo = m_pPermanentHandlers; pInfo; pInfo = pInfo->m_pNext) {
+ m_arHandlers.insert(pInfo);
+ return pInfo;
+}
+
+bool CJabberPresenceManager::DeletePermanentHandler(CJabberPresencePermanentInfo *pInfo)
+{
+ mir_cslock lck(m_cs);
+ return m_arHandlers.remove(pInfo) == 1;
+}
+
+bool CJabberPresenceManager::HandlePresencePermanent(HXML node, ThreadData *pThreadData)
+{
+ for (int i = 0; i < m_arHandlers.getCount(); i++) {
+ CJabberPresencePermanentInfo &pInfo = m_arHandlers[i];
+
CJabberPresenceInfo presenceInfo;
- presenceInfo.m_pUserData = pInfo->m_pUserData;
- if ((ppro->*(pInfo->m_pHandler))(node, pThreadData, &presenceInfo))
+ presenceInfo.m_pUserData = pInfo.m_pUserData;
+ if ((ppro->*(pInfo.m_pHandler))(node, pThreadData, &presenceInfo))
return true;
}
diff --git a/protocols/JabberG/src/jabber_presence_manager.h b/protocols/JabberG/src/jabber_presence_manager.h index ff753dfdf6..9b33288192 100644 --- a/protocols/JabberG/src/jabber_presence_manager.h +++ b/protocols/JabberG/src/jabber_presence_manager.h @@ -64,22 +64,24 @@ class CJabberPresencePermanentInfo {
friend class CJabberPresenceManager;
- CJabberPresencePermanentInfo* m_pNext;
-
JABBER_PRESENCE_HANDLER m_pHandler;
void *m_pUserData;
PRESENCE_USER_DATA_FREE_FUNC m_pUserDataFree;
int m_iPriority;
+
public:
CJabberPresencePermanentInfo()
{
ZeroMemory(this, sizeof(CJabberPresencePermanentInfo));
}
+
~CJabberPresencePermanentInfo()
{
if (m_pUserDataFree)
m_pUserDataFree(m_pUserData);
}
+
+ __forceinline int getPriority() const { return m_iPriority; }
};
class CJabberPresenceManager
@@ -87,89 +89,16 @@ class CJabberPresenceManager protected:
CJabberProto *ppro;
mir_cs m_cs;
- CJabberPresencePermanentInfo* m_pPermanentHandlers;
+ OBJLIST<CJabberPresencePermanentInfo> m_arHandlers;
public:
- CJabberPresenceManager(CJabberProto* proto)
- {
- m_pPermanentHandlers = NULL;
- ppro = proto;
- }
- ~CJabberPresenceManager()
- {
- CJabberPresencePermanentInfo *pInfo = m_pPermanentHandlers;
- while (pInfo) {
- CJabberPresencePermanentInfo *pTmp = pInfo->m_pNext;
- delete pInfo;
- pInfo = pTmp;
- }
- m_pPermanentHandlers = NULL;
- }
- BOOL Start()
- {
- return TRUE;
- }
- BOOL Shutdown()
- {
- return TRUE;
- }
- CJabberPresencePermanentInfo* AddPermanentHandler(JABBER_PRESENCE_HANDLER pHandler, void *pUserData = NULL, PRESENCE_USER_DATA_FREE_FUNC pUserDataFree = NULL, int iPriority = JH_PRIORITY_DEFAULT)
- {
- CJabberPresencePermanentInfo* pInfo = new CJabberPresencePermanentInfo();
- if (!pInfo)
- return NULL;
-
- pInfo->m_pHandler = pHandler;
- pInfo->m_pUserData = pUserData;
- pInfo->m_pUserDataFree = pUserDataFree;
- pInfo->m_iPriority = iPriority;
-
- mir_cslock lck(m_cs);
- if (!m_pPermanentHandlers)
- m_pPermanentHandlers = pInfo;
- else {
- if (m_pPermanentHandlers->m_iPriority > pInfo->m_iPriority) {
- pInfo->m_pNext = m_pPermanentHandlers;
- m_pPermanentHandlers = pInfo;
- }
- else {
- CJabberPresencePermanentInfo* pTmp = m_pPermanentHandlers;
- while (pTmp->m_pNext && pTmp->m_pNext->m_iPriority <= pInfo->m_iPriority)
- pTmp = pTmp->m_pNext;
- pInfo->m_pNext = pTmp->m_pNext;
- pTmp->m_pNext = pInfo;
- }
- }
-
- return pInfo;
- }
- BOOL DeletePermanentHandler(CJabberPresencePermanentInfo *pInfo)
- { // returns TRUE when pInfo found, or FALSE otherwise
- mir_cslock lck(m_cs);
- if (!m_pPermanentHandlers)
- return FALSE;
-
- if (m_pPermanentHandlers == pInfo) { // check first item
- m_pPermanentHandlers = m_pPermanentHandlers->m_pNext;
- delete pInfo;
- return TRUE;
- }
-
- CJabberPresencePermanentInfo *pTmp = m_pPermanentHandlers;
- while (pTmp->m_pNext) {
- if (pTmp->m_pNext == pInfo) {
- pTmp->m_pNext = pTmp->m_pNext->m_pNext;
- delete pInfo;
- return TRUE;
- }
- pTmp = pTmp->m_pNext;
- }
-
- return FALSE;
- }
+ CJabberPresenceManager(CJabberProto*);
+ ~CJabberPresenceManager();
+
+ CJabberPresencePermanentInfo* AddPermanentHandler(JABBER_PRESENCE_HANDLER pHandler, void *pUserData = NULL, PRESENCE_USER_DATA_FREE_FUNC pUserDataFree = NULL, int iPriority = JH_PRIORITY_DEFAULT);
+ bool DeletePermanentHandler(CJabberPresencePermanentInfo *pInfo);
- BOOL HandlePresencePermanent(HXML node, ThreadData *pThreadData);
- BOOL FillPermanentHandlers();
+ bool HandlePresencePermanent(HXML node, ThreadData *pThreadData);
};
#endif
diff --git a/protocols/JabberG/src/jabber_proto.cpp b/protocols/JabberG/src/jabber_proto.cpp index 5705dbef00..e222a40427 100644 --- a/protocols/JabberG/src/jabber_proto.cpp +++ b/protocols/JabberG/src/jabber_proto.cpp @@ -127,9 +127,6 @@ CJabberProto::CJabberProto(const char *aProtoName, const TCHAR *aUserName) : m_iqManager.FillPermanentHandlers();
m_iqManager.Start();
m_messageManager.FillPermanentHandlers();
- m_presenceManager.FillPermanentHandlers();
- m_presenceManager.Start();
- m_sendManager.Start();
m_adhocManager.FillDefaultNodes();
m_clientCapsManager.AddDefaultCaps();
@@ -293,8 +290,6 @@ int __cdecl CJabberProto::OnPreShutdown(WPARAM, LPARAM) m_iqManager.ExpireAll();
m_iqManager.Shutdown();
- m_presenceManager.Shutdown();
- m_sendManager.Shutdown();
ConsoleUninit();
StatusIconData sid = { sizeof(sid) };
diff --git a/protocols/JabberG/src/jabber_send_manager.cpp b/protocols/JabberG/src/jabber_send_manager.cpp index 0ada2e018a..174ec38784 100644 --- a/protocols/JabberG/src/jabber_send_manager.cpp +++ b/protocols/JabberG/src/jabber_send_manager.cpp @@ -25,20 +25,49 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "jabber.h"
-#include "jabber_send_manager.h"
-BOOL CJabberSendManager::FillPermanentHandlers()
+static int CompareItems(const CJabberSendPermanentInfo *p1, const CJabberSendPermanentInfo *p2)
{
- return TRUE;
+ return p1->getPriority() - p2->getPriority();
}
-BOOL CJabberSendManager::HandleSendPermanent(HXML node, ThreadData *pThreadData)
+CJabberSendManager::CJabberSendManager(CJabberProto* proto) :
+ m_arHandlers(1, CompareItems)
{
+ ppro = proto;
+}
+
+CJabberSendManager::~CJabberSendManager()
+{
+}
+
+CJabberSendPermanentInfo* CJabberSendManager::AddPermanentHandler(JABBER_SEND_HANDLER pHandler, void *pUserData, SEND_USER_DATA_FREE_FUNC pUserDataFree, int iPriority)
+{
+ CJabberSendPermanentInfo *pInfo = new CJabberSendPermanentInfo();
+ pInfo->m_pHandler = pHandler;
+ pInfo->m_pUserData = pUserData;
+ pInfo->m_pUserDataFree = pUserDataFree;
+ pInfo->m_iPriority = iPriority;
+
mir_cslock lck(m_cs);
- for (CJabberSendPermanentInfo *pInfo = m_pPermanentHandlers; pInfo; pInfo = pInfo->m_pNext) {
+ m_arHandlers.insert(pInfo);
+ return pInfo;
+}
+
+bool CJabberSendManager::DeletePermanentHandler(CJabberSendPermanentInfo *pInfo)
+{
+ mir_cslock lck(m_cs);
+ return m_arHandlers.remove(pInfo) == 1;
+}
+
+bool CJabberSendManager::HandleSendPermanent(HXML node, ThreadData *pThreadData)
+{
+ for (int i = 0; i < m_arHandlers.getCount(); i++) {
+ CJabberSendPermanentInfo &pInfo = m_arHandlers[i];
+
CJabberSendInfo sendInfo;
- sendInfo.m_pUserData = pInfo->m_pUserData;
- if ((ppro->*(pInfo->m_pHandler))(node, pThreadData, &sendInfo))
+ sendInfo.m_pUserData = pInfo.m_pUserData;
+ if ((ppro->*(pInfo.m_pHandler))(node, pThreadData, &sendInfo))
return true;
}
diff --git a/protocols/JabberG/src/jabber_send_manager.h b/protocols/JabberG/src/jabber_send_manager.h index ac1ae878a5..375b279b05 100644 --- a/protocols/JabberG/src/jabber_send_manager.h +++ b/protocols/JabberG/src/jabber_send_manager.h @@ -75,11 +75,14 @@ public: {
ZeroMemory(this, sizeof(CJabberSendPermanentInfo));
}
+
~CJabberSendPermanentInfo()
{
if (m_pUserDataFree)
m_pUserDataFree(m_pUserData);
}
+
+ __forceinline int getPriority() const { return m_iPriority; }
};
class CJabberSendManager
@@ -87,86 +90,16 @@ class CJabberSendManager protected:
CJabberProto *ppro;
mir_cs m_cs;
- CJabberSendPermanentInfo* m_pPermanentHandlers;
+ OBJLIST<CJabberSendPermanentInfo> m_arHandlers;
public:
- CJabberSendManager(CJabberProto* proto)
- {
- m_pPermanentHandlers = NULL;
- ppro = proto;
- }
- ~CJabberSendManager()
- {
- CJabberSendPermanentInfo *pInfo = m_pPermanentHandlers;
- while (pInfo) {
- CJabberSendPermanentInfo *pTmp = pInfo->m_pNext;
- delete pInfo;
- pInfo = pTmp;
- }
- m_pPermanentHandlers = NULL;
- }
- BOOL Start()
- {
- return TRUE;
- }
- BOOL Shutdown()
- {
- return TRUE;
- }
- CJabberSendPermanentInfo* AddPermanentHandler(JABBER_SEND_HANDLER pHandler, void *pUserData = NULL, SEND_USER_DATA_FREE_FUNC pUserDataFree = NULL, int iPriority = JH_PRIORITY_DEFAULT)
- {
- CJabberSendPermanentInfo* pInfo = new CJabberSendPermanentInfo();
- if (!pInfo)
- return NULL;
-
- pInfo->m_pHandler = pHandler;
- pInfo->m_pUserData = pUserData;
- pInfo->m_pUserDataFree = pUserDataFree;
- pInfo->m_iPriority = iPriority;
-
- mir_cslock lck(m_cs);
- if (!m_pPermanentHandlers)
- m_pPermanentHandlers = pInfo;
- else {
- if (m_pPermanentHandlers->m_iPriority > pInfo->m_iPriority) {
- pInfo->m_pNext = m_pPermanentHandlers;
- m_pPermanentHandlers = pInfo;
- }
- else {
- CJabberSendPermanentInfo* pTmp = m_pPermanentHandlers;
- while (pTmp->m_pNext && pTmp->m_pNext->m_iPriority <= pInfo->m_iPriority)
- pTmp = pTmp->m_pNext;
- pInfo->m_pNext = pTmp->m_pNext;
- pTmp->m_pNext = pInfo;
- }
- }
- return pInfo;
- }
- BOOL DeletePermanentHandler(CJabberSendPermanentInfo *pInfo)
- { // returns TRUE when pInfo found, or FALSE otherwise
- mir_cslock lck(m_cs);
- if (!m_pPermanentHandlers)
- return FALSE;
-
- if (m_pPermanentHandlers == pInfo) { // check first item
- m_pPermanentHandlers = m_pPermanentHandlers->m_pNext;
- delete pInfo;
- return TRUE;
- }
-
- CJabberSendPermanentInfo* pTmp = m_pPermanentHandlers;
- while (pTmp->m_pNext) {
- if (pTmp->m_pNext == pInfo) {
- pTmp->m_pNext = pTmp->m_pNext->m_pNext;
- delete pInfo;
- return TRUE;
- }
- pTmp = pTmp->m_pNext;
- }
- return FALSE;
- }
- BOOL HandleSendPermanent(HXML node, ThreadData *pThreadData);
- BOOL FillPermanentHandlers();
+ CJabberSendManager(CJabberProto* proto);
+ ~CJabberSendManager();
+
+ CJabberSendPermanentInfo* AddPermanentHandler(JABBER_SEND_HANDLER pHandler, void *pUserData = NULL, SEND_USER_DATA_FREE_FUNC pUserDataFree = NULL, int iPriority = JH_PRIORITY_DEFAULT);
+ bool DeletePermanentHandler(CJabberSendPermanentInfo *pInfo);
+
+ bool HandleSendPermanent(HXML node, ThreadData *pThreadData);
};
#endif
|