Browse code

- changed db api: now several db modules can be used simultaneously; all the modules were updated to use the new api - small cleaups, like using static db related variables in modules (were it was possible) - changed version no.

Andrei Pelinescu-Onciul authored on 08/06/2004 10:55:29
Showing 8 changed files
... ...
@@ -45,7 +45,7 @@ export makefile_defs
45 45
 VERSION = 0
46 46
 PATCHLEVEL = 8
47 47
 SUBLEVEL =   13
48
-EXTRAVERSION = -dev-29
48
+EXTRAVERSION = -dev-30-db_api
49 49
 
50 50
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
51 51
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -24,6 +24,11 @@
24 24
  * along with this program; if not, write to the Free Software 
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27
+ /*
28
+  * History:
29
+  * --------
30
+  *  2004-06-06  bind_dbmod takes dbf as parameter (andrei)
31
+  */
27 32
 
28 33
 
29 34
 #include "db.h"
... ...
@@ -33,25 +38,36 @@
33 38
 #include "../str.h"
34 39
 #include "../ut.h"
35 40
 
36
-db_func_t dbf;
37 41
 
38 42
 
39
-int bind_dbmod(char* mod)
43
+/* fills mydbf with the corresponding db module callbacks
44
+ * returns 0 on success, -1 on error
45
+ * on error mydbf will contain only 0s */
46
+int bind_dbmod(char* mod, db_func_t* mydbf)
40 47
 {
41 48
 	char* tmp, *p;
42 49
 	int len;
50
+	db_func_t dbf;
43 51
 
44 52
 	if (!mod) {
45
-		LOG(L_ERR, "bind_dbmod(): Invalid database module name\n");
53
+		LOG(L_CRIT, "BUG: bind_dbmod(): null database module name\n");
46 54
 		return -1;
47 55
 	}
56
+	if (mydbf==0) {
57
+		LOG(L_CRIT, "BUG: bind_dbmod(): null dbf parameter\n");
58
+		return -1;
59
+	}
60
+	/* for safety we initialize mydbf with 0 (this will cause
61
+	 *  a segfault immediately if someone tries to call a function
62
+	 *  from it without checking the return code from bind_dbmod -- andrei */
63
+	memset((void*)mydbf, 0, sizeof(db_func_t));
48 64
 
49 65
 	p = strchr(mod, ':');
50 66
 	if (p) {
51 67
 		len = p - mod;
52 68
 		tmp = (char*)pkg_malloc(len + 1);
53 69
 		if (!tmp) {
54
-			LOG(L_ERR, "bind_dbmod(): No memory left\n");
70
+			LOG(L_ERR, "ERROR: bind_dbmod(): No memory left\n");
55 71
 			return -1;
56 72
 		}
57 73
 		memcpy(tmp, mod, len);
... ...
@@ -60,33 +76,35 @@ int bind_dbmod(char* mod)
60 76
 		tmp = mod;
61 77
 	}
62 78
 
63
-	db_use_table = (db_use_table_f)find_mod_export(tmp, "db_use_table", 2, 0);
64
-	if (db_use_table == 0) goto err;
79
+	dbf.use_table = (db_use_table_f)find_mod_export(tmp, "db_use_table", 2, 0);
80
+	if (dbf.use_table == 0) goto err;
65 81
 
66
-	db_init = (db_init_f)find_mod_export(tmp, "db_init", 1, 0);
67
-	if (db_init == 0) goto err;
82
+	dbf.init = (db_init_f)find_mod_export(tmp, "db_init", 1, 0);
83
+	if (dbf.init == 0) goto err;
68 84
 
69
-	db_close = (db_close_f)find_mod_export(tmp, "db_close", 2, 0);
70
-	if (db_close == 0) goto err;
85
+	dbf.close = (db_close_f)find_mod_export(tmp, "db_close", 2, 0);
86
+	if (dbf.close == 0) goto err;
71 87
 
72
-	db_query = (db_query_f)find_mod_export(tmp, "db_query", 2, 0);
73
-	if (db_query == 0) goto err;
88
+	dbf.query = (db_query_f)find_mod_export(tmp, "db_query", 2, 0);
89
+	if (dbf.query == 0) goto err;
74 90
 
75
-	db_raw_query = (db_raw_query_f)find_mod_export(tmp, "db_raw_query", 2, 0);
76
-	if (db_raw_query == 0) goto err;
91
+	dbf.raw_query = (db_raw_query_f)find_mod_export(tmp, "db_raw_query", 2, 0);
92
+	if (dbf.raw_query == 0) goto err;
77 93
 
78
-	db_free_query = (db_free_query_f)find_mod_export(tmp, "db_free_query", 2, 0);
79
-	if (db_free_query == 0) goto err;
94
+	dbf.free_query = (db_free_query_f)find_mod_export(tmp, "db_free_query", 2,
95
+														0);
96
+	if (dbf.free_query == 0) goto err;
80 97
 
81
-	db_insert = (db_insert_f)find_mod_export(tmp, "db_insert", 2, 0);
82
-	if (db_insert == 0) goto err;
98
+	dbf.insert = (db_insert_f)find_mod_export(tmp, "db_insert", 2, 0);
99
+	if (dbf.insert == 0) goto err;
83 100
 
84
-	db_delete = (db_delete_f)find_mod_export(tmp, "db_delete", 2, 0);
85
-	if (db_delete == 0) goto err;
101
+	dbf.delete = (db_delete_f)find_mod_export(tmp, "db_delete", 2, 0);
102
+	if (dbf.delete == 0) goto err;
86 103
 
87
-	db_update = (db_update_f)find_mod_export(tmp, "db_update", 2, 0);
88
-	if (db_update == 0) goto err;
104
+	dbf.update = (db_update_f)find_mod_export(tmp, "db_update", 2, 0);
105
+	if (dbf.update == 0) goto err;
89 106
 
107
+	*mydbf=dbf; /* copy */
90 108
 	return 0;
91 109
 
92 110
  err:
... ...
@@ -99,19 +117,19 @@ int bind_dbmod(char* mod)
99 117
  * Get version of a table
100 118
  * If there is no row for the given table, return version 0
101 119
  */
102
-int table_version(db_con_t* connection, const str* table)
120
+int table_version(db_func_t* dbf, db_con_t* connection, const str* table)
103 121
 {
104 122
 	db_key_t key[1], col[1];
105 123
 	db_val_t val[1];
106 124
 	db_res_t* res;
107 125
 	int ret;
108 126
 
109
-	if (!connection || !table) {
110
-		LOG(L_ERR, "table_version(): Invalid parameter value\n");
127
+	if (!dbf||!connection || !table) {
128
+		LOG(L_CRIT, "BUG: table_version(): Invalid parameter value\n");
111 129
 		return -1;
112 130
 	}
113 131
 
114
-	if (db_use_table(connection, VERSION_TABLE) < 0) {
132
+	if (dbf->use_table(connection, VERSION_TABLE) < 0) {
115 133
 		LOG(L_ERR, "table_version(): Error while changing table\n");
116 134
 		return -1;
117 135
 	}
... ...
@@ -124,7 +142,7 @@ int table_version(db_con_t* connection, const str* table)
124 142
 	
125 143
 	col[0] = VERSION_COLUMN;
126 144
 	
127
-	if (db_query(connection, key, 0, val, col, 1, 1, 0, &res) < 0) {
145
+	if (dbf->query(connection, key, 0, val, col, 1, 1, 0, &res) < 0) {
128 146
 		LOG(L_ERR, "table_version(): Error in db_query\n");
129 147
 		return -1;
130 148
 	}
... ...
@@ -136,11 +154,11 @@ int table_version(db_con_t* connection, const str* table)
136 154
 
137 155
 	if (RES_ROW_N(res) != 1) {
138 156
 		LOG(L_ERR, "table_version(): Invalid number of rows received: %d, %.*s\n", RES_ROW_N(res), table->len, ZSW(table->s));
139
-		db_free_query(connection, res);
157
+		dbf->free_query(connection, res);
140 158
 		return -1;
141 159
 	}
142 160
 
143 161
 	ret = VAL_INT(ROW_VALUES(RES_ROWS(res)));
144
-	db_free_query(connection, res);
162
+	dbf->free_query(connection, res);
145 163
 	return ret;
146 164
 }
... ...
@@ -24,6 +24,11 @@
24 24
  * along with this program; if not, write to the Free Software 
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27
+/*
28
+ * History:
29
+ * --------
30
+ *  2004-06-06  removed db_* macros and global dbf (andrei)
31
+ */
27 32
 
28 33
 
29 34
 #ifndef DB_H
... ...
@@ -141,27 +146,13 @@ typedef struct db_func {
141 146
 } db_func_t;
142 147
 
143 148
 
149
+
144 150
 /*
145 151
  * Bind database module functions
146 152
  * returns TRUE if everything went OK
147 153
  * FALSE otherwise
148 154
  */
149
-
150
-extern db_func_t dbf;
151
-
152
-
153
-#define db_use_table  (dbf.use_table)
154
-#define db_init       (dbf.init)
155
-#define db_close      (dbf.close)
156
-#define db_query      (dbf.query)
157
-#define db_raw_query  (dbf.raw_query)
158
-#define db_free_query (dbf.free_query)
159
-#define db_insert     (dbf.insert)
160
-#define db_delete     (dbf.delete)
161
-#define db_update     (dbf.update)
162
-
163
-
164
-int bind_dbmod(char* mod);
155
+int bind_dbmod(char* mod, db_func_t* dbf);
165 156
 
166 157
 
167 158
 /*
... ...
@@ -169,7 +160,7 @@ int bind_dbmod(char* mod);
169 160
  * no row for the table then the function returns
170 161
  * version 0. -1 is returned on error.
171 162
  */
172
-int table_version(db_con_t* con, const str* table);
163
+int table_version(db_func_t* dbf, db_con_t* con, const str* table);
173 164
 
174 165
 
175 166
 #endif /* DB_H */
... ...
@@ -27,6 +27,7 @@
27 27
  * History:
28 28
  * --------
29 29
  *  2003-10-21  file created (bogdan)
30
+ *  2004-06-06  init_db_fifo added, DB api updated (andrei)
30 31
  */
31 32
 
32 33
 
... ...
@@ -43,6 +44,7 @@
43 44
 #include "../dprint.h"
44 45
 #include "../str.h"
45 46
 #include "db.h"
47
+#include "db_fifo.h"
46 48
 
47 49
 #define MAX_SIZE_LINE 512
48 50
 #define MAX_ARRAY     32
... ...
@@ -119,7 +121,8 @@
119 121
 
120 122
 static char   buf[MAX_SIZE_LINE];
121 123
 static FILE*  rpl;
122
-db_con_t*     fifo_db_con;
124
+static db_con_t*     fifo_db_con=0;
125
+static db_func_t fifo_dbf;
123 126
 
124 127
 
125 128
 
... ...
@@ -558,6 +561,32 @@ static inline void print_res(db_res_t* res, FILE *rpl)
558 561
 
559 562
 
560 563
 
564
+/* binds the database module, initializes the database and 
565
+ * registers the db fifo cmd
566
+ * returns 0 on success, -1 on error */
567
+int init_db_fifo(char* fifo_db_url)
568
+{
569
+	if ( bind_dbmod(fifo_db_url, &fifo_dbf)==0 ) {
570
+		if ( (fifo_db_con=fifo_dbf.init( fifo_db_url ))==0) {
571
+			/* connection failed */
572
+			LOG(L_ERR,"ERROR: init_db_fifo: unable to connect to database -> "
573
+				"fifo DB commands disabled!\n");
574
+		}else if (register_fifo_cmd(db_fifo_cmd, FIFO_DB, 0)<0) {
575
+			LOG(L_ERR, "ERROR: init_db_fifo: unable to register '%s'"
576
+					" FIFO cmd\n", FIFO_DB);
577
+		} else {
578
+			return 0; /* success */
579
+		}
580
+	}else{
581
+		LOG(L_WARN, "WARNING: init_db_fifo: unable to find any db module - "
582
+			"fifo DB commands disabled!\n");
583
+	}
584
+	return -1; /* error */
585
+}
586
+
587
+
588
+
589
+
561 590
 
562 591
 int db_fifo( FILE *fifo, char *response_file )
563 592
 {
... ...
@@ -577,6 +606,8 @@ int db_fifo( FILE *fifo, char *response_file )
577 606
 	ret = -1; /* default is error */
578 607
 	rpl =  0;
579 608
 
609
+	if (fifo_db_con==0) /* disabled due to database init/binding errors */
610
+		goto error;
580 611
 	/* first check the response file */
581 612
 	rpl = open_reply_pipe( response_file );
582 613
 	if (rpl==0)
... ...
@@ -649,9 +680,9 @@ int db_fifo( FILE *fifo, char *response_file )
649 680
 		trim_spaces(line);
650 681
 		/* run the command */
651 682
 		if (db_cmd==RAWQUERY_CMD)
652
-			n = db_raw_query( fifo_db_con, line.s, 0);
683
+			n = fifo_dbf.raw_query( fifo_db_con, line.s, 0);
653 684
 		else
654
-			n = db_raw_query( fifo_db_con, line.s, &select_res);
685
+			n = fifo_dbf.raw_query( fifo_db_con, line.s, &select_res);
655 686
 		if (n!=0) {
656 687
 			double_log("Internal Server error - DB query failed");
657 688
 			goto error;
... ...
@@ -661,7 +692,7 @@ int db_fifo( FILE *fifo, char *response_file )
661 692
 			/* get all response and write them into reply fifo */
662 693
 			print_res( select_res, rpl);
663 694
 			/* free the query response */
664
-			db_free_query( fifo_db_con, select_res);
695
+			fifo_dbf.free_query( fifo_db_con, select_res);
665 696
 		}
666 697
 		/* done with success */
667 698
 		goto done;
... ...
@@ -677,7 +708,7 @@ int db_fifo( FILE *fifo, char *response_file )
677 708
 
678 709
 	/* select the correct table */
679 710
 	line.s[line.len] = 0; /* make it null terminated */
680
-	db_use_table( fifo_db_con, line.s);
711
+	fifo_dbf.use_table( fifo_db_con, line.s);
681 712
 
682 713
 	/*read 'where' avps */
683 714
 	if (get_avps( fifo , keys2, ops2, vals2, &nr2, MAX_ARRAY)!=0 )
... ...
@@ -686,8 +717,8 @@ int db_fifo( FILE *fifo, char *response_file )
686 717
 	switch (db_cmd) {
687 718
 		case SELECT_CMD:
688 719
 			/* push the query */
689
-			n = db_query( fifo_db_con, nr2?keys2:0, nr2?ops2:0, nr2?vals2:0,
690
-				nr1?keys1:0, nr2, nr1, 0, &select_res );
720
+			n = fifo_dbf.query( fifo_db_con, nr2?keys2:0, nr2?ops2:0,
721
+						nr2?vals2:0, nr1?keys1:0, nr2, nr1, 0, &select_res );
691 722
 			if (n!=0) {
692 723
 				double_log("Internal Server error - DB query failed");
693 724
 				goto error2;
... ...
@@ -695,7 +726,7 @@ int db_fifo( FILE *fifo, char *response_file )
695 726
 			/* get all response and write them into reply fifo */
696 727
 			print_res( select_res, rpl);
697 728
 			/* free the query response */
698
-			db_free_query( fifo_db_con, select_res);
729
+			fifo_dbf.free_query( fifo_db_con, select_res);
699 730
 			break;
700 731
 		case UPDATE_CMD:
701 732
 			if (nr1==0) {
... ...
@@ -711,8 +742,8 @@ int db_fifo( FILE *fifo, char *response_file )
711 742
 				}
712 743
 			}/*end for*/
713 744
 			/* push the query */
714
-			n = db_update( fifo_db_con, nr2?keys2:0, nr2?ops2:0, nr2?vals2:0,
715
-				keys1, vals1, nr2, nr1 );
745
+			n = fifo_dbf.update( fifo_db_con, nr2?keys2:0, nr2?ops2:0,
746
+					nr2?vals2:0, keys1, vals1, nr2, nr1 );
716 747
 			if (n!=0) {
717 748
 				double_log("Internal Server error - DB query failed");
718 749
 				goto error2;
... ...
@@ -720,8 +751,8 @@ int db_fifo( FILE *fifo, char *response_file )
720 751
 			break;
721 752
 		case DELETE_CMD:
722 753
 			/* push the query */
723
-			n = db_delete( fifo_db_con, nr2?keys2:0, nr2?ops2:0, nr2?vals2:0,
724
-				nr2);
754
+			n = fifo_dbf.delete( fifo_db_con, nr2?keys2:0, nr2?ops2:0,
755
+					nr2?vals2:0, nr2);
725 756
 			if (n!=0) {
726 757
 				double_log("Internal Server error - DB query failed");
727 758
 				goto error2;
... ...
@@ -741,7 +772,7 @@ int db_fifo( FILE *fifo, char *response_file )
741 772
 				}
742 773
 			}/*end for*/
743 774
 			/* push the query */
744
-			n = db_insert( fifo_db_con, nr2?keys2:0, nr2?vals2:0, nr2);
775
+			n = fifo_dbf.insert( fifo_db_con, nr2?keys2:0, nr2?vals2:0, nr2);
745 776
 			if (n!=0) {
746 777
 				double_log("Internal Server error - DB query failed");
747 778
 				goto error2;
... ...
@@ -35,8 +35,7 @@
35 35
 #define db_fifo_cmd  db_fifo
36 36
 #define FIFO_DB      "DB"
37 37
 
38
-extern db_con_t*   fifo_db_con;
39
-
38
+int init_db_fifo(char* db_url);
40 39
 int db_fifo( FILE *fifo_stream, char *response_file );
41 40
 
42 41
 
... ...
@@ -1,4 +1,8 @@
1
-$Id$
1
+# $Id$
2
+# 
3
+# History:
4
+# --------
5
+#  2004-06-06  updated (bind_dbmod and obsoleted db_* macros)  (andrei)
2 6
 
3 7
 Generic Database Interface
4 8
 --------------------------
... ...
@@ -332,19 +336,28 @@ prefix). This function MUST be called __FIRST__ !
332 336
 
333 337
 2.1.2 Prototype
334 338
 
335
-   int bind_dbmod(void);
339
+   int bind_dbmod(char* db_url, db_func_t* dbf);
336 340
 
337 341
 2.1.3 Parameters
338 342
 
339
-The function takes no parameters.
343
+The function takes two parameters, the first parameter must contain a database 
344
+connection URL or a database module name. The db_url is of the form 
345
+"mysql://username:password@host:port/database" or
346
+"mysql" (database module name).
347
+In the case of a database connection URL, this function looks only at the first
348
+token (the database protocol). In the example above that would be "mysql":
349
+The second parameter will be filled by this function with the corresponding
350
+ database module callbacks (see the db_func_t structure definition in
351
+  db.h and the callbacks definitions below).
352
+
340 353
 
341 354
 2.1.4 Return Value
342 355
 
343
-The function returns 0 if it was able to find addresses of all other 
344
-functions, otherwise value < 0 is returned.
356
+The function returns 0 if it was able to find the addresses of all the 
357
+corresponding module database functions and a value < 0 otherwise.
345 358
 
346 359
 
347
-2.2 Function db_init
360
+2.2 Callback dbf.init
348 361
 
349 362
 2.2.1 Description
350 363
 
... ...
@@ -354,7 +367,7 @@ function is called.
354 367
 
355 368
 2.2.2 Prototype
356 369
 
357
-   db_con_t* db_init(const char* _sql_url);
370
+   db_con_t* (*db_init_f)(const char* _sql_url);
358 371
 
359 372
 2.2.3 Parameters
360 373
 
... ...
@@ -378,7 +391,7 @@ The function returns pointer to db_con_t* representing the connection if it was
378 391
 successful, otherwise 0 is returned.
379 392
 
380 393
 
381
-2.3 Function db_close
394
+2.3 Callback dbf.close
382 395
 
383 396
 2.3.1 Description
384 397
 
... ...
@@ -388,7 +401,7 @@ allocated memory. The function db_close must be the very last function called.
388 401
 
389 402
 2.3.2 Prototype
390 403
 
391
-   void db_close(db_con_t* _h);
404
+   void (*db_close_f)(db_con_t* _h);
392 405
 
393 406
 2.3.3 Parameters
394 407
 
... ...
@@ -400,7 +413,7 @@ structure representing database connection that should be closed.
400 413
 Function doesn't return anything.
401 414
 
402 415
 
403
-2.4 Function db_query
416
+2.4 Callback dbf.query
404 417
 
405 418
 2.4.1 Description
406 419
 
... ...
@@ -408,7 +421,7 @@ This function implements SELECT SQL directive.
408 421
 
409 422
 2.4.2 Prototype
410 423
 
411
-   int db_query(db_con_t* _h, db_key_t* _k, db_op_t* _op,
424
+   int (*db_query_f)(db_con_t* _h, db_key_t* _k, db_op_t* _op,
412 425
                 db_val_t* _v, db_key_t* _c, 
413 426
 	        int _n, int _nc, db_key_t _o, db_res_t** _r);
414 427
 
... ...
@@ -443,7 +456,7 @@ You must call db_free_query _BEFORE_ you can call db_query again !
443 456
 The function returns 0 if everything is OK, otherwise value < 0 is returned.
444 457
 
445 458
 
446
-2.5 Function db_free_query
459
+2.5 Callback dbf.free_query
447 460
 
448 461
 2.5.1 Description
449 462
 
... ...
@@ -454,7 +467,7 @@ again !
454 467
 
455 468
 2.5.2 Prototype
456 469
 
457
-   int db_free_query(db_con_t* _h, db_res_t* _r);
470
+   int (*db_free_query_f)(db_con_t* _h, db_res_t* _r);
458 471
 
459 472
 2.5.3 Parameters
460 473
 
... ...
@@ -468,7 +481,7 @@ The function returns 0 if everything is OK, otherwise the function returns
468 481
 value < 0.
469 482
 
470 483
 
471
-2.6 Function db_insert
484
+2.6 Callback dbf.insert
472 485
 
473 486
 2.6.1 Description
474 487
 
... ...
@@ -477,7 +490,7 @@ rows in a table using this function.
477 490
 
478 491
 2.6.2 Prototype
479 492
 
480
-   int db_insert(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n);
493
+   int (*db_insert_f)(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n);
481 494
 
482 495
 2.6.3 Parameters
483 496
 
... ...
@@ -493,7 +506,7 @@ The function returns 0 if everything is OK, otherwise the function returns
493 506
 value < 0.
494 507
 
495 508
 
496
-2.7 Function db_delete
509
+2.7 Callback dbf.delete
497 510
 
498 511
 2.7.1 Description
499 512
 
... ...
@@ -502,7 +515,8 @@ more rows from a table.
502 515
 
503 516
 2.7.2 Prototype
504 517
 
505
-   int db_delete(db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n);
518
+   int (*db_delete_f)(db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
519
+                       int _n);
506 520
 
507 521
 2.7.3 Parameters
508 522
 
... ...
@@ -524,7 +538,7 @@ The function returns 0 if everything is OK, otherwise the function returns
524 538
 value < 0.
525 539
 
526 540
 
527
-2.8 Function db_update
541
+2.8 Callback dbf.update
528 542
 
529 543
 2.8.1 Description
530 544
 
... ...
@@ -533,7 +547,7 @@ or more rows in a table using this function.
533 547
 
534 548
 2.8.2 Prototype
535 549
 
536
-   int db_update(db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
550
+   int (*db_update_f)(db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
537 551
 	         db_key_t* _uk, db_val_t* _uv, int _n, int _un);
538 552
 
539 553
 2.8.3 Parameters
... ...
@@ -554,7 +568,7 @@ The function returns 0 if everything is OK, otherwise the function returns
554 568
 value < 0.
555 569
 
556 570
 
557
-2.9 Function db_use_table
571
+2.9 Callback dbf.use_table
558 572
 
559 573
 2.9.1 Description
560 574
 
... ...
@@ -564,7 +578,7 @@ that table.
564 578
 
565 579
 2.9.2 Prototype
566 580
 
567
-   int db_use_table_f(db_con_t* _h, const char* _t);
581
+   int (*db_use_table_f)(db_con_t* _h, const char* _t);
568 582
 
569 583
 2.9.3 Parameters
570 584
 
... ...
@@ -62,6 +62,7 @@
62 62
  *  2003-10-30  DB interface exported via FIFO (bogdan)
63 63
  *  2004-03-09  open_fifo_server split into init_ and start_ (andrei)
64 64
  *  2004-04-29  added chown(sock_user, sock_group)  (andrei)
65
+ *  2004-06-06  updated to the new DB interface  & init_db_fifo (andrei)
65 66
  */
66 67
 
67 68
 
... ...
@@ -97,6 +98,8 @@ char *fifo=0; /* FIFO name */
97 98
 char* fifo_dir=DEFAULT_FIFO_DIR; /* dir where reply fifos are allowed */
98 99
 char *fifo_db_url = 0;
99 100
 pid_t fifo_pid;
101
+
102
+
100 103
 /* file descriptors */
101 104
 static int fifo_read=0;
102 105
 static int fifo_write=0;
... ...
@@ -890,20 +893,8 @@ int register_core_fifo()
890 893
 	if (fifo_db_url==0) {
891 894
 		LOG(L_WARN,"WARNING: no fifo_db_url given - "
892 895
 			"fifo DB commands disabled!\n");
893
-	} else if ( bind_dbmod(fifo_db_url)==0 ) {
894
-		if (register_fifo_cmd(db_fifo_cmd, FIFO_DB, 0)<0) {
895
-			LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_DB);
896
-			return -1;
897
-		} else {
898
-			if ( (fifo_db_con=db_init( fifo_db_url ))==0) {
899
-				/* connection failed */
900
-			LOG(L_ERR,"ERROR: unable to connect to database -> "
901
-				"fifo DB commands disabled!\n");
902
-			}
903
-		}
904
-	} else {
905
-		LOG(L_WARN,"WARNING: unable to find any db module - "
906
-			"fifo DB commands disabled!\n");
896
+	} else if (init_db_fifo(fifo_db_url)<0){
897
+		return -1;
907 898
 	}
908 899
 	return 1;
909 900
 }
... ...
@@ -27,6 +27,7 @@
27 27
  * History:
28 28
  * ---------
29 29
  *  2004-02-06  created (bogdan)
30
+ *  2004-06-06  updated to the current DB api (andrei)
30 31
  */
31 32
 
32 33
 
... ...
@@ -43,6 +44,7 @@
43 44
 
44 45
 
45 46
 static db_con_t  *avp_db_con = 0;
47
+static db_func_t avp_dbf; /* database call backs */
46 48
 struct usr_avp   *users_avps = 0;
47 49
 char             *avp_db_url = 0;
48 50
 
... ...
@@ -59,16 +61,16 @@ int init_avp_child( int rank )
59 61
 			return 0;
60 62
 		}
61 63
 		/* init db connection */
62
-		if ( bind_dbmod(avp_db_url) < 0 ) {
64
+		if ( bind_dbmod(avp_db_url, &avp_dbf) < 0 ) {
63 65
 			LOG(L_ERR,"ERROR:init_avp_child: unable to find any db module\n");
64 66
 			return -1;
65 67
 		}
66
-		if ( (avp_db_con=db_init( avp_db_url ))==0) {
68
+		if ( (avp_db_con=avp_dbf.init( avp_db_url ))==0) {
67 69
 			/* connection failed */
68 70
 			LOG(L_ERR,"ERROR:init_avp_child: unable to connect to database\n");
69 71
 			return -1;
70 72
 		}
71
-		if (db_use_table( avp_db_con, AVP_DB_TABLE )<0) {
73
+		if (avp_dbf.use_table( avp_db_con, AVP_DB_TABLE )<0) {
72 74
 			/* table selection failed */
73 75
 			LOG(L_ERR,"ERROR:init_avp_child: unable to select db table\n");
74 76
 			return -1;
... ...
@@ -167,7 +169,7 @@ inline static db_res_t *do_db_query(struct sip_uri *uri,char *attr,int use_dom)
167 169
 	}
168 170
 
169 171
 	/* do the DB query */
170
-	if ( db_query( avp_db_con, keys_cmp, 0/*op*/, vals_cmp, keys_ret,
172
+	if ( avp_dbf.query( avp_db_con, keys_cmp, 0/*op*/, vals_cmp, keys_ret,
171 173
 	nr_keys_cmp, 3, 0/*order*/, &res) < 0)
172 174
 		return 0;
173 175
 
... ...
@@ -291,7 +293,7 @@ int load_avp( struct sip_msg *msg, int uri_type, char *attr, int use_dom)
291 293
 		DBG("DEBUG:load_avp: no avp found for %.*s@%.*s <%s>\n",
292 294
 			uri.user.len,uri.user.s,(use_dom!=0)*uri.host.len,uri.host.s,
293 295
 			attr?attr:"NULL");
294
-		db_free_query( avp_db_con, res);
296
+		avp_dbf.free_query( avp_db_con, res);
295 297
 		/*no avp found*/
296 298
 		return 1;
297 299
 	}
... ...
@@ -334,7 +336,7 @@ int load_avp( struct sip_msg *msg, int uri_type, char *attr, int use_dom)
334 336
 		users_avps = avp;
335 337
 	}
336 338
 
337
-	db_free_query( avp_db_con, res);
339
+	avp_dbf.free_query( avp_db_con, res);
338 340
 	return 0;
339 341
 error:
340 342
 	return -1;