db_oracle.c

00001 /*
00002  * $Id$
00003  *
00004  * Oracle module interface
00005  *
00006  * Copyright (C) 2007,2008 TRUNK MOBILE
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  * History:
00026  * --------
00027  */
00028 
00029 #include <sys/time.h>
00030 #include <oci.h>
00031 #include "../../sr_module.h"
00032 #include "../../lib/srdb1/db.h"
00033 #include "../../lib/srdb1/db_query.h"
00034 #include "dbase.h"
00035 #include "asynch.h"
00036 
00037 static int oracle_mod_init(void);
00038 static void destroy(void);
00039 static int db_oracle_bind_api(db_func_t *dbb);
00040 
00041 MODULE_VERSION
00042 
00043 
00044 /*
00045  * Oracle database module interface
00046  */
00047 static cmd_export_t cmds[] = {
00048         {"db_bind_api",         (cmd_function)db_oracle_bind_api,    0, 0, 0, 0},
00049         {0, 0, 0, 0, 0, 0}
00050 };
00051 
00052 
00053 /*
00054  * Exported parameters
00055  */
00056 static param_export_t params[] = {
00057         {"timeout",     STR_PARAM|USE_FUNC_PARAM, (void*)&set_timeout },
00058         {"reconnect",   STR_PARAM|USE_FUNC_PARAM, (void*)&set_reconnect },
00059         {0, 0, 0}
00060 };
00061 
00062 
00063 struct module_exports exports = {
00064         "db_oracle",
00065         DEFAULT_DLFLAGS, /* dlopen flags */
00066         cmds,
00067         params,          /*  module parameters */
00068         0,               /* exported statistics */
00069         0,               /* exported MI functions */
00070         0,               /* exported pseudo-variables */
00071         0,               /* extra processes */
00072         oracle_mod_init, /* module initialization function */
00073         0,               /* response function*/
00074         destroy,         /* destroy function */
00075         0                /* per-child init function */
00076 };
00077 
00078 
00079 int mod_register(char *path, int *dlflags, void *p1, void *p2)
00080 {
00081         if(db_api_init()<0)
00082                 return -1;
00083         return 0;
00084 }
00085 
00086 static int oracle_mod_init(void)
00087 {
00088         sword major, minor, update, patch, port;
00089 
00090         OCIClientVersion(&major, &minor, &update, &patch, &port);
00091         LM_DBG("Oracle client version is %d.%d.%d.%d.%d\n",
00092                 major, minor, update, patch, port);
00093         return 0;
00094 }
00095 
00096 
00097 static void destroy(void)
00098 {
00099         LM_INFO("Oracle terminate\n");
00100         OCITerminate(OCI_DEFAULT);
00101 }
00102 
00103 
00104 static int db_oracle_bind_api(db_func_t *dbb)
00105 {
00106         if(dbb==NULL)
00107                 return -1;
00108 
00109         memset(dbb, 0, sizeof(db_func_t));
00110 
00111         dbb->use_table        = db_oracle_use_table;
00112         dbb->init             = db_oracle_init;
00113         dbb->close            = db_oracle_close;
00114         dbb->query            = db_oracle_query;
00115         dbb->raw_query        = db_oracle_raw_query;
00116         dbb->free_result      = db_oracle_free_result;
00117         dbb->insert           = db_oracle_insert;
00118         dbb->delete           = db_oracle_delete; 
00119         dbb->update           = db_oracle_update;
00120 
00121         return 0;
00122 }