km_db_mysql.c

Go to the documentation of this file.
00001 /* 
00002  * $Id$ 
00003  *
00004  * MySQL module interface
00005  *
00006  * Copyright (C) 2001-2003 FhG Fokus
00007  * Copyright (C) 2008 1&1 Internet AG
00008  *
00009  * This file is part of Kamailio, a free SIP server.
00010  *
00011  * Kamailio is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version
00015  *
00016  * Kamailio is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License 
00022  * along with this program; if not, write to the Free Software 
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  */
00025 /*
00026  * History:
00027  * --------
00028  *  2003-03-11  updated to the new module exports interface (andrei)
00029  *  2003-03-16  flags export parameter added (janakj)
00030  */
00031 
00044 #include "../../sr_module.h"
00045 #include "../../dprint.h"
00046 #include "km_dbase.h"
00047 #include "km_db_mysql.h"
00048 
00049 #include <mysql/mysql.h>
00050 
00051 unsigned int db_mysql_timeout_interval = 2;   /* Default is 6 seconds */
00052 unsigned int db_mysql_auto_reconnect = 1;     /* Default is enabled   */
00053 
00054 /* MODULE_VERSION */
00055 
00059 static kam_cmd_export_t cmds[] = {
00060         {"db_bind_api",         (cmd_function)db_mysql_bind_api,      0, 0, 0, 0},
00061         {0, 0, 0, 0, 0, 0}
00062 };
00063 
00067 static param_export_t params[] = {
00068 /*      {"ping_interval",    INT_PARAM, &db_mysql_ping_interval}, */
00069         {"timeout_interval", INT_PARAM, &db_mysql_timeout_interval},
00070         {"auto_reconnect",   INT_PARAM, &db_mysql_auto_reconnect},
00071         {0, 0, 0}
00072 };
00073 
00074 struct kam_module_exports kam_exports = {       
00075         "db_mysql",
00076         DEFAULT_DLFLAGS, /* dlopen flags */
00077         cmds,
00078         params,          /*  module parameters */
00079         0,               /* exported statistics */
00080         0,               /* exported MI functions */
00081         0,               /* exported pseudo-variables */
00082         0,               /* extra processes */
00083         kam_mysql_mod_init,  /* module initialization function */
00084         0,               /* response function*/
00085         0,               /* destroy function */
00086         0                /* per-child init function */
00087 };
00088 
00089 
00090 int kam_mysql_mod_init(void)
00091 {
00092         LM_DBG("MySQL client version is %s\n", mysql_get_client_info());
00093         return 0;
00094 }
00095 
00096 int db_mysql_bind_api(db_func_t *dbb)
00097 {
00098         if(dbb==NULL)
00099                 return -1;
00100 
00101         memset(dbb, 0, sizeof(db_func_t));
00102 
00103         dbb->use_table        = db_mysql_use_table;
00104         dbb->init             = db_mysql_init;
00105         dbb->close            = db_mysql_close;
00106         dbb->query            = db_mysql_query;
00107         dbb->fetch_result     = db_mysql_fetch_result;
00108         dbb->raw_query        = db_mysql_raw_query;
00109         dbb->free_result      = db_mysql_free_result;
00110         dbb->insert           = db_mysql_insert;
00111         dbb->delete           = db_mysql_delete;
00112         dbb->update           = db_mysql_update;
00113         dbb->replace          = db_mysql_replace;
00114         dbb->last_inserted_id = db_mysql_last_inserted_id;
00115         dbb->insert_update    = db_mysql_insert_update;
00116         dbb->insert_delayed   = db_mysql_insert_delayed;
00117         dbb->affected_rows    = db_mysql_affected_rows;
00118 
00119         return 0;
00120 }