db_mysql.c

Go to the documentation of this file.
00001 /* 
00002  * $Id: db_mysql.c 5425 2009-01-07 08:43:22Z henningw $ 
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 
00032 /*! \file
00033  *  \brief DB_MYSQL :: Core
00034  *  \ingroup db_mysql
00035  *  Module: \ref db_mysql
00036  */
00037 
00038 /*! \defgroup db_mysql DB_MYSQL :: the MySQL driver for Kamailio
00039  *  \brief The Kamailio database interface to the MySQL database
00040  *  - http://www.mysql.org
00041  *
00042  */
00043 
00044 #include "../../sr_module.h"
00045 #include "../../db/db.h"
00046 #include "dbase.h"
00047 #include "db_mysql.h"
00048 
00049 #include <mysql/mysql.h>
00050 
00051 unsigned int db_mysql_ping_interval = 5 * 60; /* Default is 5 minutes */
00052 unsigned int db_mysql_timeout_interval = 2;   /* Default is 6 seconds */
00053 unsigned int db_mysql_auto_reconnect = 1;     /* Default is enabled   */
00054 
00055 static int mysql_mod_init(void);
00056 
00057 MODULE_VERSION
00058 
00059 int db_mysql_bind_api(db_func_t *dbb);
00060 
00061 /*! \brief
00062  * MySQL database module interface
00063  */
00064 static cmd_export_t cmds[] = {
00065    {"db_bind_api",         (cmd_function)db_mysql_bind_api,      0, 0, 0, 0},
00066    {0, 0, 0, 0, 0, 0}
00067 };
00068 
00069 
00070 /*! \brief
00071  * Exported parameters
00072  */
00073 static param_export_t params[] = {
00074    {"ping_interval",    INT_PARAM, &db_mysql_ping_interval},
00075    {"timeout_interval", INT_PARAM, &db_mysql_timeout_interval},
00076    {"auto_reconnect",   INT_PARAM, &db_mysql_auto_reconnect},
00077    {0, 0, 0}
00078 };
00079 
00080 
00081 struct module_exports exports = {   
00082    "db_mysql",
00083    DEFAULT_DLFLAGS, /* dlopen flags */
00084    cmds,
00085    params,          /*  module parameters */
00086    0,               /* exported statistics */
00087    0,               /* exported MI functions */
00088    0,               /* exported pseudo-variables */
00089    0,               /* extra processes */
00090    mysql_mod_init,  /* module initialization function */
00091    0,               /* response function*/
00092    0,               /* destroy function */
00093    0                /* per-child init function */
00094 };
00095 
00096 
00097 static int mysql_mod_init(void)
00098 {
00099    LM_DBG("MySQL client version is %s\n", mysql_get_client_info());
00100    return 0;
00101 }
00102 
00103 int db_mysql_bind_api(db_func_t *dbb)
00104 {
00105    if(dbb==NULL)
00106       return -1;
00107 
00108    memset(dbb, 0, sizeof(db_func_t));
00109 
00110    dbb->use_table        = db_mysql_use_table;
00111    dbb->init             = db_mysql_init;
00112    dbb->close            = db_mysql_close;
00113    dbb->query            = db_mysql_query;
00114    dbb->fetch_result     = db_mysql_fetch_result;
00115    dbb->raw_query        = db_mysql_raw_query;
00116    dbb->free_result      = db_mysql_free_result;
00117    dbb->insert           = db_mysql_insert;
00118    dbb->delete           = db_mysql_delete;
00119    dbb->update           = db_mysql_update;
00120    dbb->replace          = db_mysql_replace;
00121    dbb->last_inserted_id = db_last_inserted_id;
00122    dbb->insert_update    = db_insert_update;
00123 
00124    return 0;
00125 }
00126 

Generated on Mon May 21 20:00:25 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6