summaryrefslogtreecommitdiff
path: root/plugins/HistoryStats/src/mirandacontact.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/HistoryStats/src/mirandacontact.cpp')
-rw-r--r--plugins/HistoryStats/src/mirandacontact.cpp166
1 files changed, 62 insertions, 104 deletions
diff --git a/plugins/HistoryStats/src/mirandacontact.cpp b/plugins/HistoryStats/src/mirandacontact.cpp
index 367a36fb4e..ee967f1065 100644
--- a/plugins/HistoryStats/src/mirandacontact.cpp
+++ b/plugins/HistoryStats/src/mirandacontact.cpp
@@ -14,12 +14,10 @@ void MirandaContact::fetchSlot(int i)
{
ContactInfo& ci = m_CIs[i];
- if (!ci.hEvent)
- {
+ if (!ci.hEvent) {
free(ci.ei.dbe.pBlob);
m_CIs.erase(m_CIs.begin() + i);
-
return;
}
@@ -29,8 +27,7 @@ void MirandaContact::fetchSlot(int i)
ei.dbe.cbBlob = db_event_getBlobSize(ci.hEvent);
ei.dbe.cbSize = sizeof(ei.dbe);
- if (ei.dbe.cbBlob > ei.nAllocated)
- {
+ if (ei.dbe.cbBlob > ei.nAllocated) {
ei.nAllocated = ei.dbe.cbBlob;
ei.dbe.pBlob = reinterpret_cast<PBYTE>(realloc(ei.dbe.pBlob, ei.dbe.cbBlob + 1));
}
@@ -44,39 +41,32 @@ void MirandaContact::fetchSlot(int i)
void MirandaContact::stripMetaID(DBEVENTINFO& dbe)
{
- if (dbe.szModule == META_PROTO)
- {
- mu_ansi* pTextBegin = reinterpret_cast<mu_ansi*>(dbe.pBlob);
+ if (dbe.szModule == META_PROTO) {
+ char* pTextBegin = reinterpret_cast<char*>(dbe.pBlob);
- if (dbe.cbBlob >= 6 && !pTextBegin[dbe.cbBlob - 1])
- {
- mu_ansi* pIDEnd = pTextBegin + dbe.cbBlob - 1;
- mu_ansi* pIDBegin = pIDEnd;
- mu_ansi* pIDSep = NULL;
+ if (dbe.cbBlob >= 6 && !pTextBegin[dbe.cbBlob - 1]) {
+ char* pIDEnd = pTextBegin + dbe.cbBlob - 1;
+ char* pIDBegin = pIDEnd;
+ char* pIDSep = NULL;
while (pIDBegin >= pTextBegin + 2 && *--pIDBegin)
- {
- if (*pIDBegin == muC('*'))
- {
+ if (*pIDBegin == '*')
pIDSep = pIDBegin;
- }
- }
++pIDBegin;
- if (pIDSep && pIDBegin < pIDSep && !*(pIDBegin - 1))
- {
+ if (pIDSep && pIDBegin < pIDSep && !*(pIDBegin - 1)) {
dbe.cbBlob = pIDBegin - pTextBegin;
}
}
}
}
-MirandaContact::MirandaContact(const ext::string& strNick, const ext::string& strProtocol, const ext::string& strGroup, const SourceHandles& sources)
- : m_strNick(strNick)
- , m_strProtocol(strProtocol)
- , m_strGroup(strGroup)
- , m_Sources(sources)
+MirandaContact::MirandaContact(const ext::string& strNick, const ext::string& strProtocol, const ext::string& strGroup, const SourceHandles& sources) :
+ m_strNick(strNick),
+ m_strProtocol(strProtocol),
+ m_strGroup(strGroup),
+ m_Sources(sources)
{
}
@@ -88,19 +78,13 @@ MirandaContact::~MirandaContact()
void MirandaContact::merge(const MirandaContact& other)
{
if (m_strNick != other.m_strNick)
- {
- m_strNick = i18n(muT("(multiple)"));
- }
+ m_strNick = TranslateT("(multiple)");
if (m_strProtocol != other.m_strProtocol)
- {
- m_strProtocol = i18n(muT("(multiple)"));
- }
+ m_strProtocol = TranslateT("(multiple)");
if (m_strGroup != other.m_strGroup)
- {
- m_strGroup = i18n(muT("(multiple)"));
- }
+ m_strGroup = TranslateT("(multiple)");
citer_each_(SourceHandles, i, other.m_Sources)
{
@@ -116,8 +100,7 @@ void MirandaContact::beginRead()
// allocate required data
m_CIs.resize(m_Sources.size());
- for (int j = m_Sources.size() - 1; j >= 0; --j)
- {
+ for (int j = m_Sources.size() - 1; j >= 0; --j) {
ContactInfo& ci = m_CIs[j];
ci.hContact = m_Sources[j];
@@ -134,9 +117,8 @@ void MirandaContact::beginRead()
void MirandaContact::endRead()
{
#if defined(_DEBUG)
- if (m_CIs.size() + m_EIs.size() + m_SpareEIs.size() > 0)
- {
- ext::string strLog = ext::str(ext::format(muT("Freeing | CIs and |+| EIs...\n")) % m_CIs.size() % m_EIs.size() % m_SpareEIs.size());
+ if (m_CIs.size() + m_EIs.size() + m_SpareEIs.size() > 0) {
+ ext::string strLog = ext::str(ext::format(_T("Freeing | CIs and |+| EIs...\n")) % m_CIs.size() % m_EIs.size() % m_SpareEIs.size());
OutputDebugString(strLog.c_str());
}
@@ -164,8 +146,7 @@ void MirandaContact::endRead()
void MirandaContact::readNext()
{
- if (!m_EIs.empty())
- {
+ if (!m_EIs.empty()) {
m_SpareEIs.push_back(m_EIs.front());
m_EIs.pop_front();
}
@@ -182,16 +163,13 @@ void MirandaContactTolerantMerge::fillQueue()
// assume that items with +/- 30 seconds may be equal
static const int timestampTol = 30;
- while (!m_CIs.empty() && (m_EIs.size() < 2 || (m_EIs.back().dbe.timestamp - m_EIs.front().dbe.timestamp) <= timestampTol))
- {
+ while (!m_CIs.empty() && (m_EIs.size() < 2 || (m_EIs.back().dbe.timestamp - m_EIs.front().dbe.timestamp) <= timestampTol)) {
// find oldest next event in chains
int nNext = 0;
DWORD timestampFirst = m_CIs.front().ei.dbe.timestamp;
- for (int i = 1; i < m_CIs.size(); ++i)
- {
- if (m_CIs[i].ei.dbe.timestamp < timestampFirst)
- {
+ for (int i = 1; i < m_CIs.size(); ++i) {
+ if (m_CIs[i].ei.dbe.timestamp < timestampFirst) {
timestampFirst = m_CIs[i].ei.dbe.timestamp;
nNext = i;
}
@@ -199,7 +177,7 @@ void MirandaContactTolerantMerge::fillQueue()
// insert the fetched at correct position or throw away if duplicate
ContactInfo& ci = m_CIs[nNext];
-
+
std::list<EventInfo>::iterator insPos = m_EIs.end();
bool bIsDuplicate = false;
@@ -208,35 +186,30 @@ void MirandaContactTolerantMerge::fillQueue()
EventInfo& j_ei = *j;
int timestampDelta = j_ei.dbe.timestamp - ci.ei.dbe.timestamp;
- if (timestampDelta > 0)
- {
+ if (timestampDelta > 0) {
insPos = j;
}
if (j_ei.hContact != ci.ei.hContact &&
- timestampDelta >= -timestampTol && timestampDelta <= timestampTol &&
- j_ei.dbe.eventType == ci.ei.dbe.eventType &&
- (j_ei.dbe.flags & ~(DBEF_FIRST | DBEF_READ)) == (ci.ei.dbe.flags & ~(DBEF_FIRST | DBEF_READ)) &&
- j_ei.dbe.cbBlob == ci.ei.dbe.cbBlob &&
- memcmp(j_ei.dbe.pBlob, ci.ei.dbe.pBlob, j_ei.dbe.cbBlob) == 0)
- {
+ timestampDelta >= -timestampTol && timestampDelta <= timestampTol &&
+ j_ei.dbe.eventType == ci.ei.dbe.eventType &&
+ (j_ei.dbe.flags & ~(DBEF_FIRST | DBEF_READ)) == (ci.ei.dbe.flags & ~(DBEF_FIRST | DBEF_READ)) &&
+ j_ei.dbe.cbBlob == ci.ei.dbe.cbBlob &&
+ memcmp(j_ei.dbe.pBlob, ci.ei.dbe.pBlob, j_ei.dbe.cbBlob) == 0) {
bIsDuplicate = true;
break;
}
}
- if (!bIsDuplicate)
- {
+ if (!bIsDuplicate) {
m_EIs.insert(insPos, ci.ei);
- if (!m_SpareEIs.empty())
- {
+ if (!m_SpareEIs.empty()) {
ci.ei = m_SpareEIs.front();
m_SpareEIs.pop_front();
}
- else
- {
+ else {
ci.ei.dbe.pBlob = NULL;
ci.ei.nAllocated = 0;
}
@@ -255,16 +228,13 @@ void MirandaContactStrictMerge::fillQueue()
// assume that items with +/- 30 seconds may be equal
static const int timestampTol = 0;
- while (!m_CIs.empty() && (m_EIs.size() < 2 || (m_EIs.back().dbe.timestamp - m_EIs.front().dbe.timestamp) <= timestampTol))
- {
+ while (!m_CIs.empty() && (m_EIs.size() < 2 || (m_EIs.back().dbe.timestamp - m_EIs.front().dbe.timestamp) <= timestampTol)) {
// find oldest next event in chains
int nNext = 0;
DWORD timestampFirst = m_CIs.front().ei.dbe.timestamp;
- for (int i = 1; i < m_CIs.size(); ++i)
- {
- if (m_CIs[i].ei.dbe.timestamp < timestampFirst)
- {
+ for (int i = 1; i < m_CIs.size(); ++i) {
+ if (m_CIs[i].ei.dbe.timestamp < timestampFirst) {
timestampFirst = m_CIs[i].ei.dbe.timestamp;
nNext = i;
}
@@ -272,7 +242,7 @@ void MirandaContactStrictMerge::fillQueue()
// insert the fetched at correct position or throw away if duplicate
ContactInfo& ci = m_CIs[nNext];
-
+
std::list<EventInfo>::iterator insPos = m_EIs.end();
bool bIsDuplicate = false;
@@ -282,34 +252,28 @@ void MirandaContactStrictMerge::fillQueue()
int timestampDelta = j_ei.dbe.timestamp - ci.ei.dbe.timestamp;
if (timestampDelta > 0)
- {
insPos = j;
- }
if (j_ei.hContact != ci.ei.hContact &&
- timestampDelta >= -timestampTol && timestampDelta <= timestampTol &&
- j_ei.dbe.eventType == ci.ei.dbe.eventType &&
- (j_ei.dbe.flags & ~(DBEF_FIRST | DBEF_READ)) == (ci.ei.dbe.flags & ~(DBEF_FIRST | DBEF_READ)) &&
- j_ei.dbe.cbBlob == ci.ei.dbe.cbBlob &&
- memcmp(j_ei.dbe.pBlob, ci.ei.dbe.pBlob, j_ei.dbe.cbBlob) == 0)
- {
+ timestampDelta >= -timestampTol && timestampDelta <= timestampTol &&
+ j_ei.dbe.eventType == ci.ei.dbe.eventType &&
+ (j_ei.dbe.flags & ~(DBEF_FIRST | DBEF_READ)) == (ci.ei.dbe.flags & ~(DBEF_FIRST | DBEF_READ)) &&
+ j_ei.dbe.cbBlob == ci.ei.dbe.cbBlob &&
+ memcmp(j_ei.dbe.pBlob, ci.ei.dbe.pBlob, j_ei.dbe.cbBlob) == 0) {
bIsDuplicate = true;
break;
}
}
- if (!bIsDuplicate)
- {
+ if (!bIsDuplicate) {
m_EIs.insert(insPos, ci.ei);
- if (!m_SpareEIs.empty())
- {
+ if (!m_SpareEIs.empty()) {
ci.ei = m_SpareEIs.front();
m_SpareEIs.pop_front();
}
- else
- {
+ else {
ci.ei.dbe.pBlob = NULL;
ci.ei.nAllocated = 0;
}
@@ -325,16 +289,13 @@ void MirandaContactStrictMerge::fillQueue()
void MirandaContactNoMerge::fillQueue()
{
- while (!m_CIs.empty() && m_EIs.size() < 1)
- {
+ while (!m_CIs.empty() && m_EIs.size() < 1) {
// find oldest next event in chains
int nNext = 0;
DWORD timestampFirst = m_CIs.front().ei.dbe.timestamp;
- for (int i = 1; i < m_CIs.size(); ++i)
- {
- if (m_CIs[i].ei.dbe.timestamp < timestampFirst)
- {
+ for (int i = 1; i < m_CIs.size(); ++i) {
+ if (m_CIs[i].ei.dbe.timestamp < timestampFirst) {
timestampFirst = m_CIs[i].ei.dbe.timestamp;
nNext = i;
}
@@ -342,16 +303,14 @@ void MirandaContactNoMerge::fillQueue()
// insert the fetched at correct position or throw away if duplicate
ContactInfo& ci = m_CIs[nNext];
-
+
m_EIs.push_back(ci.ei);
- if (!m_SpareEIs.empty())
- {
+ if (!m_SpareEIs.empty()) {
ci.ei = m_SpareEIs.front();
m_SpareEIs.pop_front();
}
- else
- {
+ else {
ci.ei.dbe.pBlob = NULL;
ci.ei.nAllocated = 0;
}
@@ -366,18 +325,17 @@ void MirandaContactNoMerge::fillQueue()
MirandaContact* MirandaContactFactory::makeMirandaContact(int MergeMode, const ext::string& strNick, const ext::string& strProtocol, const ext::string& strGroup, const MirandaContact::SourceHandles& sources)
{
- switch (MergeMode)
- {
- case Settings::mmTolerantMerge:
- return new MirandaContactTolerantMerge(strNick, strProtocol, strGroup, sources);
+ switch (MergeMode) {
+ case Settings::mmTolerantMerge:
+ return new MirandaContactTolerantMerge(strNick, strProtocol, strGroup, sources);
- case Settings::mmStrictMerge:
- return new MirandaContactStrictMerge(strNick, strProtocol, strGroup, sources);
+ case Settings::mmStrictMerge:
+ return new MirandaContactStrictMerge(strNick, strProtocol, strGroup, sources);
- case Settings::mmNoMerge:
- return new MirandaContactNoMerge(strNick, strProtocol, strGroup, sources);
+ case Settings::mmNoMerge:
+ return new MirandaContactNoMerge(strNick, strProtocol, strGroup, sources);
- default:
- return 0;
+ default:
+ return 0;
}
}