1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
/*
Import plugin for Miranda NG
Copyright (c) 2012-18 Miranda NG team (https://miranda-ng.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
#include <memory>
#include <vector>
#define HEADER_STR "BHBF"
static int mc_makeDatabase(const wchar_t*)
{
return 1;
}
/////////////////////////////////////////////////////////////////////////////////////////
// CDbxMcontacts database driver, read-only
#pragma pack(push, 1)
struct MC_FileHeader
{
unsigned char signature[4];
unsigned char version;
unsigned char extraFlags;
unsigned short int reserved;
unsigned int codepage;
unsigned short int dataStart;
};
struct MC_MsgHeader
{
DWORD timestamp;
WORD eventType;
WORD flags;
};
#pragma pack(pop)
class CDbxMc : public MDatabaseCommon, public MZeroedObject
{
HANDLE m_hFile = INVALID_HANDLE_VALUE;
MC_FileHeader m_hdr;
std::vector<DWORD> m_events;
std::vector<DWORD>::iterator m_curr;
CMStringA readString()
{
CMStringA res;
char c;
DWORD dwRead;
while (ReadFile(m_hFile, &c, 1, &dwRead, 0)) {
if (c == 0)
break;
res.AppendChar(c);
}
return res;
}
public:
CDbxMc()
{}
~CDbxMc()
{
if (m_hFile != INVALID_HANDLE_VALUE)
::CloseHandle(m_hFile);
}
void Load()
{
MC_MsgHeader hdr;
while (true) {
DWORD dwPos = SetFilePointer(m_hFile, 0, 0, FILE_CURRENT), dwRead;
BOOL r = ReadFile(m_hFile, &hdr, sizeof(hdr), &dwRead, 0);
if (!r || dwPos < sizeof(hdr))
return;
readString();
m_events.push_back(dwPos);
}
}
int Open(const wchar_t *profile)
{
m_hFile = CreateFile(profile, GENERIC_READ, 0, 0, OPEN_ALWAYS, 0, 0);
if (m_hFile == INVALID_HANDLE_VALUE)
return EGROKPRF_CANTREAD;
DWORD dwRead;
BOOL r = ReadFile(m_hFile, &m_hdr, sizeof(m_hdr), &dwRead, nullptr);
if (!r)
return EGROKPRF_CANTREAD;
return memcmp(&m_hdr.signature, HEADER_STR, 4) ? EGROKPRF_UNKHEADER : EGROKPRF_NOERROR;
}
STDMETHODIMP_(BOOL) IsRelational(void) override { return FALSE; }
STDMETHODIMP_(void) SetCacheSafetyMode(BOOL) override {};
STDMETHODIMP_(LONG) GetContactCount(void) override
{
return 1;
}
STDMETHODIMP_(LONG) DeleteContact(MCONTACT) override { return 1; }
STDMETHODIMP_(MCONTACT) AddContact(void) override { return 0; }
STDMETHODIMP_(BOOL) IsDbContact(MCONTACT contactID) override { return contactID == 1; }
STDMETHODIMP_(LONG) GetContactSize(void) override { return sizeof(DBCachedContact); }
STDMETHODIMP_(LONG) GetEventCount(MCONTACT) override { return (LONG)m_events.size(); }
STDMETHODIMP_(MEVENT) AddEvent(MCONTACT, DBEVENTINFO*) override { return 0; }
STDMETHODIMP_(BOOL) DeleteEvent(MCONTACT, MEVENT) override { return 1; }
STDMETHODIMP_(LONG) GetBlobSize(MEVENT) override { return 0; }
STDMETHODIMP_(BOOL) GetEvent(MEVENT, DBEVENTINFO*) override { return 0; }
STDMETHODIMP_(BOOL) MarkEventRead(MCONTACT, MEVENT) override { return 1; }
STDMETHODIMP_(MCONTACT) GetEventContact(MEVENT) override { return 0; }
STDMETHODIMP_(MEVENT) FindFirstEvent(MCONTACT) override
{
m_curr = m_events.begin();
return *m_curr;
}
STDMETHODIMP_(MEVENT) FindNextEvent(MCONTACT, MEVENT) override
{
if (m_curr == m_events.end())
return 0;
++m_curr;
return *m_curr;
}
STDMETHODIMP_(MEVENT) FindLastEvent(MCONTACT) override
{
m_curr = m_events.end();
return *m_curr;
}
STDMETHODIMP_(MEVENT) FindPrevEvent(MCONTACT, MEVENT) override
{
if (m_curr == m_events.begin())
return 0;
--m_curr;
return *m_curr;
}
STDMETHODIMP_(MEVENT) FindFirstUnreadEvent(MCONTACT) override { return 0; }
STDMETHODIMP_(BOOL) EnumModuleNames(DBMODULEENUMPROC, void *) override { return 0; }
STDMETHODIMP_(BOOL) GetContactSettingWorker(MCONTACT, LPCSTR, LPCSTR, DBVARIANT*, int) override { return 1; }
STDMETHODIMP_(BOOL) WriteContactSetting(MCONTACT, DBCONTACTWRITESETTING*) override { return 1; }
STDMETHODIMP_(BOOL) DeleteContactSetting(MCONTACT, LPCSTR, LPCSTR) override { return 1; }
STDMETHODIMP_(BOOL) EnumContactSettings(MCONTACT, DBSETTINGENUMPROC, const char*, void*) override { return 1; }
STDMETHODIMP_(BOOL) MetaMergeHistory(DBCachedContact*, DBCachedContact*) override { return 1; }
STDMETHODIMP_(BOOL) MetaSplitHistory(DBCachedContact*, DBCachedContact*) override { return 1; }
};
static int mc_grokHeader(const wchar_t *profile)
{
return CDbxMc().Open(profile);
}
static MDatabaseCommon* mc_load(const wchar_t *profile, BOOL)
{
std::auto_ptr<CDbxMc> db(new CDbxMc());
if (db->Open(profile))
return nullptr;
db->Load();
return db.release();
}
static DATABASELINK dblink =
{
0,
"mcontacts",
L"mContacts file driver",
mc_makeDatabase,
mc_grokHeader,
mc_load
};
void RegisterMContacts()
{
RegisterDatabasePlugin(&dblink);
}
|