[80966b]: src / core / modules / db_mysql / db_mysql.c Maximize Restore History

Download this file

db_mysql.c    115 lines (98 with data), 3.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* $Id: db_mysql.c 5976 2009-08-18 13:35:23Z bogdan_iancu $
*
* MySQL module interface
*
* Copyright (C) 2001-2003 FhG Fokus
* Copyright (C) 2008 1&1 Internet AG
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* History:
* --------
* 2003-03-11 updated to the new module exports interface (andrei)
* 2003-03-16 flags export parameter added (janakj)
*/
#include "../../db/db_to_module.h"
#include "dbase.h"
#include "db_mysql.h"
#include "../../modules.h"
#include <string.h>
#include <mysql/mysql.h>
unsigned int db_mysql_ping_interval = 5 * 60; /* Default is 5 minutes */
unsigned int db_mysql_timeout_interval = 6; /* Default is 6 seconds */
static db_func_t dbb =
{
db_mysql_use_table, /* Specify table name */
db_mysql_init, /* Initialize database connection */
db_mysql_close, /* Close database connection */
db_mysql_query, /* query a table */
db_mysql_fetch_next_row,/* fetch next row */
db_mysql_raw_query, /* Raw query - SQL */
db_mysql_free_result, /* Free a query result */
db_mysql_insert, /* Insert into table */
db_mysql_delete, /* Delete from table */
db_mysql_update, /* Update table */
db_mysql_last_inserted_id, /* Retrieve the last inserted ID in a table */
db_insert_update_func, /* Insert into table, update on duplicate key */
db_mysql_socket,
db_mysql_resume,
DB_CAP_SYNC_PREP_STMT
};
static int mysql_mod_init(void);
static void mysql_mod_destroy(void);
static config_param_t module_params[] = {
{"ping_interval", &db_mysql_ping_interval, PARAM_TYPE_INT, 0},
{"timeout_interval",&db_mysql_timeout_interval, PARAM_TYPE_INT, 0},
{0, 0, 0, 0}
};
struct core_module_interface interface = {
"db_mysql",
OPENSIPS_FULL_VERSION, /* compile version */
OPENSIPS_COMPILE_FLAGS, /* compile flags */
CORE_MODULE_UTILS,
0,
/* parameters */
module_params,
NULL,
/* functions */
mysql_mod_init,
mysql_mod_destroy,
NULL,
NULL
};
static int mysql_mod_init(void)
{
LM_DBG("mysql: MySQL client version is %s\n", mysql_get_client_info());
if( mysql_thread_safe() !=1 )
{
LM_ERR("MySQL client is not compiled as thread-safe\n");
return -1;
}
if( mysql_library_init(0, NULL, NULL) )
{
LM_ERR("Unable to initialize MySQL library\n");
return -1;
}
register_module("mysql", &dbb);
return 0;
}
static void mysql_mod_destroy(void)
{
mysql_library_end();
}