db_sqlite.c

00001 /*
00002  * $Id$
00003  *
00004  * SQlite module interface
00005  *
00006  * Copyright (C) 2010 Timo Teräs
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  */
00024 
00025 #include <sys/time.h>
00026 #include <sqlite3.h>
00027 
00028 #include "../../sr_module.h"
00029 #include "../../lib/srdb1/db_query.h"
00030 #include "../../lib/srdb1/db.h"
00031 #include "dbase.h"
00032 
00033 MODULE_VERSION
00034 
00035 static int sqlite_bind_api(db_func_t *dbb)
00036 {
00037         if(dbb==NULL)
00038                 return -1;
00039 
00040         memset(dbb, 0, sizeof(db_func_t));
00041 
00042         dbb->use_table          = db_sqlite_use_table;
00043         dbb->init               = db_sqlite_init;
00044         dbb->close              = db_sqlite_close;
00045         dbb->free_result        = db_sqlite_free_result;
00046         dbb->query              = db_sqlite_query;
00047         dbb->insert             = db_sqlite_insert;
00048         dbb->delete             = db_sqlite_delete;
00049         dbb->update             = db_sqlite_update;
00050         dbb->raw_query          = db_sqlite_raw_query;
00051 
00052         return 0;
00053 }
00054 
00055 static cmd_export_t cmds[] = {
00056         {"db_bind_api", (cmd_function)sqlite_bind_api, 0, 0, 0, 0},
00057         {0, 0, 0, 0, 0, 0}
00058 };
00059 
00060 int mod_register(char *path, int *dlflags, void *p1, void *p2)
00061 {
00062         if(db_api_init()<0)
00063                 return -1;
00064         return 0;
00065 }
00066 
00067 static int sqlite_mod_init(void)
00068 {
00069         sqlite3_initialize();
00070 
00071         LM_INFO("SQlite library version %s (compiled using %s)\n",
00072                 sqlite3_libversion(),
00073                 SQLITE_VERSION);
00074         return 0;
00075 }
00076 
00077 
00078 static void sqlite_mod_destroy(void)
00079 {
00080         LM_INFO("SQlite terminate\n");
00081 
00082         sqlite3_shutdown();
00083 }
00084 
00085 struct module_exports exports = {
00086         "db_sqlite",
00087         DEFAULT_DLFLAGS,        /* dlopen flags */
00088         cmds,                   /* module commands */
00089         0,                      /* module parameters */
00090         0,                      /* exported statistics */
00091         0,                      /* exported MI functions */
00092         0,                      /* exported pseudo-variables */
00093         0,                      /* extra processes */
00094         sqlite_mod_init,        /* module initialization function */
00095         0,                      /* response function*/
00096         sqlite_mod_destroy,     /* destroy function */
00097         0                       /* per-child init function */
00098 };