Browse code

database module interface moved.

Jan Janak authored on 09/07/2002 09:08:25
Showing 17 changed files
... ...
@@ -10,7 +10,7 @@
10 10
 #include "../../mem/shm_mem.h"
11 11
 #include "../../data_lump_rpl.h"
12 12
 #include "cred.h"
13
-#include "db.h"
13
+#include "../../db/db.h"
14 14
 #include "calc.h"
15 15
 #include "../../md5global.h"
16 16
 #include "../../md5.h"
... ...
@@ -5,7 +5,7 @@
5 5
 #ifndef auth_mod_h
6 6
 #define auth_mod_h
7 7
 
8
-#include "db.h"
8
+#include "../../db/db.h"
9 9
 #include "defs.h"
10 10
 #include "../../str.h"
11 11
 
12 12
deleted file mode 100644
... ...
@@ -1,37 +0,0 @@
1
-/*
2
- * $Id$
3
- */
4
-
5
-#include "db.h"
6
-#include "../../sr_module.h"
7
-
8
-db_func_t dbf;
9
-
10
-
11
-int bind_dbmod(void)
12
-{
13
-	dbf.use_table = (db_use_table_f)find_export("db_use_table", 2);
14
-
15
-	dbf.init = (db_init_f)find_export("db_init", 1);
16
-	if (!dbf.init) return 1;
17
-
18
-	dbf.close = (db_close_f)find_export("db_close", 2);
19
-	if (!dbf.close) return 1;
20
-
21
-	dbf.query = (db_query_f)find_export("db_query", 2);
22
-	if (!dbf.query) return 1;
23
-
24
-	dbf.free_query = (db_free_query_f)find_export("db_free_query", 2);
25
-	if (!dbf.free_query) return 1;
26
-
27
-	dbf.insert = (db_insert_f)find_export("db_insert", 2);
28
-	if (!dbf.insert) return 1;
29
-
30
-	dbf.delete = (db_delete_f)find_export("db_delete", 2);
31
-	if (!dbf.delete) return 1;
32
-
33
-	dbf.update = (db_update_f)find_export("db_update", 2);
34
-	if (!dbf.update) return 1;
35
-
36
-	return 0;
37
-}
38 0
deleted file mode 100644
... ...
@@ -1,255 +0,0 @@
1
-/*
2
- * $Id$
3
- */
4
-
5
-#ifndef __DB_H__
6
-#define __DB_H__
7
-
8
-#include <time.h>
9
-
10
-/*
11
- * Generic database interface
12
- *
13
- * $id$
14
- */
15
-
16
-
17
-/* =================== db_key =============== */
18
-
19
-/*
20
- * Type of a database key (column)
21
- */
22
-typedef const char* db_key_t;
23
-
24
-
25
-/* =================== db_val =============== */
26
-
27
-/*
28
- * Accepted column types
29
- */
30
-typedef enum {
31
-	DB_INT,
32
-        DB_DOUBLE,
33
-	DB_STRING,
34
-	DB_DATETIME
35
-} db_type_t;
36
-
37
-
38
-/*
39
- * Column value structure
40
- */
41
-typedef struct {
42
-	db_type_t type;                  /* Type of the value */
43
-	int nul;                         /* Means that the column in database has no value */
44
-	union {
45
-		int          int_val;    /* integer value */
46
-		double       double_val; /* double value */
47
-		time_t       time_val;   /* unix time value */
48
-		const char*  string_val; /* NULL terminated string */
49
-	} val;                           /* union of all possible types */
50
-} db_val_t;
51
-
52
-
53
-/*
54
- * Useful macros for accessing attributes of db_val structure
55
- */
56
-
57
-/* Get value type */
58
-#define VAL_TYPE(dv)   ((dv)->type)
59
-
60
-/* Get null flag (means that value in dabase is null) */
61
-#define VAL_NULL(dv)   ((dv)->nul)
62
-
63
-/* Get integer value */
64
-#define VAL_INT(dv)    ((dv)->val.int_val)
65
-
66
-/* Get double value */
67
-#define VAL_DOUBLE(dv) ((dv)->val.double_val)
68
-
69
-/* Get time_t value */
70
-#define VAL_TIME(dv)   ((dv)->val.time_val)
71
-
72
-/* Get char* value */
73
-#define VAL_STRING(dv) ((dv)->val.string_val)
74
-
75
-
76
-/* ==================== db_con ======================= */
77
-
78
-/*
79
- * This structure represents a database connection
80
- * and pointer to this structure is used as a connection
81
- * handle
82
- */
83
-typedef struct {
84
-	char* table;     /* Default table to use */
85
-	void* con;       /* Mysql Connection */
86
-	void* res;       /* Result of previous operation */
87
-	void* row;       /* Actual row in the result */
88
-	int   connected; /* TRUE if connection is established */
89
-} db_con_t;
90
-
91
-
92
-/* ===================== db_row ====================== */
93
-
94
-/*
95
- * Structure holding result of query_table function (ie. table row)
96
- */
97
-typedef struct db_row {
98
-	db_val_t* values;  /* Columns in the row */
99
-	int n;             /* Number of columns in the row */
100
-} db_row_t;
101
-
102
-/* Useful macros for manipulating db_row structure attributes */
103
-
104
-/* Get row members */
105
-#define ROW_VALUES(rw) ((rw)->values)
106
-
107
-/* Get number of member in the row */
108
-#define ROW_N(rw)      ((rw)->n)
109
-
110
-
111
-/* ===================== db_res ====================== */
112
-
113
-typedef struct db_res {
114
-	struct {
115
-		db_key_t* names;   /* Column names */
116
-		db_type_t* types;  /* Column types */
117
-		int n;             /* Number of columns */
118
-	} col;
119
-	struct db_row* rows;       /* Rows */
120
-	int n;                     /* Number of rows */
121
-} db_res_t;
122
-
123
-/* Useful macros for manipulating db_res attributes */
124
-
125
-/* Column names */
126
-#define RES_NAMES(re) ((re)->col.names)
127
-
128
-/* Column types */
129
-#define RES_TYPES(re) ((re)->col.types)
130
-
131
-/* Number of columns */
132
-#define RES_COL_N(re) ((re)->col.n)
133
-
134
-/* Rows */
135
-#define RES_ROWS(re)  ((re)->rows)
136
-
137
-/* Number of rows */
138
-#define RES_ROW_N(re) ((re)->n)
139
-
140
-
141
-/*
142
- * Specify table name that will be used for
143
- * subsequent operations
144
- */
145
-typedef int (*db_use_table_f)(db_con_t* _h, const char* _t);
146
-
147
-
148
-/*
149
- * Initialize database connection and
150
- * obtain the connection handle
151
- */
152
-typedef db_con_t* (*db_init_f) (const char* _sqlurl);
153
-
154
-
155
-/*
156
- * Close a database connection and free
157
- * all memory used
158
- */
159
-typedef void (*db_close_f) (db_con_t* _h); 
160
-
161
-
162
-/*
163
- * Query table for specified rows
164
- * _h: structure representing database connection
165
- * _k: key names
166
- * _v: values of the keys that must match
167
- * _c: column names to return
168
- * _n: nmber of key=values pairs to compare
169
- * _nc: number of columns to return
170
- * _o: order by the specified column
171
- * _r: Result will be stored in this variable
172
- *     NULL if there is no result
173
- */
174
-typedef int (*db_query_f) (db_con_t* _h, db_key_t* _k, 
175
-			   db_val_t* _v, db_key_t* _c, 
176
-			   int _n, int _nc,
177
-			   db_key_t _o, db_res_t** _r);
178
-
179
-
180
-/*
181
- * Free a result allocated by db_query
182
- * _h: structure representing database connection
183
- * _r: db_res structure
184
- */
185
-typedef int (*db_free_query_f) (db_con_t* _h, db_res_t* _r);
186
-
187
-
188
-/*
189
- * Insert a row into specified table
190
- * _h: structure representing database connection
191
- * _k: key names
192
- * _v: values of the keys
193
- * _n: number of key=value pairs
194
- */
195
-typedef int (*db_insert_f) (db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n);
196
-
197
-
198
-/*
199
- * Delete a row from the specified table
200
- * _h: structure representing database connection
201
- * _k: key names
202
- * _v: values of the keys that must match
203
- * _n: number of key=value pairs
204
- */
205
-typedef int (*db_delete_f) (db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n);
206
-
207
-
208
-/*
209
- * Update some rows in the specified table
210
- * _h: structure representing database connection
211
- * _k: key names
212
- * _v: values of the keys that must match
213
- * _uk: updated columns
214
- * _uv: updated values of the columns
215
- * _n: number of key=value pairs
216
- * _un: number of columns to update
217
- */
218
-typedef int (*db_update_f) (db_con_t* _h, db_key_t* _k, db_val_t* _v,
219
-			    db_key_t* _uk, db_val_t* _uv, int _n, int _un);
220
-
221
-
222
-
223
-typedef struct db_func{
224
-	db_use_table_f  use_table;   /* Specify table name */
225
-	db_init_f       init;        /* Initialize dabase connection */
226
-	db_close_f      close;       /* Close database connection */
227
-	db_query_f      query;       /* query a table */
228
-	db_free_query_f free_query;  /* Free a query result */
229
-	db_insert_f     insert;      /* Insert into table */
230
-	db_delete_f     delete;      /* Delete from table */ 
231
-	db_update_f     update;      /* Update table */
232
-} db_func_t;
233
-
234
-
235
-/*
236
- * Bind database module functions
237
- * returns TRUE if everything went OK
238
- * FALSE otherwise
239
- */
240
-int bind_dbmod(void);
241
-
242
-
243
-extern db_func_t dbf;
244
-
245
-
246
-#define db_use_table  (dbf.use_table)
247
-#define db_init       (dbf.init)
248
-#define db_close      (dbf.close)
249
-#define db_query      (dbf.query)
250
-#define db_free_query (dbf.free_query)
251
-#define db_insert     (dbf.insert)
252
-#define db_delete     (dbf.delete)
253
-#define db_update     (dbf.update)
254
- 
255
-#endif
... ...
@@ -5,7 +5,7 @@
5 5
 #include "group.h"
