summaryrefslogtreecommitdiff
path: root/plugins/NewStory
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-05-13 16:09:27 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-05-13 16:09:27 +0300
commit2b30685427500c9eedac4c0c4862b32af144a90c (patch)
treea34df3dd8446a4ec9cb466ddd0632b2fcbcde448 /plugins/NewStory
parente27e90cf6167d5d23a4458ae99479df6135a16b2 (diff)
kinda first working version of database event cursors
Diffstat (limited to 'plugins/NewStory')
-rw-r--r--plugins/NewStory/src/history.cpp86
1 files changed, 44 insertions, 42 deletions
diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp
index cee9ad0dd4..16653b3683 100644
--- a/plugins/NewStory/src/history.cpp
+++ b/plugins/NewStory/src/history.cpp
@@ -711,58 +711,60 @@ public:
SetFilePointer(hFile, -3, nullptr, FILE_CURRENT);
// export events
- MEVENT hDbEvent = db_event_first(m_hContact);
bool bAppendOnly = false;
- while (hDbEvent != NULL) {
- DBEVENTINFO dbei = {};
- int nSize = db_event_getBlobSize(hDbEvent);
- if (nSize > 0) {
- dbei.cbBlob = nSize;
- dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob + 2);
- dbei.pBlob[dbei.cbBlob] = 0;
- dbei.pBlob[dbei.cbBlob + 1] = 0;
- // Double null terminate, this should prevent most errors
- // where the blob received has an invalid format
- }
-
- if (!db_event_get(hDbEvent, &dbei)) {
- if (bAppendOnly) {
- SetFilePointer(hFile, -3, nullptr, FILE_END);
- WriteFile(hFile, ",", 1, &dwBytesWritten, nullptr);
+ if (auto *pCursor = DB::Events(m_hContact)) {
+ while (MEVENT hDbEvent = pCursor->FetchNext()) {
+ DBEVENTINFO dbei = {};
+ int nSize = db_event_getBlobSize(hDbEvent);
+ if (nSize > 0) {
+ dbei.cbBlob = nSize;
+ dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob + 2);
+ dbei.pBlob[dbei.cbBlob] = 0;
+ dbei.pBlob[dbei.cbBlob + 1] = 0;
+ // Double null terminate, this should prevent most errors
+ // where the blob received has an invalid format
}
- JSONNode pRoot2;
- pRoot2.push_back(JSONNode("type", dbei.eventType));
- if (mir_strcmp(dbei.szModule, proto))
- pRoot2.push_back(JSONNode("module", dbei.szModule));
+ if (!db_event_get(hDbEvent, &dbei)) {
+ if (bAppendOnly) {
+ SetFilePointer(hFile, -3, nullptr, FILE_END);
+ WriteFile(hFile, ",", 1, &dwBytesWritten, nullptr);
+ }
- pRoot2.push_back(JSONNode("timestamp", dbei.timestamp));
+ JSONNode pRoot2;
+ pRoot2.push_back(JSONNode("type", dbei.eventType));
- wchar_t szTemp[500];
- TimeZone_PrintTimeStamp(UTC_TIME_HANDLE, dbei.timestamp, L"I", szTemp, _countof(szTemp), 0);
- pRoot2.push_back(JSONNode("isotime", T2Utf(szTemp).get()));
+ if (mir_strcmp(dbei.szModule, proto))
+ pRoot2.push_back(JSONNode("module", dbei.szModule));
- std::string flags;
- if (dbei.flags & DBEF_SENT)
- flags += "m";
- if (dbei.flags & DBEF_READ)
- flags += "r";
- pRoot2.push_back(JSONNode("flags", flags));
+ pRoot2.push_back(JSONNode("timestamp", dbei.timestamp));
- ptrW msg(DbEvent_GetTextW(&dbei, CP_ACP));
- if (msg)
- pRoot2.push_back(JSONNode("body", T2Utf(msg).get()));
+ wchar_t szTemp[500];
+ TimeZone_PrintTimeStamp(UTC_TIME_HANDLE, dbei.timestamp, L"I", szTemp, _countof(szTemp), 0);
+ pRoot2.push_back(JSONNode("isotime", T2Utf(szTemp).get()));
- output = pRoot2.write_formatted();
- output += "\n]}";
+ std::string flags;
+ if (dbei.flags & DBEF_SENT)
+ flags += "m";
+ if (dbei.flags & DBEF_READ)
+ flags += "r";
+ pRoot2.push_back(JSONNode("flags", flags));
- WriteFile(hFile, output.c_str(), (int)output.size(), &dwBytesWritten, nullptr);
- if (dbei.pBlob)
- mir_free(dbei.pBlob);
- }
+ ptrW msg(DbEvent_GetTextW(&dbei, CP_ACP));
+ if (msg)
+ pRoot2.push_back(JSONNode("body", T2Utf(msg).get()));
- bAppendOnly = true;
- hDbEvent = db_event_next(m_hContact, hDbEvent);
+ output = pRoot2.write_formatted();
+ output += "\n]}";
+
+ WriteFile(hFile, output.c_str(), (int)output.size(), &dwBytesWritten, nullptr);
+ if (dbei.pBlob)
+ mir_free(dbei.pBlob);
+ }
+
+ bAppendOnly = true;
+ }
+ delete pCursor;
}
// Close the file