summaryrefslogtreecommitdiff
path: root/protocols/JabberG
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/JabberG')
-rw-r--r--protocols/JabberG/src/jabber_disco.cpp280
-rw-r--r--protocols/JabberG/src/jabber_disco.h104
-rw-r--r--protocols/JabberG/src/jabber_presence_manager.h4
-rw-r--r--protocols/JabberG/src/jabber_privacy.h4
-rw-r--r--protocols/JabberG/src/jabber_rc.cpp59
-rw-r--r--protocols/JabberG/src/jabber_rc.h34
6 files changed, 212 insertions, 273 deletions
diff --git a/protocols/JabberG/src/jabber_disco.cpp b/protocols/JabberG/src/jabber_disco.cpp
index 452cb746ae..d3030a3b7e 100644
--- a/protocols/JabberG/src/jabber_disco.cpp
+++ b/protocols/JabberG/src/jabber_disco.cpp
@@ -168,12 +168,10 @@ static void sttApplyNodeIcon(HTREELISTITEM hItem, CJabberSDNode *pNode);
void CJabberProto::OnIqResultServiceDiscoveryInfo(HXML iqNode, CJabberIqInfo *pInfo)
{
- m_SDManager.Lock();
+ mir_cslockfull lck(m_SDManager.cs());
CJabberSDNode *pNode = m_SDManager.FindByIqId(pInfo->GetIqId(), TRUE);
- if (!pNode) {
- m_SDManager.Unlock();
+ if (!pNode)
return;
- }
if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) {
HXML query = xmlGetChild(iqNode , "query");
@@ -204,7 +202,7 @@ void CJabberProto::OnIqResultServiceDiscoveryInfo(HXML iqNode, CJabberIqInfo *pI
pNode->SetInfoRequestId(JABBER_DISCO_RESULT_ERROR);
}
- m_SDManager.Unlock();
+ lck.unlock();
if (m_pDlgServiceDiscovery) {
ApplyNodeIcon(pNode->GetTreeItemHandle(), pNode);
@@ -214,12 +212,10 @@ void CJabberProto::OnIqResultServiceDiscoveryInfo(HXML iqNode, CJabberIqInfo *pI
void CJabberProto::OnIqResultServiceDiscoveryItems(HXML iqNode, CJabberIqInfo *pInfo)
{
- m_SDManager.Lock();
+ mir_cslockfull lck(m_SDManager.cs());
CJabberSDNode *pNode = m_SDManager.FindByIqId(pInfo->GetIqId(), FALSE);
- if (!pNode) {
- m_SDManager.Unlock();
+ if (!pNode)
return;
- }
if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) {
HXML query = xmlGetChild(iqNode , "query");
@@ -227,9 +223,8 @@ void CJabberProto::OnIqResultServiceDiscoveryItems(HXML iqNode, CJabberIqInfo *p
pNode->SetItemsRequestId(JABBER_DISCO_RESULT_ERROR);
else {
HXML item;
- for (int i = 1; (item = xmlGetNthChild(query, _T("item"), i)) != NULL; i++) {
+ for (int i = 1; (item = xmlGetNthChild(query, _T("item"), i)) != NULL; i++)
pNode->AddChildNode(xmlGetAttrValue(item, _T("jid")), xmlGetAttrValue(item, _T("node")), xmlGetAttrValue(item, _T("name")));
- }
pNode->SetItemsRequestId(JABBER_DISCO_RESULT_OK);
pNode->SetItemsRequestErrorText(NULL);
@@ -248,7 +243,7 @@ void CJabberProto::OnIqResultServiceDiscoveryItems(HXML iqNode, CJabberIqInfo *p
pNode->SetItemsRequestId(JABBER_DISCO_RESULT_ERROR);
}
- m_SDManager.Unlock();
+ lck.unlock();
if (m_pDlgServiceDiscovery) {
ApplyNodeIcon(pNode->GetTreeItemHandle(), pNode);
@@ -259,19 +254,19 @@ void CJabberProto::OnIqResultServiceDiscoveryItems(HXML iqNode, CJabberIqInfo *p
void CJabberProto::OnIqResultServiceDiscoveryRootInfo(HXML iqNode, CJabberIqInfo *pInfo)
{
if (!pInfo->m_pUserData) return;
- m_SDManager.Lock();
+
+ mir_cslockfull lck(m_SDManager.cs());
if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) {
HXML query = xmlGetChild(iqNode , "query");
if (query) {
HXML feature;
- int i;
- for (i = 1; (feature = xmlGetNthChild(query, _T("feature"), i)) != NULL; i++) {
+ for (int i = 1; (feature = xmlGetNthChild(query, _T("feature"), i)) != NULL; i++) {
if (!lstrcmp(xmlGetAttrValue(feature, _T("var")), (TCHAR *)pInfo->m_pUserData)) {
CJabberSDNode *pNode = m_SDManager.AddPrimaryNode(pInfo->GetReceiver(), xmlGetAttrValue(iqNode, _T("node")), NULL);
SendBothRequests(pNode, NULL);
break;
} } } }
- m_SDManager.Unlock();
+ lck.unlock();
UI_SAFE_NOTIFY(m_pDlgServiceDiscovery, WM_JABBER_REFRESH);
}
@@ -282,7 +277,7 @@ void CJabberProto::OnIqResultServiceDiscoveryRootItems(HXML iqNode, CJabberIqInf
return;
XmlNode packet(NULL);
- m_SDManager.Lock();
+ mir_cslockfull lck(m_SDManager.cs());
if (pInfo->GetIqType() == JABBER_IQ_TYPE_RESULT) {
HXML query = xmlGetChild(iqNode , "query");
if (query) {
@@ -298,7 +293,7 @@ void CJabberProto::OnIqResultServiceDiscoveryRootItems(HXML iqNode, CJabberIqInf
iq << XQUERY(JABBER_FEAT_DISCO_INFO) << XATTR(_T("node"), szNode);
xmlAddChild(packet, iq);
} } }
- m_SDManager.Unlock();
+ lck.unlock();
if (xmlGetChild(packet ,0))
m_ThreadInfo->send(packet);
@@ -393,79 +388,80 @@ void CJabberProto::PerformBrowse(HWND hwndDlg)
ComboAddRecentString(hwndDlg, IDC_COMBO_JID, "discoWnd_rcJid", szJid);
ComboAddRecentString(hwndDlg, IDC_COMBO_NODE, "discoWnd_rcNode", szNode);
- if (_tcslen(szJid)) {
- HWND hwndList = GetDlgItem(hwndDlg, IDC_TREE_DISCO);
- TreeList_Reset(hwndList);
+ if (szJid[0] == 0)
+ return;
- m_SDManager.Lock();
- m_SDManager.RemoveAll();
- if (!lstrcmp(szJid, _T(SD_FAKEJID_MYAGENTS))) {
- sttBrowseMode = SD_BROWSE_MYAGENTS;
- JABBER_LIST_ITEM *item = NULL;
- LISTFOREACH(i, this, LIST_ROSTER)
- {
- if ((item=ListGetItemPtrFromIndex(i)) != NULL) {
- if (_tcschr(item->jid, '@') == NULL && _tcschr(item->jid, '/') == NULL && item->subscription!=SUB_NONE) {
- MCONTACT hContact = HContactFromJID(item->jid);
- if (hContact != NULL)
- setByte(hContact, "IsTransport", TRUE);
+ HWND hwndList = GetDlgItem(hwndDlg, IDC_TREE_DISCO);
+ TreeList_Reset(hwndList);
- if (m_lstTransports.getIndex(item->jid) == -1)
- m_lstTransports.insert(mir_tstrdup(item->jid));
+ mir_cslockfull lck(m_SDManager.cs());
+ m_SDManager.RemoveAll();
+ if (!lstrcmp(szJid, _T(SD_FAKEJID_MYAGENTS))) {
+ sttBrowseMode = SD_BROWSE_MYAGENTS;
+ JABBER_LIST_ITEM *item = NULL;
+ LISTFOREACH(i, this, LIST_ROSTER)
+ {
+ if ((item=ListGetItemPtrFromIndex(i)) != NULL) {
+ if (_tcschr(item->jid, '@') == NULL && _tcschr(item->jid, '/') == NULL && item->subscription!=SUB_NONE) {
+ MCONTACT hContact = HContactFromJID(item->jid);
+ if (hContact != NULL)
+ setByte(hContact, "IsTransport", TRUE);
- CJabberSDNode *pNode = m_SDManager.AddPrimaryNode(item->jid, NULL, NULL);
- SendBothRequests(pNode, NULL);
- } }
- } }
- else if (!lstrcmp(szJid, _T(SD_FAKEJID_CONFERENCES))) {
- sttBrowseMode = SD_BROWSE_CONFERENCES;
- TCHAR *szServerJid = mir_a2t(m_ThreadInfo->server);
- CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnIqResultServiceDiscoveryRootItems, JABBER_IQ_TYPE_GET, szServerJid);
- pInfo->m_pUserData = (void*)JABBER_FEAT_MUC;
- pInfo->SetTimeout(30000);
- XmlNodeIq iq(pInfo);
- iq << XQUERY(JABBER_FEAT_DISCO_ITEMS);
- m_ThreadInfo->send(iq);
- mir_free(szServerJid);
- }
- else if (!lstrcmp(szJid, _T(SD_FAKEJID_AGENTS))) {
- sttBrowseMode = SD_BROWSE_AGENTS;
- TCHAR *szServerJid = mir_a2t(m_ThreadInfo->server);
- CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnIqResultServiceDiscoveryRootItems, JABBER_IQ_TYPE_GET, szServerJid);
- pInfo->m_pUserData = (void*)_T("jabber:iq:gateway");
- pInfo->SetTimeout(30000);
- XmlNodeIq iq(pInfo);
- iq << XQUERY(JABBER_FEAT_DISCO_ITEMS);
- m_ThreadInfo->send(iq);
- mir_free(szServerJid);
- }
- else if (!lstrcmp(szJid, _T(SD_FAKEJID_FAVORITES))) {
- sttBrowseMode = SD_BROWSE_FAVORITES;
- int count = getDword("discoWnd_favCount", 0);
- for (int i=0; i < count; i++) {
- char setting[MAXMODULELABELLENGTH];
- mir_snprintf(setting, sizeof(setting), "discoWnd_favName_%d", i);
- ptrT tszName( getTStringA(setting));
- if (tszName == NULL)
- continue;
+ if (m_lstTransports.getIndex(item->jid) == -1)
+ m_lstTransports.insert(mir_tstrdup(item->jid));
+
+ CJabberSDNode *pNode = m_SDManager.AddPrimaryNode(item->jid, NULL, NULL);
+ SendBothRequests(pNode, NULL);
+ } }
+ } }
+ else if (!lstrcmp(szJid, _T(SD_FAKEJID_CONFERENCES))) {
+ sttBrowseMode = SD_BROWSE_CONFERENCES;
+ TCHAR *szServerJid = mir_a2t(m_ThreadInfo->server);
+ CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnIqResultServiceDiscoveryRootItems, JABBER_IQ_TYPE_GET, szServerJid);
+ pInfo->m_pUserData = (void*)JABBER_FEAT_MUC;
+ pInfo->SetTimeout(30000);
+ XmlNodeIq iq(pInfo);
+ iq << XQUERY(JABBER_FEAT_DISCO_ITEMS);
+ m_ThreadInfo->send(iq);
+ mir_free(szServerJid);
+ }
+ else if (!lstrcmp(szJid, _T(SD_FAKEJID_AGENTS))) {
+ sttBrowseMode = SD_BROWSE_AGENTS;
+ TCHAR *szServerJid = mir_a2t(m_ThreadInfo->server);
+ CJabberIqInfo *pInfo = AddIQ(&CJabberProto::OnIqResultServiceDiscoveryRootItems, JABBER_IQ_TYPE_GET, szServerJid);
+ pInfo->m_pUserData = (void*)_T("jabber:iq:gateway");
+ pInfo->SetTimeout(30000);
+ XmlNodeIq iq(pInfo);
+ iq << XQUERY(JABBER_FEAT_DISCO_ITEMS);
+ m_ThreadInfo->send(iq);
+ mir_free(szServerJid);
+ }
+ else if (!lstrcmp(szJid, _T(SD_FAKEJID_FAVORITES))) {
+ sttBrowseMode = SD_BROWSE_FAVORITES;
+ int count = getDword("discoWnd_favCount", 0);
+ for (int i=0; i < count; i++) {
+ char setting[MAXMODULELABELLENGTH];
+ mir_snprintf(setting, sizeof(setting), "discoWnd_favName_%d", i);
+ ptrT tszName( getTStringA(setting));
+ if (tszName == NULL)
+ continue;
- mir_snprintf(setting, sizeof(setting), "discoWnd_favJID_%d", i);
- ptrT dbvJid( getTStringA(setting));
- mir_snprintf(setting, sizeof(setting), "discoWnd_favNode_%d", i);
- ptrT dbvNode( getTStringA(setting));
- CJabberSDNode *pNode = m_SDManager.AddPrimaryNode(dbvJid, dbvNode, tszName);
- SendBothRequests(pNode, NULL);
- }
- }
- else {
- sttBrowseMode = SD_BROWSE_NORMAL;
- CJabberSDNode *pNode = m_SDManager.AddPrimaryNode(szJid, _tcslen(szNode) ? szNode : NULL, NULL);
+ mir_snprintf(setting, sizeof(setting), "discoWnd_favJID_%d", i);
+ ptrT dbvJid( getTStringA(setting));
+ mir_snprintf(setting, sizeof(setting), "discoWnd_favNode_%d", i);
+ ptrT dbvNode( getTStringA(setting));
+ CJabberSDNode *pNode = m_SDManager.AddPrimaryNode(dbvJid, dbvNode, tszName);
SendBothRequests(pNode, NULL);
}
- m_SDManager.Unlock();
-
- PostMessage(hwndDlg, WM_JABBER_REFRESH, 0, 0);
}
+ else {
+ sttBrowseMode = SD_BROWSE_NORMAL;
+ CJabberSDNode *pNode = m_SDManager.AddPrimaryNode(szJid, _tcslen(szNode) ? szNode : NULL, NULL);
+ SendBothRequests(pNode, NULL);
+ }
+ lck.unlock();
+
+ PostMessage(hwndDlg, WM_JABBER_REFRESH, 0, 0);
}
BOOL CJabberProto::IsNodeRegistered(CJabberSDNode *pNode)
@@ -731,9 +727,10 @@ void CJabberDlgDiscovery::OnClose()
void CJabberDlgDiscovery::OnDestroy()
{
m_proto->m_pDlgServiceDiscovery = NULL;
- m_proto->m_SDManager.Lock();
- m_proto->m_SDManager.RemoveAll();
- m_proto->m_SDManager.Unlock();
+ {
+ mir_cslock lck(m_proto->m_SDManager.cs());
+ m_proto->m_SDManager.RemoveAll();
+ }
TreeList_Destroy(GetDlgItem(m_hwnd, IDC_TREE_DISCO));
CSuper::OnDestroy();
@@ -901,10 +898,11 @@ void CJabberDlgDiscovery::btnBookmarks_OnClick(CCtrlButton *)
void CJabberDlgDiscovery::btnRefresh_OnClick(CCtrlButton *)
{
HTREELISTITEM hItem = (HTREELISTITEM)TreeList_GetActiveItem(GetDlgItem(m_hwnd, IDC_TREE_DISCO));
- if (!hItem) return;
+ if (!hItem)
+ return;
- m_proto->m_SDManager.Lock();
XmlNode packet(NULL);
+ mir_cslockfull lck(m_proto->m_SDManager.cs());
CJabberSDNode *pNode = (CJabberSDNode*)TreeList_GetData(hItem);
if (pNode) {
TreeList_ResetItem(GetDlgItem(m_hwnd, IDC_TREE_DISCO), hItem);
@@ -912,7 +910,7 @@ void CJabberDlgDiscovery::btnRefresh_OnClick(CCtrlButton *)
m_proto->SendBothRequests(pNode, packet);
TreeList_MakeFakeParent(hItem, FALSE);
}
- m_proto->m_SDManager.Unlock();
+ lck.unlock();
if (xmlGetChild(packet ,0))
m_proto->m_ThreadInfo->send(packet);
@@ -966,7 +964,7 @@ INT_PTR CJabberDlgDiscovery::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
case WM_TIMER:
if (wParam == REFRESH_TIMER) {
- m_proto->m_SDManager.Lock();
+ mir_cslockfull lck(m_proto->m_SDManager.cs());
CJabberSDNode *pNode = m_proto->m_SDManager.GetPrimaryNode();
while (pNode)
@@ -984,7 +982,7 @@ INT_PTR CJabberDlgDiscovery::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
m_proto->SyncTree(NULL, pNode);
pNode = pNode->GetNext();
}
- m_proto->m_SDManager.Unlock();
+ lck.unlock();
TreeList_Update(GetDlgItem(m_hwnd, IDC_TREE_DISCO));
KillTimer(m_hwnd, REFRESH_TIMER);
m_proto->m_dwSDLastRefresh = GetTickCount();
@@ -1005,24 +1003,25 @@ INT_PTR CJabberDlgDiscovery::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
if (iFirst < 0) return FALSE;
if (iLast < 0) iLast = ListView_GetItemCount(hwndList) - 1;
- m_proto->m_SDManager.Lock();
XmlNode packet(NULL);
- for (int i = iFirst; i <= iLast; i++)
{
- LVITEM lvi = {0};
- lvi.mask = LVIF_PARAM;
- lvi.iItem = i;
- ListView_GetItem(hwndList, &lvi);
- if (!lvi.lParam)
- continue;
-
- CJabberSDNode *pNode = (CJabberSDNode *)TreeList_GetData((HTREELISTITEM)lvi.lParam);
- if (!pNode || pNode->GetInfoRequestId())
- continue;
-
- m_proto->SendInfoRequest(pNode, packet);
+ mir_cslock lck(m_proto->m_SDManager.cs());
+ for (int i = iFirst; i <= iLast; i++)
+ {
+ LVITEM lvi = {0};
+ lvi.mask = LVIF_PARAM;
+ lvi.iItem = i;
+ ListView_GetItem(hwndList, &lvi);
+ if (!lvi.lParam)
+ continue;
+
+ CJabberSDNode *pNode = (CJabberSDNode *)TreeList_GetData((HTREELISTITEM)lvi.lParam);
+ if (!pNode || pNode->GetInfoRequestId())
+ continue;
+
+ m_proto->SendInfoRequest(pNode, packet);
+ }
}
- m_proto->m_SDManager.Unlock();
if (xmlGetChild(packet, 0))
m_proto->m_ThreadInfo->send(packet);
@@ -1069,26 +1068,24 @@ INT_PTR CJabberDlgDiscovery::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
lvi.iItem = pInfoTip->iItem;
ListView_GetItem(pHeader->hwndFrom, &lvi);
HTREELISTITEM hItem = (HTREELISTITEM)lvi.lParam;
- m_proto->m_SDManager.Lock();
+
+ mir_cslock lck(m_proto->m_SDManager.cs());
CJabberSDNode *pNode = (CJabberSDNode*)TreeList_GetData(hItem);
if (pNode)
pNode->GetTooltipText(pInfoTip->pszText, pInfoTip->cchTextMax);
-
- m_proto->m_SDManager.Unlock();
}
else if (pHeader->code == TVN_ITEMEXPANDED) {
NMTREEVIEW *pNmTreeView = (NMTREEVIEW *)lParam;
HTREELISTITEM hItem = (HTREELISTITEM)pNmTreeView->itemNew.hItem;
-
- m_proto->m_SDManager.Lock();
XmlNode packet(NULL);
- CJabberSDNode *pNode = (CJabberSDNode*)TreeList_GetData(hItem);
- if (pNode) {
- m_proto->SendBothRequests(pNode, packet);
- TreeList_MakeFakeParent(hItem, FALSE);
+ {
+ mir_cslock lck(m_proto->m_SDManager.cs());
+ CJabberSDNode *pNode = (CJabberSDNode*)TreeList_GetData(hItem);
+ if (pNode) {
+ m_proto->SendBothRequests(pNode, packet);
+ TreeList_MakeFakeParent(hItem, FALSE);
+ }
}
- m_proto->m_SDManager.Unlock();
-
if (xmlGetChild(packet))
m_proto->m_ThreadInfo->send(packet);
}
@@ -1283,17 +1280,16 @@ void CJabberProto::ServiceDiscoveryShowMenu(CJabberSDNode *pNode, HTREELISTITEM
switch (res) {
case SD_ACT_REFRESH:
{
- m_SDManager.Lock();
XmlNode packet(NULL);
- if (pNode)
{
- TreeList_ResetItem(GetDlgItem(m_pDlgServiceDiscovery->GetHwnd(), IDC_TREE_DISCO), hItem);
- pNode->ResetInfo();
- SendBothRequests(pNode, packet);
- TreeList_MakeFakeParent(hItem, FALSE);
+ mir_cslock lck(m_SDManager.cs());
+ if (pNode) {
+ TreeList_ResetItem(GetDlgItem(m_pDlgServiceDiscovery->GetHwnd(), IDC_TREE_DISCO), hItem);
+ pNode->ResetInfo();
+ SendBothRequests(pNode, packet);
+ TreeList_MakeFakeParent(hItem, FALSE);
+ }
}
- m_SDManager.Unlock();
-
if (xmlGetChild(packet))
m_ThreadInfo->send(packet);
}
@@ -1301,25 +1297,25 @@ void CJabberProto::ServiceDiscoveryShowMenu(CJabberSDNode *pNode, HTREELISTITEM
case SD_ACT_REFRESHCHILDREN:
{
- m_SDManager.Lock();
XmlNode packet(NULL);
- for (int iChild = TreeList_GetChildrenCount(hItem); iChild--;) {
- HTREELISTITEM hNode = TreeList_GetChild(hItem, iChild);
- CJabberSDNode *pNode = (CJabberSDNode *)TreeList_GetData(hNode);
- if (pNode)
- {
- TreeList_ResetItem(GetDlgItem(m_pDlgServiceDiscovery->GetHwnd(), IDC_TREE_DISCO), hNode);
- pNode->ResetInfo();
- SendBothRequests(pNode, packet);
- TreeList_MakeFakeParent(hNode, FALSE);
- }
-
- if (xmlGetChildCount(packet) > 50) {
- m_ThreadInfo->send(packet);
- packet = XmlNode(NULL);
+ {
+ mir_cslock lck(m_SDManager.cs());
+ for (int iChild = TreeList_GetChildrenCount(hItem); iChild--;) {
+ HTREELISTITEM hNode = TreeList_GetChild(hItem, iChild);
+ CJabberSDNode *pNode = (CJabberSDNode *)TreeList_GetData(hNode);
+ if (pNode) {
+ TreeList_ResetItem(GetDlgItem(m_pDlgServiceDiscovery->GetHwnd(), IDC_TREE_DISCO), hNode);
+ pNode->ResetInfo();
+ SendBothRequests(pNode, packet);
+ TreeList_MakeFakeParent(hNode, FALSE);
+ }
+
+ if (xmlGetChildCount(packet) > 50) {
+ m_ThreadInfo->send(packet);
+ packet = XmlNode(NULL);
+ }
}
}
- m_SDManager.Unlock();
if (xmlGetChildCount(packet))
m_ThreadInfo->send(packet);
diff --git a/protocols/JabberG/src/jabber_disco.h b/protocols/JabberG/src/jabber_disco.h
index 2514cf0119..ad534d35fa 100644
--- a/protocols/JabberG/src/jabber_disco.h
+++ b/protocols/JabberG/src/jabber_disco.h
@@ -114,7 +114,6 @@ public:
}
};
-class CJabberSDNode;
class CJabberSDNode
{
protected:
@@ -331,97 +330,65 @@ public:
pNode->SetNext(m_pChild);
m_pChild = pNode;
-
return TRUE;
}
- BOOL AppendString(TCHAR **ppBuffer, TCHAR *szString)
- {
- if (!*ppBuffer) {
- *ppBuffer = mir_tstrdup(szString);
- return TRUE;
- }
- *ppBuffer = (TCHAR *)mir_realloc(*ppBuffer, (_tcslen(*ppBuffer) + _tcslen(szString) + 1) * sizeof(TCHAR));
- _tcscat(*ppBuffer, szString);
-
- return TRUE;
- }
BOOL SetItemsRequestErrorText(TCHAR *szError)
{
replaceStrT(m_szItemsError, szError);
return TRUE;
}
+
BOOL SetInfoRequestErrorText(TCHAR *szError)
{
replaceStrT(m_szInfoError, szError);
return TRUE;
}
+
BOOL GetTooltipText(TCHAR *szText, int nMaxLength)
{
- TCHAR *szBuffer = NULL;
+ CMString tszTmp;
- TCHAR szTmp[ 8192 ];
+ tszTmp.AppendFormat(_T("Jid: %s\r\n"), m_szJid);
- mir_sntprintf(szTmp, SIZEOF(szTmp), _T("Jid: %s\r\n"), m_szJid);
- AppendString(&szBuffer, szTmp);
-
- if (m_szNode) {
- mir_sntprintf(szTmp, SIZEOF(szTmp), _T("%s: %s\r\n"), TranslateT("Node"), m_szNode);
- AppendString(&szBuffer, szTmp);
- }
+ if (m_szNode)
+ tszTmp.AppendFormat(_T("%s: %s\r\n"), TranslateT("Node"), m_szNode);
if (m_pIdentities) {
- mir_sntprintf(szTmp, SIZEOF(szTmp), _T("\r\n%s:\r\n"), TranslateT("Identities"));
- AppendString(&szBuffer, szTmp);
+ tszTmp.AppendFormat(_T("\r\n%s:\r\n"), TranslateT("Identities"));
CJabberSDIdentity *pIdentity = m_pIdentities;
while (pIdentity) {
if (pIdentity->GetName())
- mir_sntprintf(szTmp, SIZEOF(szTmp), _T(" %c %s (%s: %s, %s: %s)\r\n"),
+ tszTmp.AppendFormat(_T(" %c %s (%s: %s, %s: %s)\r\n"),
CHR_BULLET, pIdentity->GetName(),
TranslateT("category"), pIdentity->GetCategory(),
TranslateT("type"), pIdentity->GetType());
else
- mir_sntprintf(szTmp, SIZEOF(szTmp), _T(" %c %s: %s, %s: %s\r\n"),
+ tszTmp.AppendFormat(_T(" %c %s: %s, %s: %s\r\n"),
CHR_BULLET,
TranslateT("Category"), pIdentity->GetCategory(),
TranslateT("Type"), pIdentity->GetType());
- AppendString(&szBuffer, szTmp);
-
pIdentity = pIdentity->GetNext();
}
}
if (m_pFeatures) {
- mir_sntprintf(szTmp, SIZEOF(szTmp), _T("\r\n%s:\r\n"), TranslateT("Supported features"));
- AppendString(&szBuffer, szTmp);
-
- CJabberSDFeature *pFeature = m_pFeatures;
- while (pFeature) {
- mir_sntprintf(szTmp, SIZEOF(szTmp), _T(" %c %s\r\n"), CHR_BULLET, pFeature->GetVar());
-
- AppendString(&szBuffer, szTmp);
-
- pFeature = pFeature->GetNext();
- }
- }
-
- if (m_szInfoError) {
- mir_sntprintf(szTmp, SIZEOF(szTmp), _T("\r\n%s: %s\r\n"), TranslateT("Info request error"), m_szInfoError);
- AppendString(&szBuffer, szTmp);
- }
+ tszTmp.AppendFormat(_T("\r\n%s:\r\n"), TranslateT("Supported features"));
- if (m_szItemsError) {
- mir_sntprintf(szTmp, SIZEOF(szTmp), _T("\r\n%s: %s\r\n"), TranslateT("Items request error"), m_szItemsError);
- AppendString(&szBuffer, szTmp);
+ for (CJabberSDFeature *pFeature = m_pFeatures; pFeature; pFeature = pFeature->GetNext())
+ tszTmp.AppendFormat(_T(" %c %s\r\n"), CHR_BULLET, pFeature->GetVar());
}
- szBuffer[lstrlen(szBuffer)-2] = 0; // remove CR/LF
- mir_sntprintf(szText, nMaxLength, _T("%s"), szBuffer);
+ if (m_szInfoError)
+ tszTmp.AppendFormat(_T("\r\n%s: %s\r\n"), TranslateT("Info request error"), m_szInfoError);
- mir_free(szBuffer);
+ if (m_szItemsError)
+ tszTmp.AppendFormat(_T("\r\n%s: %s\r\n"), TranslateT("Items request error"), m_szItemsError);
+ tszTmp.TrimRight();
+ _tcsncpy_s(szText, nMaxLength, tszTmp, _TRUNCATE);
return TRUE;
}
};
@@ -429,42 +396,37 @@ public:
class CJabberSDManager
{
protected:
- CRITICAL_SECTION m_cs;
+ mir_cs m_cs;
CJabberSDNode *m_pPrimaryNodes;
+
public:
CJabberSDManager()
{
m_pPrimaryNodes = NULL;
- InitializeCriticalSection(&m_cs);
}
+
~CJabberSDManager()
{
- DeleteCriticalSection(&m_cs);
RemoveAll();
}
+
+ CRITICAL_SECTION& cs() { return m_cs; }
+
void RemoveAll()
{
delete m_pPrimaryNodes;
m_pPrimaryNodes = NULL;
}
- BOOL Lock()
- {
- EnterCriticalSection(&m_cs);
- return TRUE;
- }
- BOOL Unlock()
- {
- LeaveCriticalSection(&m_cs);
- return TRUE;
- }
+
CJabberSDNode* GetPrimaryNode()
{
return m_pPrimaryNodes;
}
+
CJabberSDNode* AddPrimaryNode(const TCHAR *szJid, const TCHAR *szNode, const TCHAR *szName)
{
if (!szJid)
- return FALSE;
+ return NULL;
CJabberSDNode *pNode = new CJabberSDNode(szJid, szNode, szName);
if (!pNode)
@@ -472,19 +434,15 @@ public:
pNode->SetNext(m_pPrimaryNodes);
m_pPrimaryNodes = pNode;
-
return pNode;
}
+
CJabberSDNode* FindByIqId(int nIqId, BOOL bInfoId = TRUE)
{
- CJabberSDNode *pNode = NULL;
- CJabberSDNode *pTmpNode = NULL;
- pNode = m_pPrimaryNodes;
- while (pNode) {
- if (pTmpNode = pNode->FindByIqId(nIqId, bInfoId))
+ for (CJabberSDNode *pNode = m_pPrimaryNodes; pNode; pNode = pNode->GetNext())
+ if (CJabberSDNode *pTmpNode = pNode->FindByIqId(nIqId, bInfoId))
return pTmpNode;
- pNode = pNode->GetNext();
- }
+
return NULL;
}
};
diff --git a/protocols/JabberG/src/jabber_presence_manager.h b/protocols/JabberG/src/jabber_presence_manager.h
index 97e9077c8a..ff753dfdf6 100644
--- a/protocols/JabberG/src/jabber_presence_manager.h
+++ b/protocols/JabberG/src/jabber_presence_manager.h
@@ -86,13 +86,12 @@ class CJabberPresenceManager
{
protected:
CJabberProto *ppro;
- CRITICAL_SECTION m_cs;
+ mir_cs m_cs;
CJabberPresencePermanentInfo* m_pPermanentHandlers;
public:
CJabberPresenceManager(CJabberProto* proto)
{
- InitializeCriticalSection(&m_cs);
m_pPermanentHandlers = NULL;
ppro = proto;
}
@@ -105,7 +104,6 @@ public:
pInfo = pTmp;
}
m_pPermanentHandlers = NULL;
- DeleteCriticalSection(&m_cs);
}
BOOL Start()
{
diff --git a/protocols/JabberG/src/jabber_privacy.h b/protocols/JabberG/src/jabber_privacy.h
index 8e7656dbbe..99a76ba966 100644
--- a/protocols/JabberG/src/jabber_privacy.h
+++ b/protocols/JabberG/src/jabber_privacy.h
@@ -326,7 +326,7 @@ protected:
public:
CJabberProto* m_proto;
- CRITICAL_SECTION m_cs;
+ mir_cs m_cs;
CPrivacyListManager(CJabberProto *ppro)
{
@@ -334,7 +334,6 @@ public:
m_szActiveListName = NULL;
m_szDefaultListName = NULL;
m_pLists = NULL;
- InitializeCriticalSection(&m_cs);
m_bModified = FALSE;
};
~CPrivacyListManager()
@@ -342,7 +341,6 @@ public:
mir_free(m_szActiveListName);
mir_free(m_szDefaultListName);
RemoveAllLists();
- DeleteCriticalSection(&m_cs);
};
void SetActiveListName(const TCHAR *szListName)
{
diff --git a/protocols/JabberG/src/jabber_rc.cpp b/protocols/JabberG/src/jabber_rc.cpp
index cc6dedf04f..0946ac6b76 100644
--- a/protocols/JabberG/src/jabber_rc.cpp
+++ b/protocols/JabberG/src/jabber_rc.cpp
@@ -74,20 +74,21 @@ BOOL CJabberAdhocManager::HandleItemsRequest(HXML, CJabberIqInfo *pInfo, const T
if (!_tcscmp(szNode, JABBER_FEAT_COMMANDS)) {
XmlNodeIq iq(_T("result"), pInfo);
HXML resultQuery = iq << XQUERY(JABBER_FEAT_DISCO_ITEMS) << XATTR(_T("node"), JABBER_FEAT_COMMANDS);
+ {
+ mir_cslock lck(m_cs);
- Lock();
- CJabberAdhocNode* pNode = GetFirstNode();
- while (pNode) {
- TCHAR *szJid = pNode->GetJid();
- if (!szJid)
- szJid = m_pProto->m_ThreadInfo->fullJID;
+ CJabberAdhocNode* pNode = GetFirstNode();
+ while (pNode) {
+ TCHAR *szJid = pNode->GetJid();
+ if (!szJid)
+ szJid = m_pProto->m_ThreadInfo->fullJID;
- resultQuery << XCHILD(_T("item")) << XATTR(_T("jid"), szJid)
- << XATTR(_T("node"), pNode->GetNode()) << XATTR(_T("name"), pNode->GetName());
+ resultQuery << XCHILD(_T("item")) << XATTR(_T("jid"), szJid)
+ << XATTR(_T("node"), pNode->GetNode()) << XATTR(_T("name"), pNode->GetName());
- pNode = pNode->GetNext();
+ pNode = pNode->GetNext();
+ }
}
- Unlock();
m_pProto->m_ThreadInfo->send(iq);
return TRUE;
@@ -116,24 +117,22 @@ BOOL CJabberAdhocManager::HandleInfoRequest(HXML, CJabberIqInfo *pInfo, const TC
return TRUE;
}
- Lock();
+ mir_cslockfull lck(m_cs);
CJabberAdhocNode *pNode = FindNode(szNode);
- if (pNode) {
- XmlNodeIq iq(_T("result"), pInfo);
- HXML resultQuery = iq << XQUERY(JABBER_FEAT_DISCO_INFO) << XATTR(_T("node"), JABBER_FEAT_DISCO_INFO);
- resultQuery << XCHILD(_T("identity")) << XATTR(_T("name"), pNode->GetName())
- << XATTR(_T("category"), _T("automation")) << XATTR(_T("type"), _T("command-node"));
+ if (pNode == NULL)
+ return FALSE;
- resultQuery << XCHILD(_T("feature")) << XATTR(_T("var"), JABBER_FEAT_COMMANDS);
- resultQuery << XCHILD(_T("feature")) << XATTR(_T("var"), JABBER_FEAT_DATA_FORMS);
- resultQuery << XCHILD(_T("feature")) << XATTR(_T("var"), JABBER_FEAT_DISCO_INFO);
+ XmlNodeIq iq(_T("result"), pInfo);
+ HXML resultQuery = iq << XQUERY(JABBER_FEAT_DISCO_INFO) << XATTR(_T("node"), JABBER_FEAT_DISCO_INFO);
+ resultQuery << XCHILD(_T("identity")) << XATTR(_T("name"), pNode->GetName())
+ << XATTR(_T("category"), _T("automation")) << XATTR(_T("type"), _T("command-node"));
- Unlock();
- m_pProto->m_ThreadInfo->send(iq);
- return TRUE;
- }
- Unlock();
- return FALSE;
+ resultQuery << XCHILD(_T("feature")) << XATTR(_T("var"), JABBER_FEAT_COMMANDS);
+ resultQuery << XCHILD(_T("feature")) << XATTR(_T("var"), JABBER_FEAT_DATA_FORMS);
+ resultQuery << XCHILD(_T("feature")) << XATTR(_T("var"), JABBER_FEAT_DISCO_INFO);
+ lck.unlock();
+ m_pProto->m_ThreadInfo->send(iq);
+ return TRUE;
}
BOOL CJabberAdhocManager::HandleCommandRequest(HXML iqNode, CJabberIqInfo *pInfo, const TCHAR *szNode)
@@ -142,10 +141,10 @@ BOOL CJabberAdhocManager::HandleCommandRequest(HXML iqNode, CJabberIqInfo *pInfo
HXML commandNode = pInfo->GetChildNode();
- Lock();
+ mir_cslockfull lck(m_cs);
CJabberAdhocNode* pNode = FindNode(szNode);
if (!pNode) {
- Unlock();
+ lck.unlock();
m_pProto->m_ThreadInfo->send(
XmlNodeIq(_T("error"), pInfo)
@@ -161,7 +160,7 @@ BOOL CJabberAdhocManager::HandleCommandRequest(HXML iqNode, CJabberIqInfo *pInfo
if (szSessionId) {
pSession = FindSession(szSessionId);
if (!pSession) {
- Unlock();
+ lck.unlock();
XmlNodeIq iq(_T("error"), pInfo);
HXML errorNode = iq << XCHILD(_T("error")) << XATTR(_T("type"), _T("modify"));
@@ -175,7 +174,7 @@ BOOL CJabberAdhocManager::HandleCommandRequest(HXML iqNode, CJabberIqInfo *pInfo
pSession = AddNewSession();
if (!pSession) {
- Unlock();
+ lck.unlock();
m_pProto->m_ThreadInfo->send(
XmlNodeIq(_T("error"), pInfo)
@@ -213,7 +212,7 @@ BOOL CJabberAdhocManager::HandleCommandRequest(HXML iqNode, CJabberIqInfo *pInfo
RemoveSession(pSession);
pSession = NULL;
}
- Unlock();
+
return TRUE;
}
diff --git a/protocols/JabberG/src/jabber_rc.h b/protocols/JabberG/src/jabber_rc.h
index 526598a5d6..806b42839f 100644
--- a/protocols/JabberG/src/jabber_rc.h
+++ b/protocols/JabberG/src/jabber_rc.h
@@ -163,7 +163,7 @@ protected:
CJabberProto *m_pProto;
CJabberAdhocNode* m_pNodes;
CJabberAdhocSession* m_pSessions;
- CRITICAL_SECTION m_cs;
+ mir_cs m_cs;
CJabberAdhocSession* FindSession(const TCHAR *szSession)
{
@@ -253,26 +253,16 @@ protected:
public:
CJabberAdhocManager(CJabberProto* pProto)
{
- ZeroMemory(this, sizeof(CJabberAdhocManager));
m_pProto = pProto;
- InitializeCriticalSection(&m_cs);
+ m_pNodes = NULL;
+ m_pSessions = NULL;
}
~CJabberAdhocManager()
{
- if (m_pNodes)
- delete m_pNodes;
- if (m_pSessions)
- delete m_pSessions;
- DeleteCriticalSection(&m_cs);
- }
- void Lock()
- {
- EnterCriticalSection(&m_cs);
- }
- void Unlock()
- {
- LeaveCriticalSection(&m_cs);
+ delete m_pNodes;
+ delete m_pSessions;
}
+
BOOL FillDefaultNodes();
BOOL AddNode(TCHAR* szJid, TCHAR* szNode, TCHAR* szName, JABBER_ADHOC_HANDLER pHandler)
{
@@ -280,7 +270,7 @@ public:
if (!pNode)
return FALSE;
- Lock();
+ mir_cslock lck(m_cs);
if (!m_pNodes)
m_pNodes = pNode;
else {
@@ -289,24 +279,24 @@ public:
pTmp = pTmp->GetNext();
pTmp->SetNext(pNode);
}
- Unlock();
-
return TRUE;
}
+
CJabberAdhocNode* GetFirstNode()
{
return m_pNodes;
}
+
BOOL HandleItemsRequest(HXML iqNode, CJabberIqInfo *pInfo, const TCHAR *szNode);
BOOL HandleInfoRequest(HXML iqNode, CJabberIqInfo *pInfo, const TCHAR *szNode);
BOOL HandleCommandRequest(HXML iqNode, CJabberIqInfo *pInfo, const TCHAR *szNode);
BOOL ExpireSessions()
{
- Lock();
+ mir_cslock lck(m_cs);
DWORD dwExpireTime = GetTickCount() - JABBER_ADHOC_SESSION_EXPIRE_TIME;
- while (_ExpireSession(dwExpireTime));
- Unlock();
+ while (_ExpireSession(dwExpireTime))
+ ;
return TRUE;
}
};