6 6
 #include <string.h>
7 7
 #include "../../dprint.h"
8
-#include "db.h"
8
+#include "../../db/db.h"
9 9
 #include "auth.h"
10 10
 #include "auth_mod.h"
11 11
 #include "utils.h"
... ...
@@ -1,10 +1,7 @@
1
-- Check for old nonce
2
-- Use stale parameter
3 1
 - cnonce, nonce-count
4
-- Conside MD5-Sess support(will require to store passwords in clear text)
2
+- Consider MD5-Sess support(will require to store passwords in clear text)
5 3
 - auth-int support
6 4
 - Database cache
7
-- Option na databazi s heslama v plaintextu
8 5
 - Option na pouzivani databaze
9 6
 - V pripade problemu posilat Internal Error
10 7
 
11 8
deleted file mode 100644
... ...
@@ -1,37 +0,0 @@
1
-/*
2
- * $Id$
3
- */
4
-
5
-#include "db.h"
6
-#include "../../sr_module.h"
7
-
8
-db_func_t dbf;
9
-
10
-
11
-int bind_dbmod(void)
12
-{
13
-	dbf.use_table = (db_use_table_f)find_export("db_use_table", 2);
14
-
15
-	dbf.init = (db_init_f)find_export("db_init", 1);
16
-	if (!dbf.init) return 1;
17
-
18
-	dbf.close = (db_close_f)find_export("db_close", 2);
19
-	if (!dbf.close) return 1;
20
-
21
-	dbf.query = (db_query_f)find_export("db_query", 2);
22
-	if (!dbf.query) return 1;
23
-
24
-	dbf.free_query = (db_free_query_f)find_export("db_free_query", 2);
25
-	if (!dbf.free_query) return 1;
26
-
27
-	dbf.insert = (db_insert_f)find_export("db_insert", 2);
28
-	if (!dbf.insert) return 1;
29
-
30
-	dbf.delete = (db_delete_f)find_export("db_delete", 2);
31
-	if (!dbf.delete) return 1;
32
-
33
-	dbf.update = (db_update_f)find_export("db_update", 2);
34
-	if (!dbf.update) return 1;
35
-
36
-	return 0;
37
-}
38 0
deleted file mode 100644
... ...
@@ -1,255 +0,0 @@
1
-/*
2
- * $Id$
3
- */
4
-
5
-#ifndef __DB_H__
6
-#define __DB_H__
7
-
8
-#include <time.h>
9
-
10
-/*
11
- * Generic database interface
12
- *
13
- * $id$
14
- */
15
-
16
-
17
-/* =================== db_key =============== */
18
-
19
-/*
20
- * Type of a database key (column)
21
- */
22
-typedef const char* db_key_t;
23
-
24
-
25
-/* =================== db_val =============== */
26
-
27
-/*
28
- * Accepted column types
29
- */
30
-typedef enum {
31
-	DB_INT,
32
-	DB_DOUBLE,
33
-	DB_STRING,
34
-	DB_DATETIME
35
-} db_type_t;
36
-
37
-
38
-/*
39
- * Column value structure
40
- */
41
-typedef struct {
42
-	db_type_t type;                  /* Type of the value */
43
-	int nul;                         /* Means that the column in database has no value */
44
-	union {
45
-		int          int_val;    /* integer value */
46
-		double       double_val; /* double value */
47
-		time_t       time_val;   /* unix time value */
48
-		const char*  string_val; /* NULL terminated string */
49
-	} val;                           /* union of all possible types */
50
-} db_val_t;
51
-
52
-
53
-/*
54
- * Useful macros for accessing attributes of db_val structure
55
- */
56
-
57
-/* Get value type */
58
-#define VAL_TYPE(dv)   ((dv)->type)
59
-
60
-/* Get null flag (means that value in dabase is null) */
61
-#define VAL_NULL(dv)   ((dv)->nul)
62
-
63
-/* Get integer value */
64
-#define VAL_INT(dv)    ((dv)->val.int_val)
65
-
66
-/* Get double value */
67
-#define VAL_DOUBLE(dv) ((dv)->val.double_val)
68
-
69
-/* Get time_t value */
70
-#define VAL_TIME(dv)   ((dv)->val.time_val)
71
-
72
-/* Get char* value */
73
-#define VAL_STRING(dv) ((dv)->val.string_val)
74
-
75
-
76
-/* ==================== db_con ======================= */
77
-
78
-/*
79
- * This structure represents a database connection
80
- * and pointer to this structure is used as a connection
81
- * handle
82
- */
83
-typedef struct {
84
-	char* table;     /* Default table to use */
85
-	void* con;       /* Mysql Connection */
86
-	void* res;       /* Result of previous operation */
87
-	void* row;       /* Actual row in the result */
88
-	int   connected; /* TRUE if connection is established */
89
-} db_con_t;
90
-
91
-
92
-/* ===================== db_row ====================== */
93
-
94
-/*
95
- * Structure holding result of query_table function (ie. table row)
96
- */
97
-typedef struct db_row {
98
-	db_val_t* values;  /* Columns in the row */
99
-	int n;             /* Number of columns in the row */
100
-} db_row_t;
101
-
102
-/* Useful macros for manipulating db_row structure attributes */
103
-
104
-/* Get row members */
105
-#define ROW_VALUES(rw) ((rw)->values)
106
-
107
-/* Get number of member in the row */
108
-#define ROW_N(rw)      ((rw)->n)
109
-
110
-
111
-/* ===================== db_res ====================== */
112
-
113
-typedef struct db_res {
114
-	struct {
115
-		db_key_t* names;   /* Column names */
116
-		db_type_t* types;  /* Column types */
117
-		int n;             /* Number of columns */
118
-	} col;
119
-	struct db_row* rows;       /* Rows */
120
-	int n;                     /* Number of rows */
121
-} db_res_t;
122
-
123
-/* Useful macros for manipulating db_res attributes */
124
-
125
-/* Column names */
126
-#define RES_NAMES(re) ((re)->col.names)
127
-
128
-/* Column types */
129
-#define RES_TYPES(re) ((re)->col.types)
130
-
131
-/* Number of columns */
132
-#define RES_COL_N(re) ((re)->col.n)
133
-
134
-/* Rows */
135
-#define RES_ROWS(re)  ((re)->rows)
136
-
137
-/* Number of rows */
138
-#define RES_ROW_N(re) ((re)->n)
139
-
140
-
141
-/*
142
- * Specify table name that will be used for
143
- * subsequent operations
144
- */
145
-typedef int (*db_use_table_f)(db_con_t* _h, const char* _t);
146
-
147
-
148
-/*
149
- * Initialize database connection and
150
- * obtain the connection handle
151
- */
152
-typedef db_con_t* (*db_init_f) (const char* _sqlurl);
153
-
154
-
155
-/*
156
- * Close a database connection and free
157
- * all memory used
158
- */
159
-typedef void (*db_close_f) (db_con_t* _h); 
160
-
161
-
162
-/*
163
- * Query table for specified rows
164
- * _h: structure representing database connection
165
- * _k: key names
166
- * _v: values of the keys that must match
167
- * _c: column names to return
168
- * _n: nmber of key=values pairs to compare
169
- * _nc: number of columns to return
170
- * _o: order by the specified column
171
- * _r: Result will be stored in this variable
172
- *     NULL if there is no result
173
- */
174
-typedef int (*db_query_f) (db_con_t* _h, db_key_t* _k, 
175
-			   db_val_t* _v, db_key_t* _c, 
176
-			   int _n, int _nc,
177
-			   db_key_t _o, db_res_t** _r);
178
-
179
-
180
-/*
181
- * Free a result allocated by db_query
182
- * _h: structure representing database connection
183
- * _r: db_res structure
184
- */
185
-typedef int (*db_free_query_f) (db_con_t* _h, db_res_t* _r);
186
-
187
-
188
-/*
189
- * Insert a row into specified table
190
- * _h: structure representing database connection
191
- * _k: key names
192
- * _v: values of the keys
193
- * _n: number of key=value pairs
194
- */
195
-typedef int (*db_insert_f) (db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n);
196
-
197
-
198
-/*
199
- * Delete a row from the specified table
200
- * _h: structure representing database connection
201
- * _k: key names
202
- * _v: values of the keys that must match
203
- * _n: number of key=value pairs
204
- */
205
-typedef int (*db_delete_f) (db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n);
206
-
207
-
208
-/*
209
- * Update some rows in the specified table
210
- * _h: structure representing database connection
211
- * _k: key names
212
- * _v: values of the keys that must match
213
- * _uk: updated columns
214
- * _uv: updated values of the columns
215
- * _n: number of key=value pairs
216
- * _un: number of columns to update
217
- */
218
-typedef int (*db_update_f) (db_con_t* _h, db_key_t* _k, db_val_t* _v,
219
-			    db_key_t* _uk, db_val_t* _uv, int _n, int _un);
220
-
221
-
222
-
223
-typedef struct db_func{
224
-	db_use_table_f  use_table;   /* Specify table name */
225
-	db_init_f       init;        /* Initialize dabase connection */
226
-	db_close_f      close;       /* Close database connection */
227
-	db_query_f      query;       /* query a table */
228
-	db_free_query_f free_query;  /* Free a query result */
229
-	db_insert_f     insert;      /* Insert into table */
230
-	db_delete_f     delete;      /* Delete from table */ 
231
-	db_update_f     update;      /* Update table */
232
-} db_func_t;
233
-
234
-
235
-/*
236
- * Bind database module functions
237
- * returns TRUE if everything went OK
238
- * FALSE otherwise
239
- */
240
-int bind_dbmod(void);
241
-
242
-
243
-extern db_func_t dbf;
244
-
245
-
246
-#define db_use_table  (dbf.use_table)
247
-#define db_init       (dbf.init)
248
-#define db_close      (dbf.close)
249
-#define db_query      (dbf.query)
250
-#define db_free_query (dbf.free_query)
251
-#define db_insert     (dbf.insert)
252
-#define db_delete     (dbf.delete)
253
-#define db_update     (dbf.update)
254
- 
255
-#endif
... ...
@@ -23,7 +23,7 @@
23 23
 
