summaryrefslogtreecommitdiff
path: root/include/m_db_int.h
blob: 2fd70ceec58c00f5e7f9a9d94dd5818572408faf (plain)
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
/*

Miranda NG: the free IM client for Microsoft* Windows*

Copyright 2012 Miranda NG project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.

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.
*/

#ifndef M_DB_INT_H__
#define M_DB_INT_H__ 1

#ifndef M_CORE_H__
	#include <m_core.h>
#endif

interface MIDatabase
{
	STDMETHOD_(void,SetCacheSafetyMode)(BOOL) PURE;

	STDMETHOD_(LONG,GetContactCount)(void) PURE;
	STDMETHOD_(HANDLE,FindFirstContact)(const char* szProto = NULL) PURE;
	STDMETHOD_(HANDLE,FindNextContact)(HANDLE hContact, const char* szProto = NULL) PURE;

	STDMETHOD_(LONG,DeleteContact)(HANDLE hContact) PURE;
	STDMETHOD_(HANDLE,AddContact)(void) PURE;
	STDMETHOD_(BOOL,IsDbContact)(HANDLE hContact) PURE;

	STDMETHOD_(LONG,GetEventCount)(HANDLE hContact) PURE;
	STDMETHOD_(HANDLE,AddEvent)(HANDLE hContact, DBEVENTINFO *dbe) PURE;
	STDMETHOD_(BOOL,DeleteEvent)(HANDLE hContact, HANDLE hDbEvent) PURE;
	STDMETHOD_(LONG,GetBlobSize)(HANDLE hDbEvent) PURE;
	STDMETHOD_(BOOL,GetEvent)(HANDLE hDbEvent, DBEVENTINFO *dbe) PURE;
	STDMETHOD_(BOOL,MarkEventRead)(HANDLE hContact, HANDLE hDbEvent) PURE;
	STDMETHOD_(HANDLE,GetEventContact)(HANDLE hDbEvent) PURE;
	STDMETHOD_(HANDLE,FindFirstEvent)(HANDLE hContact) PURE;
	STDMETHOD_(HANDLE,FindFirstUnreadEvent)(HANDLE hContact) PURE;
	STDMETHOD_(HANDLE,FindLastEvent)(HANDLE hContact) PURE;
	STDMETHOD_(HANDLE,FindNextEvent)(HANDLE hDbEvent) PURE;
	STDMETHOD_(HANDLE,FindPrevEvent)(HANDLE hDbEvent) PURE;

	STDMETHOD_(BOOL,EnumModuleNames)(DBMODULEENUMPROC pFunc, void *pParam) PURE;

	STDMETHOD_(BOOL,GetContactSetting)(HANDLE hContact, DBCONTACTGETSETTING *dbcgs) PURE;
	STDMETHOD_(BOOL,GetContactSettingStr)(HANDLE hContact, DBCONTACTGETSETTING *dbcgs) PURE;
	STDMETHOD_(BOOL,GetContactSettingStatic)(HANDLE hContact, DBCONTACTGETSETTING *dbcgs) PURE;
	STDMETHOD_(BOOL,FreeVariant)(DBVARIANT *dbv) PURE;
	STDMETHOD_(BOOL,WriteContactSetting)(HANDLE hContact, DBCONTACTWRITESETTING *dbcws) PURE;
	STDMETHOD_(BOOL,DeleteContactSetting)(HANDLE hContact, DBCONTACTGETSETTING *dbcgs) PURE;
	STDMETHOD_(BOOL,EnumContactSettings)(HANDLE hContact, DBCONTACTENUMSETTINGS* dbces) PURE;
	STDMETHOD_(BOOL,SetSettingResident)(BOOL bIsResident, const char *pszSettingName) PURE;
	STDMETHOD_(BOOL,EnumResidentSettings)(DBMODULEENUMPROC pFunc, void *pParam) PURE;
};

///////////////////////////////////////////////////////////////////////////////
// Each database plugin should register itself using this structure

struct DATABASELINK
{
	int cbSize;
	char* szShortName;  // uniqie short database name
	TCHAR* szFullName;  // in English, auto-translated by the core

	/*
		profile: pointer to a string which contains full path + name
		Affect: The database plugin should create the profile, the filepath will not exist at
			the time of this call, profile will be C:\..\<name>.dat
		Returns: 0 on success, non zero on failure - error contains extended error information, see EMKPRF_*
	*/
	int (*makeDatabase)(const TCHAR *profile, int *error);

	/*
		profile: [in] a null terminated string to file path of selected profile
		error: [in/out] pointer to an int to set with error if any
		Affect: Ask the database plugin if it supports the given profile, if it does it will
			return 0, if it doesnt return 1, with the error set in error -- EGROKPRF_* can be valid error
			condition, most common error would be [EGROKPRF_UNKHEADER]
		Note: Just because 1 is returned, doesnt mean the profile is not supported, the profile might be damaged
			etc.
		Returns: 0 on success, non zero on failure
	*/
	int (*grokHeader)(const TCHAR *profile, int * error);

	/*
	Affect: Tell the database to create all services/hooks that a 3.xx legecy database might support into link,
		which is a PLUGINLINK structure
	Returns: 0 on success, nonzero on failure
	*/
	MIDatabase* (*Load) (const TCHAR *profile);

	/*
	Affect: The database plugin should shutdown, unloading things from the core and freeing internal structures
	Returns: 0 on success, nonzero on failure
	Note: Unload() might be called even if Load(void) was never called, wasLoaded is set to 1 if Load(void) was ever called.
	*/
	int (*Unload)(MIDatabase*);
};

///////////////////////////////////////////////////////////////////////////////
// Database list's services

// MS_DB_REGISTER_PLUGIN : registers a database plugin
// wParam : 0 (unused)
// lParam : DATABASELINK* = database link description

#define MS_DB_REGISTER_PLUGIN "DB/RegisterPlugin"

__inline static void RegisterDatabasePlugin(DATABASELINK* pDescr)
{	CallService(MS_DB_REGISTER_PLUGIN, 0, (LPARAM)pDescr);
}

// MS_DB_FIND_PLUGIN : looks for a database plugin suitable to open this file
// wParam : 0 (unused)
// lParam : const TCHAR* = name of the database file
// returns DATABASELINK* of the required plugin or NULL on error

#define MS_DB_FIND_PLUGIN "DB/FindPlugin"

__inline static DATABASELINK* FindDatabasePlugin(const TCHAR* ptszFileName)
{	return (DATABASELINK*)CallService(MS_DB_FIND_PLUGIN, 0, (LPARAM)ptszFileName);
}

#endif // M_DB_INT_H__