Bläddra i källkod

- port to new logging system
- increase log level for messages in db operation errors


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2851 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt 18 år sedan
förälder
incheckning
be2347445d
4 ändrade filer med 273 tillägg och 329 borttagningar
  1. 55 69
      modules/db_berkeley/bdb_lib.c
  2. 120 127
      modules/db_berkeley/bdb_res.c
  3. 20 20
      modules/db_berkeley/bdb_val.c
  4. 78 113
      modules/db_berkeley/db_berkeley.c

+ 55 - 69
modules/db_berkeley/bdb_lib.c

@@ -52,7 +52,7 @@ int sclib_init(db_parms_p _p)
 	{
 		_cachedb = pkg_malloc( sizeof(database_p) );
 		if (!_cachedb) 
-		{	LOG(L_CRIT,"sclib_init: no enough pkg mem\n");
+		{	LM_CRIT("not enough private memory\n");
 			return -1;
 		}
 		
@@ -61,7 +61,7 @@ int sclib_init(db_parms_p _p)
 		/*create default parms*/
 		db_parms_p dp = (db_parms_p) pkg_malloc( sizeof(db_parms_t) );
 		if (!dp) 
-		{	LOG(L_CRIT,"sclib_init: no enough pkg mem\n");
+		{	LM_CRIT("not enough private memory\n");
 			return -1;
 		}
 		
@@ -126,7 +126,7 @@ int sclib_close(char* _n)
 		!strncasecmp(s.s, _db_p->name.s, _db_p->name.len))
 		{
 			//close the whole dbenv
-			DBG("-- sclib_close ENV %.*s \n", s.len, s.s);
+			LM_DBG("ENV %.*s \n", s.len, s.s);
 			while(_tbc)
 			{
 				if(_tbc->dtp)
@@ -136,8 +136,7 @@ int sclib_close(char* _n)
 					if(_db)
 						rc = _db->close(_db, 0);
 					if(rc != 0)
-						LOG(L_CRIT,"lib_close: error closing %s\n"
-							, _tbc->dtp->name.s);
+						LM_CRIT("error closing %s\n", _tbc->dtp->name.s);
 					_tbc->dtp->db = NULL;
 					
 					lock_release(&_tbc->dtp->sem);
@@ -154,7 +153,7 @@ int sclib_close(char* _n)
 		{
 			if(_tbc->dtp)
 			{
-				DBG("-- sclib_close DB %.*s \n", s.len, s.s);
+				LM_DBG("DB %.*s \n", s.len, s.s);
 				if(_tbc->dtp->name.len == s.len && 
 				!strncasecmp(_tbc->dtp->name.s, s.s, s.len ))
 				{
@@ -163,8 +162,7 @@ int sclib_close(char* _n)
 					if(_db)
 						rc = _db->close(_db, 0);
 					if(rc != 0)
-						LOG(L_CRIT,"lib_close: error closing %s\n"
-							, _tbc->dtp->name.s);
+						LM_CRIT("error closing %s\n", _tbc->dtp->name.s);
 					_tbc->dtp->db = NULL;
 					lock_release(&_tbc->dtp->sem);
 					return 0;
@@ -207,7 +205,7 @@ int sclib_reopen(char* _n)
 		!strncasecmp(s.s, _db_p->name.s,_db_p->name.len))
 		{
 			//open the whole dbenv
-			DBG("-- sclib_reopen ENV %.*s \n", s.len, s.s);
+			LM_DBG("-- sclib_reopen ENV %.*s \n", s.len, s.s);
 			if(!_db_p->dbenv)
 			{	rc = sclib_create_dbenv(&_env, _n);
 				_db_p->dbenv = _env;
@@ -226,15 +224,14 @@ int sclib_reopen(char* _n)
 					{
 						if ((rc = db_create(&_db, _env, 0)) != 0)
 						{	_env->err(_env, rc, "db_create");
-							LOG(L_CRIT, "sclib_reopen: error in db_create.\n");
-							LOG(L_CRIT, "sclib_reopen: db error: %s.\n",db_strerror(rc));
+							LM_CRIT("error in db_create, db error: %s.\n",db_strerror(rc));
 							sclib_recover(_tbc->dtp, rc);
 						}
 					}
 					
 					if ((rc = _db->open(_db, NULL, _n, NULL, DB_HASH, DB_CREATE, 0664)) != 0)
 					{	_db->dbenv->err(_env, rc, "DB->open: %s", _n);
-						LOG(L_CRIT, "sclib_reopen:bdb open: %s.\n",db_strerror(rc));
+						LM_CRIT("error in db_open: %s.\n",db_strerror(rc));
 						sclib_recover(_tbc->dtp, rc);
 					}
 					
@@ -252,7 +249,7 @@ int sclib_reopen(char* _n)
 		{
 			if(_tbc->dtp)
 			{
-				DBG("-- sclib_reopen DB %.*s \n", s.len, s.s);
+				LM_DBG("DB %.*s \n", s.len, s.s);
 				if(_tbc->dtp->name.len == s.len && 
 				!strncasecmp(_tbc->dtp->name.s, s.s, s.len ))
 				{
@@ -261,15 +258,14 @@ int sclib_reopen(char* _n)
 					{
 						if ((rc = db_create(&_db, _env, 0)) != 0)
 						{	_env->err(_env, rc, "db_create");
-							LOG(L_CRIT, "sclib_reopen: error in db_create.\n");
-							LOG(L_CRIT, "sclib_reopen: db error: %s.\n",db_strerror(rc));
+							LM_CRIT("error in db_create, db error: %s.\n",db_strerror(rc));
 							sclib_recover(_tbc->dtp, rc);
 						}
 					}
 					
 					if ((rc = _db->open(_db, NULL, _n, NULL, DB_HASH, DB_CREATE, 0664)) != 0)
 					{	_db->dbenv->err(_env, rc, "DB->open: %s", _n);
-						LOG(L_CRIT, "sclib_reopen:bdb open: %s.\n",db_strerror(rc));
+						LM_CRIT("bdb open: %s.\n",db_strerror(rc));
 						sclib_recover(_tbc->dtp, rc);
 					}
 					_tbc->dtp->db = _db;
@@ -299,8 +295,7 @@ int sclib_create_dbenv(DB_ENV **_dbenv, char* _home)
 	/* Create an environment and initialize it for additional error * reporting. */ 
 	if ((rc = db_env_create(&env, 0)) != 0) 
 	{
-		LOG(L_ERR, "sclib_create_dbenv: db_env_create failed !\n");
-		LOG(L_ERR, "sc_lib:bdb error: %s.\n",db_strerror(rc)); 
+		LM_ERR("db_env_create failed! bdb error: %s.\n", db_strerror(rc)); 
 		return (rc);
 	}
  
@@ -309,8 +304,7 @@ int sclib_create_dbenv(DB_ENV **_dbenv, char* _home)
 	/*  Specify the shared memory buffer pool cachesize */ 
 	if ((rc = env->set_cachesize(env, 0, _db_parms->cache_size, 0)) != 0) 
 	{
-		LOG(L_ERR, "sclib_create_dbenv: dbenv set_cachsize failed !\n");
-		LOG(L_ERR, "sc_lib:bdb error: %s.\n",db_strerror(rc));
+		LM_ERR("dbenv set_cachsize failed! bdb error: %s.\n", db_strerror(rc));
 		env->err(env, rc, "set_cachesize"); 
 		goto err; 
 	}
@@ -335,8 +329,7 @@ int sclib_create_dbenv(DB_ENV **_dbenv, char* _home)
 	/* Open the environment */ 
 	if ((rc = env->open(env, _home, flags, 0)) != 0) 
 	{ 
-		LOG(L_ERR, "sclib_create_dbenv: dbenv is not initialized!\n");
-		LOG(L_ERR, "sc_lib:bdb error: %s.\n",db_strerror(rc));
+		LM_ERR("dbenv is not initialized! bdb error: %s.\n",db_strerror(rc));
 		env->err(env, rc, "environment open: %s", _home); 
 		goto err; 
 	}
@@ -362,28 +355,27 @@ database_p sclib_get_db(str *_s)
 
 	if( !_cachedb)
 	{
-		LOG(L_ERR, "sclib_get_db: _cachedb is not initialized!\n");
+		LM_ERR("_cachedb is not initialized!\n");
 		return NULL;
 	}
 
 	_db_p = *_cachedb;
 	if(_db_p)
 	{
-		DBG("sclib_get_db: db already cached!\n");
+		LM_DBG("db already cached!\n");
 		return _db_p;
 	}
 
 	if(!sc_is_database(_s))
 	{	
-		LOG(L_ERR, "sclib_get_db: database [%.*s] does not exists!\n"
-			,_s->len , _s->s);
+		LM_ERR("database [%.*s] does not exists!\n" ,_s->len , _s->s);
 		return NULL;
 	}
 
 	_db_p = (database_p)pkg_malloc(sizeof(database_t));
 	if(!_db_p)
 	{
-		LOG(L_ERR, "sclib_get_db: no memory for dbenv_t.\n");
+		LM_ERR("no private memory for dbenv_t.\n");
 		pkg_free(_db_p);
 		return NULL;
 	}
@@ -397,7 +389,7 @@ database_p sclib_get_db(str *_s)
 
 	if ((rc = sclib_create_dbenv(&(_db_p->dbenv), name)) != 0)
 	{
-		LOG(L_ERR, "sclib_get_db: sclib_create_dbenv failed");
+		LM_ERR("sclib_create_dbenv failed");
 		pkg_free(_db_p->name.s);
 		pkg_free(_db_p);
 		return NULL;
@@ -455,12 +447,12 @@ tbl_cache_p sclib_get_table(database_p _db, str *_s)
 	_tp = sclib_create_table(_db, _s);
 
 #ifdef SC_EXTRA_DEBUG
-	DBG("DBG:sclib_get_table: %.*s\n", _s->len, _s->s);
+	LM_DBG("table: %.*s\n", _s->len, _s->s);
 #endif
 
 	if(!_tp)
 	{
-		LOG(L_ERR, "sclib_get_table: failed to create table.\n");
+		LM_ERR("failed to create table.\n");
 		pkg_free(_tbc);
 		return NULL;
 	}
@@ -497,7 +489,7 @@ void sclib_log(int op, table_p _tp, char* _msg, int len)
 			{	/*try to roll logfile*/
 				if(sclib_create_journal(_tp))
 				{
-					LOG(L_ERR, "sclib_log: Journaling has FAILED !\n");
+					LM_ERR("Journaling has FAILED !\n");
 					return;
 				}
 			}
@@ -551,22 +543,21 @@ table_p sclib_create_table(database_p _db, str *_s)
 
 	if(!_db || !_db->dbenv)
 	{
-		LOG(L_ERR, "sclib_create_table: no database_p or dbenv.\n");
+		LM_ERR("no database_p or dbenv.\n");
 		return NULL;
 	}
 
 	tp = (table_p)pkg_malloc(sizeof(table_t));
 	if(!tp)
 	{
-		LOG(L_ERR, "sclib_create_table: no memory for table_t.\n");
+		LM_ERR("no private memory for table_t.\n");
 		return NULL;
 	}
 
 	if ((rc = db_create(&bdb, _db->dbenv, 0)) != 0)
 	{ 
 		_db->dbenv->err(_db->dbenv, rc, "database create");
-		LOG(L_ERR, "sclib_create_table: error in db_create.\n");
-		LOG(L_ERR, "sc_lib:bdb error: %s.\n",db_strerror(rc));
+		LM_ERR("error in db_create, bdb error: %s.\n",db_strerror(rc));
 		pkg_free(tp);
 		return NULL;
 	}
@@ -575,9 +566,7 @@ table_p sclib_create_table(database_p _db, str *_s)
 	strncpy(tblname, _s->s, _s->len);
 
 #ifdef SC_EXTRA_DEBUG
-	DBG("-----------------------------------\n");
-	DBG("------- CREATE TABLE = %s\n", tblname);
-	DBG("-----------------------------------\n");
+	LM_DBG("CREATE TABLE = %s\n", tblname);
 #endif
 
 	flags = DB_CREATE | DB_THREAD;
@@ -585,7 +574,7 @@ table_p sclib_create_table(database_p _db, str *_s)
 	if ((rc = bdb->open(bdb, NULL, tblname, NULL, DB_HASH, flags, 0664)) != 0)
 	{ 
 		_db->dbenv->err(_db->dbenv, rc, "DB->open: %s", tblname);
-		LOG(L_ERR, "sclib_create_table:bdb open: %s.\n",db_strerror(rc));
+		LM_ERR("bdb open: %s.\n",db_strerror(rc));
 		pkg_free(tp);
 		return NULL;
 	}
@@ -616,14 +605,14 @@ table_p sclib_create_table(database_p _db, str *_s)
 	rc = load_metadata_columns(tp);
 	if(rc!=0)
 	{
-		LOG(L_ERR, "sclib_create_table: FAILED to load METADATA COLS in table: %s.\n", tblname);
+		LM_ERR("FAILED to load METADATA COLS in table: %s.\n", tblname);
 		goto error;
 	}
 
 	rc = load_metadata_keys(tp);
 	if(rc!=0)
 	{
-		LOG(L_ERR, "sclib_create_table: FAILED to load METADATA KEYS in table: %s.\n", tblname);
+		LM_ERR("FAILED to load METADATA KEYS in table: %s.\n", tblname);
 		/*will have problems later figuring column types*/
 		goto error;
 	}
@@ -632,7 +621,7 @@ table_p sclib_create_table(database_p _db, str *_s)
 	rc = load_metadata_readonly(tp);
 	if(rc!=0)
 	{
-		LOG(L_INFO, "sclib_create_table: No METADATA_READONLY in table: %s.\n", tblname);
+		LM_INFO("No METADATA_READONLY in table: %s.\n", tblname);
 		/*non-critical; table will default to READWRITE*/
 	}
 
@@ -640,14 +629,14 @@ table_p sclib_create_table(database_p _db, str *_s)
 	{	
 		/*schema defines this table RO readonly*/
 #ifdef SC_EXTRA_DEBUG
-		DBG("TABLE %.*s is changing to READONLY mode\n"
+		LM_DBG("TABLE %.*s is changing to READONLY mode\n"
 			, tp->name.len, tp->name.s);
 #endif
 		
 		if ((rc = bdb->close(bdb,0)) != 0)
 		{ 
 			_db->dbenv->err(_db->dbenv, rc, "DB->close: %s", tblname);
-			LOG(L_ERR, "sclib_create_table:bdb close: %s.\n",db_strerror(rc));
+			LM_ERR("bdb close: %s.\n",db_strerror(rc));
 			goto error;
 		}
 		
@@ -655,7 +644,7 @@ table_p sclib_create_table(database_p _db, str *_s)
 		if ((rc = db_create(&bdb, _db->dbenv, 0)) != 0)
 		{ 
 			_db->dbenv->err(_db->dbenv, rc, "database create");
-			LOG(L_ERR, "sclib_create_table: error in db_create.\n");
+			LM_ERR("error in db_create.\n");
 			goto error;
 		}
 		
@@ -663,7 +652,7 @@ table_p sclib_create_table(database_p _db, str *_s)
 		if ((rc = bdb->open(bdb, NULL, tblname, NULL, DB_HASH, flags, 0664)) != 0)
 		{ 
 			_db->dbenv->err(_db->dbenv, rc, "DB->open: %s", tblname);
-			LOG(L_ERR, "sclib_create_table:bdb open: %s.\n",db_strerror(rc));
+			LM_ERR("bdb open: %s.\n",db_strerror(rc));
 			goto error;
 		}
 		tp->db=bdb;
@@ -674,7 +663,7 @@ table_p sclib_create_table(database_p _db, str *_s)
 	*/
 	rc = load_metadata_logflags(tp);
 	if(rc!=0)
-		LOG(L_INFO, "sclib_create_table: No METADATA_LOGFLAGS in table: %s.\n", tblname);
+		LM_INFO("No METADATA_LOGFLAGS in table: %s.\n", tblname);
 	
 	if ((tp->logflags & JLOG_FILE) == JLOG_FILE)
 		sclib_create_journal(tp);
@@ -723,8 +712,8 @@ int sclib_create_journal(table_p _tp)
 	if(_tp->fp)
 	{	/* must be rolling. */
 		if( fclose(_tp->fp) )
-		{	LOG(L_ERR, "sclib_create_journal: Failed to Close Log in table: %.*s .\n"
-				,_tp->name.len, _tp->name.s);
+		{	LM_ERR("Failed to Close Log in table: %.*s .\n", _tp->name.len,
+			 _tp->name.s);
 			return -1;
 		}
 	}
@@ -735,8 +724,7 @@ int sclib_create_journal(table_p _tp)
 	}
 	else
 	{
-		LOG(L_ERR, "sclib_create_journal: Failed to Open Log in table: %.*s .\n"
-			,_tp->name.len, _tp->name.s);
+		LM_ERR("Failed to Open Log in table: %.*s .\n",_tp->name.len, _tp->name.s);
 		return -1;
 	}
 	
@@ -778,7 +766,7 @@ int load_metadata_columns(table_p _tp)
 	if ((ret = db->get(db, NULL, &key, &data, 0)) != 0) 
 	{
 		db->err(db, ret, "load_metadata_columns DB->get failed");
-		LOG(L_ERR, "load_metadata_columns: FAILED to find METADATA_COLUMNS in DB \n");
+		LM_ERR("FAILED to find METADATA_COLUMNS in DB \n");
 		return -1;
 	}
 
@@ -792,7 +780,7 @@ int load_metadata_columns(table_p _tp)
 		/* create column*/
 		col = (column_p) pkg_malloc(sizeof(column_t));
 		if(!col)
-		{	LOG(L_ERR, "load_metadata_columns: out of memory \n");
+		{	LM_ERR("out of private memory \n");
 			return -1;
 		}
 		
@@ -854,7 +842,7 @@ int load_metadata_keys(table_p _tp)
 	if ((ret = db->get(db, NULL, &key, &data, 0)) != 0) 
 	{
 		db->err(db, ret, "load_metadata_keys DB->get failed");
-		LOG(L_ERR, "load_metadata_keys: FAILED to find METADATA in table \n");
+		LM_ERR("FAILED to find METADATA in table \n");
 		return ret;
 	}
 	
@@ -968,9 +956,7 @@ int sclib_valtochar(table_p _tp, int* _lres, char* _k, int* _klen, db_val_t* _v,
 	if(! _lres)
 	{	
 #ifdef SC_EXTRA_DEBUG
-		DBG("-------------------------------------------------\n");
-		DBG("-- sclib_valtochar: schema has NOT specified any keys! \n");
-		DBG("-------------------------------------------------\n");	
+		LM_DBG("schema has NOT specified any keys! \n");
 #endif
 
 		/* schema has not specified keys
@@ -979,13 +965,13 @@ int sclib_valtochar(table_p _tp, int* _lres, char* _k, int* _klen, db_val_t* _v,
 		for(i=0;i<_n;i++)
 		{	len = total - sum;
 			if ( sc_val2str(&_v[i], sk, &len) != 0 ) 
-			{	LOG(L_ERR, "sclib_makekey: error building composite key \n");
+			{	LM_ERR("error building composite key \n");
 				return -2;
 			}
 
 			sum += len;
 			if(sum > total)
-			{	LOG(L_ERR, "[sclib_makekey]: Destination buffer too short for subval %s\n",sk);
+			{	LM_ERR("Destination buffer too short for subval %s\n",sk);
 				return -2;
 			} 
 
@@ -996,7 +982,7 @@ int sclib_valtochar(table_p _tp, int* _lres, char* _k, int* _klen, db_val_t* _v,
 
 			sum += DELIM_LEN;
 			if(sum > total)
-			{	LOG(L_ERR, "[sclib_makekey]: Destination buffer too short for delim \n");
+			{	LM_ERR("Destination buffer too short for delim \n");
 				return -3;
 			}
 			
@@ -1045,7 +1031,7 @@ int sclib_valtochar(table_p _tp, int* _lres, char* _k, int* _klen, db_val_t* _v,
 				 index k for anything else
 				*/
 #ifdef SC_EXTRA_DEBUG
-				DBG("-- KEY PROVIDED[%i]: %.*s.%.*s \n", i 
+				LM_DBG("KEY PROVIDED[%i]: %.*s.%.*s \n", i 
 					, _tp->name.len , ZSW(_tp->name.s) 
 					, _tp->colp[i]->name.len, ZSW(_tp->colp[i]->name.s)
 				   );
@@ -1053,13 +1039,13 @@ int sclib_valtochar(table_p _tp, int* _lres, char* _k, int* _klen, db_val_t* _v,
 
 				len = total - sum;
 				if ( sc_val2str(&_v[j], sk, &len) != 0)
-				{	LOG(L_ERR, "[sclib_makekey]: Destination buffer too short for subval %s\n",sk);
+				{	LM_ERR("Destination buffer too short for subval %s\n",sk);
 					return -4;
 				}
 				
 				sum += len;
 				if(sum > total)
-				{	LOG(L_ERR, "[sclib_makekey]: Destination buffer too short for subval %s\n",sk);
+				{	LM_ERR("Destination buffer too short for subval %s\n",sk);
 					return -5;
 				}
 
@@ -1069,7 +1055,7 @@ int sclib_valtochar(table_p _tp, int* _lres, char* _k, int* _klen, db_val_t* _v,
 
 				sum += DELIM_LEN;
 				if(sum > total)
-				{	LOG(L_ERR, "[sclib_makekey]: Destination buffer too short for delim \n");
+				{	LM_ERR("Destination buffer too short for delim \n");
 					return -5;
 				} 
 				
@@ -1093,7 +1079,7 @@ int sclib_valtochar(table_p _tp, int* _lres, char* _k, int* _klen, db_val_t* _v,
 		 is considered a key according to our schema.
 		*/
 #ifdef SC_EXTRA_DEBUG
-		DBG("-- Missing KEY[%i]: %.*s.%.*s \n", i
+		LM_DBG("Missing KEY[%i]: %.*s.%.*s \n", i
 			, _tp->name.len , ZSW(_tp->name.s) 
 			, _tp->colp[i]->name.len, ZSW(_tp->colp[i]->name.s)
 		   );
@@ -1101,7 +1087,7 @@ int sclib_valtochar(table_p _tp, int* _lres, char* _k, int* _klen, db_val_t* _v,
 		len = strlen(cNULL);
 		sum += len;
 		if(sum > total)
-		{	LOG(L_ERR, "[sclib_makekey]: Destination buffer too short for subval %s\n",cNULL);
+		{	LM_ERR("Destination buffer too short for subval %s\n",cNULL);
 			return -5;
 		}
 		
@@ -1111,7 +1097,7 @@ int sclib_valtochar(table_p _tp, int* _lres, char* _k, int* _klen, db_val_t* _v,
 		
 		sum += DELIM_LEN;
 		if(sum > total)
-		{	LOG(L_ERR, "[sclib_makekey]: Destination buffer too short for delim \n");
+		{	LM_ERR("Destination buffer too short for delim \n");
 			return -5;
 		} 
 		
@@ -1211,10 +1197,10 @@ int sclib_recover(table_p _tp, int _rc)
 	switch(_rc)
 	{
 		case DB_LOCK_DEADLOCK:
-		LOG(L_ERR, "[sclib_recover] DB_LOCK_DEADLOCK detected !!\n");
+		LM_ERR("DB_LOCK_DEADLOCK detected !!\n");
 		
 		case DB_RUNRECOVERY:
-		LOG(L_ERR, "[sclib_recover] DB_RUNRECOVERY detected !! \n");
+		LM_ERR("DB_RUNRECOVERY detected !! \n");
 		sclib_destroy();
 		exit(1);
 		break;

+ 120 - 127
modules/db_berkeley/bdb_res.c

@@ -41,61 +41,61 @@ int sc_get_columns(table_p _tp, db_res_t* _res, int* _lres, int _nc)
 {
 	int col, len;
 
-        if (!_res) 
-	{	LOG(L_ERR, "sc_get_columns: db_res_t parameter cannot be NULL\n");
-                return -1;
-        }
+	if (!_res) 
+	{
+		LM_ERR("db_res_t parameter cannot be NULL\n");
+		return -1;
+	}
 
 	if (_nc < 0 ) 
-	{	LOG(L_ERR, "sc_get_columns: _nc parameter cannot be negative \n");
-                return -1;
-        }
+	{
+		LM_ERR("_nc parameter cannot be negative \n");
+		return -1;
+	}
 
         /* the number of rows (tuples) in the query result. */
 	RES_NUM_ROWS(_res) = 1;
 
-        if (!_lres) 
+	if (!_lres)
 		_nc = _tp->ncols;
 
 	/* Allocate storage to hold a pointer to each column name */
-        RES_NAMES(_res) = (db_key_t*)pkg_malloc(sizeof(db_key_t) * _nc);
+	RES_NAMES(_res) = (db_key_t*)pkg_malloc(sizeof(db_key_t) * _nc);
 
 #ifdef SC_EXTRA_DEBUG
-	LOG(L_DBG, "sc_get_columns: %p=pkg_malloc(%lu) RES_NAMES\n"
-		, RES_NAMES(_res)
+	LM_DBG, "%p=pkg_malloc(%lu) RES_NAMES\n", RES_NAMES(_res)
 		, (unsigned long)(sizeof(db_key_t) * _nc));
 #endif
 
 	if (!RES_NAMES(_res)) 
 	{
-                LOG(L_ERR, "sc_get_columns: Failed to allocate %lu bytes for column names\n"
+		LM_ERR("Failed to allocate %lu bytes for column names\n"
 			, (unsigned long)(sizeof(db_key_t) * _nc));
 		
-                return -3;
-        }
+		return -3;
+	}
 
 	/* Allocate storage to hold the type of each column */
-        RES_TYPES(_res) = (db_type_t*)pkg_malloc(sizeof(db_type_t) * _nc);
+	RES_TYPES(_res) = (db_type_t*)pkg_malloc(sizeof(db_type_t) * _nc);
 
 #ifdef SC_EXTRA_DEBUG
-	LOG(L_DBG, "sc_get_columns: %p=pkg_malloc(%lu) RES_TYPES\n"
-		, RES_TYPES(_res)
+	LM_DBG("%p=pkg_malloc(%lu) RES_TYPES\n", RES_TYPES(_res)
 		, (unsigned long)(sizeof(db_type_t) * _nc));
 #endif
 
-        if (!RES_TYPES(_res)) 
+	if (!RES_TYPES(_res)) 
 	{
-                LOG(L_ERR, "sc_get_columns: Failed to allocate %lu bytes for column types\n"
-			, (unsigned long)(sizeof(db_type_t) * _nc));
+		LM_ERR("Failed to allocate %lu bytes for column types\n"
+		, (unsigned long)(sizeof(db_type_t) * _nc));
 		
 		/* Free previously allocated storage that was to hold column names */
-		LOG(L_DBG, "sc_get_columns: %p=pkg_free() RES_NAMES\n", RES_NAMES(_res));
+		LM_DBG("%p=pkg_free() RES_NAMES\n", RES_NAMES(_res));
 		pkg_free(RES_NAMES(_res));
-                return -4;
-        }
+		return -4;
+	}
 
 	/* Save number of columns in the result structure */
-        RES_COL_N(_res) = _nc;
+	RES_COL_N(_res) = _nc;
 
 	/* 
 	 * For each column both the name and the data type are saved.
@@ -108,23 +108,21 @@ int sc_get_columns(table_p _tp, db_res_t* _res, int* _lres, int _nc)
 		RES_NAMES(_res)[col] = pkg_malloc(len+1);
 		
 #ifdef SC_EXTRA_DEBUG
-		LOG(L_DBG, "sc_get_columns: %p=pkg_malloc(%d) RES_NAMES[%d]\n"
+		LM_DBG("%p=pkg_malloc(%d) RES_NAMES[%d]\n"
 			, RES_NAMES(_res)[col], len+1, col);
 #endif
 
 		if (! RES_NAMES(_res)[col]) 
 		{
-			LOG(L_ERR, "sc_get_columns: Failed to allocate %d bytes to hold column name\n", len+1);
+			LM_ERR("Failed to allocate %d bytes to hold column name\n", len+1);
 			return -1;
 		}
 		
 		memset((char *)RES_NAMES(_res)[col], 0, len+1);
 		strncpy((char *)RES_NAMES(_res)[col], cp->name.s, len); 
 
-		LOG(L_DBG, "sc_get_columns: RES_NAMES(%p)[%d]=[%s]\n"
-			, RES_NAMES(_res)[col]
-			, col
-			, RES_NAMES(_res)[col]);
+		LM_DBG("RES_NAMES(%p)[%d]=[%s]\n", RES_NAMES(_res)[col]
+			, col, RES_NAMES(_res)[col]);
 
 		RES_TYPES(_res)[col] = cp->type;
 	}
@@ -143,18 +141,20 @@ int sc_convert_row(db_res_t* _res, char *bdb_result, int* _lres)
 	db_row_t* row = NULL;
 	col = len = i = j = 0;
 	
-        if (!_res)  
-	{	LOG(L_ERR, "sc_convert_row: db_res_t parameter cannot be NULL\n");
-                return -1;
-        }
+	if (!_res)
+	{
+		LM_ERR("sc_convert_row: db_res_t parameter cannot be NULL\n");
+		return -1;
+	}
 
 	/* Allocate a single row structure */
 	len = sizeof(db_row_t); 
 	row = (db_row_t*)pkg_malloc(len);
-        if (!row) 
-	{	LOG(L_ERR, "sc_convert_row: Failed to allocate %d bytes for row structure\n", len);
-                return -1;
-        }
+	if (!row)
+	{
+		LM_ERR("Failed to allocate %d bytes for row structure\n", len);
+		return -1;
+	}
 	memset(row, 0, len);
 	RES_ROWS(_res) = row;
 	
@@ -164,19 +164,20 @@ int sc_convert_row(db_res_t* _res, char *bdb_result, int* _lres)
 	/* Allocate storage to hold the bdb result values */
 	len = sizeof(db_val_t) * RES_COL_N(_res);
 	ROW_VALUES(row) = (db_val_t*)pkg_malloc(len);
-        LOG(L_DBG, "sc_convert_row: %p=pkg_malloc(%d) ROW_VALUES for %d columns\n"
+    LM_DBG("%p=pkg_malloc(%d) ROW_VALUES for %d columns\n"
 		 , ROW_VALUES(row)
 		 , len
 		 , RES_COL_N(_res));
 
-        if (!ROW_VALUES(row)) 
-	{	LOG(L_ERR, "sc_convert_row: No memory left\n");
-                return -1;
-        }
+	if (!ROW_VALUES(row)) 
+	{	
+		LM_ERR("sc_convert_row: No memory left\n");
+		return -1;
+	}
 	memset(ROW_VALUES(row), 0, len);
 
 	/* Save the number of columns in the ROW structure */
-        ROW_N(row) = RES_COL_N(_res);
+	ROW_N(row) = RES_COL_N(_res);
 
 	/*
 	 * Allocate an array of pointers one per column.
@@ -184,10 +185,11 @@ int sc_convert_row(db_res_t* _res, char *bdb_result, int* _lres)
 	 */
 	len = sizeof(char *) * RES_COL_N(_res);
 	row_buf = (char **)pkg_malloc(len);
-        if (!row_buf) 
-	{	LOG(L_ERR, "[sc_convert_row]: Failed to allocate %d bytes for row buffer\n", len);
+	if (!row_buf)
+	{
+		LM_ERR("Failed to allocate %d bytes for row buffer\n", len);
 		return -1;
-        }
+	}
 	memset(row_buf, 0, len);
 
 	/*populate the row_buf with bdb_result*/
@@ -206,7 +208,7 @@ int sc_convert_row(db_res_t* _res, char *bdb_result, int* _lres)
 					row_buf[i] = pkg_malloc(len+1);
 					if (!row_buf[i])
 					{
-						LOG(L_ERR, "[sc_convert_row]: Failed to allocate %d bytes for row_buf[%d]\n", len+1, col);
+						LM_ERR("Failed to allocate %d bytes for row_buf[%d]\n", len+1, col);
 						return -1;
 					}
 					memset(row_buf[i], 0, len+1);
@@ -220,7 +222,7 @@ int sc_convert_row(db_res_t* _res, char *bdb_result, int* _lres)
 			len = strlen(s);
 			row_buf[col] = pkg_malloc(len+1);
 			if (!row_buf[col]) {
-				LOG(L_ERR, "[sc_convert_row]: Failed to allocate %d bytes for row_buf[%d]\n", len+1, col);
+				LM_ERR("Failed to allocate %d bytes for row_buf[%d]\n", len+1, col);
 				return -1;
 			}
 			memset(row_buf[col], 0, len+1);
@@ -237,19 +239,19 @@ int sc_convert_row(db_res_t* _res, char *bdb_result, int* _lres)
 		/*skip the unrequested cols (as already specified)*/
 		if(!row_buf[col])  continue;
 
-		LOG(L_DBG, "sc_convert_row: col[%d]\n", col);
+		LM_DBG("col[%d]\n", col);
 		/* Convert the string representation into the value representation */
 		if (sc_str2val(	RES_TYPES(_res)[col]
 				, &(ROW_VALUES(row)[col])
 				, row_buf[col]
 				, strlen(row_buf[col])) < 0) 
 		{
-                        LOG(L_ERR, "sc_convert_row: Error while converting value\n");
-        		 LOG(L_DBG, "sc_convert_row: %p=pkg_free() _row\n", row);
-                        sc_free_row(row);
-                        return -3;
-                }
-        }
+			LM_ERR("Error while converting value\n");
+			LM_DBG("%p=pkg_free() _row\n", row);
+			sc_free_row(row);
+			return -3;
+		}
+	}
 
 	/* pkg_free() must be done for the above allocations now that the row has been converted.
 	 * During sc_convert_row (and subsequent sc_str2val) processing, data types that don't need to be
@@ -273,12 +275,11 @@ int sc_convert_row(db_res_t* _res, char *bdb_result, int* _lres)
 				break;
 			default:
 #ifdef SC_EXTRA_DEBUG
-			LOG(L_DBG, "sc_convert_row: col[%d] Col[%s] Type[%d] Freeing row_buf[%p]\n"
-				, col
+			LM_DBG("col[%d] Col[%s] Type[%d] Freeing row_buf[%p]\n", col
 				, RES_NAMES(_res)[col], RES_TYPES(_res)[col]
 				, (char*) row_buf[col]);
 			
-			LOG(L_DBG, "sc_convert_row: %p=pkg_free() row_buf[%d]\n", (char *)row_buf[col], col);
+			LM_DBG("%p=pkg_free() row_buf[%d]\n", (char *)row_buf[col], col);
 #endif
 
 			pkg_free((char *)row_buf[col]);
@@ -293,26 +294,27 @@ int sc_convert_row(db_res_t* _res, char *bdb_result, int* _lres)
 		row_buf[col] = (char *)NULL;
 	}
 
-	LOG(L_DBG, "sc_convert_row: %p=pkg_free() row_buf\n", row_buf);
+	LM_DBG("%p=pkg_free() row_buf\n", row_buf);
 	pkg_free(row_buf);
 	row_buf = NULL;
 
-        return 0;
+	return 0;
 
 }
 
 /*rx is row index*/
 int sc_append_row(db_res_t* _res, char *bdb_result, int* _lres, int _rx)
 {
-        int col, len, i, j;
+	int col, len, i, j;
 	char **row_buf, *s;
 	db_row_t* row = NULL;
 	col = len = i = j = 0;
 	
-        if (!_res)  
-	{	LOG(L_ERR, "sc_append_row: db_res_t parameter cannot be NULL\n");
-                return -1;
-        }
+	if (!_res)
+	{
+		LM_ERR("db_res_t parameter cannot be NULL\n");
+		return -1;
+	}
 	
 	row = &(RES_ROWS(_res)[_rx]);
 	
@@ -320,15 +322,16 @@ int sc_append_row(db_res_t* _res, char *bdb_result, int* _lres, int _rx)
 	len = sizeof(db_val_t) * RES_COL_N(_res);
 	ROW_VALUES(row) = (db_val_t*)pkg_malloc(len);
 	
-        if (!ROW_VALUES(row)) 
-	{	LOG(L_ERR, "sc_append_row: No memory left\n");
-                return -1;
-        }
+	if (!ROW_VALUES(row)) 
+	{
+		LM_ERR("No private memory left\n");
+		return -1;
+	}
 	
 	memset(ROW_VALUES(row), 0, len);
 	
 	/* Save the number of columns in the ROW structure */
-        ROW_N(row) = RES_COL_N(_res);
+	ROW_N(row) = RES_COL_N(_res);
 	
 	/*
 	 * Allocate an array of pointers one per column.
@@ -336,10 +339,11 @@ int sc_append_row(db_res_t* _res, char *bdb_result, int* _lres, int _rx)
 	 */
 	len = sizeof(char *) * RES_COL_N(_res);
 	row_buf = (char **)pkg_malloc(len);
-        if (!row_buf) 
-	{	LOG(L_ERR, "[sc_append_row]: Failed to allocate %d bytes for row buffer\n", len);
+	if (!row_buf) 
+	{
+		LM_ERR("Failed to allocate %d bytes for row buffer\n", len);
 		return -1;
-        }
+	}
 	memset(row_buf, 0, len);
 	
 	/*populate the row_buf with bdb_result*/
@@ -358,7 +362,7 @@ int sc_append_row(db_res_t* _res, char *bdb_result, int* _lres, int _rx)
 					row_buf[i] = pkg_malloc(len+1);
 					if (!row_buf[i])
 					{
-						LOG(L_ERR, "[sc_append_row]: Failed to allocate %d bytes for row_buf[%d]\n", len+1, col);
+						LM_ERR("Failed to allocate %d bytes for row_buf[%d]\n", len+1, col);
 						return -1;
 					}
 					memset(row_buf[i], 0, len+1);
@@ -372,13 +376,13 @@ int sc_append_row(db_res_t* _res, char *bdb_result, int* _lres, int _rx)
 			len = strlen(s);
 
 #ifdef SC_EXTRA_DEBUG
-		DBG("     [sc_append_row] : col[%i] = [%.*s]\n", col , len, s );
+		LM_DBG("col[%i] = [%.*s]\n", col , len, s );
 #endif
 
 			row_buf[col] = (char*)pkg_malloc(len+1);
 			if (!row_buf[col]) 
 			{
-				LOG(L_ERR, "[sc_append_row]: Failed to allocate %d bytes for row_buf[%d]\n", len+1, col);
+				LM_ERR("Failed to allocate %d bytes for row_buf[%d]\n", len+1, col);
 				return -1;
 			}
 			memset(row_buf[col], 0, len+1);
@@ -390,17 +394,17 @@ int sc_append_row(db_res_t* _res, char *bdb_result, int* _lres, int _rx)
 	}
 	
 	/*do the type conversion per col*/
-        for(col = 0; col < ROW_N(row); col++) 
+	for(col = 0; col < ROW_N(row); col++) 
 	{
 #ifdef SC_EXTRA_DEBUG
-		DBG("     [sc_append_row] tc 1: col[%i] == ", col );
+		LM_DBG("tc 1: col[%i] == ", col );
 #endif
 
 		/*skip the unrequested cols (as already specified)*/
 		if(!row_buf[col])  continue;
 
 #ifdef SC_EXTRA_DEBUG
-		DBG("     tc 2: col[%i] \n", col );
+		LM_DBG("tc 2: col[%i] \n", col );
 #endif
 
 		/* Convert the string representation into the value representation */
@@ -409,14 +413,14 @@ int sc_append_row(db_res_t* _res, char *bdb_result, int* _lres, int _rx)
 				, row_buf[col]
 				, strlen(row_buf[col])) < 0) 
 		{
-                        LOG(L_ERR, "sc_append_row: Error while converting value\n");
-        		 LOG(L_DBG, "sc_append_row: %p=pkg_free() _row\n", row);
-                        sc_free_row(row);
-                        return -3;
-                }
+			LM_ERR("Error while converting value\n");
+			LM_DBG("%p=pkg_free() _row\n", row);
+			sc_free_row(row);
+			return -3;
+		}
 		
-		LOG(L_DBG, "sc_append_row: col[%d] : %s\n", col, row_buf[col] );
-        }
+		LM_DBG("col[%d] : %s\n", col, row_buf[col] );
+	}
 
 	/* pkg_free() must be done for the above allocations now that the row has been converted.
 	 * During sc_convert_row (and subsequent sc_str2val) processing, data types that don't need to be
@@ -436,7 +440,7 @@ int sc_append_row(db_res_t* _res, char *bdb_result, int* _lres, int _rx)
 		if (RES_TYPES(_res)[col] != DB_STRING) 
 		{
 #ifdef SC_EXTRA_DEBUG
-			LOG(L_DBG, "sc_append_row: [%d][%d] Col[%s] Type[%d] Freeing row_buf[%i]\n"
+			LM_DBG("[%d][%d] Col[%s] Type[%d] Freeing row_buf[%i]\n"
 				, _rx, col, RES_NAMES(_res)[col], RES_TYPES(_res)[col], col);
 #endif
 			pkg_free((char *)row_buf[col]);
@@ -451,11 +455,10 @@ int sc_append_row(db_res_t* _res, char *bdb_result, int* _lres, int _rx)
 		row_buf[col] = (char *)NULL;
 	}
 
-	LOG(L_DBG, "sc_append_row: %p=pkg_free() row_buf\n", row_buf);
+	LM_DBG("%p=pkg_free() row_buf\n", row_buf);
 	pkg_free(row_buf);
 	row_buf = NULL;
-        return 0;
-
+	return 0;
 }
 
 
@@ -486,7 +489,7 @@ int* sc_get_colmap(table_p _dtp, db_key_t* _k, int _n)
 		
 		if(i>=_dtp->ncols)
 		{
-			DBG("sc_get_colmap: ERROR column <%s> not found\n", _k[i]);
+			LM_DBG("ERROR column <%s> not found\n", _k[i]);
 			pkg_free(_lref);
 			return NULL;
 		}
@@ -500,12 +503,12 @@ db_res_t* sc_result_new(void)
 {
 	db_res_t* _res = NULL;
 	_res = (db_res_t*)pkg_malloc(sizeof(db_res_t));
-        if (!_res) 
+	if (!_res) 
 	{
-                LOG(L_ERR, "sc_get_result: Failed to allocate %lu bytes for result structure\n"
+		LM_ERR("Failed to allocate %lu bytes for result structure\n"
 			, (unsigned long)sizeof(db_res_t));
-                return NULL;
-        }
+		return NULL;
+	}
 	
 	memset(_res, 0, sizeof(db_res_t));
 	return _res;
@@ -516,8 +519,8 @@ int sc_free_result(db_res_t* _res)
 {
 	sc_free_columns(_res);
 	sc_free_rows(_res);
-        LOG(L_DBG, "sc_result_free: %p=pkg_free() _res\n", _res);
-        pkg_free(_res);
+	LM_DBG("%p=pkg_free() _res\n", _res);
+	pkg_free(_res);
 	_res = NULL;
 
 	return 0;
@@ -530,19 +533,19 @@ int sc_free_rows(db_res_t* _res)
 {
 	int row;
 
-	LOG(L_DBG, "sc_free_rows: Freeing %d rows\n", RES_ROW_N(_res));
+	LM_DBG("Freeing %d rows\n", RES_ROW_N(_res));
 
 	for(row = 0; row < RES_ROW_N(_res); row++) 
 	{
-		LOG(L_DBG, "sc_free_rows: Row[%d]=%p\n", row, &(RES_ROWS(_res)[row]));
+		LM_DBG("Row[%d]=%p\n", row, &(RES_ROWS(_res)[row]));
 		sc_free_row(&(RES_ROWS(_res)[row]));
 	}
 
 	RES_ROW_N(_res) = 0;
 
-        if (RES_ROWS(_res)) 
+	if (RES_ROWS(_res)) 
 	{
-                LOG(L_DBG, "sc_free_rows: %p=pkg_free() RES_ROWS\n", RES_ROWS(_res));
+		LM_DBG("%p=pkg_free() RES_ROWS\n", RES_ROWS(_res));
 		pkg_free(RES_ROWS(_res));
 		RES_ROWS(_res) = NULL;
 	}
@@ -569,13 +572,13 @@ int sc_free_row(db_row_t* _row)
 		switch (VAL_TYPE(_val)) 
 		{
 		case DB_STRING:
-			LOG(L_DBG, "[sc_free_row]: %p=pkg_free() VAL_STRING[%d]\n", (char *)VAL_STRING(_val), col);
+			LM_DBG("%p=pkg_free() VAL_STRING[%d]\n", (char *)VAL_STRING(_val), col);
 			pkg_free((char *)(VAL_STRING(_val)));
 			VAL_STRING(_val) = (char *)NULL;
 			break;
 
 		case DB_STR:
-			LOG(L_DBG, "[sc_free_row]: %p=pkg_free() VAL_STR[%d]\n", (char *)(VAL_STR(_val).s), col);
+			LM_DBG("%p=pkg_free() VAL_STR[%d]\n", (char *)(VAL_STR(_val).s), col);
 			pkg_free((char *)(VAL_STR(_val).s));
 			VAL_STR(_val).s = (char *)NULL;
 			break;
@@ -585,15 +588,13 @@ int sc_free_row(db_row_t* _row)
 	}
 
 	/* Free db_val_t structure. */
-        if (ROW_VALUES(_row)) 
+	if (ROW_VALUES(_row)) 
 	{
-                LOG(L_DBG, "sc_free_row: %p=pkg_free() ROW_VALUES\n"
-			, ROW_VALUES(_row));
-		
-                pkg_free(ROW_VALUES(_row));
+		LM_DBG("%p=pkg_free() ROW_VALUES\n", ROW_VALUES(_row));
+		pkg_free(ROW_VALUES(_row));
 		ROW_VALUES(_row) = NULL;
 	}
-        return 0;
+	return 0;
 }
 
 /**
@@ -604,37 +605,29 @@ int sc_free_columns(db_res_t* _res)
 	int col;
 
 	/* Free memory previously allocated to save column names */
-        for(col = 0; col < RES_COL_N(_res); col++) 
+	for(col = 0; col < RES_COL_N(_res); col++) 
 	{
 #ifdef SC_EXTRA_DEBUG
-                LOG(L_DBG, "sc_free_columns: Freeing RES_NAMES(%p)[%d] -> free(%p) '%s'\n"
-			, _res
-			, col
-			, RES_NAMES(_res)[col]
-			, RES_NAMES(_res)[col]);
-
-                LOG(L_DBG, "sc_free_columns: %p=pkg_free() RES_NAMES[%d]\n"
-			, RES_NAMES(_res)[col]
-			, col);
+		LM_DBG("Freeing RES_NAMES(%p)[%d] -> free(%p) '%s'\n", _res
+			, col, RES_NAMES(_res)[col], RES_NAMES(_res)[col]);
+		LM_DBG, "%p=pkg_free() RES_NAMES[%d]\n", RES_NAMES(_res)[col], col);
 #endif
 		
-                pkg_free((char *)RES_NAMES(_res)[col]);
+		pkg_free((char *)RES_NAMES(_res)[col]);
 		RES_NAMES(_res)[col] = (char *)NULL;
 	}
 	
-        if (RES_NAMES(_res)) 
+	if (RES_NAMES(_res)) 
 	{
-                LOG(L_DBG, "sc_free_columns: %p=pkg_free() RES_NAMES\n"
-			, RES_NAMES(_res));
+		LM_DBG("%p=pkg_free() RES_NAMES\n", RES_NAMES(_res));
 		
 		pkg_free(RES_NAMES(_res));
 		RES_NAMES(_res) = NULL;
 	}
 	
-        if (RES_TYPES(_res)) 
+	if (RES_TYPES(_res)) 
 	{
-                LOG(L_DBG, "sc_free_columns: %p=pkg_free() RES_TYPES\n"
-			, RES_TYPES(_res));
+		LM_DBG("%p=pkg_free() RES_TYPES\n", RES_TYPES(_res));
 		
 		pkg_free(RES_TYPES(_res));
 		RES_TYPES(_res) = NULL;

+ 20 - 20
modules/db_berkeley/bdb_val.c

@@ -62,7 +62,7 @@ int sc_str2val(db_type_t _t, db_val_t* _v, char* _s, int _l)
 	switch(_t) {
 	case DB_INT:
 		if (db_str2int(_s, &VAL_INT(_v)) < 0) {
-			LOG(L_ERR, "berkeley_db[str2val]: Error while converting INT value from string\n");
+			LM_ERR("Error while converting INT value from string\n");
 			return -2;
 		} else {
 			VAL_TYPE(_v) = DB_INT;
@@ -72,7 +72,7 @@ int sc_str2val(db_type_t _t, db_val_t* _v, char* _s, int _l)
 
 	case DB_BITMAP:
 		if (db_str2int(_s, &VAL_INT(_v)) < 0) {
-			LOG(L_ERR, "berkeley_db[str2val]: Error while converting BITMAP value from string\n");
+			LM_ERR("Error while converting BITMAP value from string\n");
 			return -3;
 		} else {
 			VAL_TYPE(_v) = DB_BITMAP;
@@ -82,7 +82,7 @@ int sc_str2val(db_type_t _t, db_val_t* _v, char* _s, int _l)
 
 	case DB_DOUBLE:
 		if (db_str2double(_s, &VAL_DOUBLE(_v)) < 0) {
-			LOG(L_ERR, "berkeley_db[str2val]: Error while converting DOUBLE value from string\n");
+			LM_ERR("Error while converting DOUBLE value from string\n");
 			return -4;
 		} else {
 			VAL_TYPE(_v) = DB_DOUBLE;
@@ -111,7 +111,7 @@ int sc_str2val(db_type_t _t, db_val_t* _v, char* _s, int _l)
 
 	case DB_DATETIME:
 		if (db_str2time(_s, &VAL_TIME(_v)) < 0) {
-			LOG(L_ERR, "berkeley_db[str2val]: Error converting datetime\n");
+			LM_ERR("Error converting datetime\n");
 			return -5;
 		} else {
 			VAL_TYPE(_v) = DB_DATETIME;
@@ -122,7 +122,7 @@ int sc_str2val(db_type_t _t, db_val_t* _v, char* _s, int _l)
 	case DB_BLOB:
 		VAL_BLOB(_v).s = _s;
 		VAL_TYPE(_v) = DB_BLOB;
-		LOG(L_DBG, "berkeley_db[str2val]: got blob len %d\n", _l);
+		LM_DBG("got blob len %d\n", _l);
 		return 0;
 	}
 
@@ -146,30 +146,30 @@ int sc_val2str(db_val_t* _v, char* _s, int* _len)
 	switch(VAL_TYPE(_v)) {
 	case DB_INT:
 		if (db_int2str(VAL_INT(_v), _s, _len) < 0) {
-			LOG(L_ERR, "berkeley_db[val2str]: Error while converting int to string\n");
+			LM_ERR("Error while converting int to string\n");
 			return -2;
 		} else {
-			LOG(L_DBG, "berkeley_db[val2str]: Converted int to string\n");
+			LM_DBG("Converted int to string\n");
 			return 0;
 		}
 		break;
 
 	case DB_BITMAP:
 		if (db_int2str(VAL_INT(_v), _s, _len) < 0) {
-			LOG(L_ERR, "berkeley_db[val2str]: Error while converting bitmap to string\n");
+			LM_ERR("Error while converting bitmap to string\n");
 			return -3;
 		} else {
-			LOG(L_DBG, "berkeley_db[val2str]: Converted bitmap to string\n");
+			LM_DBG("Converted bitmap to string\n");
 			return 0;
 		}
 		break;
 
 	case DB_DOUBLE:
 		if (db_double2str(VAL_DOUBLE(_v), _s, _len) < 0) {
-			LOG(L_ERR, "berkeley_db[val2str]: Error while converting double  to string\n");
+			LM_ERR("Error while converting double  to string\n");
 			return -3;
 		} else {
-			LOG(L_DBG, "berkeley_db[val2str]: Converted double to string\n");
+			LM_DBG("Converted double to string\n");
 			return 0;
 		}
 		break;
@@ -177,11 +177,11 @@ int sc_val2str(db_val_t* _v, char* _s, int* _len)
 	case DB_STRING:
 		l = strlen(VAL_STRING(_v));
 		if (*_len < l ) 
-		{	LOG(L_ERR, "berkeley_db[val2str]: Destination buffer too short for string\n");
+		{	LM_ERR("Destination buffer too short for string\n");
 			return -4;
 		} 
 		else 
-		{	LOG(L_DBG, "berkeley_db[val2str]: Converted string to string\n");
+		{	LM_DBG("Converted string to string\n");
 			strncpy(_s, VAL_STRING(_v) , l);
 			_s[l] = 0;
 			*_len = l;
@@ -193,12 +193,12 @@ int sc_val2str(db_val_t* _v, char* _s, int* _len)
 		l = VAL_STR(_v).len;
 		if (*_len < l) 
 		{
-			LOG(L_ERR, "berkeley_db[val2str]: Destination buffer too short for str\n");
+			LM_ERR("Destination buffer too short for str\n");
 			return -5;
 		} 
 		else 
 		{
-			LOG(L_DBG, "berkeley_db[val2str]: Converted str to string\n");
+			LM_DBG("Converted str to string\n");
 			strncpy(_s, VAL_STR(_v).s , VAL_STR(_v).len);
 			*_len = VAL_STR(_v).len;
 			return 0;
@@ -207,10 +207,10 @@ int sc_val2str(db_val_t* _v, char* _s, int* _len)
 
 	case DB_DATETIME:
 		if (db_time2str(VAL_TIME(_v), _s, _len) < 0) {
-			LOG(L_ERR, "berkeley_db[val2str]: Error while converting time_t to string\n");
+			LM_ERR("Error while converting time_t to string\n");
 			return -6;
 		} else {
-			LOG(L_DBG, "berkeley_db[val2str]: Converted time_t to string\n");
+			LM_DBG("Converted time_t to string\n");
 			return 0;
 		}
 		break;
@@ -219,12 +219,12 @@ int sc_val2str(db_val_t* _v, char* _s, int* _len)
 		l = VAL_BLOB(_v).len;
 		if (*_len < l) 
 		{
-			LOG(L_ERR, "berkeley_db[val2str]: Destination buffer too short for blob\n");
+			LM_ERR("Destination buffer too short for blob\n");
 			return -7;
 		} 
 		else 
 		{
-			LOG(L_DBG, "berkeley_db[str2val]: Converting BLOB [%s]\n", _s);
+			LM_DBG("Converting BLOB [%s]\n", _s);
 			_s = VAL_BLOB(_v).s;
 			*_len = 0;
 			return -8;
@@ -232,7 +232,7 @@ int sc_val2str(db_val_t* _v, char* _s, int* _len)
 		break;
 
 	default:
-		LOG(L_DBG, "berkeley_db[val2str]: Unknown data type\n");
+		LM_DBG("Unknown data type\n");
 		return -8;
 	}
 	return -9;

+ 78 - 113
modules/db_berkeley/db_berkeley.c

@@ -150,7 +150,7 @@ db_con_t* sc_init(const char* _sqlurl)
 	_s.len = strlen(_sqlurl);
 	if(_s.len <= SC_ID_LEN || strncmp(_s.s, SC_ID, SC_ID_LEN)!=0)
 	{
-		LOG(L_ERR, "sc_init: invalid database URL - should be:"
+		LM_ERR("invalid database URL - should be:"
 			" <%s[/]path/to/directory>\n", SC_ID);
 		return NULL;
 	}
@@ -161,7 +161,7 @@ db_con_t* sc_init(const char* _sqlurl)
 	{
 		if(sizeof(CFG_DIR)+_s.len+2 > SC_PATH_LEN)
 		{
-			LOG(L_ERR, "sc_init: path to database is too long\n");
+			LM_ERR("path to database is too long\n");
 			return NULL;
 		}
 		strcpy(sc_path, CFG_DIR);
@@ -174,7 +174,7 @@ db_con_t* sc_init(const char* _sqlurl)
 	_res = pkg_malloc(sizeof(db_con_t)+sizeof(sc_con_t));
 	if (!_res)
 	{
-		LOG(L_ERR, "sc_init: No memory left\n");
+		LM_ERR("No private memory left\n");
 		return NULL;
 	}
 	memset(_res, 0, sizeof(db_con_t) + sizeof(sc_con_t));
@@ -183,7 +183,7 @@ db_con_t* sc_init(const char* _sqlurl)
 	SC_CON_CONNECTION(_res) = sclib_get_db(&_s);
 	if (!SC_CON_CONNECTION(_res))
 	{
-		LOG(L_ERR, "sc_init: cannot get the link to database\n");
+		LM_ERR("cannot get the link to database\n");
 		return NULL;
 	}
 
@@ -208,9 +208,7 @@ void sc_reload(char* _n)
 {
 	
 #ifdef SC_EXTRA_DEBUG
-	DBG("-------------------------------------------------\n");
-	DBG("------- RELOAD in %s\n", _n);
-	DBG("-------------------------------------------------\n");
+	LM_DBG("RELOAD in %s\n", _n);
 #endif
 
 	sclib_close(_n);
@@ -244,7 +242,7 @@ void sc_check_reload(db_con_t* _con)
 	len+=s.len;
 	
 	if(len > MAX_ROW_SIZE)
-	{	LOG(L_ERR, "sc_check_reload: dbenv name too long \n");
+	{	LM_ERR("dbenv name too long \n");
 		return;
 	}
 	
@@ -253,7 +251,7 @@ void sc_check_reload(db_con_t* _con)
 	
 	len++;
 	if(len > MAX_ROW_SIZE)
-	{	LOG(L_ERR, "sc_check_reload: dbenv name too long \n");
+	{	LM_ERR("dbenv name too long \n");
 		return;
 	}
 	
@@ -267,7 +265,7 @@ void sc_check_reload(db_con_t* _con)
 	len+=s.len;
 	
 	if((len>MAX_ROW_SIZE) || (s.len > MAX_TABLENAME_SIZE) )
-	{	LOG(L_ERR, "sc_check_reload: table name too long \n");
+	{	LM_ERR("table name too long \n");
 		return;
 	}
 
@@ -284,7 +282,7 @@ void sc_check_reload(db_con_t* _con)
 	if( (tp = tbc->dtp) == NULL)
 		return;
 	
-	DBG("sc_check_reload: stat file [%.*s]\n", len, n);
+	LM_DBG("stat file [%.*s]\n", len, n);
 	rc = stat(n, &st);
 	if(!rc)
 	{	if((tp->ino!=0) && (st.st_ino != tp->ino))
@@ -338,7 +336,7 @@ int sc_query(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 	if ((!_con) || (!_r) || !CON_TABLE(_con))
 	{
 #ifdef SC_EXTRA_DEBUG
-		LOG(L_ERR, "sc_query: Invalid parameter value\n");
+		LM_ERR("Invalid parameter value\n");
 #endif
 		return -1;
 	}
@@ -353,23 +351,21 @@ int sc_query(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 
 	_tbc = sclib_get_table(SC_CON_CONNECTION(_con), &s);
 	if(!_tbc)
-	{	DBG("sc_query: table does not exist!\n");
+	{	LM_WARN("table does not exist!\n");
 		return -1;
 	}
 
 	_tp = _tbc->dtp;
 	if(!_tp)
-	{	DBG("sc_query: table not loaded!\n");
+	{	LM_WARN("table not loaded!\n");
 		return -1;
 	}
 
 #ifdef SC_EXTRA_DEBUG
-	DBG("-------------------------------------------------\n");
-	DBG("------- QUERY in %.*s\n", _tp->name.len, _tp->name.s);
-	DBG("-------------------------------------------------\n");
+	LM_DBG("QUERY in %.*s\n", _tp->name.len, _tp->name.s);
 
-	if (_o)  DBG("sc_query: DONT-CARE : _o: order by the specified column \n");
-	if (_op) DBG("sc_query: DONT-CARE : _op: operators for refining query \n");
+	if (_o)  LM_DBG("DONT-CARE : _o: order by the specified column \n");
+	if (_op) LM_DBG("DONT-CARE : _op: operators for refining query \n");
 #endif
 	
 	db = _tp->db;
@@ -409,14 +405,12 @@ int sc_query(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 		i =0 ;
 
 #ifdef SC_EXTRA_DEBUG
-		DBG("------------------------------------------------------\n");
-		DBG("------- SELECT * FROM %.*s\n", _tp->name.len, _tp->name.s);
-		DBG("------------------------------------------------------\n");
+		LM_DBG("SELECT * FROM %.*s\n", _tp->name.len, _tp->name.s);
 #endif
 
 		/* Acquire a cursor for the database. */
 		if ((ret = db->cursor(db, NULL, &dbcp, 0)) != 0) 
-		{	LOG(L_ERR, "sc_query: Error creating cursor\n");
+		{	LM_ERR("Error creating cursor\n");
 			goto error;
 		}
 		
@@ -431,12 +425,12 @@ int sc_query(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 		ret=0;
 		
 #ifdef SC_EXTRA_DEBUG
-		DBG("--- %i = SELECT COUNT(*) FROM %.*s\n", i, _tp->name.len, _tp->name.s);
+		LM_DBG("%i = SELECT COUNT(*) FROM %.*s\n", i, _tp->name.len, _tp->name.s);
 #endif
 
 		*_r = sc_result_new();
 		if (!*_r) 
-		{	LOG(L_ERR, "sc_query: no memory left for result \n");
+		{	LM_ERR("no memory left for result \n");
 			ret = -2;
 			goto error;
 		}
@@ -457,13 +451,13 @@ int sc_query(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 		
 		/*fill in the column part of db_res_t (metadata) */
 		if ((ret = sc_get_columns(_tbc->dtp, *_r, lres, _nc)) < 0) 
-		{	LOG(L_ERR, "sc_query: Error while getting column names\n");
+		{	LM_ERR("Error while getting column names\n");
 			goto error;
 		}
 		
 		/* Acquire a cursor for the database. */
 		if ((ret = db->cursor(db, NULL, &dbcp, 0)) != 0) 
-		{	LOG(L_ERR, "sc_query: Error creating cursor\n");
+		{	LM_ERR("Error creating cursor\n");
 			goto error;
 		}
 
@@ -475,7 +469,7 @@ int sc_query(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 				continue;
 			
 #ifdef SC_EXTRA_DEBUG
-		DBG("     KEY:  [%.*s]\n     DATA: [%.*s]\n"
+		LM_DBG("KEY: [%.*s]\nDATA: [%.*s]\n"
 			, (int)   key.size
 			, (char *)key.data
 			, (int)   data.size
@@ -484,7 +478,7 @@ int sc_query(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 
 			/*fill in the row part of db_res_t */
 			if ((ret=sc_append_row( *_r, dbuf, lres, i)) < 0) 
-			{	LOG(L_ERR, "sc_query: Error while converting row\n");
+			{	LM_ERR("Error while converting row\n");
 				goto error;
 			}
 			i++;
@@ -496,7 +490,7 @@ int sc_query(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 	}
 
 	if ( (ret = sclib_valtochar(_tp, lkey, kbuf, &klen, _v, _n, SC_KEY)) != 0 ) 
-	{	LOG(L_ERR, "sc_query: error in query key \n");
+	{	LM_ERR("error in query key \n");
 		goto error;
 	}
 
@@ -512,7 +506,7 @@ int sc_query(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 	/*create an empty db_res_t which gets returned even if no result*/
 	*_r = sc_result_new();
 	if (!*_r) 
-	{	LOG(L_ERR, "sc_convert_result: no memory left for result \n");
+	{	LM_ERR("no memory left for result \n");
 		ret = -2;
 		goto error;
 	}
@@ -520,34 +514,30 @@ int sc_query(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 	SC_CON_RESULT(_con) = *_r;
 
 #ifdef SC_EXTRA_DEBUG
-		DBG("-------------------------------------------------\n");
-		DBG("SELECT  KEY: [%.*s]\n"
+		LM_DBG("SELECT  KEY: [%.*s]\n"
 			, (int)   key.size
 			, (char *)key.data );
-		DBG("-------------------------------------------------\n");
 #endif
 
 	/*query Berkely DB*/
 	if ((ret = db->get(db, NULL, &key, &data, 0)) == 0) 
 	{
 #ifdef SC_EXTRA_DEBUG
-		DBG("-------------------------------------------------\n");
-		DBG("-- RESULT\n     KEY:  [%.*s]\n     DATA: [%.*s]\n"
+		LM_DBG("RESULT\nKEY:  [%.*s]\nDATA: [%.*s]\n"
 			, (int)   key.size
 			, (char *)key.data
 			, (int)   data.size
 			, (char *)data.data);
-		DBG("-------------------------------------------------\n");
 #endif
 
 		/*fill in the col part of db_res_t */
 		if ((ret = sc_get_columns(_tbc->dtp, *_r, lres, _nc)) < 0) 
-		{	LOG(L_ERR, "sc_query: Error while getting column names\n");
+		{	LM_ERR("Error while getting column names\n");
 			goto error;
 		}
 		/*fill in the row part of db_res_t */
 		if ((ret=sc_convert_row( *_r, dbuf, lres)) < 0) 
-		{	LOG(L_ERR, "sc_query: Error while converting row\n");
+		{	LM_ERR("Error while converting row\n");
 			goto error;
 		}
 		
@@ -565,9 +555,7 @@ int sc_query(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 		case DB_NOTFOUND:
 		
 #ifdef SC_EXTRA_DEBUG
-			DBG("------------------------------\n");
-			DBG("-- NO RESULT for QUERY \n");
-			DBG("------------------------------\n");
+			LM_DBG("NO RESULT for QUERY \n");
 #endif
 		
 			ret=0;
@@ -579,7 +567,7 @@ int sc_query(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 		// A secondary index references a nonexistent primary key. 
 		case DB_RUNRECOVERY:
 		default:
-			LOG(L_CRIT,"sc_query: DB->get error: %s.\n", db_strerror(ret));
+			LM_CRIT("DB->get error: %s.\n", db_strerror(ret));
 			sclib_recover(_tp,ret);
 			goto error;
 		}
@@ -606,11 +594,7 @@ error:
  */
 int sc_raw_query(db_con_t* _h, char* _s, db_res_t** _r)
 {
-#ifdef SC_EXTRA_DEBUG
-	DBG("-------------------------------------------------\n");
-	DBG("------- Todo: Implement DB RAW QUERY \n");
-	DBG("-------------------------------------------------\n");
-#endif
+	LM_CRIT("DB RAW QUERY not implemented!\n");
 	return -1;
 }
 
@@ -640,9 +624,7 @@ int sc_insert(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 	if (!_k)
 	{
 #ifdef SC_EXTRA_DEBUG
-	DBG("-------------------------------------------------\n");
-	DBG("------- Todo: Implement DB INSERT w.o KEYs !! \n");
-	DBG("-------------------------------------------------\n");
+	LM_FATAL("DB INSERT without KEYs not implemented! \n");
 #endif
 		return -2;
 	}
@@ -652,20 +634,18 @@ int sc_insert(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 
 	_tbc = sclib_get_table(SC_CON_CONNECTION(_h), &s);
 	if(!_tbc)
-	{	DBG("sc_insert: table does not exist!\n");
+	{	LM_WARN("table does not exist!\n");
 		return -3;
 	}
 
 	_tp = _tbc->dtp;
 	if(!_tp)
-	{	DBG("sc_insert: table not loaded!\n");
+	{	LM_WARN("table not loaded!\n");
 		return -4;
 	}
 
 #ifdef SC_EXTRA_DEBUG
-		DBG("---------------------------------------------------\n");
-		DBG("------- INSERT in %.*s\n", _tp->name.len, _tp->name.s );
-		DBG("---------------------------------------------------\n");
+	LM_DBG("INSERT in %.*s\n", _tp->name.len, _tp->name.s );
 #endif
 	
 	db = _tp->db;
@@ -673,12 +653,12 @@ int sc_insert(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 	memset(kbuf, 0, klen);
 	
 	if(_tp->ncols<_n) 
-	{	DBG("sc_insert: more values than columns!!\n");
+	{	LM_WARN("more values than columns!!\n");
 		return -5;
 	}
 
 	if(_tp->ncols>_n) 
-	{	DBG("sc_insert: not enough values(%i) to fill the columns(%i) !!\n", _n, _tp->ncols);
+	{	LM_WARN("not enough values(%i) to fill the columns(%i) !!\n", _n, _tp->ncols);
 		return -6;
 	}
 	
@@ -691,7 +671,7 @@ int sc_insert(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 	{	j = (lkey)?lkey[i]:i;
 		if(sc_is_neq_type(_tp->colp[j]->type, _v[i].type))
 		{
-			DBG("sc_insert: incompatible types v[%d] - c[%d]!\n", i, j);
+			LM_WARN("incompatible types v[%d] - c[%d]!\n", i, j);
 			ret = -8;
 			goto error;
 		}
@@ -699,7 +679,7 @@ int sc_insert(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 	
 	/* make the key */
 	if ( (ret = sclib_valtochar(_tp, lkey, kbuf, &klen, _v, _n, SC_KEY)) != 0 ) 
-	{	LOG(L_ERR, "sc_insert: error in sclib_valtochar  \n");
+	{	LM_ERR("Error in sclib_valtochar  \n");
 		ret = -9;
 		goto error;
 	}
@@ -714,7 +694,7 @@ int sc_insert(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 	memset(dbuf, 0, MAX_ROW_SIZE);
 
 	if ( (ret = sclib_valtochar(_tp, lkey, dbuf, &dlen, _v, _n, SC_VALUE)) != 0 ) 
-	{	LOG(L_ERR, "sc_insert: error in sclib_valtochar \n");
+	{	LM_ERR("Error in sclib_valtochar \n");
 		ret = -9;
 		goto error;
 	}
@@ -729,13 +709,11 @@ int sc_insert(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 		sclib_log(JLOG_INSERT, _tp, dbuf, dlen);
 
 #ifdef SC_EXTRA_DEBUG
-	DBG("-------------------------------------------------\n");
-	DBG("-- INSERT\n     KEY:  [%.*s]\n     DATA: [%.*s]\n"
+	LM_DBG("INSERT\nKEY:  [%.*s]\nDATA: [%.*s]\n"
 		, (int)   key.size
 		, (char *)key.data
 		, (int)   data.size
 		, (char *)data.data);
-	DBG("-------------------------------------------------\n");
 #endif
 	}
 	else
@@ -748,7 +726,7 @@ int sc_insert(db_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 		
 		case DB_RUNRECOVERY:
 		default:
-			LOG(L_CRIT, "sc_insert: DB->put error: %s.\n", db_strerror(ret));
+			LM_CRIT("DB->put error: %s.\n", db_strerror(ret));
 			sclib_recover(_tp, ret);
 			goto error;
 		}
@@ -797,20 +775,18 @@ int sc_delete(db_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, int _n)
 
 	_tbc = sclib_get_table(SC_CON_CONNECTION(_h), &s);
 	if(!_tbc)
-	{	DBG("sc_delete: table does not exist!\n");
+	{	LM_WARN("table does not exist!\n");
 		return -3;
 	}
 
 	_tp = _tbc->dtp;
 	if(!_tp)
-	{	DBG("sc_delete: table not loaded!\n");
+	{	LM_WARN("table not loaded!\n");
 		return -4;
 	}
 
 #ifdef SC_EXTRA_DEBUG
-		DBG("-------------------------------------------------\n");
-		DBG("------- DELETE in %.*s\n", _tp->name.len, _tp->name.s );
-		DBG("-------------------------------------------------\n");
+		LM_DBG("DELETE in %.*s\n", _tp->name.len, _tp->name.s );
 #endif
 
 	db = _tp->db;
@@ -821,7 +797,7 @@ int sc_delete(db_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, int _n)
 	{
 		/* Acquire a cursor for the database. */
 		if ((ret = db->cursor(db, NULL, &dbcp, DB_WRITECURSOR) ) != 0) 
-		{	LOG(L_ERR, "sc_query: Error creating cursor\n");
+		{	LM_ERR("Error creating cursor\n");
 			goto error;
 		}
 		
@@ -830,7 +806,7 @@ int sc_delete(db_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, int _n)
 			if(!strncasecmp((char*)key.data,"METADATA",8)) 
 				continue;
 #ifdef SC_EXTRA_DEBUG
-			DBG("     KEY: [%.*s]\n "
+			LM_DBG("KEY: [%.*s]\n"
 				, (int)   key.size
 				, (char *)key.data);
 #endif
@@ -846,7 +822,7 @@ int sc_delete(db_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, int _n)
 
 	/* make the key */
 	if ( (ret = sclib_valtochar(_tp, lkey, kbuf, &klen, _v, _n, SC_KEY)) != 0 ) 
-	{	LOG(L_ERR, "sc_delete: error in sclib_makekey  \n");
+	{	LM_ERR("Error in sclib_makekey\n");
 		ret = -6;
 		goto error;
 	}
@@ -861,9 +837,7 @@ int sc_delete(db_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, int _n)
 		sclib_log(JLOG_DELETE, _tp, kbuf, klen);
 
 #ifdef SC_EXTRA_DEBUG
-		DBG("-------------------------------------------------\n");
-		DBG("-- DELETED ROW \n KEY: %s \n", (char *)key.data);
-		DBG("-------------------------------------------------\n");
+		LM_DBG("DELETED ROW \n KEY: %s \n", (char *)key.data);
 #endif
 	}
 	else
@@ -881,7 +855,7 @@ int sc_delete(db_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, int _n)
 		/* A secondary index references a nonexistent primary key. */
 		case DB_RUNRECOVERY:
 		default:
-			LOG(L_CRIT,"sc_delete: DB->del error: %s.\n"
+			LM_CRIT("DB->del error: %s.\n"
 				, db_strerror(ret));
 			sclib_recover(_tp, ret);
 			goto error;
@@ -929,20 +903,18 @@ int _sc_delete_cursor(db_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, in
 
 	_tbc = sclib_get_table(SC_CON_CONNECTION(_h), &s);
 	if(!_tbc)
-	{	DBG("_sc_delete_cursor: table does not exist!\n");
+	{	LM_WARN("table does not exist!\n");
 		return -3;
 	}
 
 	_tp = _tbc->dtp;
 	if(!_tp)
-	{	DBG("_sc_delete_cursor: table not loaded!\n");
+	{	LM_WARN("table not loaded!\n");
 		return -4;
 	}
 	
 #ifdef SC_EXTRA_DEBUG
-	DBG("-------------------------------------------------\n");
-	DBG("------- DELETE by cursor in %.*s\n", _tp->name.len, _tp->name.s );
-	DBG("-------------------------------------------------\n");
+	LM_DBG("DELETE by cursor in %.*s\n", _tp->name.len, _tp->name.s );
 #endif
 
 	if(_k)
@@ -956,14 +928,14 @@ int _sc_delete_cursor(db_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, in
 	/* create an empty db_res_t which gets returned even if no result */
 	_r = sc_result_new();
 	if (!_r) 
-	{	LOG(L_ERR, "_sc_delete_cursor: no memory for result \n");
+	{	LM_ERR("no memory for result \n");
 	}
 	
 	RES_ROW_N(_r) = 0;
 	
 	/* fill in the col part of db_res_t */
 	if ((ret = sc_get_columns(_tp, _r, 0, 0)) != 0) 
-	{	LOG(L_ERR, "_sc_delete_cursor: Error while getting column names\n");
+	{	LM_ERR("Error while getting column names\n");
 		goto error;
 	}
 	
@@ -979,7 +951,7 @@ int _sc_delete_cursor(db_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, in
 	
 	/* Acquire a cursor for the database. */
 	if ((ret = db->cursor(db, NULL, &dbcp, DB_WRITECURSOR)) != 0) 
-	{	LOG(L_ERR, "_sc_delete_cursor: Error creating cursor\n");
+	{	LM_ERR("Error creating cursor\n");
 	}
 	
 	while ((ret = dbcp->c_get(dbcp, &key, &data, DB_NEXT)) == 0)
@@ -989,7 +961,7 @@ int _sc_delete_cursor(db_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, in
 		
 		/*fill in the row part of db_res_t */
 		if ((ret=sc_convert_row( _r, dbuf, 0)) < 0) 
-		{	LOG(L_ERR, "_sc_delete_cursor: Error while converting row\n");
+		{	LM_ERR("Error while converting row\n");
 			goto error;
 		}
 		
@@ -997,15 +969,14 @@ int _sc_delete_cursor(db_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, in
 		{
 
 #ifdef SC_EXTRA_DEBUG
-			DBG("[_sc_delete_cursor] DELETE ROW by KEY:  [%.*s]\n"
-				, (int) key.size, (char *)key.data);
+			LM_DBG("DELETE ROW by KEY:  [%.*s]\n", (int) key.size, 
+				(char *)key.data);
 #endif
 
 			if((ret = dbcp->c_del(dbcp, 0)) != 0)
 			{	
 				/* Berkeley DB error handler */
-				LOG(L_CRIT,"_sc_delete_cursor: DB->get error: %s.\n"
-					, db_strerror(ret));
+				LM_CRIT("DB->get error: %s.\n", db_strerror(ret));
 				sclib_recover(_tp,ret);
 			}
 			
@@ -1063,27 +1034,25 @@ int sc_update(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 
 	_tbc = sclib_get_table(SC_CON_CONNECTION(_con), &s);
 	if(!_tbc)
-	{	LOG(L_ERR, "ERROR: sc_update:: table does not exist\n");
+	{	LM_ERR("table does not exist\n");
 		return -1;
 	}
 
 	_tp = _tbc->dtp;
 	if(!_tp)
-	{	LOG(L_ERR, "ERROR: sc_update:: table not loaded\n");
+	{	LM_ERR("table not loaded\n");
 		return -1;
 	}
 	
 	db = _tp->db;
 	if(!db)
-	{	LOG(L_ERR, "ERROR: sc_update:: DB null ptr\n");
+	{	LM_ERR("DB null ptr\n");
 		return -1;
 	}
 	
 #ifdef SC_EXTRA_DEBUG
-	DBG("-------------------------------------------------\n");
-	DBG("-- UPDATE in %.*s\n", _tp->name.len, _tp->name.s);
-	DBG("-------------------------------------------------\n");
-	if (_op) DBG("sc_update: DONT-CARE : _op: operators for refining query \n");
+	LM_DBG("UPDATE in %.*s\n", _tp->name.len, _tp->name.s);
+	if (_op) LM_DBG("DONT-CARE : _op: operators for refining query \n");
 #endif
 	
 	memset(&key, 0, sizeof(DBT));
@@ -1101,14 +1070,14 @@ int sc_update(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 	}
 	else
 	{
-		LOG(L_ERR, "ERROR: sc_update:: Null keys in update _k=0 \n");
+		LM_ERR("Null keys in update _k=0 \n");
 		return -1;
 	}
 	
 	len = MAX_ROW_SIZE;
 	
 	if ( (ret = sclib_valtochar(_tp, lkey, kbuf, &len, _v, _n, SC_KEY)) != 0 ) 
-	{	LOG(L_ERR, "sc_update: error in query key \n");
+	{	LM_ERR("Error in query key \n");
 		goto cleanup;
 	}
 	
@@ -1124,7 +1093,7 @@ int sc_update(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 	{
 
 #ifdef SC_EXTRA_DEBUG
-		DBG("---1 uRESULT\n     KEY:  [%.*s]\n     DATA: [%.*s]\n"
+		LM_DBG("RESULT\nKEY:  [%.*s]\nDATA: [%.*s]\n"
 			, (int)   key.size
 			, (char *)key.data
 			, (int)   qdata.size
@@ -1159,7 +1128,7 @@ int sc_update(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 		sum+=len;
 		
 		if(sum > MAX_ROW_SIZE)
-		{	LOG(L_ERR, "sc_update: value too long for string \n");
+		{	LM_ERR("value too long for string \n");
 			ret = -3;
 			goto cleanup;
 		}
@@ -1171,7 +1140,7 @@ int sc_update(db_con_t* _con, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 			{	/* update this col */
 				int j = MAX_ROW_SIZE - sum;
 				if( sc_val2str( &_uv[i], t, &j) )
-				{	LOG(L_ERR, "sc_update: value too long for string \n");
+				{	LM_ERR("value too long for string \n");
 					ret = -3;
 					goto cleanup;
 				}
@@ -1190,7 +1159,7 @@ next:
 		/* append DELIM */
 		sum += DELIM_LEN;
 		if(sum > MAX_ROW_SIZE)
-		{	LOG(L_ERR, "sc_update: value too long for string \n");
+		{	LM_ERR("value too long for string \n");
 			ret = -3;
 			goto cleanup;
 		}
@@ -1209,7 +1178,7 @@ next:
 	udata.size  = sum;
 
 #ifdef SC_EXTRA_DEBUG
-	DBG("---2 MODIFIED Data\n     KEY:  [%.*s]\n     DATA: [%.*s]\n"
+	LM_DBG("MODIFIED Data\nKEY:  [%.*s]\nDATA: [%.*s]\n"
 		, (int)   key.size
 		, (char *)key.data
 		, (int)   udata.size
@@ -1219,7 +1188,7 @@ next:
 	if ((ret = db->del(db, NULL, &key, 0)) == 0)
 	{
 #ifdef SC_EXTRA_DEBUG
-		DBG("---3 uDELETED ROW \n KEY: %s \n", (char *)key.data);
+		LM_DBG("DELETED ROW\nKEY: %s \n", (char *)key.data);
 #endif
 	}
 	else
@@ -1231,7 +1200,7 @@ next:
 	{
 		sclib_log(JLOG_UPDATE, _tp, ubuf, sum);
 #ifdef SC_EXTRA_DEBUG
-	DBG("---4 INSERT \n     KEY:  [%.*s]\n     DATA: [%.*s]\n"
+	LM_DBG("INSERT \nKEY:  [%.*s]\nDATA: [%.*s]\n"
 		, (int)   key.size
 		, (char *)key.data
 		, (int)   udata.size
@@ -1243,9 +1212,7 @@ next:
 	}
 
 #ifdef SC_EXTRA_DEBUG
-	DBG("-------------------------------------------------\n");
-	DBG("-- UPDATE COMPLETE \n");
-	DBG("-------------------------------------------------\n");
+	LM_DBG("UPDATE COMPLETE \n");
 #endif
 
 
@@ -1265,9 +1232,7 @@ db_error:
 	case DB_NOTFOUND:
 	
 #ifdef SC_EXTRA_DEBUG
-		DBG("------------------------------\n");
-		DBG("--- NO RESULT \n");
-		DBG("------------------------------\n");
+		LM_DBG("NO RESULT \n");
 #endif
 		return -1;
 	
@@ -1278,7 +1243,7 @@ db_error:
 	/* A secondary index references a nonexistent primary key.*/ 
 	case DB_RUNRECOVERY:
 	default:
-		LOG(L_CRIT,"sc_update: DB->get error: %s.\n", db_strerror(ret));
+		LM_CRIT("DB->get error: %s.\n", db_strerror(ret));
 		sclib_recover(_tp,ret);
 	}