24 24
 #include "sip2jabber.h"
25 25
 #include "jc_pool.h"
26
-#include "db.h"
26
+#include "../../db/db.h"
27 27
 
28 28
 jab_wlist jwl = NULL;
29 29
 
... ...
@@ -17,7 +17,7 @@
17 17
 #include "sip2jabber.h"
18 18
 #include "tree234.h"
19 19
 #include "../../str.h"
20
-#include "db.h"
20
+#include "../../db/db.h"
21 21
 #include "lock.h"
22 22
 
23 23
 /**********             ***/
... ...
@@ -4,6 +4,6 @@
4 4
 
5 5
 auto_gen=
6 6
 NAME=mysql.so
7
-LIBS=-lmysqlclient -L/usr/lib/mysql
7
+LIBS=-lmysqlclient #-L/usr/lib/mysql
8 8
 
9 9
 include ../../Makefile.modules
... ...
@@ -8,7 +8,7 @@
8 8
 #include "c_slot.h"
9 9
 #include "c_elem.h"
10 10
 #include "location.h"
11
-#include "db.h"
11
+#include "../../db/db.h"
12 12
 #include "../../fastlock.h"
13 13
 #include "../../str.h"
14 14
 
... ...
@@ -7,7 +7,7 @@
7 7
 
8 8
 #include <time.h>
