From 109877a3c75cb290c55755dcfc88794d2453669d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 30 Mar 2013 17:32:39 +0000 Subject: MS_DB_EVENT_* services remained, but their calls removed git-svn-id: http://svn.miranda-ng.org/main/trunk@4255 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- .../src/ex_import/classExImContactXML.cpp | 100 +++++++++------------ plugins/UserInfoEx/src/mir_db.cpp | 75 +++------------- plugins/UserInfoEx/src/mir_db.h | 4 - 3 files changed, 54 insertions(+), 125 deletions(-) (limited to 'plugins/UserInfoEx') diff --git a/plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp b/plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp index 1fe64c96bf..6ec7ac7bdd 100644 --- a/plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp +++ b/plugins/UserInfoEx/src/ex_import/classExImContactXML.cpp @@ -460,32 +460,25 @@ int CExImContactXML::ExportSetting(TiXmlElement *xmlModule, LPCSTR pszModule, LP **/ BYTE CExImContactXML::ExportEvents() { - DBEVENTINFO dbei; - HANDLE hDbEvent; PBYTE pbEventBuf = NULL; DWORD cbEventBuf = 0, - dwNumEvents = 0, dwNumEventsAdded = 0; LPSTR pBase64Data = NULL; - INT_PTR cbBase64Data = 0, - cbNewBase64Data = 0; - TiXmlNode *xmlModule = NULL; - TiXmlElement *xmlEvent = NULL; - TiXmlText *xmlText = NULL; + int dwNumEvents = db_event_count(_hContact); + if (dwNumEvents == 0) + return FALSE; - dwNumEvents = CallService(MS_DB_EVENT_GETCOUNT, (WPARAM)_hContact, NULL); - if(dwNumEvents == 0) return FALSE; + INT_PTR cbBase64Data = 0; - try { - ZeroMemory(&dbei, sizeof(DBEVENTINFO)); - dbei.cbSize = sizeof(DBEVENTINFO); + DBEVENTINFO dbei = { sizeof(DBEVENTINFO) }; + try { // read out all events for the current contact - for (hDbEvent = DB::Event::FindFirst(_hContact); hDbEvent != NULL; hDbEvent = DB::Event::FindNext(hDbEvent)) { + for (HANDLE hDbEvent = db_event_first(_hContact); hDbEvent != NULL; hDbEvent = db_event_next(hDbEvent)) { if (!DB::Event::GetInfoWithData(hDbEvent, &dbei)) { // new buffer for base64 encoded data - cbNewBase64Data = Base64EncodeGetRequiredLength(dbei.cbBlob, BASE64_FLAG_NOCRLF); + INT_PTR cbNewBase64Data = Base64EncodeGetRequiredLength(dbei.cbBlob, BASE64_FLAG_NOCRLF); if (cbNewBase64Data > cbBase64Data) { pBase64Data = (LPSTR)mir_realloc(pBase64Data, cbNewBase64Data + 5); if (pBase64Data == NULL) { @@ -498,16 +491,17 @@ BYTE CExImContactXML::ExportEvents() // encode data if (Base64Encode(dbei.pBlob, dbei.cbBlob, pBase64Data, &cbNewBase64Data, BASE64_FLAG_NOCRLF)) { pBase64Data[cbNewBase64Data] = 0; - xmlEvent = new TiXmlElement("evt"); + TiXmlElement *xmlEvent = new TiXmlElement("evt"); if (xmlEvent) { xmlEvent->SetAttribute("type", dbei.eventType); xmlEvent->SetAttribute("time", dbei.timestamp); xmlEvent->SetAttribute("flag", dbei.flags); - xmlText = new TiXmlText(pBase64Data); + TiXmlText *xmlText = new TiXmlText(pBase64Data); xmlEvent->LinkEndChild(xmlText); // find module + TiXmlNode *xmlModule; for (xmlModule = _xmlNode->FirstChild(); xmlModule != NULL; xmlModule = xmlModule->NextSibling()) if (!mir_stricmp(((TiXmlElement*)xmlModule)->Attribute("key"), dbei.szModule)) break; @@ -515,13 +509,13 @@ BYTE CExImContactXML::ExportEvents() // create new module if (!xmlModule) { xmlModule = _xmlNode->InsertEndChild(TiXmlElement(XKEY_MOD)); - if (!xmlModule) break; + if (!xmlModule) + break; ((TiXmlElement*)xmlModule)->SetAttribute("key", dbei.szModule); } xmlModule->LinkEndChild(xmlEvent); dwNumEventsAdded++; - xmlEvent = NULL; // avoid final deleting } } MIR_FREE(dbei.pBlob); @@ -536,7 +530,6 @@ BYTE CExImContactXML::ExportEvents() mir_free(pbEventBuf); mir_free(pBase64Data); - if (xmlEvent) delete xmlEvent; return dwNumEventsAdded == dwNumEvents; } @@ -1057,16 +1050,9 @@ int CExImContactXML::ImportSetting(LPCSTR pszModule, TiXmlElement *xmlEntry) **/ int CExImContactXML::ImportEvent(LPCSTR pszModule, TiXmlElement *xmlEvent) { - DBEVENTINFO dbei; - TiXmlText *xmlValue; - LPCSTR tmp; - size_t cbSrc; - INT_PTR baselen; - // dont import events from metacontact - if (isMeta()) { + if (isMeta()) return ERROR_DUPLICATED; - } if (!xmlEvent || !pszModule || !*pszModule) return ERROR_INVALID_PARAMS; @@ -1075,48 +1061,42 @@ int CExImContactXML::ImportEvent(LPCSTR pszModule, TiXmlElement *xmlEvent) return ERROR_NOT_ADDED; // timestamp must be valid + DBEVENTINFO dbei = { sizeof(dbei) }; xmlEvent->Attribute("time", (LPINT)&dbei.timestamp); - if (dbei.timestamp == 0) return ERROR_INVALID_TIMESTAMP; + if (dbei.timestamp == 0) + return ERROR_INVALID_TIMESTAMP; - xmlValue = (TiXmlText*)xmlEvent->FirstChild(); + TiXmlText *xmlValue = (TiXmlText*)xmlEvent->FirstChild(); if (!xmlValue || xmlValue->Type() != TiXmlText::TEXT) return ERROR_INVALID_VALUE; - tmp = xmlValue->Value(); + + LPCSTR tmp = xmlValue->Value(); if (!tmp || tmp[0] == 0) return ERROR_INVALID_VALUE; - cbSrc = strlen(tmp); - baselen = Base64DecodeGetRequiredLength(cbSrc); - dbei.cbBlob = NULL; - dbei.pBlob = NULL; - dbei.pBlob = (PBYTE)mir_alloc(baselen + 1); - if (dbei.pBlob != NULL) { - if (Base64Decode(tmp, cbSrc, dbei.pBlob, &baselen)) { - INT_PTR hEvent; - - // event owning module - dbei.cbSize = sizeof(dbei); - dbei.szModule = (LPSTR)pszModule; - dbei.cbBlob = baselen; - - xmlEvent->Attribute("type", (LPINT)&dbei.eventType); - xmlEvent->Attribute("flag", (LPINT)&dbei.flags); - if (dbei.flags == 0) dbei.flags = DBEF_READ; - - // search in new and existing contact for existing event to avoid duplicates - if (/*!_isNewContact && */DB::Event::Exists(_hContact, _hEvent, &dbei)) { - mir_free(dbei.pBlob); - return ERROR_DUPLICATED; - } + size_t cbSrc = strlen(tmp); + INT_PTR baselen = Base64DecodeGetRequiredLength(cbSrc); - hEvent = CallService(MS_DB_EVENT_ADD, (WPARAM)_hContact, (LPARAM)&dbei); + dbei.pBlob = (PBYTE)_alloca(baselen+1); + if (Base64Decode(tmp, cbSrc, dbei.pBlob, &baselen)) { + // event owning module + dbei.szModule = (LPSTR)pszModule; + dbei.cbBlob = baselen; + + xmlEvent->Attribute("type", (LPINT)&dbei.eventType); + xmlEvent->Attribute("flag", (LPINT)&dbei.flags); + if (dbei.flags == 0) + dbei.flags = DBEF_READ; + + // search in new and existing contact for existing event to avoid duplicates + if (/*!_isNewContact && */DB::Event::Exists(_hContact, _hEvent, &dbei)) { mir_free(dbei.pBlob); - if (hEvent) { - _hEvent = (HANDLE)hEvent; - return ERROR_OK; - } + return ERROR_DUPLICATED; } - mir_free(dbei.pBlob); + + if ((_hEvent = db_event_add(_hContact, &dbei)) != 0) + return ERROR_OK; } + return ERROR_NOT_ADDED; } diff --git a/plugins/UserInfoEx/src/mir_db.cpp b/plugins/UserInfoEx/src/mir_db.cpp index ed1501abed..9f9d3b8ed6 100644 --- a/plugins/UserInfoEx/src/mir_db.cpp +++ b/plugins/UserInfoEx/src/mir_db.cpp @@ -181,7 +181,7 @@ DWORD WhenAdded(DWORD dwUIN, LPCSTR pszProto) ZeroMemory(&dbei, sizeof(dbei)); dbei.cbSize = sizeof(dbei); - for (edbe = DB::Event::FindFirst(NULL); edbe != NULL; edbe = DB::Event::FindNext(edbe)) { + for (edbe = db_event_first(NULL); edbe != NULL; edbe = db_event_next(edbe)) { // get eventtype and compare if (!DB::Event::GetInfo(edbe, &dbei) && dbei.eventType == EVENTTYPE_ADDED) { if (!DB::Event::GetInfoWithData(edbe, &dbei)) { @@ -1009,53 +1009,9 @@ BYTE dbv2String(DBVARIANT* dbv, const BYTE destType) namespace Event { -/** - * This function searches for the first event for the given contact. - * @param hContact - the handle of the contact to search events for - * - * @return This function returns the HANDLE of the first event for the given contact. - **/ -HANDLE FindFirst(HANDLE hContact) -{ - return (HANDLE)CallService(MS_DB_EVENT_FINDFIRST, (WPARAM)hContact, 0); -} - -/** - * This function searches for the last event for the given contact. - * @param hContact - the handle of the contact to search events for - * - * @return This function returns the HANDLE of the last event for the given contact. - **/ -HANDLE FindLast(HANDLE hContact) -{ - return (HANDLE)CallService(MS_DB_EVENT_FINDLAST, (WPARAM)hContact, 0); -} - -/** - * This function searches for the next event in the chain, which follows the given event. - * @param hEvent - the handle of the event where to continue searching - * - * @return This function returns the HANDLE of the next event in the event chain. - **/ -HANDLE FindNext(HANDLE hEvent) -{ - return (HANDLE)CallService(MS_DB_EVENT_FINDNEXT, (WPARAM)hEvent, 0); -} - -/** - * This function searches for the previous event in the chain, which follows the given event. - * @param hEvent - the handle of the event where to continue searching - * - * @return This function returns the HANDLE of the previous event in the event chain. - **/ -HANDLE FindPrev(HANDLE hEvent) -{ - return (HANDLE)CallService(MS_DB_EVENT_FINDPREV, (WPARAM)hEvent, 0); -} - /** * This function initializes the DBEVENTINFO structure and calls - * the MS_DB_EVENT_GET service to retrieve information about an event. + * db_event_get() to retrieve information about an event. * @param hEvent - the handle of the event to get information for * @param dbei - the pointer to a DBEVENTINFO structure, which retrieves all information. * @@ -1067,12 +1023,12 @@ BYTE GetInfo(HANDLE hEvent, DBEVENTINFO *dbei) dbei->cbSize = sizeof(DBEVENTINFO); dbei->cbBlob = 0; dbei->pBlob = NULL; - return CallService(MS_DB_EVENT_GET, (WPARAM)hEvent, (LPARAM)dbei) != 0; + return db_event_get(hEvent, dbei) != 0; } /** * This function initializes the DBEVENTINFO structure and calls - * the MS_DB_EVENT_GET service to retrieve information about an event. + * db_event_get() to retrieve information about an event. * @param hEvent - the handle of the event to get information for * @param dbei - the pointer to a DBEVENTINFO structure, which retrieves all information. * @@ -1081,7 +1037,6 @@ BYTE GetInfo(HANDLE hEvent, DBEVENTINFO *dbei) **/ BYTE GetInfoWithData(HANDLE hEvent, DBEVENTINFO *dbei) { - BYTE result; dbei->cbSize = sizeof(DBEVENTINFO); if (!dbei->cbBlob) { INT_PTR size = BlobSizeOf(hEvent); @@ -1093,11 +1048,9 @@ BYTE GetInfoWithData(HANDLE hEvent, DBEVENTINFO *dbei) dbei->cbBlob = 0; } } - else { - dbei->pBlob = NULL; - } + else dbei->pBlob = NULL; - result = CallService(MS_DB_EVENT_GET, (WPARAM)hEvent, (LPARAM)dbei) != 0; + BYTE result = db_event_get(hEvent, dbei) != 0; if (result && dbei->pBlob) { mir_free(dbei->pBlob); dbei->pBlob = NULL; @@ -1131,7 +1084,7 @@ DWORD TimeOf(HANDLE hEvent) **/ INT_PTR BlobSizeOf(HANDLE hEvent) { - return CallService(MS_DB_EVENT_GETBLOBSIZE, (WPARAM)hEvent, 0); + return db_event_getBlobSize(hEvent); } /** @@ -1182,7 +1135,7 @@ BYTE Exists(HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei) edbe; if (!hDbExistingEvent) { - hDbExistingEvent = FindFirst(hContact); + hDbExistingEvent = db_event_first(hContact); if (hDbExistingEvent) { if (!GetInfo(hDbExistingEvent, &edbei)) { if ((dbei->timestamp < edbei.timestamp)) { @@ -1198,10 +1151,10 @@ BYTE Exists(HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei) } } } - edbe = FindLast(hContact); - if (edbe == hDbExistingEvent) { + edbe = db_event_last(hContact); + if (edbe == hDbExistingEvent) return FALSE; - } + hDbExistingEvent = edbe; } } @@ -1209,7 +1162,7 @@ BYTE Exists(HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei) sdbe = hDbExistingEvent; for ( edbe = sdbe; edbe && !GetInfo(edbe, &edbei) && (dbei->timestamp <= edbei.timestamp); - edbe = FindPrev(edbe)) { + edbe = db_event_prev(edbe)) { hDbExistingEvent = edbe; //compare without data (faster) if ( result = IsEqual(dbei, &edbei, false)) { @@ -1224,9 +1177,9 @@ BYTE Exists(HANDLE hContact, HANDLE& hDbExistingEvent, DBEVENTINFO *dbei) } /*end for*/ if (!result) { - for ( edbe = FindNext(sdbe); + for ( edbe = db_event_next(sdbe); edbe && !GetInfo(edbe, &edbei) && (dbei->timestamp >= edbei.timestamp); - edbe = FindNext(edbe)) { + edbe = db_event_next(edbe)) { hDbExistingEvent = edbe; //compare without data (faster) if ( result = IsEqual(dbei, &edbei, false)) { diff --git a/plugins/UserInfoEx/src/mir_db.h b/plugins/UserInfoEx/src/mir_db.h index c2383fc590..5bc5504374 100644 --- a/plugins/UserInfoEx/src/mir_db.h +++ b/plugins/UserInfoEx/src/mir_db.h @@ -182,11 +182,7 @@ namespace Variant { } /* namespace Variant */ namespace Event { - - HANDLE FindFirst (HANDLE hContact); HANDLE FindLast (HANDLE hContact); - HANDLE FindNext (HANDLE hEvent); - HANDLE FindPrev (HANDLE hEvent); BYTE GetInfo (HANDLE hEvent, DBEVENTINFO *dbei); BYTE GetInfoWithData(HANDLE hEvent, DBEVENTINFO *dbei); DWORD GetTime (HANDLE hEvent); -- cgit v1.2.3