2 OpenChange Storage Abstraction Layer library
3 MAPIStore SQLite backend
7 Copyright (C) Julien Kerihuel 2009
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "mapistore_sqlite3.h"
27 \details Initialize sqlite3 mapistore backend
29 \return MAPISTORE_SUCCESS on success
31 static int sqlite3_init(void)
33 DEBUG(0, ("sqlite3 backend initialized\n"));
35 return MAPISTORE_SUCCESS;
40 \details Create a connection context to the sqlite3 backend
42 \param mem_ctx pointer to the memory context
43 \param uri pointer to the database path
44 \param private_data pointer to the private backend context
47 \return MAPISTORE_SUCCESS on success
49 static int sqlite3_create_context(TALLOC_CTX *mem_ctx, const char *uri, void **private_data)
51 struct sqlite3_context *sqlite_ctx;
55 DEBUG(0, ("[%s:%d]\n", __FUNCTION__, __LINE__));
57 ret = sqlite3_open(uri, &db);
59 DEBUG(3, ("[%s:%d]: %s\n", __FUNCTION__, __LINE__,
65 sqlite_ctx = talloc_zero(mem_ctx, struct sqlite3_context);
67 sqlite_ctx->private_data = NULL;
69 *private_data = (void *)sqlite_ctx;
71 return MAPISTORE_SUCCESS;
76 \details Delete a connection context from the sqlite3 backend
78 \param private_data pointer to the current sqlite3 context
80 \return MAPISTORE_SUCCESS on success, otherwise MAPISTORE_ERROR
82 static int sqlite3_delete_context(void *private_data)
84 struct sqlite3_context *sqlite_ctx = (struct sqlite3_context *)private_data;
87 DEBUG(5, ("[%s:%d]\n", __FUNCTION__, __LINE__));
90 return MAPISTORE_SUCCESS;
93 ret = sqlite3_close(sqlite_ctx->db);
94 if (ret) return MAPISTORE_ERROR;
96 return MAPISTORE_SUCCESS;
101 \details Atomic operation: Create directory (mkdir)
103 \param private_data generic pointer to the sqlite3 context
105 \return MAPI_E_SUCCESS on success
107 static int sqlite3_op_mkdir(void *private_data)
109 struct sqlite3_context *sqlite_ctx = (struct sqlite3_context *)private_data;
112 return MAPISTORE_ERROR;
115 return MAPISTORE_SUCCESS;
120 \details Atomic operation: Delete directory (rmdir)
122 \param private_data generic pointer to the sqlite3 context
124 \return MAPI_E_SUCCESS on success
126 static int sqlite3_op_rmdir(void *private_data)
128 struct sqlite3_context *sqlite_ctx = (struct sqlite3_context *)private_data;
131 return MAPISTORE_ERROR;
134 return MAPISTORE_SUCCESS;
139 \details Atomic operation: Open directory (opendir)
141 \param private_data generic pointer to the sqlite3 context
142 \param parent_fid the parent folder identifier
143 \param fid the identifier of the colder to open
145 \return MAPI_E_SUCCESS on success
147 static int sqlite3_op_opendir(void *private_data, uint64_t parent_fid, uint64_t fid)
149 struct sqlite3_context *sqlite_ctx = (struct sqlite3_context *)private_data;
152 return MAPISTORE_ERROR;
155 return MAPISTORE_SUCCESS;
160 \details Atomic operation: Close directory (closedir)
162 \param private_data generic pointer to the sqlite3 context
164 \return MAPI_E_SUCCESS on success
166 static int sqlite3_op_closedir(void *private_data)
168 struct sqlite3_context *sqlite_ctx = (struct sqlite3_context *)private_data;
171 return MAPISTORE_ERROR;
174 return MAPISTORE_SUCCESS;
179 \details Entry point for mapistore SQLite backend
181 \return MAPISTORE_SUCCESS on success, otherwise -1
183 int mapistore_init_backend(void)
185 struct mapistore_backend backend;
188 /* Fill in our name */
189 backend.name = "sqlite3";
190 backend.description = "mapistore sqlite3 backend";
191 backend.namespace = "sqlite://";
193 /* Fill in all the operations */
194 backend.init = sqlite3_init;
195 backend.create_context = sqlite3_create_context;
196 backend.delete_context = sqlite3_delete_context;
197 backend.op_mkdir = sqlite3_op_mkdir;
198 backend.op_rmdir = sqlite3_op_rmdir;
199 backend.op_opendir = sqlite3_op_opendir;
200 backend.op_closedir = sqlite3_op_closedir;
201 backend.op_readdir_count = NULL;
203 /* Register ourselves with the MAPISTORE subsystem */
204 ret = mapistore_backend_register(&backend);
205 if (ret != MAPISTORE_SUCCESS) {
206 DEBUG(0, ("Failed to register the '%s' mapistore backend!\n", backend.name));
210 return MAPISTORE_SUCCESS;