#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <mysql/errmsg.h>
#include "config.h"
#include "mysql_header.h"
#include "strings_utils.h"
#include "mysqld_error.h"
Go to the source code of this file.
Functions | |
void | set_last_error (struct smysql *mysql_info) |
Safely copy error message from MySql. More... | |
void | clear_error_reporting (struct smysql *mysql_info) |
Clear all error reporting data. More... | |
void | copy_error (struct smysql *mysql_info, char *m) |
Safely copy a specific error message to the error reporting system. This function is intended to set functional error message (that does not have MySql system error defined). More... | |
int | standard_query (struct smysql *mysql_info, char *query) |
Execute SQL statements that does not return data (UPDATE, DELETE, INSERT, REPLACE and otjer). More... | |
int | my_fake_syslog (const char *file, const char *fmt,...) |
This is a handler to a fake loggin service. It is used if no logging service is specified in the MySql configuration handler. More... | |
void | mysql_set_logger (int(*logger)(const char *file, const char *fmt,...), struct smysql *mysql_info) |
Assign a logging service to a given MySql handler. More... | |
void | init_mysql_structure (struct smysql *mysql_info) |
Initialise the Mysql management structure. More... | |
int | connect_to_mysql (struct smysql *mysql_info) |
Connect to Mysql server. More... | |
void | disconnect_from_mysql (struct smysql *mysql_info) |
Close the connection with the Mysql server and free allocated memory. More... | |
int | sql_update (struct smysql *mysql_info, char *query) |
Execute an UPDATE SQL statement. More... | |
int | sql_insert (struct smysql *mysql_info, char *query) |
Execute an INSERT SQL statement. More... | |
int | sql_replace (struct smysql *mysql_info, char *query) |
Execute a REPLACE SQL statement. More... | |
int | sql_delete (struct smysql *mysql_info, char *query) |
Execute a DELETE SQL statement. More... | |
int | sql_select (struct smysql *mysql_info, char *query) |
Execute a SELECT SQL statement. More... | |
int | load_mysql_configuration_from_file (char *path, struct smysql *mysql_info, char *tags[MYSQL_CONFIGURATION_TAG_NUMBER], int(*logger)(const char *file, const char *fmt,...)) |
Load MySql configuration from a given configuration file. More... | |
time_t | get_unix_timestamp (struct smysql *mysql_info, int *error) |
Return the UNIX timestamp of the MySql server. More... | |
Variables | |
char | mysql_error_str [MYSQL_MAX_ERROR_SIZE] |
Last MySql error message. This variable is defined in the file 'mysql.c'. | |
int | mysql_error_errno |
Last MySql error code. This variable is defined in the file 'mysql.c'. |
Definition in file mysql.c.
|
Clear all error reporting data.
Definition at line 55 of file mysql.c. References smysql::last_error_int, smysql::last_error_str, mysql_error_errno, mysql_error_str, and MYSQL_MAX_ERROR_SIZE. Referenced by connect_to_mysql(), copy_error(), init_mysql_structure(), load_mysql_configuration_from_file(), set_last_error(), sql_select(), and standard_query(). |
|
Connect to Mysql server.
Definition at line 149 of file mysql.c. References clear_error_reporting(), smysql::connect_retry, smysql::connect_sleep, smysql::connect_timeout, smysql::connected, smysql::db, smysql::handler, smysql::host, smysql::log_file, my_fake_syslog(), smysql::my_syslog, my_syslog(), smysql::passwd, smysql::port, set_last_error(), smysql::socket, and smysql::user. Referenced by main(), sql_select(), and standard_query(). |
|
Safely copy a specific error message to the error reporting system. This function is intended to set functional error message (that does not have MySql system error defined).
Definition at line 99 of file mysql.c. References clear_error_reporting(), smysql::last_error_int, smysql::last_error_str, mysql_error_errno, mysql_error_str, and MYSQL_MAX_ERROR_SIZE. Referenced by sql_select(), and standard_query(). |
|
Close the connection with the Mysql server and free allocated memory.
Definition at line 253 of file mysql.c. References smysql::handler. Referenced by sql_select(), and standard_query(). |
|
Return the UNIX timestamp of the MySql server.
Definition at line 1261 of file mysql.c. References smysql::debug, smysql::log_file, my_fake_syslog(), smysql::my_syslog, my_syslog(), MYSQL_CONNECTION_LOST, MYSQL_NO_TIMESTAMP, MYSQL_RECONNECTION_FAILED, MYSQL_REQUEST_SKIPED, MYSQL_SQL_PROBLEM, MYSQL_UNEXPECTED_ERROR, smysql::result, and sql_select(). Referenced by load_pool(), load_vlan(), release_ip_from_pool(), try_find_and_reserve_ip_from_pool(), and try_reserve_ip_from_pool(). |
|
Initialise the Mysql management structure.
Definition at line 114 of file mysql.c. References clear_error_reporting(), smysql::connected, smysql::handler, smysql::last_connection_timestamp, smysql::num_fields, smysql::num_rows, and smysql::result. Referenced by main(). |
|
Load MySql configuration from a given configuration file.
The size of the array is MYSQL_CONFIGURATION_TAG_NUMBER.
int (*logger) (const char *file, const char * fmt,...) If NULL, then logging is not activated (no matter if a log file is defined).
Definition at line 786 of file mysql.c. References clear_error_reporting(), smysql::connect_retry, smysql::connect_sleep, smysql::connect_timeout, smysql::db, DB_HOST_MAX_SIZE, DB_NAME_MAX_SIZE, DB_PASSWD_MAX_SIZE, DB_USER_MAX_SIZE, smysql::debug, get_value(), smysql::host, smysql::last_error_str, smysql::log_file, my_fake_syslog(), smysql::my_syslog, my_syslog(), MYSQL_CONFIGURATION_TAG_NUMBER, MYSQL_DEBUG_FILE_MAX_SIZE, MYSQL_MAX_ERROR_SIZE, mysql_set_logger(), MYSQL_SOCKET_FILE_MAX_SIZE, parse_configuration_file(), PARSE_CONFIGURATION_OK, smysql::passwd, smysql::port, smysql::reconnection_delay, smysql::socket, and smysql::user. Referenced by main(). |
|
This is a handler to a fake loggin service. It is used if no logging service is specified in the MySql configuration handler.
Definition at line 37 of file mysql.c. Referenced by connect_to_mysql(), get_unix_timestamp(), load_mysql_configuration_from_file(), sql_select(), and standard_query(). |
|
Assign a logging service to a given MySql handler.
Definition at line 48 of file mysql.c. References smysql::my_syslog. Referenced by load_mysql_configuration_from_file(). |
|
Safely copy error message from MySql.
Definition at line 68 of file mysql.c. References clear_error_reporting(), smysql::handler, smysql::last_error_int, smysql::last_error_str, mysql_error_errno, mysql_error_str, and MYSQL_MAX_ERROR_SIZE. Referenced by connect_to_mysql(), sql_select(), and standard_query(). |
|
Execute a DELETE SQL statement.
Definition at line 542 of file mysql.c. References standard_query(). Referenced by send_to_mydns(), and send_to_radonline(). |
|
Execute an INSERT SQL statement.
Definition at line 500 of file mysql.c. References standard_query(). Referenced by send_to_mydns(), send_to_radonline(), and signal_unknown_mac_address(). |
|
Execute a REPLACE SQL statement.
Definition at line 521 of file mysql.c. References standard_query(). |
|
Execute a SELECT SQL statement.
Definition at line 563 of file mysql.c. References clear_error_reporting(), connect_to_mysql(), smysql::connected, copy_error(), disconnect_from_mysql(), smysql::handler, smysql::last_connection_timestamp, smysql::last_error_int, smysql::last_error_str, smysql::log_file, my_fake_syslog(), smysql::my_syslog, my_syslog(), MYSQL_RECONNECTION_FAILED, MYSQL_REQUEST_SKIPED, MYSQL_SQL_PROBLEM, MYSQL_UNEXPECTED_ERROR, smysql::num_fields, smysql::num_rows, smysql::reconnection_delay, smysql::result, and set_last_error(). Referenced by get_unix_timestamp(), load_abonne_ip(), load_abonnes(), load_ip_lease(), load_logistic(), load_options(), load_pool(), load_vlan(), and mydns_init(). |
|
Execute an UPDATE SQL statement.
Definition at line 479 of file mysql.c. References standard_query(). Referenced by blackhole_abonne(), nack_flag_abonne(), release_ip_from_pool(), remove_autoconf_bh(), set_flag_check_radius(), try_find_and_reserve_ip_from_pool(), and try_reserve_ip_from_pool(). |
|
Execute SQL statements that does not return data (UPDATE, DELETE, INSERT, REPLACE and otjer).
Definition at line 278 of file mysql.c. References clear_error_reporting(), connect_to_mysql(), smysql::connected, copy_error(), disconnect_from_mysql(), smysql::handler, smysql::last_connection_timestamp, smysql::last_error_int, smysql::last_error_str, smysql::log_file, my_fake_syslog(), my_syslog(), smysql::my_syslog, MYSQL_CONNECTION_LOST, MYSQL_RECONNECTION_FAILED, MYSQL_REQUEST_SKIPED, MYSQL_SQL_PROBLEM, MYSQL_UNEXPECTED_ERROR, smysql::reconnection_delay, and set_last_error(). Referenced by sql_delete(), sql_insert(), sql_replace(), and sql_update(). |