2
0
Эх сурвалжийг харах

- 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 21 жил өмнө
parent
commit
e397136516
8 өөрчлөгдсөн 149 нэмэгдсэн , 103 устгасан
  1. 1 1
      Makefile.defs
  2. 47 29
      db/db.c
  3. 8 17
      db/db.h
  4. 44 13
      db/db_fifo.c
  5. 1 2
      db/db_fifo.h
  6. 35 21
      db/doc/db-api.txt
  7. 5 14
      fifo_server.c
  8. 8 6
      usr_avp.c

+ 1 - 1
Makefile.defs

@@ -45,7 +45,7 @@ export makefile_defs
 VERSION = 0
 VERSION = 0
 PATCHLEVEL = 8
 PATCHLEVEL = 8
 SUBLEVEL =   13
 SUBLEVEL =   13
-EXTRAVERSION = -dev-29
+EXTRAVERSION = -dev-30-db_api
 
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 47 - 29
db/db.c

@@ -24,6 +24,11 @@
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
  */
+ /*
+  * History:
+  * --------
+  *  2004-06-06  bind_dbmod takes dbf as parameter (andrei)
+  */
 
 
 
 
 #include "db.h"
 #include "db.h"
@@ -33,25 +38,36 @@
 #include "../str.h"
 #include "../str.h"
 #include "../ut.h"
 #include "../ut.h"
 
 
