Removed "mapistore_indexing_get_tdb_wrap" as it is now useless
[jelmer/openchange.git] / mapiproxy / libmapistore / mapistore.h
1 /*
2    OpenChange Storage Abstraction Layer library
3
4    OpenChange Project
5
6    Copyright (C) Julien Kerihuel 2009-2010
7
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #ifndef __MAPISTORE_H
23 #define __MAPISTORE_H
24
25 #ifndef _GNU_SOURCE
26 #define _GNU_SOURCE
27 #endif
28
29 #ifndef _PUBLIC_
30 #define _PUBLIC_
31 #endif
32
33 #include <sys/types.h>
34 #include <sys/stat.h>
35
36 #include <stdio.h>
37 #include <unistd.h>
38 #include <stdint.h>
39 #include <stdbool.h>
40
41 #include <tdb.h>
42 #include <ldb.h>
43 #include <talloc.h>
44 #include <util/debug.h>
45
46 #include "libmapi/libmapi.h"
47
48 #define MAPISTORE_SUCCESS       0
49
50 typedef int (*init_backend_fn) (void);
51
52 #define MAPISTORE_INIT_MODULE   "mapistore_init_backend"
53
54 #define MAPISTORE_FOLDER_TABLE          1
55 #define MAPISTORE_MESSAGE_TABLE         2
56 #define MAPISTORE_FAI_TABLE             3
57 #define MAPISTORE_RULE_TABLE            4
58 #define MAPISTORE_ATTACHMENT_TABLE      5
59 #define MAPISTORE_PERMISSIONS_TABLE     6
60
61 #define MAPISTORE_FOLDER        1
62 #define MAPISTORE_MESSAGE       2
63 #define MAPISTORE_ATTACHMENT    3
64 #define MAPISTORE_TABLE         4
65
66 #define MAPISTORE_SOFT_DELETE           1
67 #define MAPISTORE_PERMANENT_DELETE      2
68
69 struct mapistore_message {
70         struct SRowSet                  *recipients;
71         struct SRow                     *properties;
72 };
73
74 struct indexing_folders_list {
75         uint64_t                        *folderID;
76         uint32_t                        count;
77 };
78
79 enum table_query_type {
80         MAPISTORE_PREFILTERED_QUERY,
81         MAPISTORE_LIVEFILTERED_QUERY,
82 };
83
84 /* proof of concept: a new structure to simplify property queries */
85 struct mapistore_property_data {
86         void *data;
87         int error; /* basically MAPISTORE_SUCCESS or MAPISTORE_ERR_NOT_FOUND */
88 };
89
90 struct mapistore_connection_info {
91         char                            *username;
92         struct GUID                     replica_guid;
93         uint16_t                        repl_id;
94         struct mapistore_context        *mstore_ctx;
95         void                            *oc_ctx;
96 };
97
98 struct tdb_wrap;
99
100 /* notes:
101    openfolder takes the folderid alone as argument
102    openmessage takes the message id and its parent folderid as arguments  */
103
104 struct mapistore_backend {
105         /** backend operations */
106         struct {
107                 const char      *name;
108                 const char      *description;
109                 const char      *namespace;
110
111                 int             (*init)(void);
112                 int             (*create_context)(TALLOC_CTX *, struct mapistore_connection_info *, struct tdb_wrap *, const char *, void **);
113         } backend;
114
115         /** context operations */
116         struct {
117                 int             (*get_path)(void *, TALLOC_CTX *, uint64_t, char **);
118                 int             (*get_root_folder)(void *, TALLOC_CTX *, uint64_t, void **);
119         } context;
120
121         /** oxcfold operations */
122         struct {
123                 int             (*open_folder)(void *, TALLOC_CTX *, uint64_t, void **);
124                 int             (*create_folder)(void *, TALLOC_CTX *, uint64_t, struct SRow *, void **);
125                 int             (*delete_folder)(void *, uint64_t);
126                 int             (*open_message)(void *, TALLOC_CTX *, uint64_t, void **, struct mapistore_message **);
127                 int             (*create_message)(void *, TALLOC_CTX *, uint64_t, uint8_t, void **);
128                 int             (*delete_message)(void *, uint64_t, uint8_t flags);
129                 int             (*get_deleted_fmids)(void *, TALLOC_CTX *, uint8_t, uint64_t, struct I8Array_r **, uint64_t *);
130                 int             (*get_child_count)(void *, uint8_t, uint32_t *);
131
132                 /* constructor: open_folder */
133                 int             (*open_table)(void *, TALLOC_CTX *, uint8_t, uint32_t, void **, uint32_t *);
134         } folder;
135
136         /** oxcmsg operations */
137         struct {
138                 int             (*modify_recipients)(void *, struct ModifyRecipientRow *, uint16_t);
139                 int             (*save)(void *);
140                 int             (*submit)(void *, enum SubmitFlags);
141                 int             (*open_attachment)(void *, TALLOC_CTX *, uint32_t, void **);
142                 int             (*create_attachment)(void *, TALLOC_CTX *, void **, uint32_t *);
143                 int             (*get_attachment_table)(void *, TALLOC_CTX *, void **, uint32_t *);
144
145                 /* attachments */
146                 int             (*open_embedded_message)(void *, TALLOC_CTX *, void **, uint64_t *, struct mapistore_message **);
147         } message;
148
149         /** oxctabl operations */
150         struct {
151                 int             (*get_available_properties)(void *, TALLOC_CTX *, struct SPropTagArray **);
152                 int             (*set_columns)(void *, uint16_t, enum MAPITAGS *);
153                 int             (*set_restrictions)(void *, struct mapi_SRestriction *, uint8_t *);
154                 int             (*set_sort_order)(void *, struct SSortOrderSet *, uint8_t *);
155                 int             (*get_row)(void *, TALLOC_CTX *, enum table_query_type, uint32_t, struct mapistore_property_data **);
156                 int             (*get_row_count)(void *, enum table_query_type, uint32_t *);
157         } table;
158
159         /** oxcprpt operations */
160         struct {
161                 int             (*get_available_properties)(void *, TALLOC_CTX *, struct SPropTagArray **);
162                 int             (*get_properties)(void *, TALLOC_CTX *, uint16_t, enum MAPITAGS *, struct mapistore_property_data *);
163                 int             (*set_properties)(void *, struct SRow *);
164         } properties;
165 };
166
167 struct indexing_context_list;
168
169 struct backend_context {
170         const struct mapistore_backend  *backend;
171         void                            *backend_object;
172         void                            *root_folder_object;
173         struct indexing_context_list    *indexing;
174         uint32_t                        context_id;
175         uint32_t                        ref_count;
176         char                            *uri;
177 };
178
179 struct backend_context_list {
180         struct backend_context          *ctx;
181         struct backend_context_list     *prev;
182         struct backend_context_list     *next;
183 };
184
185 struct processing_context;
186
187 struct mapistore_context {
188         struct processing_context               *processing_ctx;
189         struct backend_context_list             *context_list;
190         struct indexing_context_list            *indexing_list;
191         struct mapistore_subscription_list      *subscriptions;
192         struct mapistore_notification_list      *notifications;
193         struct tdb_wrap                         *replica_mapping_ctx;
194         void                                    *nprops_ctx;
195         struct mapistore_connection_info        *conn_info;
196 };
197
198 #ifndef __BEGIN_DECLS
199 #ifdef __cplusplus
200 #define __BEGIN_DECLS           extern "C" {
201 #define __END_DECLS             }
202 #else
203 #define __BEGIN_DECLS
204 #define __END_DECLS
205 #endif
206 #endif
207
208 __BEGIN_DECLS
209
210 /* definitions from mapistore_interface.c */
211
212 /* these 2 will soon disappear */
213 int mapistore_getprops(struct mapistore_context *, uint32_t, TALLOC_CTX *, uint64_t, uint8_t, struct SPropTagArray *, struct SRow *);
214 int mapistore_setprops(struct mapistore_context *, uint32_t, uint64_t, uint8_t, struct SRow *);
215
216 struct mapistore_context *mapistore_init(TALLOC_CTX *, const char *);
217 int mapistore_release(struct mapistore_context *);
218 int mapistore_add_context(struct mapistore_context *, const char *, const char *, uint64_t, uint32_t *, void **);
219 int mapistore_add_context_ref_count(struct mapistore_context *, uint32_t);
220 int mapistore_del_context(struct mapistore_context *, uint32_t);
221 int mapistore_search_context_by_uri(struct mapistore_context *, const char *, uint32_t *, void **);
222 const char *mapistore_errstr(int);
223
224 int mapistore_folder_open_folder(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, uint64_t, void **);
225 int mapistore_folder_create_folder(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, uint64_t, struct SRow *, void **);
226 int mapistore_folder_delete_folder(struct mapistore_context *, uint32_t, void *, uint64_t, uint8_t);
227 int mapistore_folder_open_message(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, uint64_t, void **, struct mapistore_message **);
228 int mapistore_folder_create_message(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, uint64_t, uint8_t, void **);
229 int mapistore_folder_delete_message(struct mapistore_context *, uint32_t, void *, uint64_t, uint8_t);
230 int mapistore_folder_get_deleted_fmids(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, uint8_t, uint64_t, struct I8Array_r **, uint64_t *);
231 int mapistore_folder_get_folder_count(struct mapistore_context *, uint32_t, void *, uint32_t *);
232 int mapistore_folder_get_message_count(struct mapistore_context *, uint32_t, void *, uint8_t, uint32_t *);
233 int mapistore_folder_get_child_fids(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, uint64_t **, uint32_t *);
234 int mapistore_folder_open_table(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, uint8_t, uint32_t, void **, uint32_t *);
235
236 int mapistore_message_modify_recipients(struct mapistore_context *, uint32_t, void *, struct ModifyRecipientRow *, uint16_t);
237 int mapistore_message_save(struct mapistore_context *, uint32_t, void *);
238 int mapistore_message_submit(struct mapistore_context *, uint32_t, void *, enum SubmitFlags);
239 int mapistore_message_open_attachment(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, uint32_t, void **);
240 int mapistore_message_create_attachment(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, void **, uint32_t *);
241 int mapistore_message_get_attachment_table(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, void **, uint32_t *);
242 int mapistore_message_attachment_open_embedded_message(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, void **, uint64_t *, struct mapistore_message **msg);
243
244 int mapistore_table_get_available_properties(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, struct SPropTagArray **);
245 int mapistore_table_set_columns(struct mapistore_context *, uint32_t, void *, uint16_t, enum MAPITAGS *);
246 int mapistore_table_set_restrictions(struct mapistore_context *, uint32_t, void *, struct mapi_SRestriction *, uint8_t *);
247 int mapistore_table_set_sort_order(struct mapistore_context *, uint32_t, void *, struct SSortOrderSet *, uint8_t *);
248 int mapistore_table_get_row(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, enum table_query_type, uint32_t, struct mapistore_property_data **);
249 int mapistore_table_get_row_count(struct mapistore_context *, uint32_t, void *, enum table_query_type, uint32_t *);
250
251 int mapistore_properties_get_available_properties(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, struct SPropTagArray **);
252 int mapistore_properties_get_properties(struct mapistore_context *, uint32_t, void *, TALLOC_CTX *, uint16_t, enum MAPITAGS *, struct mapistore_property_data *);
253 int mapistore_properties_set_properties(struct mapistore_context *, uint32_t, void *, struct SRow *);
254
255 /* definitions from mapistore_processing.c */
256 int mapistore_set_mapping_path(const char *);
257
258 /* definitions from mapistore_backend.c */
259 extern int      mapistore_backend_register(const void *);
260 const char      *mapistore_backend_get_installdir(void);
261 init_backend_fn *mapistore_backend_load(TALLOC_CTX *, const char *);
262 struct backend_context *mapistore_backend_lookup(struct backend_context_list *, uint32_t);
263 struct backend_context *mapistore_backend_lookup_by_uri(struct backend_context_list *, const char *);
264 bool            mapistore_backend_run_init(init_backend_fn *);
265
266 /* definitions from mapistore_indexing.c */
267 int mapistore_indexing_record_add_fid(struct mapistore_context *, uint32_t, uint64_t);
268 int mapistore_indexing_record_del_fid(struct mapistore_context *, uint32_t, uint64_t, uint8_t);
269 int mapistore_indexing_record_add_mid(struct mapistore_context *, uint32_t, uint64_t);
270 int mapistore_indexing_record_del_mid(struct mapistore_context *, uint32_t, uint64_t, uint8_t);
271 int mapistore_indexing_record_get_uri(struct mapistore_context *, const char *, TALLOC_CTX *, uint64_t, char **, bool *);
272 int mapistore_indexing_record_get_fmid(struct mapistore_context *, const char *, const char *, uint64_t *, bool *);
273
274 /* definitions from mapistore_replica_mapping.c */
275 _PUBLIC_ int mapistore_replica_mapping_add(struct mapistore_context *, const char *);
276 _PUBLIC_ int mapistore_replica_mapping_guid_to_replid(struct mapistore_context *, const struct GUID *, uint16_t *);
277 _PUBLIC_ int mapistore_replica_mapping_replid_to_guid(struct mapistore_context *, uint16_t, struct GUID *);
278
279 /* definitions from mapistore_namedprops.c */
280 int mapistore_namedprops_get_mapped_id(void *ldb_ctx, struct MAPINAMEID, uint16_t *);
281 int mapistore_namedprops_get_nameid(TALLOC_CTX *, void *, uint16_t, struct MAPINAMEID **);
282
283 /* definitions from mapistore_notifications.c (proof-of-concept) */
284
285 /* notifications subscriptions */
286 struct mapistore_subscription_list {
287         struct mapistore_subscription *subscription;
288         struct mapistore_subscription_list *next;
289         struct mapistore_subscription_list *prev;
290 };
291
292 struct mapistore_table_subscription_parameters {
293         uint8_t table_type;
294         uint64_t folder_id; /* the parent folder id */
295 };
296
297 struct mapistore_object_subscription_parameters {
298         bool whole_store;
299         uint64_t folder_id;
300         uint64_t object_id;
301 };
302
303 struct mapistore_subscription {
304         uint32_t        handle;
305         uint16_t        notification_types;
306         union {
307                 struct mapistore_table_subscription_parameters table_parameters;
308                 struct mapistore_object_subscription_parameters object_parameters;
309         } parameters;
310 };
311
312 struct mapistore_subscription *mapistore_new_subscription(TALLOC_CTX *, uint32_t, uint16_t, void *);
313
314 /* notifications (implementation) */
315
316 struct mapistore_notification_list {
317         struct mapistore_notification *notification;
318         struct mapistore_notification_list *next;
319         struct mapistore_notification_list *prev;
320 };
321
322 enum mapistore_notification_type {
323         MAPISTORE_OBJECT_CREATED = 1,
324         MAPISTORE_OBJECT_MODIFIED = 2,
325         MAPISTORE_OBJECT_DELETED = 3
326 };
327
328 struct mapistore_table_notification_parameters {
329         uint8_t table_type;
330         uint32_t row_id;
331
332         uint32_t handle;
333         uint64_t folder_id; /* the parent folder id */
334         uint64_t object_id; /* the folder/message id */
335         uint32_t instance_id;
336 };
337
338 struct mapistore_object_notification_parameters {
339         uint64_t folder_id; /* the parent folder id */
340         uint64_t object_id; /* the folder/message id */
341         uint16_t tag_count;
342         enum MAPITAGS *tags;
343         bool new_message_count;
344         uint32_t message_count;
345 };
346
347 struct mapistore_notification {
348         uint32_t object_type;
349         enum mapistore_notification_type event;
350         union {
351                 struct mapistore_table_notification_parameters table_parameters;
352                 struct mapistore_object_notification_parameters object_parameters;
353         } parameters;
354 };
355
356 struct mapistore_subscription_list *mapistore_find_matching_subscriptions(struct mapistore_context *, struct mapistore_notification *);
357 void mapistore_push_notification(struct mapistore_context *, uint8_t, enum mapistore_notification_type, void *);
358
359 __END_DECLS
360
361 #endif  /* ! __MAPISTORE_H */