Browse Source

Various changes to get rid of conflicts and make km_ files compile.

List of changes:
 * Path to header files updated to point to lib/srdb1
 * Comment out MODULE_VERSION (already used pg_mod.c)
 * cmd_export_t renamed to kam_cmd_export_t
 * exports structure renamed to kam_exports (exports symbol is already
   defined by pg_mod.c)
 * module_exports renamed to kam_module_exports
 * db_con_t renamed to db1_con_t
 * db_res_t renamed to db1_res_t
 * DB field types renamed to DB1_*
Jan Janak 16 years ago
parent
commit
a7bac3b9ab

+ 5 - 5
modules/db_postgres/km_db_postgres.c

@@ -35,12 +35,12 @@
 
 #include <stdio.h>
 #include "../../sr_module.h"
-#include "../../db/db_con.h"
-#include "../../db/db.h"
+#include "../../lib/srdb1/db_con.h"
+#include "../../lib/srdb1/db.h"
 #include "km_dbase.h"
 
 
-MODULE_VERSION
+/*MODULE_VERSION*/
 
 int db_postgres_bind_api(db_func_t *dbb);
 
@@ -50,14 +50,14 @@ static int mod_init(void);
  * PostgreSQL database module interface
  */
 
-static cmd_export_t cmds[]={
+static kam_cmd_export_t cmds[]={
 	{"db_bind_api",     (cmd_function)db_postgres_bind_api,     0, 0, 0, 0},
 	{0,0,0,0,0,0}
 };
 
 
 
-struct module_exports exports = {
+struct kam_module_exports kam_exports = {
 	"db_postgres",
 	DEFAULT_DLFLAGS, /* dlopen flags */
 	cmds,

+ 21 - 21
modules/db_postgres/km_dbase.c

@@ -71,15 +71,15 @@
 #include <stdio.h>
 #include "../../dprint.h"
 #include "../../mem/mem.h"
-#include "../../db/db.h"
-#include "../../db/db_ut.h"
-#include "../../db/db_query.h"
+#include "../../lib/srdb1/db.h"
+#include "../../lib/srdb1/db_ut.h"
+#include "../../lib/srdb1/db_query.h"
 #include "km_dbase.h"
 #include "km_pg_con.h"
 #include "km_val.h"
 #include "km_res.h"
 
-static void db_postgres_free_query(const db_con_t* _con);
+static void db_postgres_free_query(const db1_con_t* _con);
 
 
 /*!
@@ -88,7 +88,7 @@ static void db_postgres_free_query(const db_con_t* _con);
  * \return database connection on success, NULL on error
  * \note this function must be called prior to any database functions
  */
-db_con_t *db_postgres_init(const str* _url)
+db1_con_t *db_postgres_init(const str* _url)
 {
 	return db_do_init(_url, (void*) db_postgres_new_connection);
 }
@@ -99,7 +99,7 @@ db_con_t *db_postgres_init(const str* _url)
  * \param _h closed connection, as returned from db_postgres_init
  * \note free all memory and resources
  */
-void db_postgres_close(db_con_t* _h)
+void db_postgres_close(db1_con_t* _h)
 {
 	db_do_close(_h, db_postgres_free_connection);
 }
@@ -111,7 +111,7 @@ void db_postgres_close(db_con_t* _h)
  * \param _s query string
  * \return 0 on success, negative on failure
  */
-static int db_postgres_submit_query(const db_con_t* _con, const str* _s)
+static int db_postgres_submit_query(const db1_con_t* _con, const str* _s)
 {
 	if(! _con || !_s || !_s->s)
 	{
@@ -172,7 +172,7 @@ static int db_postgres_submit_query(const db_con_t* _con, const str* _s)
  * \param nrows number of fetches rows
  * \return 0 on success, negative on failure
  */
-int db_postgres_fetch_result(const db_con_t* _con, db_res_t** _res, const int nrows)
+int db_postgres_fetch_result(const db1_con_t* _con, db1_res_t** _res, const int nrows)
 {
 	int rows;
 	PGresult *res = NULL;
@@ -295,7 +295,7 @@ int db_postgres_fetch_result(const db_con_t* _con, db_res_t** _res, const int nr
  * \brief Free database and any old query results
  * \param _con database connection
  */
-static void db_postgres_free_query(const db_con_t* _con)
+static void db_postgres_free_query(const db1_con_t* _con)
 {
 	if(CON_RESULT(_con))
 	{
@@ -312,7 +312,7 @@ static void db_postgres_free_query(const db_con_t* _con)
  * \param _r result set
  * \return 0 on success, -1 on failure
  */
-int db_postgres_free_result(db_con_t* _con, db_res_t* _r)
+int db_postgres_free_result(db1_con_t* _con, db1_res_t* _r)
 {
      if ((!_con) || (!_r)) {
 	     LM_ERR("invalid parameter value\n");
@@ -340,9 +340,9 @@ int db_postgres_free_result(db_con_t* _con, db_res_t* _r)
  * \param _r result set
  * \return 0 on success, negative on failure
  */
-int db_postgres_query(const db_con_t* _h, const db_key_t* _k, const db_op_t* _op,
+int db_postgres_query(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _op,
 	     const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc,
-	     const db_key_t _o, db_res_t** _r)
+	     const db_key_t _o, db1_res_t** _r)
 {
 	return db_do_query(_h, _k, _op, _v, _c, _n, _nc, _o, _r, db_postgres_val2str,
 		db_postgres_submit_query, db_postgres_store_result);
@@ -356,7 +356,7 @@ int db_postgres_query(const db_con_t* _h, const db_key_t* _k, const db_op_t* _op
  * \param _r result set
  * \return 0 on success, negative on failure
  */
-int db_postgres_raw_query(const db_con_t* _h, const str* _s, db_res_t** _r)
+int db_postgres_raw_query(const db1_con_t* _h, const str* _s, db1_res_t** _r)
 {
 	return db_do_raw_query(_h, _s, _r, db_postgres_submit_query,
 		db_postgres_store_result);
@@ -376,7 +376,7 @@ int db_postgres_raw_query(const db_con_t* _h, const str* _s, db_res_t** _r)
  * result structure. If this routine returns < 0, then the result structure
  * is freed before returning to the caller.
  */
-int db_postgres_store_result(const db_con_t* _con, db_res_t** _r)
+int db_postgres_store_result(const db1_con_t* _con, db1_res_t** _r)
 {
 	PGresult *res = NULL;
 	ExecStatusType pqresult;
@@ -462,10 +462,10 @@ done:
  * \param _n number of key=value pairs
  * \return 0 on success, negative on failure
  */
-int db_postgres_insert(const db_con_t* _h, const db_key_t* _k, const db_val_t* _v,
+int db_postgres_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v,
 		const int _n)
 {
-	db_res_t* _r = NULL;
+	db1_res_t* _r = NULL;
 
 	int tmp = db_do_insert(_h, _k, _v, _n, db_postgres_val2str, db_postgres_submit_query);
 	// finish the async query, otherwise the next query will not complete
@@ -488,10 +488,10 @@ int db_postgres_insert(const db_con_t* _h, const db_key_t* _k, const db_val_t* _
  * \param _n number of key=value pairs
  * \return 0 on success, negative on failure
  */
-int db_postgres_delete(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
+int db_postgres_delete(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o,
 		const db_val_t* _v, const int _n)
 {
-	db_res_t* _r = NULL;
+	db1_res_t* _r = NULL;
 	int tmp = db_do_delete(_h, _k, _o, _v, _n, db_postgres_val2str,
 		db_postgres_submit_query);
 
@@ -517,11 +517,11 @@ int db_postgres_delete(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o
  * \param _un number of columns to update
  * \return 0 on success, negative on failure
  */
-int db_postgres_update(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
+int db_postgres_update(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o,
 		const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv, const int _n,
 		const int _un)
 {
-	db_res_t* _r = NULL;
+	db1_res_t* _r = NULL;
 	int tmp = db_do_update(_h, _k, _o, _v, _uk, _uv, _n, _un, db_postgres_val2str,
 		db_postgres_submit_query);
 
@@ -541,7 +541,7 @@ int db_postgres_update(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o
  * \param _t table name
  * \return 0 on success, negative on error
  */
-int db_postgres_use_table(db_con_t* _con, const str* _t)
+int db_postgres_use_table(db1_con_t* _con, const str* _t)
 {
 	return db_use_table(_con, _t);
 }

+ 17 - 17
modules/db_postgres/km_dbase.h

@@ -34,80 +34,80 @@
 #ifndef KM_DBASE_H
 #define KM_DBASE_H
 
-#include "../../db/db_con.h"
-#include "../../db/db_res.h"
-#include "../../db/db_key.h"
-#include "../../db/db_op.h"
-#include "../../db/db_val.h"
+#include "../../lib/srdb1/db_con.h"
+#include "../../lib/srdb1/db_res.h"
+#include "../../lib/srdb1/db_key.h"
+#include "../../lib/srdb1/db_op.h"
+#include "../../lib/srdb1/db_val.h"
 
 
 /*
  * Initialize database connection
  */
-db_con_t* db_postgres_init(const str* _url);
+db1_con_t* db_postgres_init(const str* _url);
 
 /*
  * Close a database connection
  */
-void db_postgres_close(db_con_t* _h);
+void db_postgres_close(db1_con_t* _h);
 
 /*
  * Return result of previous query
  */
-int db_postgres_store_result(const db_con_t* _h, db_res_t** _r);
+int db_postgres_store_result(const db1_con_t* _h, db1_res_t** _r);
 
 
 /*
  * Free all memory allocated by get_result
  */
-int db_postgres_free_result(db_con_t* _h, db_res_t* _r);
+int db_postgres_free_result(db1_con_t* _h, db1_res_t* _r);
 
 
 /*
  * Do a query
  */
-int db_postgres_query(const db_con_t* _h, const db_key_t* _k, const db_op_t* _op,
+int db_postgres_query(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _op,
 		const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc,
-		const db_key_t _o, db_res_t** _r);
+		const db_key_t _o, db1_res_t** _r);
 
 /*
  * Raw SQL query
  */
-int db_postgres_raw_query(const db_con_t* _h, const str* _s, db_res_t** _r);
+int db_postgres_raw_query(const db1_con_t* _h, const str* _s, db1_res_t** _r);
 
 
 /*
  * Insert a row into table
  */
-int db_postgres_insert(const db_con_t* _h, const db_key_t* _k, const db_val_t* _v,
+int db_postgres_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v,
 		const int _n);
 
 
 /*
  * Delete a row from table
  */
-int db_postgres_delete(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
+int db_postgres_delete(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o,
 		const db_val_t* _v, const int _n);
 
 
 /*
  * Update a row in table
  */
-int db_postgres_update(const db_con_t* _h, const db_key_t* _k, const db_op_t* _o,
+int db_postgres_update(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o,
 		const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv, const int _n,
 		const int _un);
 
 /*
  * fetch rows from a result
  */
-int db_postgres_fetch_result(const db_con_t* _h, db_res_t** _r, const int nrows);
+int db_postgres_fetch_result(const db1_con_t* _h, db1_res_t** _r, const int nrows);
 
 
 /*
  * Store name of table that will be used by
  * subsequent database functions
  */
-int db_postgres_use_table(db_con_t* _h, const str* _t);
+int db_postgres_use_table(db1_con_t* _h, const str* _t);
 
 
 #endif /* KM_DBASE_H */

+ 2 - 2
modules/db_postgres/km_pg_con.h

@@ -34,8 +34,8 @@
 #ifndef KM_PG_CON_H
 #define KM_PG_CON_H
 
-#include "../../db/db_pool.h"
-#include "../../db/db_id.h"
+#include "../../lib/srdb1/db_pool.h"
+#include "../../lib/srdb1/db_id.h"
 
 #include <time.h>
 #include <libpq-fe.h>

+ 24 - 24
modules/db_postgres/km_res.c

@@ -25,7 +25,7 @@
  * -------
  * 2003-04-06 initial code written (Greg Fausak/Andy Fullford)
  *
- * 2006-07-26 added BPCHAROID as a valid type for DB_STRING conversions
+ * 2006-07-26 added BPCHAROID as a valid type for DB1_STRING conversions
  *            this removes the "unknown type 1042" log messages (norm)
  *
  * 2006-10-27 Added fetch support (norm)
@@ -42,9 +42,9 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include "../../db/db_id.h"
-#include "../../db/db_res.h"
-#include "../../db/db_con.h"
+#include "../../lib/srdb1/db_id.h"
+#include "../../lib/srdb1/db_res.h"
+#include "../../lib/srdb1/db_con.h"
 #include "../../dprint.h"
 #include "../../mem/mem.h"
 #include "km_res.h"
@@ -59,7 +59,7 @@
  * \param _r result set
  * \return 0 on success, negative on error
  */
-int db_postgres_convert_result(const db_con_t* _h, db_res_t* _r)
+int db_postgres_convert_result(const db1_con_t* _h, db1_res_t* _r)
 {
 	if (!_h || !_r)  {
 		LM_ERR("invalid parameter value\n");
@@ -86,7 +86,7 @@ int db_postgres_convert_result(const db_con_t* _h, db_res_t* _r)
  * \param _r result set
  * \return 0 on success, negative on error
  */
-int db_postgres_get_columns(const db_con_t* _h, db_res_t* _r)
+int db_postgres_get_columns(const db1_con_t* _h, db1_res_t* _r)
 {
 	int col, datatype;
 
@@ -137,53 +137,53 @@ int db_postgres_get_columns(const db_con_t* _h, db_res_t* _r)
 		{
 			case INT2OID:
 			case INT4OID:
-				LM_DBG("use DB_INT result type\n");
-				RES_TYPES(_r)[col] = DB_INT;
+				LM_DBG("use DB1_INT result type\n");
+				RES_TYPES(_r)[col] = DB1_INT;
 			break;
 
 			case INT8OID:
-				LM_DBG("use DB_BIGINT result type\n");
-				RES_TYPES(_r)[col] = DB_BIGINT;
+				LM_DBG("use DB1_BIGINT result type\n");
+				RES_TYPES(_r)[col] = DB1_BIGINT;
 
 			case FLOAT4OID:
 			case FLOAT8OID:
 			case NUMERICOID:
-				LM_DBG("use DB_DOUBLE result type\n");
-				RES_TYPES(_r)[col] = DB_DOUBLE;
+				LM_DBG("use DB1_DOUBLE result type\n");
+				RES_TYPES(_r)[col] = DB1_DOUBLE;
 			break;
 
 			case DATEOID:
 			case TIMESTAMPOID:
 			case TIMESTAMPTZOID:
-				LM_DBG("use DB_DATETIME result type\n");
-				RES_TYPES(_r)[col] = DB_DATETIME;
+				LM_DBG("use DB1_DATETIME result type\n");
+				RES_TYPES(_r)[col] = DB1_DATETIME;
 			break;
 
 			case BOOLOID:
 			case CHAROID:
 			case VARCHAROID:
 			case BPCHAROID:
-				LM_DBG("use DB_STRING result type\n");
-				RES_TYPES(_r)[col] = DB_STRING;
+				LM_DBG("use DB1_STRING result type\n");
+				RES_TYPES(_r)[col] = DB1_STRING;
 			break;
 
 			case TEXTOID:
 			case BYTEAOID:
-				LM_DBG("use DB_BLOB result type\n");
-				RES_TYPES(_r)[col] = DB_BLOB;
+				LM_DBG("use DB1_BLOB result type\n");
+				RES_TYPES(_r)[col] = DB1_BLOB;
 			break;
 
 			case BITOID:
 			case VARBITOID:
-				LM_DBG("use DB_BITMAP result type\n");
-				RES_TYPES(_r)[col] = DB_BITMAP;
+				LM_DBG("use DB1_BITMAP result type\n");
+				RES_TYPES(_r)[col] = DB1_BITMAP;
 			break;
 				
 			default:
 				LM_WARN("unhandled data type column (%.*s) type id (%d), "
-						"use DB_STRING as default\n", RES_NAMES(_r)[col]->len,
+						"use DB1_STRING as default\n", RES_NAMES(_r)[col]->len,
 						RES_NAMES(_r)[col]->s, datatype);
-				RES_TYPES(_r)[col] = DB_STRING;
+				RES_TYPES(_r)[col] = DB1_STRING;
 			break;
 		}
 	}
@@ -197,7 +197,7 @@ int db_postgres_get_columns(const db_con_t* _h, db_res_t* _r)
  * \param _r result set
  * \return 0 on success, negative on error
  */
-int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r)
+int db_postgres_convert_rows(const db1_con_t* _h, db1_res_t* _r)
 {
 	char **row_buf, *s;
 	int row, col, len;
@@ -278,7 +278,7 @@ int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r)
  * \param row_buf row buffer
  * \return 0 on success, negative on error
  */
-int db_postgres_convert_row(const db_con_t* _h, db_res_t* _r, db_row_t* _row,
+int db_postgres_convert_row(const db1_con_t* _h, db1_res_t* _r, db_row_t* _row,
 		char **row_buf)
 {
 	int col, col_len;

+ 5 - 5
modules/db_postgres/km_res.h

@@ -30,15 +30,15 @@
 #ifndef KM_RES_H
 #define KM_RES_H
 
-#include "../../db/db_row.h"
+#include "../../lib/srdb1/db_row.h"
 
-int db_postgres_convert_result(const db_con_t* _h, db_res_t* _r);
+int db_postgres_convert_result(const db1_con_t* _h, db1_res_t* _r);
 
-int db_postgres_convert_row(const db_con_t* _h, db_res_t* _res, db_row_t* _r,
+int db_postgres_convert_row(const db1_con_t* _h, db1_res_t* _res, db_row_t* _r,
 	char **row_buf);
 
-int db_postgres_get_columns(const db_con_t* _h, db_res_t* _r);
+int db_postgres_get_columns(const db1_con_t* _h, db1_res_t* _r);
 
-int db_postgres_convert_rows(const db_con_t* _h, db_res_t* _r);
+int db_postgres_convert_rows(const db1_con_t* _h, db1_res_t* _r);
 
 #endif

+ 8 - 8
modules/db_postgres/km_val.c

@@ -34,8 +34,8 @@
  *  Module: \ref db_postgres
  */
 
-#include "../../db/db_val.h"
-#include "../../db/db_ut.h"
+#include "../../lib/srdb1/db_val.h"
+#include "../../lib/srdb1/db_ut.h"
 #include "../../dprint.h"
 #include "km_pg_con.h"
 
@@ -58,7 +58,7 @@
 int db_postgres_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l)
 {
 	/* use common function for non BLOB, NULL setting and input parameter checking */
-	if ( _t != DB_BLOB || _s == NULL || _v == NULL) {
+	if ( _t != DB1_BLOB || _s == NULL || _v == NULL) {
 		return db_str2val(_t, _v, _s, _l, 1);
 	} else {
 		char * tmp_s = NULL;
@@ -82,7 +82,7 @@ int db_postgres_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const
 		memcpy(VAL_BLOB(_v).s, tmp_s, VAL_BLOB(_v).len);
 		PQfreemem(tmp_s);
 
-		VAL_TYPE(_v) = DB_BLOB;
+		VAL_TYPE(_v) = DB1_BLOB;
 		VAL_FREE(_v) = 1;
 
 		LM_DBG("got blob len %d\n", _l);
@@ -102,7 +102,7 @@ int db_postgres_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const
  * \param _len target string length
  * \return 0 on success, negative on error
  */
-int db_postgres_val2str(const db_con_t* _con, const db_val_t* _v, char* _s, int* _len)
+int db_postgres_val2str(const db1_con_t* _con, const db_val_t* _v, char* _s, int* _len)
 {
 	int l, ret, tmp;
 	int pgret;
@@ -115,7 +115,7 @@ int db_postgres_val2str(const db_con_t* _con, const db_val_t* _v, char* _s, int*
 		return tmp;
 
 	switch(VAL_TYPE(_v)) {
-	case DB_STRING:
+	case DB1_STRING:
 		l = strlen(VAL_STRING(_v));
 		if (*_len < (l * 2 + 3)) {
 			LM_ERR("destination buffer too short for string\n");
@@ -140,7 +140,7 @@ int db_postgres_val2str(const db_con_t* _con, const db_val_t* _v, char* _s, int*
 		}
 		break;
 
-	case DB_STR:
+	case DB1_STR:
 		l = VAL_STR(_v).len;
 		if (*_len < (l * 2 + 3)) {
 			LM_ERR("destination buffer too short for str\n");
@@ -164,7 +164,7 @@ int db_postgres_val2str(const db_con_t* _con, const db_val_t* _v, char* _s, int*
 		}
 		break;
 
-	case DB_BLOB:
+	case DB1_BLOB:
 		l = VAL_BLOB(_v).len;
 		/* this estimation is not always correct, thus we need to check later again */
 		if (*_len < (l * 2 + 3)) {

+ 1 - 1
modules/db_postgres/km_val.h

@@ -31,6 +31,6 @@
 
 int db_postgres_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l);
 
-int db_postgres_val2str(const db_con_t* _con, const db_val_t* _v, char* _s, int* _len);
+int db_postgres_val2str(const db1_con_t* _con, const db_val_t* _v, char* _s, int* _len);
 
 #endif