-db_func_t dbf;
 
 
 
 
-int bind_dbmod(char* mod)
+/* fills mydbf with the corresponding db module callbacks
+ * returns 0 on success, -1 on error
+ * on error mydbf will contain only 0s */
+int bind_dbmod(char* mod, db_func_t* mydbf)
 {
 {
 	char* tmp, *p;
 	char* tmp, *p;
 	int len;
 	int len;
+	db_func_t dbf;
 
 
 	if (!mod) {
 	if (!mod) {
-		LOG(L_ERR, "bind_dbmod(): Invalid database module name\n");
+		LOG(L_CRIT, "BUG: bind_dbmod(): null database module name\n");
 		return -1;
 		return -1;
 	}
 	}
+	if (mydbf==0) {
+		LOG(L_CRIT, "BUG: bind_dbmod(): null dbf parameter\n");
+		return -1;
+	}
+	/* for safety we initialize mydbf with 0 (this will cause
+	 *  a segfault immediately if someone tries to call a function
+	 *  from it without checking the return code from bind_dbmod -- andrei */
+	memset((void*)mydbf, 0, sizeof(db_func_t));
 
 
 	p = strchr(mod, ':');
 	p = strchr(mod, ':');
 	if (p) {
 	if (p) {
 		len = p - mod;
 		len = p - mod;
 		tmp = (char*)pkg_malloc(len + 1);
 		tmp = (char*)pkg_malloc(len + 1);
 		if (!tmp) {
 		if (!tmp) {
-			LOG(L_ERR, "bind_dbmod(): No memory left\n");
+			LOG(L_ERR, "ERROR: bind_dbmod(): No memory left\n");
 			return -1;
 			return -1;
 		}
 		}
 		memcpy(tmp, mod, len);
 		memcpy(tmp, mod, len);
@@ -60,33 +76,35 @@ int bind_dbmod(char* mod)
 		tmp = mod;
 		tmp = mod;
 	}
 	}
 
 
-	db_use_table = (db_use_table_f)find_mod_export(tmp, "db_use_table", 2, 0);
-	if (db_use_table == 0) goto err;
+	dbf.use_table = (db_use_table_f)find_mod_export(tmp, "db_use_table", 2, 0);
+	if (dbf.use_table == 0) goto err;
 
 
-	db_init = (db_init_f)find_mod_export(tmp, "db_init", 1, 0);
-	if (db_init == 0) goto err;
+	dbf.init = (db_init_f)find_mod_export(tmp, "db_init", 1, 0);
+	if (dbf.init == 0) goto err;
 
 
-	db_close = (db_close_f)find_mod_export(tmp, "db_close", 2, 0);
-	if (db_close == 0) goto err;
+	dbf.close = (db_close_f)find_mod_export(tmp, "db_close", 2, 0);
+	if (dbf.close == 0) goto err;
 
 
-	db_query = (db_query_f)find_mod_export(tmp, "db_query", 2, 0);
-	if (db_query == 0) goto err;
+	dbf.query = (db_query_f)find_mod_export(tmp, "db_query", 2, 0);
+	if (dbf.query == 0) goto err;
 
 
-	db_raw_query = (db_raw_query_f)find_mod_export(tmp, "db_raw_query", 2, 0);
-	if (db_raw_query == 0) goto err;
+	dbf.raw_query = (db_raw_query_f)find_mod_export(tmp, "db_raw_query", 2, 0);
+	if (dbf.raw_query == 0) goto err;
 
 
-	db_free_query = (db_free_query_f)find_mod_export(tmp, "db_free_query", 2, 0);
-	if (db_free_query == 0) goto err;
+	dbf.free_query = (db_free_query_f)find_mod_export(tmp, "db_free_query", 2,
+														0);
+	if (dbf.free_query == 0) goto err;
 
 
-	db_insert = (db_insert_f)find_mod_export(tmp, "db_insert", 2, 0);
-	if (db_insert == 0) goto err;
+	dbf.insert = (db_insert_f)find_mod_export(tmp, "db_insert", 2, 0);
+	if (dbf.insert == 0) goto err;
 
 
-	db_delete = (db_delete_f)find_mod_export(tmp, "db_delete", 2, 0);
-	if (db_delete == 0) goto err;
+	dbf.delete = (db_delete_f)find_mod_export(tmp, "db_delete", 2, 0);
+	if (dbf.delete == 0) goto err;
 
 
-	db_update = (db_update_f)find_mod_export(tmp, "db_update", 2, 0);
-	if (db_update == 0) goto err;
+	dbf.update = (db_update_f)find_mod_export(tmp, "db_update", 2, 0);
+	if (dbf.update == 0) goto err;
 
 
+	*mydbf=dbf; /* copy */
 	return 0;
 	return 0;
 
 
  err:
  err:
@@ -99,19 +117,19 @@ int bind_dbmod(char* mod)
  * Get version of a table
  * Get version of a table
  * If there is no row for the given table, return version 0
  * If there is no row for the given table, return version 0
  */
  */
-int table_version(db_con_t* connection, const str* table)
+int table_version(db_func_t* dbf, db_con_t* connection, const str* table)
 {
 {
 	db_key_t key[1], col[1];
 	db_key_t key[1], col[1];
 	db_val_t val[1];
 	db_val_t val[1];
 	db_res_t* res;
 	db_res_t* res;
 	int ret;
 	int ret;
 
 
-	if (!connection || !table) {
-		LOG(L_ERR, "table_version(): Invalid parameter value\n");
+	if (!dbf||!connection || !table) {
+		LOG(L_CRIT, "BUG: table_version(): Invalid parameter value\n");
 		return -1;
 		return -1;
 	}
 	}
 
 
-	if (db_use_table(connection, VERSION_TABLE) < 0) {
+	if (dbf->use_table(connection, VERSION_TABLE) < 0) {
 		LOG(L_ERR, "table_version(): Error while changing table\n");
 		LOG(L_ERR, "table_version(): Error while changing table\n");
 		return -1;
 		return -1;
 	}
 	}
@@ -124,7 +142,7 @@ int table_version(db_con_t* connection, const str* table)
 	
 	
 	col[0] = VERSION_COLUMN;
 	col[0] = VERSION_COLUMN;
 	
 	
-	if (db_query(connection, key, 0, val, col, 1, 1, 0, &res) < 0) {
+	if (dbf->query(connection, key, 0, val, col, 1, 1, 0, &res) < 0) {
 		LOG(L_ERR, "table_version(): Error in db_query\n");
 		LOG(L_ERR, "table_version(): Error in db_query\n");
 		return -1;
 		return -1;
 	}
 	}
@@ -136,11 +154,11 @@ int table_version(db_con_t* connection, const str* table)
 
 
 	if (RES_ROW_N(res) != 1) {
 	if (RES_ROW_N(res) != 1) {
 		LOG(L_ERR, "table_version(): Invalid number of rows received: %d, %.*s\n", RES_ROW_N(res), table->len, ZSW(table->s));
 		LOG(L_ERR, "table_version(): Invalid number of rows received: %d, %.*s\n", RES_ROW_N(res), table->len, ZSW(table->s));
-		db_free_query(connection, res);
+		dbf->free_query(connection, res);
 		return -1;
 		return -1;
 	}
 	}
 
 
 	ret = VAL_INT(ROW_VALUES(RES_ROWS(res)));
 	ret = VAL_INT(ROW_VALUES(RES_ROWS(res)));
-	db_free_query(connection, res);
+	dbf->free_query(connection, res);
 	return ret;
 	return ret;
 }
 }

+ 8 - 17
db/db.h

@@ -24,6 +24,11 @@
  * along with this program; if not, write to the Free Software 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
  */
+/*
+ * History:
+ * --------
+ *  2004-06-06  removed db_* macros and global dbf (andrei)
+ */
 
 
 
 
 #ifndef DB_H
 #ifndef DB_H
@@ -141,27 +146,13 @@ typedef struct db_func {
 } db_func_t;
 } db_func_t;
 
 
 
 
+
 /*
 /*
  * Bind database module functions
  * Bind database module functions
  * returns TRUE if everything went OK
  * returns TRUE if everything went OK
  * FALSE otherwise
  * FALSE otherwise
  */
  */
-
-extern db_func_t dbf;
-
-
-#define db_use_table  (dbf.use_table)
-#define db_init       (dbf.init)
-#define db_close      (dbf.close)
-#define db_query      (dbf.query)
-#define db_raw_query  (dbf.raw_query)
-#define db_free_query (dbf.free_query)
-#define db_insert     (dbf.insert)
-#define db_delete     (dbf.delete)
-#define db_update     (dbf.update)
-
-
-int bind_dbmod(char* mod);
+int bind_dbmod(char* mod, db_func_t* dbf);
 
 
 
 
 /*
 /*
@@ -169,7 +160,7 @@ int bind_dbmod(char* mod);
  * no row for the table then the function returns
  * no row for the table then the function returns
  * version 0. -1 is returned on error.
  * version 0. -1 is returned on error.
  */
  */
-int table_version(db_con_t* con, const str* table);
+int table_version(db_func_t* dbf, db_con_t* con, const str* table);
 
 
 
 
 #endif /* DB_H */
 #endif /* DB_H */

+ 44 - 13
db/db_fifo.c

@@ -27,6 +27,7 @@
  * History:
  * History:
  * --------
  * --------
  *  2003-10-21  file created (bogdan)
  *  2003-10-21  file created (bogdan)
+ *  2004-06-06  init_db_fifo added, DB api updated (andrei)
  */
  */
 
 
 
 
@@ -43,6 +44,7 @@
 #include "../dprint.h"
 #include "../dprint.h"
 #include "../str.h"
 #include "../str.h"
 #include "db.h"
 #include "db.h"
+#include "db_fifo.h"
 
 
 #define MAX_SIZE_LINE 512
 #define MAX_SIZE_LINE 512
 #define MAX_ARRAY     32
 #define MAX_ARRAY     32
@@ -119,7 +121,8 @@
 
 
 static char   buf[MAX_SIZE_LINE];
 static char   buf[MAX_SIZE_LINE];
 static FILE*  rpl;
 static FILE*  rpl;
-db_con_t*     fifo_db_con;
+static db_con_t*     fifo_db_con=0;
+static db_func_t fifo_dbf;
 
 
 
 
 
 
@@ -558,6 +561,32 @@ static inline void print_res(db_res_t* res, FILE *rpl)
 
 
 
 
 
 
+/* binds the database module, initializes the database and 
+ * registers the db fifo cmd
+ * returns 0 on success, -1 on error */
+int init_db_fifo(char* fifo_db_url)
+{
+	if ( bind_dbmod(fifo_db_url, &fifo_dbf)==0 ) {
+		if ( (fifo_db_con=fifo_dbf.init( fifo_db_url ))==0) {
+			/* connection failed */
+			LOG(L_ERR,"ERROR: init_db_fifo: unable to connect to database -> "
+				"fifo DB commands disabled!\n");
+		}else if (register_fifo_cmd(db_fifo_cmd, FIFO_DB, 0)<0) {
+			LOG(L_ERR, "ERROR: init_db_fifo: unable to register '%s'"
+					" FIFO cmd\n", FIFO_DB);
+		} else {
+			return 0; /* success */
+		}
+	}else{
+		LOG(L_WARN, "WARNING: init_db_fifo: unable to find any db module - "
+			"fifo DB commands disabled!\n");
+	}
+	return -1; /* error */
+}
+
+
+
+
 
 
 int db_fifo( FILE *fifo, char *response_file )
 int db_fifo( FILE *fifo, char *response_file )
 {
 {
@@ -577,6 +606,8 @@ int db_fifo( FILE *fifo, char *response_file )
 	ret = -1; /* default is error */
 	ret = -1; /* default is error */
 	rpl =  0;
 	rpl =  0;
 
 
+	if (fifo_db_con==0) /* disabled due to database init/binding errors */
+		goto error;
 	/* first check the response file */
 	/* first check the response file */
 	rpl = open_reply_pipe( response_file );
 	rpl = open_reply_pipe( response_file );
 	if (rpl==0)
 	if (rpl==0)
@@ -649,9 +680,9 @@ int db_fifo( FILE *fifo, char *response_file )
 		trim_spaces(line);
 		trim_spaces(line);
 		/* run the command */
 		/* run the command */
 		if (db_cmd==RAWQUERY_CMD)
 		if (db_cmd==RAWQUERY_CMD)
-			n = db_raw_query( fifo_db_con, line.s, 0);
+			n = fifo_dbf.raw_query( fifo_db_con, line.s, 0);
 		else
 		else
-			n = db_raw_query( fifo_db_con, line.s, &select_res);
+			n = fifo_dbf.raw_query( fifo_db_con, line.s, &select_res);
 		if (n!=0) {
 		if (n!=0) {
 			double_log("Internal Server error - DB query failed");
 			double_log("Internal Server error - DB query failed");
 			goto error;
 			goto error;
@@ -661,7 +692,7 @@ int db_fifo( FILE *fifo, char *response_file )
 			/* get all response and write them into reply fifo */
 			/* get all response and write them into reply fifo */
 			print_res( select_res, rpl);
 			print_res( select_res, rpl);
 			/* free the query response */
 			/* free the query response */
-			db_free_query( fifo_db_con, select_res);
+			fifo_dbf.free_query( fifo_db_con, select_res);
 		}
 		}
 		/* done with success */
 		/* done with success */
 		goto done;
 		goto done;
@@ -677,7 +708,7 @@ int db_fifo( FILE *fifo, char *response_file )
 
 
 	/* select the correct table */
 	/* select the correct table */
 	line.s[line.len] = 0; /* make it null terminated */
 	line.s[line.len] = 0; /* make it null terminated */
-	db_use_table( fifo_db_con, line.s);
+	fifo_dbf.use_table( fifo_db_con, line.s);
 
 
 	/*read 'where' avps */
 	/*read 'where' avps */
 	if (get_avps( fifo , keys2, ops2, vals2, &nr2, MAX_ARRAY)!=0 )
 	if (get_avps( fifo , keys2, ops2, vals2, &nr2, MAX_ARRAY)!=0 )
@@ -686,8 +717,8 @@ int db_fifo( FILE *fifo, char *response_file )
 	switch (db_cmd) {
 	switch (db_cmd) {
 		case SELECT_CMD:
 		case SELECT_CMD:
 			/* push the query */
 			/* push the query */
-			n = db_query( fifo_db_con, nr2?keys2:0, nr2?ops2:0, nr2?vals2:0,
-				nr1?keys1:0, nr2, nr1, 0, &select_res );
+			n = fifo_dbf.query( fifo_db_con, nr2?keys2:0, nr2?ops2:0,
+						nr2?vals2:0, nr1?keys1:0, nr2, nr1, 0, &select_res );
 			if (n!=0) {
 			if (n!=0) {
 				double_log("Internal Server error - DB query failed");
 				double_log("Internal Server error - DB query failed");
 				goto error2;
 				goto error2;
@@ -695,7 +726,7 @@ int db_fifo( FILE *fifo, char *response_file )
 			/* get all response and write them into reply fifo */
 			/* get all response and write them into reply fifo */
 			print_res( select_res, rpl);
 			print_res( select_res, rpl);
 			/* free the query response */
 			/* free the query response */
-			db_free_query( fifo_db_con, select_res);
+			fifo_dbf.free_query( fifo_db_con, select_res);
 			break;
 			break;
 		case UPDATE_CMD:
 		case UPDATE_CMD:
 			if (nr1==0) {
 			if (nr1==0) {
@@ -711,8 +742,8 @@ int db_fifo( FILE *fifo, char *response_file )
 				}
 				}
 			}/*end for*/
 			}/*end for*/
 			/* push the query */
 			/* push the query */
-			n = db_update( fifo_db_con, nr2?keys2:0, nr2?ops2:0, nr2?vals2:0,
-				keys1, vals1, nr2, nr1 );
+			n = fifo_dbf.update( fifo_db_con, nr2?keys2:0, nr2?ops2:0,
+					nr2?vals2:0, keys1, vals1, nr2, nr1 );
 			if (n!=0) {
 			if (n!=0) {
 				double_log("Internal Server error - DB query failed");
 				double_log("Internal Server error - DB query failed");
 				goto error2;
 				goto error2;
@@ -720,8 +751,8 @@ int db_fifo( FILE *fifo, char *response_file )
 			break;
 			break;
 		case DELETE_CMD:
 		case DELETE_CMD:
 			/* push the query */
 			/* push the query */
-			n = db_delete( fifo_db_con, nr2?keys2:0, nr2?ops2:0, nr2?vals2:0,
-				nr2);
+			n = fifo_dbf.delete( fifo_db_con, nr2?keys2:0, nr2?ops2:0,
+					nr2?vals2:0, nr2);
 			if (n!=0) {
 			if (n!=0) {
 				double_log("Internal Server error - DB query failed");
 				double_log("Internal Server error - DB query failed");
 				goto error2;
 				goto error2;
@@ -741,7 +772,7 @@ int db_fifo( FILE *fifo, char *response_file )
 				}
 				}
 			}/*end for*/
 			}/*end for*/
 			/* push the query */
 			/* push the query */
-			n = db_insert( fifo_db_con, nr2?keys2:0, nr2?vals2:0, nr2);
+			n = fifo_dbf.insert( fifo_db_con, nr2?keys2:0, nr2?vals2:0, nr2);
 			if (n!=0) {
 			if (n!=0) {
 				double_log("Internal Server error - DB query failed");
 				double_log("Internal Server error - DB query failed");
 				goto error2;
 				goto error2;

+ 1 - 2
db/db_fifo.h

@@ -35,8 +35,7 @@
 #define db_fifo_cmd  db_fifo
 #define db_fifo_cmd  db_fifo
 #define FIFO_DB      "DB"
 #define FIFO_DB      "DB"
 
 
-extern db_con_t*   fifo_db_con;
-
+int init_db_fifo(char* db_url);
 int db_fifo( FILE *fifo_stream, char *response_file );
 int db_fifo( FILE *fifo_stream, char *response_file );
 
 
 
 

+ 35 - 21
db/doc/db-api.txt

@@ -1,4 +1,8 @@
-$Id$
+# $Id$
+# 
+# History:
+# --------
+#  2004-06-06  updated (bind_dbmod and obsoleted db_* macros)  (andrei)
 
 
 Generic Database Interface
 Generic Database Interface
 --------------------------
 --------------------------
@@ -332,19 +336,28 @@ prefix). This function MUST be called __FIRST__ !
 
 
 2.1.2 Prototype
 2.1.2 Prototype
 
 
-   int bind_dbmod(void);
+   int bind_dbmod(char* db_url, db_func_t* dbf);
 
 
 2.1.3 Parameters
 2.1.3 Parameters
 
 
-The function takes no parameters.
+The function takes two parameters, the first parameter must contain a database 
+connection URL or a database module name. The db_url is of the form 
+"mysql://username:password@host:port/database" or
+"mysql" (database module name).
+In the case of a database connection URL, this function looks only at the first
+token (the database protocol). In the example above that would be "mysql":
+The second parameter will be filled by this function with the corresponding
+ database module callbacks (see the db_func_t structure definition in
+  db.h and the callbacks definitions below).
+
 
 
 2.1.4 Return Value
 2.1.4 Return Value
 
 
-The function returns 0 if it was able to find addresses of all other 
-functions, otherwise value < 0 is returned.
+The function returns 0 if it was able to find the addresses of all the 
+corresponding module database functions and a value < 0 otherwise.
 
 
 
 
-2.2 Function db_init
+2.2 Callback dbf.init
 
 
 2.2.1 Description
 2.2.1 Description
 
 
@@ -354,7 +367,7 @@ function is called.
 
 
 2.2.2 Prototype
 2.2.2 Prototype
 
 
-   db_con_t* db_init(const char* _sql_url);
+   db_con_t* (*db_init_f)(const char* _sql_url);
 
 
 2.2.3 Parameters
 2.2.3 Parameters
 
 
@@ -378,7 +391,7 @@ The function returns pointer to db_con_t* representing the connection if it was
 successful, otherwise 0 is returned.
 successful, otherwise 0 is returned.
 
 
 
 
-2.3 Function db_close
+2.3 Callback dbf.close
 
 
 2.3.1 Description
 2.3.1 Description
 
 
@@ -388,7 +401,7 @@ allocated memory. The function db_close must be the very last function called.
 
 
 2.3.2 Prototype
 2.3.2 Prototype
 
 
-   void db_close(db_con_t* _h);
+   void (*db_close_f)(db_con_t* _h);
 
 
 2.3.3 Parameters
 2.3.3 Parameters
 
 
@@ -400,7 +413,7 @@ structure representing database connection that should be closed.
 Function doesn't return anything.
 Function doesn't return anything.
 
 
 
 
-2.4 Function db_query
+2.4 Callback dbf.query
 
 
 2.4.1 Description
 2.4.1 Description
 
 
@@ -408,7 +421,7 @@ This function implements SELECT SQL directive.
 
 
 2.4.2 Prototype
 2.4.2 Prototype
 
 
-   int db_query(db_con_t* _h, db_key_t* _k, db_op_t* _op,
+   int (*db_query_f)(db_con_t* _h, db_key_t* _k, db_op_t* _op,
                 db_val_t* _v, db_key_t* _c, 
                 db_val_t* _v, db_key_t* _c, 
 	        int _n, int _nc, db_key_t _o, db_res_t** _r);
 	        int _n, int _nc, db_key_t _o, db_res_t** _r);
 
 
@@ -443,7 +456,7 @@ You must call db_free_query _BEFORE_ you can call db_query again !
 The function returns 0 if everything is OK, otherwise value < 0 is returned.
 The function returns 0 if everything is OK, otherwise value < 0 is returned.
 
 
 
 
-2.5 Function db_free_query
+2.5 Callback dbf.free_query
 
 
 2.5.1 Description
 2.5.1 Description
 
 
@@ -454,7 +467,7 @@ again !
 
 
 2.5.2 Prototype
 2.5.2 Prototype
 
 
-   int db_free_query(db_con_t* _h, db_res_t* _r);
+   int (*db_free_query_f)(db_con_t* _h, db_res_t* _r);
 
 
 2.5.3 Parameters
 2.5.3 Parameters
 
 
@@ -468,7 +481,7 @@ The function returns 0 if everything is OK, otherwise the function returns
 value < 0.
 value < 0.
 
 
 
 
-2.6 Function db_insert
+2.6 Callback dbf.insert
 
 
 2.6.1 Description
 2.6.1 Description
 
 
@@ -477,7 +490,7 @@ rows in a table using this function.
 
 
 2.6.2 Prototype
 2.6.2 Prototype
 
 
-   int db_insert(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n);
+   int (*db_insert_f)(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n);
 
 
 2.6.3 Parameters
 2.6.3 Parameters
 
 
@@ -493,7 +506,7 @@ The function returns 0 if everything is OK, otherwise the function returns
 value < 0.
 value < 0.
 
 
 
 
-2.7 Function db_delete
+2.7 Callback dbf.delete
 
 
 2.7.1 Description
 2.7.1 Description
 
 
@@ -502,7 +515,8 @@ more rows from a table.
 
 
 2.7.2 Prototype
 2.7.2 Prototype
 
 
-   int db_delete(db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n);
+   int (*db_delete_f)(db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
+                       int _n);
 
 
 2.7.3 Parameters
 2.7.3 Parameters
 
 
@@ -524,7 +538,7 @@ The function returns 0 if everything is OK, otherwise the function returns
 value < 0.
 value < 0.
 
 
 
 
-2.8 Function db_update
+2.8 Callback dbf.update
 
 
 2.8.1 Description
 2.8.1 Description
 
 
@@ -533,7 +547,7 @@ or more rows in a table using this function.
 
 
 2.8.2 Prototype
 2.8.2 Prototype
 
 
-   int db_update(db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
+   int (*db_update_f)(db_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
 	         db_key_t* _uk, db_val_t* _uv, int _n, int _un);
 	         db_key_t* _uk, db_val_t* _uv, int _n, int _un);
 
 
 2.8.3 Parameters
 2.8.3 Parameters
@@ -554,7 +568,7 @@ The function returns 0 if everything is OK, otherwise the function returns
 value < 0.
 value < 0.
 
 
 
 
-2.9 Function db_use_table
+2.9 Callback dbf.use_table
 
 
 2.9.1 Description
 2.9.1 Description
 
 
@@ -564,7 +578,7 @@ that table.
 
 
 2.9.2 Prototype
 2.9.2 Prototype
 
 
-   int db_use_table_f(db_con_t* _h, const char* _t);
+   int (*db_use_table_f)(db_con_t* _h, const char* _t);
 
 
 2.9.3 Parameters
 2.9.3 Parameters
 
 

+ 5 - 14
fifo_server.c

@@ -62,6 +62,7 @@
  *  2003-10-30  DB interface exported via FIFO (bogdan)
  *  2003-10-30  DB interface exported via FIFO (bogdan)
  *  2004-03-09  open_fifo_server split into init_ and start_ (andrei)
  *  2004-03-09  open_fifo_server split into init_ and start_ (andrei)
  *  2004-04-29  added chown(sock_user, sock_group)  (andrei)
  *  2004-04-29  added chown(sock_user, sock_group)  (andrei)
+ *  2004-06-06  updated to the new DB interface  & init_db_fifo (andrei)
  */
  */
 
 
 
 
@@ -97,6 +98,8 @@ char *fifo=0; /* FIFO name */
 char* fifo_dir=DEFAULT_FIFO_DIR; /* dir where reply fifos are allowed */
 char* fifo_dir=DEFAULT_FIFO_DIR; /* dir where reply fifos are allowed */
 char *fifo_db_url = 0;
 char *fifo_db_url = 0;
 pid_t fifo_pid;
 pid_t fifo_pid;
+
+
 /* file descriptors */
 /* file descriptors */
 static int fifo_read=0;
 static int fifo_read=0;
 static int fifo_write=0;
 static int fifo_write=0;
@@ -890,20 +893,8 @@ int register_core_fifo()
 	if (fifo_db_url==0) {
 	if (fifo_db_url==0) {
 		LOG(L_WARN,"WARNING: no fifo_db_url given - "
 		LOG(L_WARN,"WARNING: no fifo_db_url given - "
 			"fifo DB commands disabled!\n");
 			"fifo DB commands disabled!\n");
-	} else if ( bind_dbmod(fifo_db_url)==0 ) {
-		if (register_fifo_cmd(db_fifo_cmd, FIFO_DB, 0)<0) {
-			LOG(L_ERR, "ERROR: unable to register '%s' FIFO cmd\n", FIFO_DB);
-			return -1;
-		} else {
-			if ( (fifo_db_con=db_init( fifo_db_url ))==0) {
-				/* connection failed */
-			LOG(L_ERR,"ERROR: unable to connect to database -> "
-				"fifo DB commands disabled!\n");
-			}
-		}
-	} else {
-		LOG(L_WARN,"WARNING: unable to find any db module - "
-			"fifo DB commands disabled!\n");
+	} else if (init_db_fifo(fifo_db_url)<0){
+		return -1;
 	}
 	}
 	return 1;
 	return 1;
 }
 }

+ 8 - 6
usr_avp.c

@@ -27,6 +27,7 @@
  * History:
  * History:
  * ---------
  * ---------
  *  2004-02-06  created (bogdan)
  *  2004-02-06  created (bogdan)
+ *  2004-06-06  updated to the current DB api (andrei)
  */
  */
 
 
 
 
@@ -43,6 +44,7 @@
 
 
 
 
 static db_con_t  *avp_db_con = 0;
 static db_con_t  *avp_db_con = 0;
+static db_func_t avp_dbf; /* database call backs */
 struct usr_avp   *users_avps = 0;
 struct usr_avp   *users_avps = 0;
 char             *avp_db_url = 0;
 char             *avp_db_url = 0;
 
 
@@ -59,16 +61,16 @@ int init_avp_child( int rank )
 			return 0;
 			return 0;
 		}
 		}
 		/* init db connection */
 		/* init db connection */
-		if ( bind_dbmod(avp_db_url) < 0 ) {
+		if ( bind_dbmod(avp_db_url, &avp_dbf) < 0 ) {
 			LOG(L_ERR,"ERROR:init_avp_child: unable to find any db module\n");
 			LOG(L_ERR,"ERROR:init_avp_child: unable to find any db module\n");
 			return -1;
 			return -1;
 		}
 		}
-		if ( (avp_db_con=db_init( avp_db_url ))==0) {
+		if ( (avp_db_con=avp_dbf.init( avp_db_url ))==0) {
 			/* connection failed */
 			/* connection failed */
 			LOG(L_ERR,"ERROR:init_avp_child: unable to connect to database\n");
 			LOG(L_ERR,"ERROR:init_avp_child: unable to connect to database\n");
 			return -1;
 			return -1;
 		}
 		}
-		if (db_use_table( avp_db_con, AVP_DB_TABLE )<0) {
+		if (avp_dbf.use_table( avp_db_con, AVP_DB_TABLE )<0) {
 			/* table selection failed */
 			/* table selection failed */
 			LOG(L_ERR,"ERROR:init_avp_child: unable to select db table\n");
 			LOG(L_ERR,"ERROR:init_avp_child: unable to select db table\n");
 			return -1;
 			return -1;
@@ -167,7 +169,7 @@ inline static db_res_t *do_db_query(struct sip_uri *uri,char *attr,int use_dom)
 	}
 	}
 
 
 	/* do the DB query */
 	/* do the DB query */
-	if ( db_query( avp_db_con, keys_cmp, 0/*op*/, vals_cmp, keys_ret,
+	if ( avp_dbf.query( avp_db_con, keys_cmp, 0/*op*/, vals_cmp, keys_ret,
 	nr_keys_cmp, 3, 0/*order*/, &res) < 0)
 	nr_keys_cmp, 3, 0/*order*/, &res) < 0)
 		return 0;
 		return 0;
 
 
@@ -291,7 +293,7 @@ int load_avp( struct sip_msg *msg, int uri_type, char *attr, int use_dom)
 		DBG("DEBUG:load_avp: no avp found for %.*s@%.*s <%s>\n",
 		DBG("DEBUG:load_avp: no avp found for %.*s@%.*s <%s>\n",
 			uri.user.len,uri.user.s,(use_dom!=0)*uri.host.len,uri.host.s,
 			uri.user.len,uri.user.s,(use_dom!=0)*uri.host.len,uri.host.s,
 			attr?attr:"NULL");
 			attr?attr:"NULL");
-		db_free_query( avp_db_con, res);
+		avp_dbf.free_query( avp_db_con, res);
 		/*no avp found*/
 		/*no avp found*/
 		return 1;
 		return 1;
 	}
 	}
@@ -334,7 +336,7 @@ int load_avp( struct sip_msg *msg, int uri_type, char *attr, int use_dom)
 		users_avps = avp;
 		users_avps = avp;
 	}
 	}
 
 
-	db_free_query( avp_db_con, res);
+	avp_dbf.free_query( avp_db_con, res);
 	return 0;
 	return 0;
 error:
 error:
 	return -1;
 	return -1;