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 context_id pointer to the context identifier the function
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 \return MAPISTORE_SUCCESS on success
80 static int sqlite3_delete_context(void *private_data)
82 struct sqlite3_context *sqlite_ctx = (struct sqlite3_context *)private_data;
85 DEBUG(5, ("[%s:%d]\n", __FUNCTION__, __LINE__));
88 return MAPISTORE_SUCCESS;
91 ret = sqlite3_close(sqlite_ctx->db);
92 if (ret) return MAPISTORE_ERROR;
94 return MAPISTORE_SUCCESS;
99 \details Entry point for mapistore SQLite backend
101 \return MAPISTORE_SUCCESS on success, otherwise -1
103 int mapistore_init_backend(void)
105 struct mapistore_backend backend;
108 /* Fill in our name */
109 backend.name = "sqlite3";
110 backend.description = "mapistore sqlite3 backend";
111 backend.namespace = "sqlite://";
113 /* Fill in all the operations */
114 backend.init = sqlite3_init;
115 backend.create_context = sqlite3_create_context;
116 backend.delete_context = sqlite3_delete_context;
118 /* Register ourselves with the MAPIPROXY subsystem */
119 ret = mapistore_backend_register(&backend);
120 if (ret != MAPISTORE_SUCCESS) {
121 DEBUG(0, ("Failed to register the '%s' mapistore backend!\n", backend.name));
125 return MAPISTORE_SUCCESS;