summaryrefslogtreecommitdiff
path: root/include/m_database.h
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-06-05 17:50:34 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-06-05 17:50:34 +0300
commitd7c9eb34f80f207efd47d2fc65e31aedf166c323 (patch)
tree338b9b905674dc31b1efab739dfcedeed3d8d7b3 /include/m_database.h
parentffc5a3d7550528281976745279e77ac9faba551b (diff)
major code cleaning in regard to db_event_getBlobSize & event memory allocation
Diffstat (limited to 'include/m_database.h')
-rw-r--r--include/m_database.h175
1 files changed, 95 insertions, 80 deletions
diff --git a/include/m_database.h b/include/m_database.h
index 1245c2a085..5947ce1c4f 100644
--- a/include/m_database.h
+++ b/include/m_database.h
@@ -178,7 +178,7 @@ struct DBEVENTINFO
// signed and can only do until 2038. In GMT.
DWORD flags; // combination of DBEF_* flags
WORD eventType; // module-defined event type field
- DWORD cbBlob; // size of pBlob in bytes
+ int cbBlob; // size of pBlob in bytes
PBYTE pBlob; // pointer to buffer containing module-defined event data
const char *szId; // server id
@@ -670,109 +670,124 @@ __inline DWORD DBGetContactSettingRangedDword(MCONTACT hContact, const char *szM
namespace DB
{
-/////////////////////////////////////////////////////////////////////////////////////////
-// Helper to process the auth req body
-// blob is: 0(DWORD), hContact(DWORD), nick(UTF8), firstName(UTF8), lastName(UTF8), email(UTF8), reason(UTF8)
+ /////////////////////////////////////////////////////////////////////////////////////////
+ // Helper to free event contents automatically
-#pragma warning(disable : 4251)
+ struct EventInfo : public DBEVENTINFO
+ {
+ __forceinline explicit EventInfo()
+ {
+ memset(this, 0, sizeof(*this));
+ }
+
+ __forceinline ~EventInfo()
+ {
+ mir_free(pBlob);
+ }
+ };
-class MIR_APP_EXPORT AUTH_BLOB
-{
- MCONTACT m_hContact;
- DWORD m_dwUin;
- ptrA m_szNick, m_szFirstName, m_szLastName, m_szEmail, m_szReason;
- DWORD m_size;
+ /////////////////////////////////////////////////////////////////////////////////////////
+ // Helper to process the auth req body
+ // blob is: 0(DWORD), hContact(DWORD), nick(UTF8), firstName(UTF8), lastName(UTF8), email(UTF8), reason(UTF8)
- PBYTE makeBlob();
+ #pragma warning(disable : 4251)
-public:
- explicit AUTH_BLOB(MCONTACT hContact, const char *nick, const char *fname, const char *lname, const char *id, const char *reason);
- explicit AUTH_BLOB(PBYTE blob);
- ~AUTH_BLOB();
+ class MIR_APP_EXPORT AUTH_BLOB
+ {
+ MCONTACT m_hContact;
+ DWORD m_dwUin;
+ ptrA m_szNick, m_szFirstName, m_szLastName, m_szEmail, m_szReason;
+ DWORD m_size;
- __forceinline operator char*() { return (char*)makeBlob(); }
- __forceinline operator BYTE*() { return makeBlob(); }
+ PBYTE makeBlob();
- __forceinline DWORD size() const { return m_size; }
+ public:
+ explicit AUTH_BLOB(MCONTACT hContact, const char *nick, const char *fname, const char *lname, const char *id, const char *reason);
+ explicit AUTH_BLOB(PBYTE blob);
+ ~AUTH_BLOB();
- __forceinline MCONTACT get_contact() const { return m_hContact; }
- __forceinline const char* get_nick() const { return m_szNick; }
- __forceinline const char* get_firstName() const { return m_szFirstName; }
- __forceinline const char* get_lastName() const { return m_szLastName; }
- __forceinline const char* get_email() const { return m_szEmail; }
- __forceinline const char* get_reason() const { return m_szReason; }
-
- __forceinline DWORD get_uin() const { return m_dwUin; }
- __forceinline void set_uin(DWORD dwValue) { m_dwUin = dwValue; }
-};
+ __forceinline operator char*() { return (char*)makeBlob(); }
+ __forceinline operator BYTE*() { return makeBlob(); }
-/////////////////////////////////////////////////////////////////////////////////////////
-// Event cursors
+ __forceinline DWORD size() const { return m_size; }
-class MIR_CORE_EXPORT EventCursor : public MZeroedObject
-{
- friend class EventIterator;
+ __forceinline MCONTACT get_contact() const { return m_hContact; }
+ __forceinline const char* get_nick() const { return m_szNick; }
+ __forceinline const char* get_firstName() const { return m_szFirstName; }
+ __forceinline const char* get_lastName() const { return m_szLastName; }
+ __forceinline const char* get_email() const { return m_szEmail; }
+ __forceinline const char* get_reason() const { return m_szReason; }
+
+ __forceinline DWORD get_uin() const { return m_dwUin; }
+ __forceinline void set_uin(DWORD dwValue) { m_dwUin = dwValue; }
+ };
-protected:
- MCONTACT hContact;
+ /////////////////////////////////////////////////////////////////////////////////////////
+ // Event cursors
-public:
- EventCursor(MCONTACT _1) :
- hContact(_1)
- { }
+ class MIR_CORE_EXPORT EventCursor : public MZeroedObject
+ {
+ friend class EventIterator;
- virtual ~EventCursor();
- virtual MEVENT FetchNext() = 0;
+ protected:
+ MCONTACT hContact;
- __forceinline MEVENT begin() {
- return FetchNext();
- }
+ public:
+ EventCursor(MCONTACT _1) :
+ hContact(_1)
+ { }
- __forceinline MEVENT end() {
- return 0;
- }
-};
+ virtual ~EventCursor();
+ virtual MEVENT FetchNext() = 0;
-class MIR_CORE_EXPORT ECPTR : public MNonCopyable
-{
- EventCursor *m_cursor;
- MEVENT m_prevFetched, m_currEvent;
+ __forceinline MEVENT begin() {
+ return FetchNext();
+ }
-public:
- ECPTR(EventCursor *_1);
- ~ECPTR();
+ __forceinline MEVENT end() {
+ return 0;
+ }
+ };
- void DeleteEvent();
- MEVENT FetchNext();
-};
+ class MIR_CORE_EXPORT ECPTR : public MNonCopyable
+ {
+ EventCursor *m_cursor;
+ MEVENT m_prevFetched, m_currEvent;
-class EventIterator
-{
- EventCursor *cursor;
- MEVENT hCurr = 0;
+ public:
+ ECPTR(EventCursor *_1);
+ ~ECPTR();
-public:
- EventIterator(EventCursor *_1) :
- cursor(_1)
- {}
+ void DeleteEvent();
+ MEVENT FetchNext();
+ };
- EventIterator operator++() {
- hCurr = cursor->FetchNext();
- return *this;
- }
+ class EventIterator
+ {
+ EventCursor *cursor;
+ MEVENT hCurr = 0;
- bool operator!=(const EventIterator &p) {
- return hCurr != p.hCurr;
- }
+ public:
+ EventIterator(EventCursor *_1) :
+ cursor(_1)
+ {}
- operator MEVENT() const {
- return hCurr;
- }
-};
+ EventIterator operator++() {
+ hCurr = cursor->FetchNext();
+ return *this;
+ }
-MIR_CORE_DLL(EventCursor*) Events(MCONTACT, MEVENT iStartEvent = 0);
-MIR_CORE_DLL(EventCursor*) EventsRev(MCONTACT, MEVENT iStartEvent = 0);
+ bool operator!=(const EventIterator &p) {
+ return hCurr != p.hCurr;
+ }
+
+ operator MEVENT() const {
+ return hCurr;
+ }
+ };
+ MIR_CORE_DLL(EventCursor*) Events(MCONTACT, MEVENT iStartEvent = 0);
+ MIR_CORE_DLL(EventCursor*) EventsRev(MCONTACT, MEVENT iStartEvent = 0);
};
#endif // M_DATABASE_H__