2 OpenChange Storage Abstraction Layer library
6 Copyright (C) Julien Kerihuel 2009-2010
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.
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.
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/>.
33 #include <sys/types.h>
44 #include <util/debug.h>
46 #include "libmapi/libmapi.h"
48 #define MAPISTORE_SUCCESS 0
50 typedef int (*init_backend_fn) (void);
52 #define MAPISTORE_INIT_MODULE "mapistore_init_backend"
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
61 #define MAPISTORE_FOLDER 1
62 #define MAPISTORE_MESSAGE 2
63 #define MAPISTORE_ATTACHMENT 3
64 #define MAPISTORE_TABLE 4
66 #define MAPISTORE_SOFT_DELETE 1
67 #define MAPISTORE_PERMANENT_DELETE 2
69 struct mapistore_message {
70 struct SRowSet *recipients;
71 struct SRow *properties;
74 struct indexing_folders_list {
79 enum table_query_type {
80 MAPISTORE_PREFILTERED_QUERY,
81 MAPISTORE_LIVEFILTERED_QUERY,
84 /* proof of concept: a new structure to simplify property queries */
85 struct mapistore_property_data {
87 int error; /* basically MAPISTORE_SUCCESS or MAPISTORE_ERR_NOT_FOUND */
90 struct mapistore_connection_info {
92 struct GUID replica_guid;
94 struct mapistore_context *mstore_ctx;
101 openfolder takes the folderid alone as argument
102 openmessage takes the message id and its parent folderid as arguments */
104 struct mapistore_backend {
105 /** backend operations */
108 const char *description;
109 const char *namespace;
112 int (*create_context)(TALLOC_CTX *, struct mapistore_connection_info *, struct tdb_wrap *, const char *, void **);
115 /** context operations */
117 int (*get_path)(void *, TALLOC_CTX *, uint64_t, char **);
118 int (*get_root_folder)(void *, TALLOC_CTX *, uint64_t, void **);
121 /** oxcfold operations */
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 *);
132 /* constructor: open_folder */
133 int (*open_table)(void *, TALLOC_CTX *, uint8_t, uint32_t, void **, uint32_t *);
136 /** oxcmsg operations */
138 int (*modify_recipients)(void *, struct ModifyRecipientRow *, uint16_t);
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 *);
146 int (*open_embedded_message)(void *, TALLOC_CTX *, void **, uint64_t *, struct mapistore_message **);
149 /** oxctabl operations */
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 *);
159 /** oxcprpt operations */
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 *);
167 struct indexing_context_list;
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;
179 struct backend_context_list {
180 struct backend_context *ctx;
181 struct backend_context_list *prev;
182 struct backend_context_list *next;
185 struct processing_context;
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;
195 struct mapistore_connection_info *conn_info;
198 #ifndef __BEGIN_DECLS
200 #define __BEGIN_DECLS extern "C" {
201 #define __END_DECLS }
203 #define __BEGIN_DECLS
210 /* definitions from mapistore_interface.c */
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 *);
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);
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 *);
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);
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 *);
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 *);
255 /* definitions from mapistore_processing.c */
256 int mapistore_set_mapping_path(const char *);
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 *);
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 *);
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 *);
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 **);
283 /* definitions from mapistore_notifications.c (proof-of-concept) */
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;
292 struct mapistore_table_subscription_parameters {
294 uint64_t folder_id; /* the parent folder id */
297 struct mapistore_object_subscription_parameters {
303 struct mapistore_subscription {
305 uint16_t notification_types;
307 struct mapistore_table_subscription_parameters table_parameters;
308 struct mapistore_object_subscription_parameters object_parameters;
312 struct mapistore_subscription *mapistore_new_subscription(TALLOC_CTX *, uint32_t, uint16_t, void *);
314 /* notifications (implementation) */
316 struct mapistore_notification_list {
317 struct mapistore_notification *notification;
318 struct mapistore_notification_list *next;
319 struct mapistore_notification_list *prev;
322 enum mapistore_notification_type {
323 MAPISTORE_OBJECT_CREATED = 1,
324 MAPISTORE_OBJECT_MODIFIED = 2,
325 MAPISTORE_OBJECT_DELETED = 3
328 struct mapistore_table_notification_parameters {
333 uint64_t folder_id; /* the parent folder id */
334 uint64_t object_id; /* the folder/message id */
335 uint32_t instance_id;
338 struct mapistore_object_notification_parameters {
339 uint64_t folder_id; /* the parent folder id */
340 uint64_t object_id; /* the folder/message id */
343 bool new_message_count;
344 uint32_t message_count;
347 struct mapistore_notification {
348 uint32_t object_type;
349 enum mapistore_notification_type event;
351 struct mapistore_table_notification_parameters table_parameters;
352 struct mapistore_object_notification_parameters object_parameters;
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 *);
361 #endif /* ! __MAPISTORE_H */