9 9
 #include "../../str.h"
10
-#include "db.h"
10
+#include "../../db/db.h"
11 11
 #include "defs.h"
12 12
 
13 13
 
14 14
deleted file mode 100644
... ...
@@ -1,37 +0,0 @@
1
-/*
2
- * $Id$
3
- */
4
-
5
-#include "db.h"
6
-#include "../../sr_module.h"
7
-
8
-db_func_t dbf;
9
-
10
-
11
-int bind_dbmod(void)
12
-{
13
-	dbf.use_table = (db_use_table_f)find_export("db_use_table", 2);
14
-
15
-	dbf.init = (db_init_f)find_export("db_init", 1);
16
-	if (!dbf.init) return 1;
17
-
18
-	dbf.close = (db_close_f)find_export("db_close", 2);
19
-	if (!dbf.close) return 1;
20
-
21
-	dbf.query = (db_query_f)find_export("db_query", 2);
22
-	if (!dbf.query) return 1;
23
-
24
-	dbf.free_query = (db_free_query_f)find_export("db_free_query", 2);
25
-	if (!dbf.free_query) return 1;
26
-
27
-	dbf.insert = (db_insert_f)find_export("db_insert", 2);
28
-	if (!dbf.insert) return 1;
29
-
30
-	dbf.delete = (db_delete_f)find_export("db_delete", 2);
31
-	if (!dbf.delete) return 1;
32
-
33
-	dbf.update = (db_update_f)find_export("db_update", 2);
34
-	if (!dbf.update) return 1;
35
-
36
-	return 0;
37
-}
38 0
deleted file mode 100644
... ...
@@ -1,255 +0,0 @@
1
-/*
2
- * $Id$
3
- */
4
-
5
-#ifndef __DB_H__
6
-#define __DB_H__
7
-
8
-#include <time.h>
9
-
10
-/*
11
- * Generic database interface
12
- *
13
- * $id$
14
- */
15
-
16
-
17
-/* =================== db_key =============== */
18
-
19
-/*
20
- * Type of a database key (column)
21
- */
22
-typedef const char* db_key_t;
23
-
24
-
25
-/* =================== db_val =============== */
26
-
27
-/*
28
- * Accepted column types
29
- */
30
-typedef enum {
31
-	DB_INT,
32
-        DB_DOUBLE,
33
-	DB_STRING,
34
-	DB_DATETIME
35
-} db_type_t;
36
-
37
-
38
-/*
39
- * Column value structure
40
- */
41
-typedef struct {
42
-	db_type_t type;                  /* Type of the value */
43
-	int nul;                         /* Means that the column in database has no value */
44
-	union {
45
-		int          int_val;    /* integer value */
46
-		double       double_val; /* double value */
47
-		time_t       time_val;   /* unix time value */
48
-		const char*  string_val; /* NULL terminated string */
49
-	} val;                           /* union of all possible types */
50
-} db_val_t;
51
-
52
-
53
-/*
54
- * Useful macros for accessing attributes of db_val structure
55
- */
56
-
57
-/* Get value type */
58
-#define VAL_TYPE(dv)   ((dv)->type)
59
-
60
-/* Get null flag (means that value in dabase is null) */
61
-#define VAL_NULL(dv)   ((dv)->nul)
62
-
63
-/* Get integer value */
64
-#define VAL_INT(dv)    ((dv)->val.int_val)
65
-
66
-/* Get double value */
67
-#define VAL_DOUBLE(dv) ((dv)->val.double_val)
68
-
69
-/* Get time_t value */
70
-#define VAL_TIME(dv)   ((dv)->val.time_val)
71
-
72
-/* Get char* value */
73
-#define VAL_STRING(dv) ((dv)->val.string_val)
74
-
75
-
76
-/* ==================== db_con ======================= */
77
-
78
-/*
79
- * This structure represents a database connection
80
- * and pointer to this structure is used as a connection
81
- * handle
82
- */
83
-typedef struct {
84
-	char* table;     /* Default table to use */
85
-	void* con;       /* Mysql Connection */
86
-	void* res;       /* Result of previous operation */
87
-	void* row;       /* Actual row in the result */
88
-	int   connected; /* TRUE if connection is established */
89
-} db_con_t;
90
-
91
-
92
-/* ===================== db_row ====================== */
93
-
94
-/*
95
- * Structure holding result of query_table function (ie. table row)
96
- */
97
-typedef struct db_row {
98
-	db_val_t* values;  /* Columns in the row */
99
-	int n;             /* Number of columns in the row */
100
-} db_row_t;
101
-
102
-/* Useful macros for manipulating db_row structure attributes */
103
-
104
-/* Get row members */
105
-#define ROW_VALUES(rw) ((rw)->values)
106
-
107
-/* Get number of member in the row */
108
-#define ROW_N(rw)      ((rw)->n)
109
-
110
-
111
-/* ===================== db_res ====================== */
112
-
113
-typedef struct db_res {
114
-	struct {
115
-		db_key_t* names;   /* Column names */
116
-		db_type_t* types;  /* Column types */
117
-		int n;             /* Number of columns */
118
-	} col;
119
-	struct db_row* rows;       /* Rows */
120
-	int n;                     /* Number of rows */
121
-} db_res_t;
122
-
123
-/* Useful macros for manipulating db_res attributes */
124
-
125
-/* Column names */
126
-#define RES_NAMES(re) ((re)->col.names)
127
-
128
-/* Column types */
129
-#define RES_TYPES(re) ((re)->col.types)
130
-
131
-/* Number of columns */
132
-#define RES_COL_N(re) ((re)->col.n)
133
-
134
-/* Rows */
135
-#define RES_ROWS(re)  ((re)->rows)
136
-
137
-/* Number of rows */
138
-#define RES_ROW_N(re) ((re)->n)
139
-
140
-
141
-/*
142
- * Specify table name that will be used for
143
- * subsequent operations
144
- */
145
-typedef int (*db_use_table_f)(db_con_t* _h, const char* _t);
146
-
147
-
148
-/*
149
- * Initialize database connection and
150
- * obtain the connection handle
151
- */
152
-typedef db_con_t* (*db_init_f) (const char* _sqlurl);
153
-
154
-
155
-/*
156
- * Close a database connection and free
157
- * all memory used
158
- */
159
-typedef void (*db_close_f) (db_con_t* _h); 
160
-
161
-
162
-/*
163
- * Query table for specified rows
164
- * _h: structure representing database connection
165
- * _k: key names
166
- * _v: values of the keys that must match
167
- * _c: column names to return
168
- * _n: nmber of key=values pairs to compare
169
- * _nc: number of columns to return
170
- * _o: order by the specified column
171
- * _r: Result will be stored in this variable
172
- *     NULL if there is no result
173
- */
174
-typedef int (*db_query_f) (db_con_t* _h, db_key_t* _k, 
175
-			   db_val_t* _v, db_key_t* _c, 
176
-			   int _n, int _nc,
177
-			   db_key_t _o, db_res_t** _r);
178
-
179
-
180
-/*
181
- * Free a result allocated by db_query
182
- * _h: structure representing database connection
183
- * _r: db_res structure
184
- */
185
-typedef int (*db_free_query_f) (db_con_t* _h, db_res_t* _r);
186
-
187
-
188
-/*
189
- * Insert a row into specified table
190
- * _h: structure representing database connection
191
- * _k: key names
192
- * _v: values of the keys
193
- * _n: number of key=value pairs
194
- */
195
-typedef int (*db_insert_f) (db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n);
196
-
197
-
198
-/*
199
- * Delete a row from the specified table
200
- * _h: structure representing database connection
201
- * _k: key names
202
- * _v: values of the keys that must match
203
- * _n: number of key=value pairs
204
- */
205
-typedef int (*db_delete_f) (db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n);
206
-
207
-
208
-/*
209
- * Update some rows in the specified table
210
- * _h: structure representing database connection
211
- * _k: key names
212
- * _v: values of the keys that must match
213
- * _uk: updated columns
214
- * _uv: updated values of the columns
215
- * _n: number of key=value pairs
216
- * _un: number of columns to update
217
- */
218
-typedef int (*db_update_f) (db_con_t* _h, db_key_t* _k, db_val_t* _v,
219
-			    db_key_t* _uk, db_val_t* _uv, int _n, int _un);
220
-
221
-
222
-
223
-typedef struct db_func{
224
-	db_use_table_f  use_table;   /* Specify table name */
225
-	db_init_f       init;        /* Initialize dabase connection */
226
-	db_close_f      close;       /* Close database connection */
227
-	db_query_f      query;       /* query a table */
228
-	db_free_query_f free_query;  /* Free a query result */
229
-	db_insert_f     insert;      /* Insert into table */
230
-	db_delete_f     delete;      /* Delete from table */ 
231
-	db_update_f     update;      /* Update table */
232
-} db_func_t;
233
-
234
-
235
-/*
236
- * Bind database module functions
237
- * returns TRUE if everything went OK
238
- * FALSE otherwise
239
- */
240
-int bind_dbmod(void);
241
-
242
-
243
-extern db_func_t dbf;
244
-
245
-
246
-#define db_use_table  (dbf.use_table)
247
-#define db_init       (dbf.init)
248
-#define db_close      (dbf.close)
249
-#define db_query      (dbf.query)
250
-#define db_free_query (dbf.free_query)
251
-#define db_insert     (dbf.insert)
252
-#define db_delete     (dbf.delete)
253
-#define db_update     (dbf.update)
254
- 
255
-#endif
... ...
@@ -8,7 +8,7 @@
8 8
 #include <time.h>
9 9
 #include "contact.h"
10 10
 #include "../../parser/msg_parser.h"
11
-#include "db.h"
11
+#include "../../db/db.h"
12 12
 
13 13
 
14 14
 /*
... ...
@@ -11,7 +11,7 @@
11 11
 #include "utils.h"
12 12
 #include "../../sr_module.h"
13 13
 #include "to_parser.h"
14
-#include "db.h"
14
+#include "../../db/db.h"
15 15
 #include "../../action.h"
16 16
 #include "defs.h"
17 17
 #include "../../data_lump_rpl.h"