00001 /*! \file mysql_header.h
00002 Header file for the MySql module 'mysql.c'.
00003 */
00004
00005 #ifdef __cplusplus
00006 extern "C" {
00007 #endif
00008
00009
00010 #ifndef MY_MYSQL_HEADER_FILE_
00011 #define MY_MYSQL_HEADER_FILE_
00012
00013 #include <time.h>
00014 #include "mysql.h" /* EXT (MySql distribution) */
00015
00016 /*! \brief Number of configuration tags for MySql in a configuration file.
00017 */
00018
00019 #define MYSQL_CONFIGURATION_TAG_NUMBER 12
00020
00021 /* ------------------------------------------------- */
00022 /* Radonline actions */
00023 /* ------------------------------------------------- */
00024
00025 /*! \brief This constant is used by the function send_to_radonline(). It tells the function that a
00026 START ticket should be inserted into the Radonline database.
00027 */
00028
00029 #define RADONLINE_START 0
00030
00031 /*! \brief This constant is used by the function send_to_radonline(). It tells the function that a
00032 STOP ticket should be inserted into the Radonline database.
00033 */
00034
00035 #define RADONLINE_STOP 1
00036
00037 /* ------------------------------------------------- */
00038 /* MyDns actions */
00039 /* ------------------------------------------------- */
00040
00041 /*! \brief This constant is used by the function send_to_mydns(). It tells the function that a
00042 START ticket should be inserted into the MyDns database.
00043 */
00044
00045 #define MYDNS_START 0
00046
00047 /*! \brief This constant is used by the function send_to_mydns(). It tells the function that a
00048 STOP ticket should be inserted into the MyDns database.
00049 */
00050
00051 #define MYDNS_STOP 1
00052
00053 /* ------------------------------------------------- */
00054 /* Sizes for all MySql data */
00055 /* ------------------------------------------------- */
00056
00057 /*! \brief Maximum number of characters for the buffer that hold the message associated with the
00058 last MySql error.
00059 */
00060
00061 #define MYSQL_MAX_ERROR_SIZE 4096
00062
00063 /*! \brief Maximum number of characters for a SQL request.
00064 */
00065
00066 #define MAX_SQL_REQUEST_SIZE 4096
00067
00068 /*! \brief Maximum number of characters for the database host name.
00069 */
00070
00071 #define DB_HOST_MAX_SIZE 256
00072
00073 /*! \brief Maximum number of characters for a database user login.
00074 */
00075
00076 #define DB_USER_MAX_SIZE 256
00077
00078 /*! \brief Maximum number of characters for a database name.
00079 */
00080
00081 #define DB_NAME_MAX_SIZE 256
00082
00083 /*! \brief Maximum number of characters for a database password.
00084 */
00085
00086 #define DB_PASSWD_MAX_SIZE 256
00087
00088 /*! \brief Maximum number of characters for the path to the MySql UNIX socket.
00089 */
00090
00091 #define MYSQL_SOCKET_FILE_MAX_SIZE 256
00092
00093 /*! \brief Maximum number of characters for the path to the MySql debug file.
00094 */
00095
00096 #define MYSQL_DEBUG_FILE_MAX_SIZE 256
00097
00098 /* ------------------------------------------------- */
00099 /* MySql configuration handler */
00100 /* ------------------------------------------------- */
00101
00102 /*! \brief Data structure used to store the configuration for MySql connection.
00103 */
00104
00105 struct smysql {
00106
00107 /* ------------------------------------ */
00108 /* Mysql management variables */
00109 /* ------------------------------------ */
00110
00111 /*! \brief Handler to the MySql session. */
00112
00113 MYSQL *handler;
00114
00115 /*! \brief Timestamp of the last connection attempt. */
00116
00117 time_t last_connection_timestamp;
00118
00119 /*! \brief This flag indicates whether the connection to the MySql server is alive or not.
00120 <UL>
00121 <LI>0: the connection to the MySql server is down.
00122 <LI>1: the connection to the MySql server is up.
00123 </UL>
00124 */
00125
00126 int connected;
00127
00128 /* ------------------------------------ */
00129 /* Data for SELECT requests */
00130 /* ------------------------------------ */
00131
00132 /*! \brief For SELECT queries, this pointer points to selected data. */
00133
00134 MYSQL_RES *result;
00135
00136 /*! \brief For SELECT queries, number of lines. */
00137
00138 unsigned int num_fields;
00139
00140 /*! \brief For SELECT queries, number of columns. */
00141
00142 unsigned int num_rows;
00143
00144 /* ------------------------------------ */
00145 /* Configuration */
00146 /* ------------------------------------ */
00147
00148 /*! \brief Name of the host that runs the MySql server. */
00149
00150 char host[DB_HOST_MAX_SIZE];
00151
00152 /*! \brief Login used to log to the MySql server. */
00153
00154 char user[DB_USER_MAX_SIZE];
00155
00156 /*! \brief Password used to access the MySql server. */
00157
00158 char passwd[DB_PASSWD_MAX_SIZE];
00159
00160 /*! \brief Mane of the database. */
00161
00162 char db[DB_NAME_MAX_SIZE];
00163
00164 /*! \brief Port number used by the MySql server. */
00165
00166 unsigned int port;
00167
00168 /*! \brief UNIX socket used by the MySql server. */
00169
00170 char socket[MYSQL_SOCKET_FILE_MAX_SIZE];
00171
00172 /*! \brief Maximum number of retries for MySql connections. */
00173
00174 int connect_retry;
00175
00176 /*! \brief Timeout (in seconds) for the connection to the MySql server. */
00177
00178 unsigned int connect_timeout;
00179
00180 /*! \brief Number of seconds netween 2 connnection atsemps. */
00181
00182 unsigned int connect_sleep;
00183
00184 /*! \brief Debug mose. */
00185
00186 int debug;
00187
00188 /*! \brief Path to the file used to log debug information.
00189 \remark If you do not want to specify a log file, then set "log_file[0]=0".
00190 */
00191
00192 char log_file[MYSQL_DEBUG_FILE_MAX_SIZE];
00193
00194 /*! \brief Delay between two reconnection attempts. */
00195
00196 time_t reconnection_delay;
00197
00198 /* ------------------------------------ */
00199 /* Error reporting */
00200 /* ------------------------------------ */
00201
00202 /*! \brief Error code for the last MySql error. */
00203
00204 int last_error_int;
00205
00206 /*! \brief Literal description of the last MySql error. */
00207
00208 char last_error_str[MYSQL_MAX_ERROR_SIZE];
00209
00210 /*! \brief Pointer to a function used to log debug information, if necessary.
00211 The signature of the function must be: <P>
00212 int my_syslog (const char *file, const char * fmt,...)<P>
00213 Upon successful completion, the function must return the value 0.
00214 Otherwize, the function returns the value 1.<P>
00215 If you set this field to the value NULL, then no output is done.
00216 */
00217
00218 int (*my_syslog) (const char *file, const char * fmt,...);
00219 };
00220
00221 /* ------------------------------------------------- */
00222 /* Return values */
00223 /* ------------------------------------------------- */
00224
00225 /*! \brief Return value for the functions:
00226 <UL>
00227 <LI>standard_query
00228 <LI>sql_update
00229 <LI>sql_insert
00230 <LI>sql_delete
00231 <LI>sql_select
00232 <LI>get_unix_timestamp
00233 </UL>
00234 The SQL request was skiped because the reconnection delay did not expired.
00235 */
00236
00237 #define MYSQL_REQUEST_SKIPED -1
00238
00239 /*! \brief Return value for the functions:
00240 <UL>
00241 <LI>standard_query
00242 <LI>sql_update
00243 <LI>sql_insert
00244 <LI>sql_delete
00245 <LI>sql_select
00246 <LI>get_unix_timestamp
00247 </UL>
00248 The connection to the MySql server was lost.
00249 */
00250
00251 #define MYSQL_CONNECTION_LOST -2
00252
00253 /*! \brief Return value for the functions:
00254 <UL>
00255 <LI>standard_query
00256 <LI>sql_update
00257 <LI>sql_insert
00258 <LI>sql_delete
00259 <LI>sql_select
00260 <LI>get_unix_timestamp
00261 </UL>
00262 The reconnection process to the MySql server failed.
00263 */
00264
00265 #define MYSQL_RECONNECTION_FAILED -3
00266
00267 /*! \brief Return value for the functions:
00268 <UL>
00269 <LI>standard_query
00270 <LI>sql_update
00271 <LI>sql_insert
00272 <LI>sql_delete
00273 <LI>sql_select
00274 <LI>get_unix_timestamp
00275 </UL>
00276 A SQL error occured.
00277 */
00278
00279 #define MYSQL_SQL_PROBLEM -4
00280
00281 /*! \brief Return value for the functions:
00282 <UL>
00283 <LI>standard_query
00284 <LI>sql_update
00285 <LI>sql_insert
00286 <LI>sql_delete
00287 <LI>sql_select
00288 <LI>get_unix_timestamp
00289 </UL>
00290 Unexpected error.
00291 */
00292
00293 #define MYSQL_UNEXPECTED_ERROR -5
00294
00295 /*! \brief Return value for the functions:
00296 <UL>
00297 <LI>get_unix_timestamp
00298 </UL>
00299 For some strange reasons, the MySql could not return the current timestamp.
00300 */
00301
00302 #define MYSQL_NO_TIMESTAMP -6
00303
00304 /* ------------------------------------------------- */
00305 /* Functionnal interface */
00306 /* ------------------------------------------------- */
00307
00308 int load_mysql_configuration_from_file (
00309 char *path,
00310 struct smysql *mysql_info,
00311 char *tags[MYSQL_CONFIGURATION_TAG_NUMBER],
00312 int (*logger) (const char *file, const char * fmt,...)
00313 );
00314
00315 void mysql_set_logger (int (*logger) (const char *file, const char * fmt,...), struct smysql *mysql_info);
00316 void init_mysql_structure (struct smysql *mysql_info);
00317 int connect_to_mysql (struct smysql *mysql_info);
00318 void disconnect_from_mysql(struct smysql *mysql_info);
00319 int sql_update (struct smysql *mysql_info, char* query);
00320 int sql_insert (struct smysql *mysql_info, char* query);
00321 int sql_delete (struct smysql *mysql_info, char* query);
00322 int sql_replace (struct smysql *mysql_info, char* query);
00323 int sql_select (struct smysql *mysql_info, char* query);
00324 time_t get_unix_timestamp (struct smysql *mysql_info, int *error);
00325
00326 #endif
00327
00328 #ifdef __cplusplus
00329 }
00330 #endif
00331
1.2.15