Explorar o código

db_text: fixed misleading indentation reported by gcc 6.2

- coherent whitespacing
Daniel-Constantin Mierla %!s(int64=9) %!d(string=hai) anos
pai
achega
5b37c3de2c

+ 8 - 7
modules/db_text/db_text.c

@@ -16,10 +16,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  */
 
 #include <stdio.h>
@@ -69,7 +69,7 @@ static param_export_t params[] = {
 
 static rpc_export_t rpc_methods[];
 
-struct module_exports exports = {	
+struct module_exports exports = {
 	"db_text",
 	DEFAULT_DLFLAGS, /* dlopen flags */
 	cmds,     /* Exported functions */
@@ -101,7 +101,7 @@ static int mod_init(void)
 	if(dbt_init_cache())
 		return -1;
 	/* return make_demo(); */
-	
+
 	return 0;
 }
 
@@ -127,12 +127,13 @@ int dbt_bind_api(db_func_t *dbb)
 	dbb->query       = (db_query_f)dbt_query;
 	dbb->free_result = dbt_free_result;
 	dbb->insert      = (db_insert_f)dbt_insert;
-	dbb->delete      = (db_delete_f)dbt_delete; 
+	dbb->delete      = (db_delete_f)dbt_delete;
 	dbb->update      = (db_update_f)dbt_update;
 	dbb->replace     = (db_replace_f)dbt_replace;
 	dbb->affected_rows = (db_affected_rows_f) dbt_affected_rows;
 	dbb->raw_query   = (db_raw_query_f) dbt_raw_query;
-	dbb->cap         = DB_CAP_ALL | DB_CAP_AFFECTED_ROWS | DB_CAP_RAW_QUERY | DB_CAP_REPLACE;
+	dbb->cap         = DB_CAP_ALL | DB_CAP_AFFECTED_ROWS | DB_CAP_RAW_QUERY
+							| DB_CAP_REPLACE;
 
 	return 0;
 }

+ 5 - 5
modules/db_text/db_text.h

@@ -15,8 +15,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -53,7 +53,7 @@ int dbt_free_result(db1_con_t* _h, db1_res_t* _r);
 /*
  * Do a query
  */
-int dbt_query(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, 
+int dbt_query(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 			db_key_t* _c, int _n, int _nc, db_key_t _o, db1_res_t** _r);
 
 
@@ -79,13 +79,13 @@ int dbt_delete(db1_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n);
  * Update a row in table
  */
 int dbt_update(db1_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);
 
 /*
  * replace a row in table
  */
 int dbt_replace(db1_con_t* _h, db_key_t* _k, db_val_t* _v,
-	      int _n, int _nk, int _m);
+		int _n, int _nk, int _m);
 
 /*
  * Affected rows

+ 13 - 13
modules/db_text/dbt_api.c

@@ -15,11 +15,11 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * 
+ *
  */
 
 #include <string.h>
@@ -42,12 +42,12 @@ int dbt_use_table(db1_con_t* _h, const str* _t)
 static int dbt_get_columns(db1_res_t* _r, dbt_result_p _dres)
 {
 	int col;
-	
+
 	if (!_r || !_dres) {
 		LM_ERR("invalid parameter\n");
 		return -1;
 	}
-	
+
 	RES_COL_N(_r) = _dres->nrcols;
 	if (!RES_COL_N(_r)) {
 		LM_ERR("no columns\n");
@@ -59,7 +59,7 @@ static int dbt_get_columns(db1_res_t* _r, dbt_result_p _dres)
 	}
 
 	for(col = 0; col < RES_COL_N(_r); col++) {
-		/* 
+		/*
 		 * Its would be not necessary to allocate here new memory, because of
 		 * the internal structure of the db_text module. But we do this anyway
 		 * to stay confirm to the other database modules.
@@ -118,7 +118,7 @@ static int dbt_convert_row(db1_res_t* _res, db_row_t* _r, dbt_row_p _r1)
 		switch(RES_TYPES(_res)[i])
 		{
 			case DB1_INT:
-				VAL_INT(&(ROW_VALUES(_r)[i])) = 
+				VAL_INT(&(ROW_VALUES(_r)[i])) =
 						_r1->fields[i].val.int_val;
 				VAL_TYPE(&(ROW_VALUES(_r)[i])) = DB1_INT;
 			break;
@@ -128,13 +128,13 @@ static int dbt_convert_row(db1_res_t* _res, db_row_t* _r, dbt_row_p _r1)
 				return -1;
 
 			case DB1_DOUBLE:
-				VAL_DOUBLE(&(ROW_VALUES(_r)[i])) = 
+				VAL_DOUBLE(&(ROW_VALUES(_r)[i])) =
 						_r1->fields[i].val.double_val;
 				VAL_TYPE(&(ROW_VALUES(_r)[i])) = DB1_DOUBLE;
 			break;
 
 			case DB1_STRING:
-				VAL_STR(&(ROW_VALUES(_r)[i])).s = 
+				VAL_STR(&(ROW_VALUES(_r)[i])).s =
 						_r1->fields[i].val.str_val.s;
 				VAL_STR(&(ROW_VALUES(_r)[i])).len =
 						_r1->fields[i].val.str_val.len;
@@ -143,7 +143,7 @@ static int dbt_convert_row(db1_res_t* _res, db_row_t* _r, dbt_row_p _r1)
 			break;
 
 			case DB1_STR:
-				VAL_STR(&(ROW_VALUES(_r)[i])).s = 
+				VAL_STR(&(ROW_VALUES(_r)[i])).s =
 						_r1->fields[i].val.str_val.s;
 				VAL_STR(&(ROW_VALUES(_r)[i])).len =
 						_r1->fields[i].val.str_val.len;
@@ -152,7 +152,7 @@ static int dbt_convert_row(db1_res_t* _res, db_row_t* _r, dbt_row_p _r1)
 			break;
 
 			case DB1_DATETIME:
-				VAL_INT(&(ROW_VALUES(_r)[i])) = 
+				VAL_INT(&(ROW_VALUES(_r)[i])) =
 						_r1->fields[i].val.int_val;
 				VAL_TYPE(&(ROW_VALUES(_r)[i])) = DB1_DATETIME;
 			break;
@@ -256,7 +256,7 @@ int dbt_get_result(db1_res_t** _r, dbt_result_p _dres)
 	}
 
 	*_r = db_new_result();
-	if (*_r == 0) 
+	if (*_r == 0)
 	{
 		LM_ERR("no private memory left\n");
 		return -2;
@@ -268,7 +268,7 @@ int dbt_get_result(db1_res_t** _r, dbt_result_p _dres)
 		pkg_free(*_r);
 		return -4;
 	}
-	
+
 	(*_r)->ptr = _dres;
 	return 0;
 }

+ 3 - 3
modules/db_text/dbt_api.h

@@ -15,10 +15,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  */
 
 

+ 54 - 54
modules/db_text/dbt_base.c

@@ -15,10 +15,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  */
 
 #include <string.h>
@@ -26,7 +26,7 @@
 #include "../../str.h"
 #include "../../mem/mem.h"
 #include "../../mem/shm_mem.h"
- 
+
 #include "db_text.h"
 #include "dbt_res.h"
 #include "dbt_api.h"
@@ -46,7 +46,7 @@ db1_con_t* dbt_init(const str* _sqlurl)
 	db1_con_t* _res;
 	str _s;
 	char dbt_path[DBT_PATH_LEN];
-	
+
 	if (!_sqlurl || !_sqlurl->s)
 	{
 		LM_ERR("invalid parameter value\n");
@@ -79,7 +79,7 @@ db1_con_t* dbt_init(const str* _sqlurl)
 		_s.len += sizeof(CFG_DIR);
 		_s.s = dbt_path;
 	}
-	
+
 	_res = pkg_malloc(sizeof(db1_con_t)+sizeof(dbt_con_t));
 	if (!_res)
 	{
@@ -97,7 +97,7 @@ db1_con_t* dbt_init(const str* _sqlurl)
 		return NULL;
 	}
 
-    return _res;
+	return _res;
 }
 
 
@@ -106,14 +106,14 @@ db1_con_t* dbt_init(const str* _sqlurl)
  */
 void dbt_close(db1_con_t* _h)
 {
-	if (!_h) 
+	if (!_h)
 	{
 		LM_ERR("invalid parameter value\n");
 		return;
 	}
-	
+
 	pkg_free(_h);
-    return;
+	return;
 }
 
 
@@ -136,7 +136,7 @@ int dbt_free_result(db1_con_t* _h, db1_res_t* _r)
 		LM_ERR("unable to free internal structure\n");
 	}
 
-	if(db_free_result(_r) < 0) 
+	if(db_free_result(_r) < 0)
 	{
 		LM_ERR("unable to free result structure\n");
 		return -1;
@@ -158,16 +158,16 @@ int dbt_free_result(db1_con_t* _h, db1_res_t* _r)
  * _o: order by the specified column
  */
 
-int dbt_query(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v, 
+int dbt_query(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 			db_key_t* _c, int _n, int _nc, db_key_t _o, db1_res_t** _r)
 {
 	dbt_table_p _tbc = NULL;
 	dbt_row_p _drp = NULL;
 	dbt_result_p _dres = NULL;
 	int result = 0;
-	
+
 	int *lkey=NULL, *lres=NULL;
-	
+
 	db_key_t *_o_k=NULL;    /* columns in order-by */
 	char *_o_op=NULL;       /* operators for oder-by */
 	int _o_n;               /* no of elements in order-by */
@@ -180,7 +180,7 @@ int dbt_query(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 		return -1;
 	}
 	*_r = NULL;
-	
+
 
 	if (_o)
 	{
@@ -226,10 +226,10 @@ int dbt_query(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 
 	LM_DBG("new res with %d cols\n", _nc);
 	_dres = dbt_result_new(_tbc, lres, _nc);
-	
+
 	if(!_dres)
 		goto error;
-	
+
 	_drp = _tbc->rows;
 	while(_drp)
 	{
@@ -245,7 +245,7 @@ int dbt_query(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 	}
 
 	dbt_table_update_flags(_tbc, DBT_TBFL_ZERO, DBT_FL_IGN, 1);
-	
+
 	/* unlock database */
 	dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
 
@@ -264,17 +264,17 @@ int dbt_query(db1_con_t* _h, db_key_t* _k, db_op_t* _op, db_val_t* _v,
 
 
 	/* dbt_result_print(_dres); */
-	
+
 	if(lkey)
 		pkg_free(lkey);
 	if(lres)
 		pkg_free(lres);
 	if(_o_k)
- 		pkg_free(_o_k);
- 	if(_o_op)
- 		pkg_free(_o_op);
- 	if(_o_l)
- 		pkg_free(_o_l);
+		pkg_free(_o_k);
+	if(_o_op)
+		pkg_free(_o_op);
+	if(_o_l)
+		pkg_free(_o_l);
 
 	result = dbt_get_result(_r, _dres);
 	if(result != 0)
@@ -342,9 +342,9 @@ int dbt_insert(db1_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 {
 	dbt_table_p _tbc = NULL;
 	dbt_row_p _drp = NULL;
-	
+
 	int *lkey=NULL, i, j;
-	
+
 	if (!_h || !CON_TABLE(_h))
 	{
 		LM_ERR("invalid parameter\n");
@@ -352,13 +352,13 @@ int dbt_insert(db1_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 	}
 
 	((dbt_con_p)_h->tail)->affected = 0;
-    
+
 	if(!_k || !_v || _n<=0)
 	{
 		LM_ERR("no key-value to insert\n");
 		return -1;
 	}
-	
+
 	/* lock database */
 	_tbc = dbt_db_get_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
 	if(!_tbc)
@@ -372,7 +372,7 @@ int dbt_insert(db1_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 		LM_ERR("more values than columns!!\n");
 		goto error;
 	}
-	
+
 	if(_k)
 	{
 		lkey = dbt_get_refs(_tbc, _k, _n);
@@ -385,7 +385,7 @@ int dbt_insert(db1_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 		LM_ERR("no shm memory for a new row!!\n");
 		goto error;
 	}
-	
+
 	for(i=0; i<_n; i++)
 	{
 		j = (lkey)?lkey[i]:i;
@@ -401,7 +401,7 @@ int dbt_insert(db1_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 			LM_ERR("cannot set v[%d] in c[%d]!\n", i, j);
 			goto clean;
 		}
-		
+
 	}
 
 	if(dbt_table_add_row(_tbc, _drp))
@@ -411,35 +411,35 @@ int dbt_insert(db1_con_t* _h, db_key_t* _k, db_val_t* _v, int _n)
 	}
 
 	((dbt_con_p)_h->tail)->affected = 1;
-    
+
 	/* dbt_print_table(_tbc, NULL); */
-	
+
 	/* unlock databse */
 	dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
 
 	if(lkey)
 		pkg_free(lkey);
 
-    return 0;
-	
+	return 0;
+
 error:
 	/* unlock database */
 	dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
 	if(lkey)
 		pkg_free(lkey);
 	LM_ERR("failed to insert row in table!\n");
-    return -1;
-	
+	return -1;
+
 clean:
 	if(lkey)
 		pkg_free(lkey);
-	
+
 	if(_drp) // free row
 		dbt_row_free(_tbc, _drp);
 	/* unlock database */
 	dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
-	
-    return -1;
+
+	return -1;
 }
 
 /*
@@ -481,7 +481,7 @@ int dbt_delete(db1_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n)
 	lkey = dbt_get_refs(_tbc, _k, _n);
 	if(!lkey)
 		goto error;
-	
+
 	_drp = _tbc->rows;
 	while(_drp)
 	{
@@ -507,17 +507,17 @@ int dbt_delete(db1_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v, int _n)
 
 	if( ((dbt_con_p)_h->tail)->affected )
 		dbt_table_update_flags(_tbc, DBT_TBFL_MODI, DBT_FL_SET, 1);
-	
+
 	/* dbt_print_table(_tbc, NULL); */
-	
+
 	/* unlock database */
 	dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
 
 	if(lkey)
 		pkg_free(lkey);
-	
+
 	return 0;
-	
+
 error:
 	/* unlock database */
 	dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
@@ -530,7 +530,7 @@ error:
  * Update a row in table
  */
 int dbt_update(db1_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)
 {
 	dbt_table_p _tbc = NULL;
 	dbt_row_p _drp = NULL;
@@ -544,7 +544,7 @@ int dbt_update(db1_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
 	}
 
 	((dbt_con_p)_h->tail)->affected = 0;
-    
+
 	/* lock database */
 	_tbc = dbt_db_get_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
 	if(!_tbc)
@@ -574,7 +574,7 @@ int dbt_update(db1_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
 					LM_ERR("incompatible types!\n");
 					goto error;
 				}
-				
+
 				if(dbt_row_update_val(_drp, &(_uv[i]),
 							_tbc->colv[lres[i]]->type, lres[i]))
 				{
@@ -592,9 +592,9 @@ int dbt_update(db1_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
 
 	if( ((dbt_con_p)_h->tail)->affected )
 		dbt_table_update_flags(_tbc, DBT_TBFL_MODI, DBT_FL_SET, 1);
-	
+
 	/* dbt_print_table(_tbc, NULL); */
-	
+
 	/* unlock database */
 	dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
 
@@ -603,7 +603,7 @@ int dbt_update(db1_con_t* _h, db_key_t* _k, db_op_t* _o, db_val_t* _v,
 	if(lres)
 		pkg_free(lres);
 
-    return 0;
+	return 0;
 
 error:
 	/* unlock database */
@@ -613,14 +613,14 @@ error:
 		pkg_free(lkey);
 	if(lres)
 		pkg_free(lres);
-	
+
 	LM_ERR("failed to update the table!\n");
 
 	return -1;
 }
 
 int dbt_replace(db1_con_t* _h, db_key_t* _k, db_val_t* _v,
-	      int _n, int _nk, int _m)
+		int _n, int _nk, int _m)
 {
 	dbt_table_p _tbc = NULL;
 	dbt_row_p _drp = NULL;
@@ -729,7 +729,7 @@ int dbt_replace(db1_con_t* _h, db_key_t* _k, db_val_t* _v,
 	if(lres)
 		pkg_free(lres);
 
-    return 0;
+	return 0;
 
 error:
 

+ 31 - 31
modules/db_text/dbt_file.c

@@ -15,10 +15,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  */
 
 #include <stdio.h>
@@ -91,11 +91,11 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
 	dbt_table_p dtp = NULL;
 	dbt_column_p colp, colp0 = NULL;
 	dbt_row_p rowp, rowp0 = NULL;
-		
+
 	enum {DBT_FLINE_ST, DBT_NLINE_ST, DBT_DATA_ST} state;
-	
+
 	LM_DBG("request for table [%.*s]\n", tbn->len, tbn->s);
-	
+
 	if(!tbn || !tbn->s || tbn->len<=0 || tbn->len>=255)
 		return NULL;
 	path[0] = 0;
@@ -115,12 +115,12 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
 		strncpy(path, tbn->s, tbn->len);
 		path[tbn->len] = 0;
 	}
-	
+
 	LM_DBG("loading file [%s]\n", path);
 	fin = fopen(path, "rt");
 	if(!fin)
-		return NULL;	
-	
+		return NULL;
+
 	buf = pkg_malloc(_db_text_read_buffer_size);
 	if(!buf) {
 		LM_ERR("error allocating read buffer, %i\n", _db_text_read_buffer_size);
@@ -183,7 +183,7 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
 				c = fgetc(fin);
 				while(c==DBT_DELIM_C)
 					c = fgetc(fin);
-				
+
 				switch(c)
 				{
 					case 's':
@@ -294,9 +294,9 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
 				if(!rowp)
 					goto clean;
 				state = DBT_DATA_ST;
-				
+
 			break;
-			
+
 			case DBT_DATA_ST:
 				//LM_DBG("state DATA!\n");
 				//while(c==DBT_DELIM)
@@ -308,7 +308,7 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
 				}
 				if(ccol>= dtp->nrcols)
 					goto clean;
-				
+
 				switch(dtp->colv[ccol]->type)
 				{
 					case DB1_INT:
@@ -317,9 +317,9 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
 						dtval.val.int_val = 0;
 						dtval.type = dtp->colv[ccol]->type;
 
-						if(c==DBT_DELIM || 
+						if(c==DBT_DELIM ||
 								(ccol==dtp->nrcols-1
-								 && (c==DBT_DELIM_R || c==EOF)))
+									&& (c==DBT_DELIM_R || c==EOF)))
 							dtval.nul = 1;
 						else
 						{
@@ -350,15 +350,15 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
 							max_auto = (max_auto<dtval.val.int_val)?
 									dtval.val.int_val:max_auto;
 					break;
-					
+
 					case DB1_DOUBLE:
 						//LM_DBG("DOUBLE value!\n");
 						dtval.val.double_val = 0.0;
 						dtval.type = DB1_DOUBLE;
 
-						if(c==DBT_DELIM || 
+						if(c==DBT_DELIM ||
 								(ccol==dtp->nrcols-1
-								 && (c==DBT_DELIM_R || c==EOF)))
+									&& (c==DBT_DELIM_R || c==EOF)))
 							dtval.nul = 1;
 						else
 						{
@@ -397,20 +397,20 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
 						if(dbt_row_set_val(rowp,&dtval,DB1_DOUBLE,ccol))
 							goto clean;
 					break;
-					
+
 					case DB1_STR:
 					case DB1_STRING:
 					case DB1_BLOB:
 						//LM_DBG("STR value!\n");
-						
+
 						dtval.val.str_val.s = NULL;
 						dtval.val.str_val.len = 0;
 						dtval.type = dtp->colv[ccol]->type;
-						
+
 						bp = 0;
-						if(c==DBT_DELIM || 
+						if(c==DBT_DELIM ||
 							(ccol == dtp->nrcols-1
-							 && (c == DBT_DELIM_R || c==EOF))) {
+								&& (c == DBT_DELIM_R || c==EOF))) {
 							/* If empty_string is enabled, we'll just return
 							 * an empty string and avoid NULL
 							 */
@@ -429,7 +429,7 @@ dbt_table_p dbt_load_file(const str *tbn, const str *dbn)
 									switch(c)
 									{
 										case 'n':
-											c = '\n';	
+											c = '\n';
 										break;
 										case 'r':
 											c = '\r';
@@ -505,7 +505,7 @@ int dbt_print_table(dbt_table_p _dtp, str *_dbn)
 	FILE *fout = NULL;
 	int ccol;
 	char *p, path[512];
-	
+
 	if(!_dtp || !_dtp->name.s || _dtp->name.len <= 0)
 		return -1;
 
@@ -526,9 +526,9 @@ int dbt_print_table(dbt_table_p _dtp, str *_dbn)
 		path[_dbn->len+_dtp->name.len+1] = 0;
 		fout = fopen(path, "wt");
 		if(!fout)
-			return -1;	
+			return -1;
 	}
-	
+
 	colp = _dtp->cols;
 	while(colp)
 	{
@@ -557,13 +557,13 @@ int dbt_print_table(dbt_table_p _dtp, str *_dbn)
 					fclose(fout);
 				return -1;
 		}
-		
+
 		if(colp->flag & DBT_FLAG_NULL)
 				fprintf(fout,",null");
 		else if(colp->type==DB1_INT && colp->flag & DBT_FLAG_AUTO)
 					fprintf(fout,",auto");
 		fprintf(fout,")");
-		
+
 		colp = colp->next;
 		if(colp)
 			fprintf(fout,"%c", DBT_DELIM_C);
@@ -634,10 +634,10 @@ int dbt_print_table(dbt_table_p _dtp, str *_dbn)
 		fprintf(fout, "%c", DBT_DELIM_R);
 		rowp = rowp->next;
 	}
-	
+
 	if(fout!=stdout)
 		fclose(fout);
-	
+
 	return 0;
 }
 

+ 26 - 26
modules/db_text/dbt_lib.c

@@ -15,10 +15,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  */
 
 #include <stdio.h>
@@ -76,7 +76,7 @@ int dbt_init_cache(void)
 	}
 	/* init tables' hash table */
 	if (!_dbt_cachetbl) {
-		_dbt_cachetbl 
+		_dbt_cachetbl
 			= (dbt_tbl_cachel_p)shm_malloc(DBT_CACHETBL_SIZE*
 					sizeof(dbt_tbl_cachel_t));
 		if(_dbt_cachetbl==NULL)
@@ -101,7 +101,7 @@ int dbt_init_cache(void)
 		}
 	}
 
-	
+
 	return 0;
 }
 
@@ -123,17 +123,17 @@ dbt_cache_p dbt_cache_get_db(str *_s)
 	LM_DBG("looking for db %.*s!\n",_s->len,_s->s);
 
 	lock_get(_dbt_cachesem);
-	
+
 	_dcache = *_dbt_cachedb;
 	while(_dcache)
 	{
-		if(_dcache->name.len==_s->len 
+		if(_dcache->name.len==_s->len
 				&& !strncasecmp(_dcache->name.s, _s->s, _s->len))
 		{
 			LM_DBG("db already cached!\n");
 			goto done;
 		}
-		
+
 		_dcache = _dcache->next;
 	}
 	if(!dbt_is_database(_s))
@@ -142,7 +142,7 @@ dbt_cache_p dbt_cache_get_db(str *_s)
 		goto done;
 	}
 	LM_DBG("new db!\n");
-	
+
 	_dcache = (dbt_cache_p)shm_malloc(sizeof(dbt_cache_t));
 	if(!_dcache)
 	{
@@ -150,7 +150,7 @@ dbt_cache_p dbt_cache_get_db(str *_s)
 		goto done;
 	}
 	memset(_dcache, 0, sizeof(dbt_cache_t));
-	
+
 	_dcache->name.s = (char*)shm_malloc((_s->len+1)*sizeof(char));
 	if(!_dcache->name.s)
 	{
@@ -159,11 +159,11 @@ dbt_cache_p dbt_cache_get_db(str *_s)
 		_dcache = NULL;
 		goto done;
 	}
-	
+
 	memcpy(_dcache->name.s, _s->s, _s->len);
 	_dcache->name.s[_s->len] = '\0';
 	_dcache->name.len = _s->len;
-	
+
 	if(*_dbt_cachedb)
 		_dcache->next = *_dbt_cachedb;
 
@@ -183,9 +183,9 @@ int dbt_cache_check_db(str *_s)
 	if(!_dbt_cachesem || !(*_dbt_cachedb)
 			|| !_s || !_s->s || _s->len<=0)
 		return -1;
-	
+
 	lock_get(_dbt_cachesem);
-	
+
 	_dcache = *_dbt_cachedb;
 	while(_dcache)
 	{
@@ -197,7 +197,7 @@ int dbt_cache_check_db(str *_s)
 		}
 		_dcache = _dcache->next;
 	}
-	
+
 	lock_release(_dbt_cachesem);
 	return -1;
 }
@@ -215,7 +215,7 @@ int dbt_db_del_table(dbt_cache_p _dc, const str *_s, int sync)
 
 	hash = core_hash(&_dc->name, _s, DBT_CACHETBL_SIZE);
 	hashidx = hash % DBT_CACHETBL_SIZE;
-	
+
 	if(sync)
 		lock_get(&_dbt_cachetbl[hashidx].sem);
 
@@ -232,7 +232,7 @@ int dbt_db_del_table(dbt_cache_p _dc, const str *_s, int sync)
 				(_tbc->prev)->next = _tbc->next;
 			else
 				_dbt_cachetbl[hashidx].dtp = _tbc->next;
-	
+
 			if(_tbc->next)
 				(_tbc->next)->prev = _tbc->prev;
 			break;
@@ -244,7 +244,7 @@ int dbt_db_del_table(dbt_cache_p _dc, const str *_s, int sync)
 		lock_release(&_dbt_cachetbl[hashidx].sem);
 
 	dbt_table_free(_tbc);
-	
+
 	return 0;
 }
 
@@ -264,7 +264,7 @@ dbt_table_p dbt_db_get_table(dbt_cache_p _dc, const str *_s)
 
 	hash = core_hash(&_dc->name, _s, DBT_CACHETBL_SIZE);
 	hashidx = hash % DBT_CACHETBL_SIZE;
-		
+
 	lock_get(&_dbt_cachetbl[hashidx].sem);
 
 	_tbc = _dbt_cachetbl[hashidx].dtp;
@@ -287,7 +287,7 @@ dbt_table_p dbt_db_get_table(dbt_cache_p _dc, const str *_s)
 		}
 		_tbc = _tbc->next;
 	}
-	
+
 	/* new table */
 	if(_tbc) /* free old one */
 	{
@@ -307,7 +307,7 @@ dbt_table_p dbt_db_get_table(dbt_cache_p _dc, const str *_s)
 	_tbc->next = _dbt_cachetbl[hashidx].dtp;
 	if(_dbt_cachetbl[hashidx].dtp)
 		_dbt_cachetbl[hashidx].dtp->prev = _tbc;
-	
+
 	_dbt_cachetbl[hashidx].dtp = _tbc;
 
 	/* table is locked */
@@ -324,7 +324,7 @@ int dbt_release_table(dbt_cache_p _dc, const str *_s)
 
 	hash = core_hash(&_dc->name, _s, DBT_CACHETBL_SIZE);
 	hashidx = hash % DBT_CACHETBL_SIZE;
-		
+
 	lock_release(&_dbt_cachetbl[hashidx].sem);
 
 	return 0;
@@ -339,10 +339,10 @@ int dbt_cache_destroy(void)
 	dbt_cache_p _dc=NULL, _dc0=NULL;
 	dbt_table_p _tbc = NULL;
 	dbt_table_p _tbc0 = NULL;
-	
+
 	if(!_dbt_cachesem)
 		return -1;
-	
+
 	lock_get(_dbt_cachesem);
 	if(	_dbt_cachedb!=NULL )
 	{
@@ -387,7 +387,7 @@ int dbt_cache_print(int _f)
 
 	if(!_dbt_cachetbl)
 		return -1;
-	
+
 	for(i=0; i< DBT_CACHETBL_SIZE; i++)
 	{
 		lock_get(&_dbt_cachetbl[i].sem);
@@ -416,7 +416,7 @@ int dbt_cache_print(int _f)
 		}
 		lock_release(&_dbt_cachetbl[i].sem);
 	}
-	
+
 	return 0;
 }
 

+ 6 - 6
modules/db_text/dbt_lib.h

@@ -15,10 +15,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  */
 
 
@@ -58,7 +58,7 @@ typedef struct _dbt_row
 	dbt_val_p fields;
 	struct _dbt_row *prev;
 	struct _dbt_row *next;
-	
+
 } dbt_row_t, *dbt_row_p;
 
 typedef struct _dbt_column
@@ -68,7 +68,7 @@ typedef struct _dbt_column
 	int flag;
 	struct _dbt_column *prev;
 	struct _dbt_column *next;
-	
+
 } dbt_column_t, *dbt_column_p;
 
 
@@ -97,7 +97,7 @@ typedef struct _dbt_tbl_cachel
 	dbt_table_p dtp;
 } dbt_tbl_cachel_t, *dbt_tbl_cachel_p;
 
-typedef struct _dbt_cache 
+typedef struct _dbt_cache
 {
 	str name;
 	int flags;

+ 97 - 97
modules/db_text/dbt_raw_query.c

@@ -15,8 +15,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -26,7 +26,7 @@
 #include "../../str.h"
 #include "../../mem/mem.h"
 #include "../../mem/shm_mem.h"
- 
+
 #include "db_text.h"
 #include "dbt_res.h"
 #include "dbt_api.h"
@@ -35,16 +35,16 @@
 
 int dbt_raw_query_select(db1_con_t* _h, str* _s, db1_res_t** _r)
 {
-    int res = -1;
-    int i, len;
-    char* table_ptr = NULL;
-    char* fields_end_ptr = NULL;
-    char* fields_ptr = NULL;
-    char* where_ptr = NULL;
-    char* order_start_ptr = NULL;
-    char** tokens = NULL;
-    str table;
-    dbt_table_p _tbc = NULL;
+	int res = -1;
+	int i, len;
+	char* table_ptr = NULL;
+	char* fields_end_ptr = NULL;
+	char* fields_ptr = NULL;
+	char* where_ptr = NULL;
+	char* order_start_ptr = NULL;
+	char** tokens = NULL;
+	str table;
+	dbt_table_p _tbc = NULL;
 	int cols;
 	int n = 0;
 	int ncols = 0;
@@ -58,39 +58,39 @@ int dbt_raw_query_select(db1_con_t* _h, str* _s, db1_res_t** _r)
 
 	LM_DBG("SQLRAW : %.*s\n", _s->len, _s->s);
 
-    fields_end_ptr = strcasestr(_s->s, " from ");
-    if(fields_end_ptr == NULL)
-    	return res;
+	fields_end_ptr = strcasestr(_s->s, " from ");
+	if(fields_end_ptr == NULL)
+		return res;
 
-    len = fields_end_ptr - (_s->s + 6) + 1;
-    fields_ptr = pkg_malloc(len);
-    strncpy(fields_ptr, _s->s + 6, len);
-    fields_ptr[len] = '\0';
-    fields_ptr = dbt_trim(fields_ptr);
+	len = fields_end_ptr - (_s->s + 6) + 1;
+	fields_ptr = pkg_malloc(len);
+	strncpy(fields_ptr, _s->s + 6, len);
+	fields_ptr[len] = '\0';
+	fields_ptr = dbt_trim(fields_ptr);
 
-    order_start_ptr = strcasestr(_s->s, " order by ");
-    if(order_start_ptr != NULL) {
-    	*order_start_ptr = '\0';
-    	order_start_ptr += 10;
-    }
+	order_start_ptr = strcasestr(_s->s, " order by ");
+	if(order_start_ptr != NULL) {
+		*order_start_ptr = '\0';
+		order_start_ptr += 10;
+	}
 
 
-    where_ptr = strcasestr(_s->s, " where ");
-    if(where_ptr == NULL) {
-    	len = strlen(fields_end_ptr + 6);
-    } else {
-    	len = where_ptr - (fields_end_ptr + 6);
-    	nc = dbt_build_where(where_ptr + 7, &_k, &_op, &_v);
-    }
+	where_ptr = strcasestr(_s->s, " where ");
+	if(where_ptr == NULL) {
+		len = strlen(fields_end_ptr + 6);
+	} else {
+		len = where_ptr - (fields_end_ptr + 6);
+		nc = dbt_build_where(where_ptr + 7, &_k, &_op, &_v);
+	}
 
-    table_ptr = pkg_malloc(len);
-    strncpy(table_ptr, fields_end_ptr + 6, len);
-    table_ptr[len] = '\0';
-    dbt_trim(table_ptr);
+	table_ptr = pkg_malloc(len);
+	strncpy(table_ptr, fields_end_ptr + 6, len);
+	table_ptr[len] = '\0';
+	dbt_trim(table_ptr);
 
-    table.s = table_ptr;
-    table.len = len;
-    LM_DBG("using table '%.*s'\n", table.len, table.s);
+	table.s = table_ptr;
+	table.len = len;
+	LM_DBG("using table '%.*s'\n", table.len, table.s);
 
 	if(dbt_use_table(_h, &table) != 0) {
 		LM_ERR("use table is invalid %.*s\n", table.len, table.s);
@@ -104,30 +104,30 @@ int dbt_raw_query_select(db1_con_t* _h, str* _s, db1_res_t** _r)
 		goto error;
 	}
 
-    tokens = dbt_str_split(fields_ptr, ',', &ncols);
-    pkg_free(fields_ptr);
-    fields_ptr = NULL;
-    if (!tokens) {
+	tokens = dbt_str_split(fields_ptr, ',', &ncols);
+	pkg_free(fields_ptr);
+	fields_ptr = NULL;
+	if (!tokens) {
 		LM_ERR("error extracting tokens\n");
-    	goto error;
-    }
-
-    if(ncols == 1 && strncmp(*tokens, "*", 1) == 0) {
-    	cols = _tbc->nrcols;
-    	result_cols = pkg_malloc(sizeof(db_key_t) * cols);
-    	memset(result_cols, 0, sizeof(db_key_t) * cols);
-    	for(n=0; n < cols; n++) {
-    		result_cols[n] = &_tbc->colv[n]->name;
-    	}
-    } else {
-    	cols = ncols;
-    	result_cols = pkg_malloc(sizeof(db_key_t) * cols);
-    	memset(result_cols, 0, sizeof(db_key_t) * cols);
-    	for(n=0; *(tokens + n); n++) {
-    		result_cols[n]->s = *(tokens + n);
-    		result_cols[n]->len = strlen(*(tokens + n));
-    	}
-    }
+		goto error;
+	}
+
+	if(ncols == 1 && strncmp(*tokens, "*", 1) == 0) {
+		cols = _tbc->nrcols;
+		result_cols = pkg_malloc(sizeof(db_key_t) * cols);
+		memset(result_cols, 0, sizeof(db_key_t) * cols);
+		for(n=0; n < cols; n++) {
+			result_cols[n] = &_tbc->colv[n]->name;
+		}
+	} else {
+		cols = ncols;
+		result_cols = pkg_malloc(sizeof(db_key_t) * cols);
+		memset(result_cols, 0, sizeof(db_key_t) * cols);
+		for(n=0; *(tokens + n); n++) {
+			result_cols[n]->s = *(tokens + n);
+			result_cols[n]->len = strlen(*(tokens + n));
+		}
+	}
 
 
 	dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
@@ -141,28 +141,28 @@ int dbt_raw_query_select(db1_con_t* _h, str* _s, db1_res_t** _r)
 
 error:
 
-    if(_tbc)
-        dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
-    
+	if(_tbc)
+		dbt_release_table(DBT_CON_CONNECTION(_h), CON_TABLE(_h));
+
 	if(tokens) {
-	    for (i = 0; *(tokens + i); i++) {
-	    	pkg_free(*(tokens + i));
-	    }
-	    pkg_free(tokens);
+		for (i = 0; *(tokens + i); i++) {
+			pkg_free(*(tokens + i));
+		}
+		pkg_free(tokens);
 	}
-    if(fields_ptr)
-    	pkg_free(fields_ptr);
+	if(fields_ptr)
+		pkg_free(fields_ptr);
 
-    if(table_ptr)
-    	pkg_free(table_ptr);
+	if(table_ptr)
+		pkg_free(table_ptr);
 
-    dbt_clean_where(nc, _k, _op, _v);
+	dbt_clean_where(nc, _k, _op, _v);
 
-    if(result_cols) {
-    	pkg_free(result_cols);
-    }
+	if(result_cols) {
+		pkg_free(result_cols);
+	}
 
- 	return res;
+	return res;
 }
 
 int dbt_raw_query_update(db1_con_t* _h, str* _s, db1_res_t** _r)
@@ -281,26 +281,26 @@ int dbt_raw_query_delete(db1_con_t* _h, str* _s, db1_res_t** _r)
 
 	LM_DBG("SQLRAW : %.*s\n", _s->len, _s->s);
 
-    fields_end_ptr = strcasestr(_s->s, " from ");
-    if(fields_end_ptr == NULL)
-    	return res;
+	fields_end_ptr = strcasestr(_s->s, " from ");
+	if(fields_end_ptr == NULL)
+		return res;
 
 	where_ptr = strcasestr(_s->s, " where ");
-    if(where_ptr == NULL) {
-    	len = strlen(fields_end_ptr + 6);
-    } else {
-    	len = where_ptr - (fields_end_ptr + 6);
-    	nkeys = dbt_build_where(where_ptr + 7, &_k, &_op1, &_kv);
-    }
-
-    table_ptr = pkg_malloc(len);
-    strncpy(table_ptr, fields_end_ptr + 6, len);
-    table_ptr[len] = '\0';
-    dbt_trim(table_ptr);
-
-    table.s = table_ptr;
-    table.len = len;
-    LM_DBG("using table '%.*s'\n", table.len, table.s);
+	if(where_ptr == NULL) {
+		len = strlen(fields_end_ptr + 6);
+	} else {
+		len = where_ptr - (fields_end_ptr + 6);
+		nkeys = dbt_build_where(where_ptr + 7, &_k, &_op1, &_kv);
+	}
+
+	table_ptr = pkg_malloc(len);
+	strncpy(table_ptr, fields_end_ptr + 6, len);
+	table_ptr[len] = '\0';
+	dbt_trim(table_ptr);
+
+	table.s = table_ptr;
+	table.len = len;
+	LM_DBG("using table '%.*s'\n", table.len, table.s);
 
 	if(dbt_use_table(_h, &table) != 0) {
 		LM_ERR("use table is invalid %.*s\n", table.len, table.s);

+ 3 - 3
modules/db_text/dbt_raw_query.h

@@ -15,10 +15,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  */
 
 

+ 93 - 93
modules/db_text/dbt_raw_util.c

@@ -15,10 +15,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  */
 
 #include <stdlib.h>
@@ -44,100 +44,100 @@ void log_regerror(int errcode, regex_t *compiled)
 
 char** dbt_str_split(char* a_str, const char a_delim, int* c)
 {
-    char** result    = 0;
-    size_t count     = 0;
-    char* tmp        = a_str;
-    char* last_comma = 0;
-    char delim[2];
-    delim[0] = a_delim;
-    delim[1] = 0;
-    int len = 0;
-
-    /* Count how many elements will be extracted. */
-    while (*tmp)
-    {
-        if (a_delim == *tmp)
-        {
-            count++;
-            last_comma = tmp;
-        }
-        tmp++;
-    }
-
-    /* Add space for trailing token. */
-    count += last_comma < (a_str + strlen(a_str) - 1);
-
-    *c = count;
-
-    /* Add space for terminating null string so caller
-       knows where the list of returned strings ends. */
-    count++;
-
-    result = pkg_malloc(sizeof(char*) * count);
-
-    if (result)
-    {
-        size_t idx  = 0;
-        char* token = strtok(a_str, delim);
-
-        while (token)
-        {
-            assert(idx < count);
-            len = strlen(token);
-            char* ptr = pkg_malloc( (len+1) * sizeof(char));
-        	memcpy(ptr, token, len);
-        	ptr[len] = '\0';
-            *(result + idx) = dbt_trim(ptr);
-            token = strtok(0, delim);
-            idx++;
-        }
-        assert(idx == count - 1);
-        *(result + idx) = 0;
-    }
-
-    return result;
+	char** result    = 0;
+	size_t count     = 0;
+	char* tmp        = a_str;
+	char* last_comma = 0;
+	char delim[2];
+	delim[0] = a_delim;
+	delim[1] = 0;
+	int len = 0;
+
+	/* Count how many elements will be extracted. */
+	while (*tmp)
+	{
+		if (a_delim == *tmp)
+		{
+			count++;
+			last_comma = tmp;
+		}
+		tmp++;
+	}
+
+	/* Add space for trailing token. */
+	count += last_comma < (a_str + strlen(a_str) - 1);
+
+	*c = count;
+
+	/* Add space for terminating null string so caller
+	   knows where the list of returned strings ends. */
+	count++;
+
+	result = pkg_malloc(sizeof(char*) * count);
+
+	if (result)
+	{
+		size_t idx  = 0;
+		char* token = strtok(a_str, delim);
+
+		while (token)
+		{
+			assert(idx < count);
+			len = strlen(token);
+			char* ptr = pkg_malloc( (len+1) * sizeof(char));
+			memcpy(ptr, token, len);
+			ptr[len] = '\0';
+			*(result + idx) = dbt_trim(ptr);
+			token = strtok(0, delim);
+			idx++;
+		}
+		assert(idx == count - 1);
+		*(result + idx) = 0;
+	}
+
+	return result;
 }
 
 
 char* dbt_trim(char *str)
 {
-    size_t len = 0;
-    char *frontp = str;
-    char *endp = NULL;
-
-    if( str == NULL ) { return NULL; }
-    if( str[0] == '\0' ) { return str; }
-
-    len = strlen(str);
-    endp = str + len;
-
-    /* Move the front and back pointers to address the first non-whitespace
-     * characters from each end.
-     */
-    while( isspace(*frontp) ) { ++frontp; }
-    if( endp != frontp )
-    {
-        while( isspace(*(--endp)) && endp != frontp ) {}
-    }
-
-    if( str + len - 1 != endp )
-            *(endp + 1) = '\0';
-    else if( frontp != str &&  endp == frontp )
-            *str = '\0';
-
-    /* Shift the string so that it starts at str so that if it's dynamically
-     * allocated, we can still free it on the returned pointer.  Note the reuse
-     * of endp to mean the front of the string buffer now.
-     */
-    endp = str;
-    if( frontp != str )
-    {
-            while( *frontp ) { *endp++ = *frontp++; }
-            *endp = '\0';
-    }
-
-
-    return str;
+	size_t len = 0;
+	char *frontp = str;
+	char *endp = NULL;
+
+	if( str == NULL ) { return NULL; }
+	if( str[0] == '\0' ) { return str; }
+
+	len = strlen(str);
+	endp = str + len;
+
+	/* Move the front and back pointers to address the first non-whitespace
+	 * characters from each end.
+	 */
+	while( isspace(*frontp) ) { ++frontp; }
+	if( endp != frontp )
+	{
+		while( isspace(*(--endp)) && endp != frontp ) {}
+	}
+
+	if( str + len - 1 != endp )
+		*(endp + 1) = '\0';
+	else if( frontp != str &&  endp == frontp )
+		*str = '\0';
+
+	/* Shift the string so that it starts at str so that if it's dynamically
+	 * allocated, we can still free it on the returned pointer.  Note the reuse
+	 * of endp to mean the front of the string buffer now.
+	 */
+	endp = str;
+	if( frontp != str )
+	{
+		while( *frontp ) { *endp++ = *frontp++; }
+		*endp = '\0';
+	}
+
+
+	return str;
 }
 
 
@@ -165,7 +165,7 @@ void dbt_clean_where(int n, db_key_t* _k, db_op_t* _op, db_val_t* _v)
 	if(_v) {
 		for(i=0; i < n; i++) {
 			if(_v[i].type == DB1_STR)
-			pkg_free(_v[i].val.str_val.s);
+				pkg_free(_v[i].val.str_val.s);
 		}
 		pkg_free(_v);
 	}

+ 3 - 3
modules/db_text/dbt_raw_util.h

@@ -15,10 +15,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  */
 
 

+ 21 - 21
modules/db_text/dbt_res.c

@@ -15,8 +15,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -38,13 +38,13 @@ dbt_result_p dbt_result_new(dbt_table_p _dtp, int *_lres, int _sz)
 	dbt_result_p _dres = NULL;
 	int i, n;
 	char *p;
-	
+
 	if(!_dtp || _sz < 0)
 		return NULL;
 
 	if(!_lres)
 		_sz = _dtp->nrcols;
-	
+
 	_dres = (dbt_result_p)pkg_malloc(sizeof(dbt_result_t));
 	if(!_dres)
 		return NULL;
@@ -73,7 +73,7 @@ dbt_result_p dbt_result_new(dbt_table_p _dtp, int *_lres, int _sz)
 		_dres->colv[i].type =
 				(_lres)?_dtp->colv[_lres[i]]->type:_dtp->colv[i]->type;
 	}
-	
+
 	_dres->nrcols = _sz;
 	_dres->nrrows = 0;
 	_dres->rows = NULL;
@@ -88,7 +88,7 @@ clean:
 	}
 	pkg_free(_dres->colv);
 	pkg_free(_dres);
-	
+
 	return NULL;
 }
 
@@ -108,7 +108,7 @@ int dbt_result_free(dbt_result_p _dres)
 		{
 			for(i=0; i<_dres->nrcols; i++)
 			{
-				if((_dres->colv[i].type==DB1_STR 
+				if((_dres->colv[i].type==DB1_STR
 							|| _dres->colv[i].type==DB1_STRING
 							|| _dres->colv[i].type==DB1_BLOB
 							)
@@ -139,7 +139,7 @@ int dbt_result_add_row(dbt_result_p _dres, dbt_row_p _drp)
 	if(!_dres || !_drp)
 		return -1;
 	_dres->nrrows++;
-	
+
 	if(_dres->rows)
 		(_dres->rows)->prev = _drp;
 	_drp->next = _dres->rows;
@@ -151,7 +151,7 @@ int dbt_result_add_row(dbt_result_p _dres, dbt_row_p _drp)
 int* dbt_get_refs(dbt_table_p _dtp, db_key_t* _k, int _n)
 {
 	int i, j, *_lref=NULL;
-	
+
 	if(!_dtp || !_k || _n < 0)
 		return NULL;
 
@@ -179,11 +179,11 @@ int* dbt_get_refs(dbt_table_p _dtp, db_key_t* _k, int _n)
 		}
 	}
 	return _lref;
-}	
+}
 
 
 int dbt_row_match(dbt_table_p _dtp, dbt_row_p _drp, int* _lkey,
-				 db_op_t* _op, db_val_t* _v, int _n)
+			db_op_t* _op, db_val_t* _v, int _n)
 {
 	int i, res;
 	if(!_dtp || !_drp)
@@ -234,10 +234,10 @@ int dbt_result_extract_fields(dbt_table_p _dtp, dbt_row_p _drp,
 {
 	dbt_row_p _rp=NULL;
 	int i, n;
-	
-	if(!_dtp || !_drp || !_dres || _dres->nrcols<=0)	
+
+	if(!_dtp || !_drp || !_dres || _dres->nrcols<=0)
 		return -1;
-	
+
 	_rp = dbt_result_new_row(_dres);
 	if(!_rp)
 		return -1;
@@ -256,7 +256,7 @@ int dbt_result_extract_fields(dbt_table_p _dtp, dbt_row_p _drp,
 			memset(&(_rp->fields[i].val), 0, sizeof(_rp->fields[i].val));
 			continue;
 		}
-		
+
 		switch(_dres->colv[i].type)
 		{
 			case DB1_INT:
@@ -307,7 +307,7 @@ clean:
 				&& !_rp->fields[i].nul
 				&& _rp->fields[i].val.str_val.s)
 			pkg_free(_rp->fields[i].val.str_val.s);
-				
+
 		i--;
 	}
 	pkg_free(_rp->fields);
@@ -328,7 +328,7 @@ int dbt_result_print(dbt_result_p _dres)
 		return -1;
 
 	fprintf(fout, "\nContent of result\n");
-	
+
 	for(i=0; i<_dres->nrcols; i++)
 	{
 		switch(_dres->colv[i].type)
@@ -443,7 +443,7 @@ int dbt_cmp_val(dbt_val_p _vp, db_val_t* _v)
 		return 1;
 	if(_vp->nul)
 		return -1;
-	
+
 	switch(VAL_TYPE(_v))
 	{
 		case DB1_INT:
@@ -508,7 +508,7 @@ dbt_row_p dbt_result_new_row(dbt_result_p _dres)
 	dbt_row_p _drp = NULL;
 	if(!_dres || _dres->nrcols<=0)
 		return NULL;
-	
+
 	_drp = (dbt_row_p)pkg_malloc(sizeof(dbt_row_t));
 	if(!_drp)
 		return NULL;
@@ -545,13 +545,13 @@ int dbt_parse_orderbyclause(db_key_t **_o_k, char **_o_op, int *_o_n, db_key_t _
 		if (_o->s[_i] == ',')
 			_n++;
 
-    /* *_o_k will include the db_key_ts, the strs, a copy of _o and \0 */
+	/* *_o_k will include the db_key_ts, the strs, a copy of _o and \0 */
 	*_o_k = pkg_malloc((sizeof(db_key_t)+sizeof(str)) * _n + _o->len + 1);
 	if (!*_o_k)
 		return -1;
 	_s = (str *)((char *)(*_o_k) + sizeof(db_key_t) * _n);
 	for (_i=0; _i < _n; _i++)
-	    (*_o_k)[_i] = &_s[_i];
+		(*_o_k)[_i] = &_s[_i];
 	_po = (char *)(*_o_k) + (sizeof(db_key_t) + sizeof(str)) * _n;
 	memcpy(_po, _o->s, _o->len);
 	*(_po+_o->len) = '\0';

+ 4 - 4
modules/db_text/dbt_res.h

@@ -15,10 +15,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  */
 
 
@@ -49,7 +49,7 @@ typedef struct _dbt_con
 dbt_result_p dbt_result_new(dbt_table_p, int*, int);
 int dbt_result_free(dbt_result_p);
 int dbt_row_match(dbt_table_p _dtp, dbt_row_p _drp, int* _lkey,
-				 db_op_t* _op, db_val_t* _v, int _n);
+				db_op_t* _op, db_val_t* _v, int _n);
 int dbt_result_extract_fields(dbt_table_p _dtp, dbt_row_p _drp,
 				int* lres, dbt_result_p _dres);
 int dbt_result_print(dbt_result_p _dres);

+ 53 - 53
modules/db_text/dbt_tb.c

@@ -15,10 +15,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  */
 
 #include <stdio.h>
@@ -69,13 +69,13 @@ dbt_column_p dbt_column_new(char *_s, int _l)
  */
 int dbt_column_free(dbt_column_p dcp)
 {
-	
+
 	if(!dcp)
 		return -1;
 	if(dcp->name.s)
 		shm_free(dcp->name.s);
 	shm_free(dcp);
- 
+
 	return 0;
 }
 
@@ -90,7 +90,7 @@ dbt_row_p dbt_row_new(int _nf)
 	_drp = (dbt_row_p)shm_malloc(sizeof(dbt_row_t));
 	if(!_drp)
 		return NULL;
-	
+
 	_drp->fields = (dbt_val_p)shm_malloc(_nf*sizeof(dbt_val_t));
 	if(!_drp->fields)
 	{
@@ -112,10 +112,10 @@ dbt_row_p dbt_row_new(int _nf)
 int dbt_row_free(dbt_table_p _dtp, dbt_row_p _drp)
 {
 	int i;
-	
+
 	if(!_dtp || !_drp)
 		return -1;
-	
+
 	if(_drp->fields)
 	{
 		for(i=0; i<_dtp->nrcols; i++)
@@ -139,7 +139,7 @@ dbt_table_p dbt_table_new(const str *_tbname, const str *_dbname, const char *pa
 	dbt_table_p dtp = NULL;
 	if(!_tbname || !_dbname || !path)
 		return NULL;
-	
+
 	dtp = (dbt_table_p)shm_malloc(sizeof(dbt_table_t));
 	if(!dtp)
 		goto done;
@@ -154,7 +154,7 @@ dbt_table_p dbt_table_new(const str *_tbname, const str *_dbname, const char *pa
 	memcpy(dtp->name.s, _tbname->s, _tbname->len);
 	dtp->name.s[_tbname->len] = '\0';
 	dtp->name.len = _tbname->len;
-	
+
 	dtp->dbname.s = (char*)shm_malloc((_dbname->len+1)*sizeof(char));
 	if(!dtp->dbname.s)
 	{
@@ -180,7 +180,7 @@ dbt_table_p dbt_table_new(const str *_tbname, const str *_dbname, const char *pa
 		dtp->mt = s.st_mtime;
 		LM_DBG("mtime is %d\n", (int)s.st_mtime);
 	}
-	
+
 done:
 	return dtp;
 }
@@ -191,7 +191,7 @@ done:
 int dbt_table_free_rows(dbt_table_p _dtp)
 {
 	dbt_row_p _rp=NULL, _rp0=NULL;
-	
+
 	if(!_dtp || !_dtp->rows || !_dtp->colv)
 		return -1;
 	_rp = _dtp->rows;
@@ -201,9 +201,9 @@ int dbt_table_free_rows(dbt_table_p _dtp)
 		_rp=_rp->next;
 		dbt_row_free(_dtp, _rp0);
 	}
-	
+
 	dbt_table_update_flags(_dtp, DBT_TBFL_MODI, DBT_FL_SET, 1);
-	
+
 	_dtp->rows = NULL;
 	_dtp->nrrows = 0;
 
@@ -217,12 +217,12 @@ int dbt_table_add_row(dbt_table_p _dtp, dbt_row_p _drp)
 {
 	if(!_dtp || !_drp)
 		return -1;
-	
+
 	if(dbt_table_check_row(_dtp, _drp))
 		return -1;
-	
+
 	dbt_table_update_flags(_dtp, DBT_TBFL_MODI, DBT_FL_SET, 1);
-	
+
 	if(_dtp->rows)
 		(_dtp->rows)->prev = _drp;
 	_drp->next = _dtp->rows;
@@ -238,7 +238,7 @@ int dbt_table_add_row(dbt_table_p _dtp, dbt_row_p _drp)
 int dbt_table_free(dbt_table_p _dtp)
 {
 	dbt_column_p _cp=NULL, _cp0=NULL;
-	
+
 	if(!_dtp)
 		return -1;
 
@@ -246,10 +246,10 @@ int dbt_table_free(dbt_table_p _dtp)
 		shm_free(_dtp->name.s);
 	if(_dtp->dbname.s)
 		shm_free(_dtp->dbname.s);
-	
+
 	if(_dtp->rows && _dtp->nrrows>0)
 		dbt_table_free_rows(_dtp);
-	
+
 	_cp = _dtp->cols;
 	while(_cp)
 	{
@@ -272,7 +272,7 @@ int dbt_row_set_val(dbt_row_p _drp, dbt_val_p _vp, int _t, int _idx)
 {
 	if(!_drp || !_vp || _idx<0)
 		return -1;
-	
+
 	_drp->fields[_idx].nul = _vp->nul;
 	_drp->fields[_idx].type = _t;
 
@@ -283,7 +283,7 @@ int dbt_row_set_val(dbt_row_p _drp, dbt_val_p _vp, int _t, int _idx)
 			case DB1_STR:
 			case DB1_BLOB:
 				_drp->fields[_idx].type = _t;
-				_drp->fields[_idx].val.str_val.s = 
+				_drp->fields[_idx].val.str_val.s =
 					(char*)shm_malloc((_vp->val.str_val.len+1)*sizeof(char));
 				if(!_drp->fields[_idx].val.str_val.s)
 				{
@@ -295,14 +295,14 @@ int dbt_row_set_val(dbt_row_p _drp, dbt_val_p _vp, int _t, int _idx)
 				_drp->fields[_idx].val.str_val.s[_vp->val.str_val.len] = '\0';
 				_drp->fields[_idx].val.str_val.len = _vp->val.str_val.len;
 			break;
-			
+
 			case DB1_STRING:
 				_drp->fields[_idx].type = _t;
 				_drp->fields[_idx].val.str_val.len=_vp->val.str_val.len;
-				
-				_drp->fields[_idx].val.str_val.s = 
+
+				_drp->fields[_idx].val.str_val.s =
 					(char*)shm_malloc((_drp->fields[_idx].val.str_val.len+1)
-									  *sizeof(char));
+								*sizeof(char));
 				if(!_drp->fields[_idx].val.str_val.s)
 				{
 					_drp->fields[_idx].nul = 1;
@@ -312,33 +312,33 @@ int dbt_row_set_val(dbt_row_p _drp, dbt_val_p _vp, int _t, int _idx)
 					_drp->fields[_idx].val.str_val.len);
 				_drp->fields[_idx].val.str_val.s[_drp->fields[_idx].val.str_val.len] = '\0';
 			break;
-			
+
 			case DB1_DOUBLE:
 				_drp->fields[_idx].type = DB1_DOUBLE;
 				_drp->fields[_idx].val.double_val = _vp->val.double_val;
 			break;
-			
+
 			case DB1_INT:
 				_drp->fields[_idx].type = DB1_INT;
 				_drp->fields[_idx].val.int_val = _vp->val.int_val;
 			break;
-			
+
 			case DB1_DATETIME:
 				_drp->fields[_idx].type = _t;
 				_drp->fields[_idx].val.int_val = (int)_vp->val.time_val;
 			break;
-			
+
 			case DB1_BITMAP:
 				_drp->fields[_idx].type = DB1_INT;
 				_drp->fields[_idx].val.int_val = (int)_vp->val.bitmap_val;
 			break;
-			
+
 			default:
 				_drp->fields[_idx].nul = 1;
 				return -1;
 		}
 	}
-	
+
 	return 0;
 }
 
@@ -349,10 +349,10 @@ int dbt_row_update_val(dbt_row_p _drp, dbt_val_p _vp, int _t, int _idx)
 {
 	if(!_drp || !_vp || _idx<0)
 		return -1;
-	
+
 	_drp->fields[_idx].nul = _vp->nul;
 	_drp->fields[_idx].type = _t;
-	
+
 	if(!_vp->nul)
 	{
 		switch(_t)
@@ -363,8 +363,8 @@ int dbt_row_update_val(dbt_row_p _drp, dbt_val_p _vp, int _t, int _idx)
 				// free if already exists
 				if(_drp->fields[_idx].val.str_val.s)
 					shm_free(_drp->fields[_idx].val.str_val.s);
-			
-				_drp->fields[_idx].val.str_val.s = 
+
+				_drp->fields[_idx].val.str_val.s =
 					(char*)shm_malloc((_vp->val.str_val.len+1)*sizeof(char));
 				if(!_drp->fields[_idx].val.str_val.s)
 				{
@@ -376,7 +376,7 @@ int dbt_row_update_val(dbt_row_p _drp, dbt_val_p _vp, int _t, int _idx)
 				_drp->fields[_idx].val.str_val.s[_vp->val.str_val.len] = '\0';
 				_drp->fields[_idx].val.str_val.len = _vp->val.str_val.len;
 			break;
-			
+
 			case DB1_STRING:
 				/* free if already exists */
 				if(_drp->fields[_idx].val.str_val.s)
@@ -388,10 +388,10 @@ int dbt_row_update_val(dbt_row_p _drp, dbt_val_p _vp, int _t, int _idx)
 				else
 					_drp->fields[_idx].val.str_val.len
 											=strlen(_vp->val.string_val);
-				
-				_drp->fields[_idx].val.str_val.s = 
+
+				_drp->fields[_idx].val.str_val.s =
 					(char*)shm_malloc((_drp->fields[_idx].val.str_val.len+1)
-									  *sizeof(char));
+									*sizeof(char));
 				if(!_drp->fields[_idx].val.str_val.s)
 				{
 					_drp->fields[_idx].nul = 1;
@@ -401,34 +401,34 @@ int dbt_row_update_val(dbt_row_p _drp, dbt_val_p _vp, int _t, int _idx)
 					_drp->fields[_idx].val.str_val.len);
 				_drp->fields[_idx].val.str_val.s[_vp->val.str_val.len] = '\0';
 			break;
-			
+
 			case DB1_DOUBLE:
 				_drp->fields[_idx].type = _t;
 				_drp->fields[_idx].val.double_val = _vp->val.double_val;
 			break;
-			
+
 			case DB1_INT:
 				_drp->fields[_idx].type = _t;
 				_drp->fields[_idx].val.int_val = _vp->val.int_val;
 			break;
-			
+
 			case DB1_DATETIME:
 				_drp->fields[_idx].type = _t;
 				_drp->fields[_idx].val.int_val = (int)_vp->val.time_val;
 			break;
-			
+
 			case DB1_BITMAP:
 				_drp->fields[_idx].type = _t;
 				_drp->fields[_idx].val.int_val = (int)_vp->val.bitmap_val;
 			break;
-			
+
 			default:
 				LM_ERR("unsupported type %d in update\n",_t);
 				_drp->fields[_idx].nul = 1;
 				return -1;
 		}
 	}
-	
+
 	return 0;
 }
 
@@ -440,10 +440,10 @@ int dbt_table_check_row(dbt_table_p _dtp, dbt_row_p _drp)
 	int i;
 	if(!_dtp || _dtp->nrcols <= 0 || !_drp)
 		return -1;
-	
+
 	for(i=0; i<_dtp->nrcols; i++)
 	{
-		if(!_drp->fields[i].nul 
+		if(!_drp->fields[i].nul
 				&& dbt_is_neq_type(_dtp->colv[i]->type, _drp->fields[i].type))
 		{
 			LM_ERR("incompatible types - field %d [%d/%d]\n",i,
@@ -452,7 +452,7 @@ int dbt_table_check_row(dbt_table_p _dtp, dbt_row_p _drp)
 		}
 		if(_dtp->colv[i]->flag & DBT_FLAG_NULL)
 			continue;
-		
+
 		if(!_drp->fields[i].nul)
 			continue;
 
@@ -468,7 +468,7 @@ int dbt_table_check_row(dbt_table_p _dtp, dbt_row_p _drp)
 		LM_ERR("null value not allowed - field %d\n",i);
 		return -1;
 	}
-	
+
 	return 0;
 }
 
@@ -479,15 +479,15 @@ int dbt_table_update_flags(dbt_table_p _dtp, int _f, int _o, int _m)
 {
 	if(!_dtp)
 		return -1;
-	
+
 	if(_o == DBT_FL_SET)
 		_dtp->flag |= _f;
 	else if(_o == DBT_FL_UNSET)
 			_dtp->flag &= ~_f;
-	
+
 	if(_m)
 		_dtp->mark = (int)time(NULL);
-	
+
 	return 0;
 }
 

+ 4 - 4
modules/db_text/dbt_util.c

@@ -15,10 +15,10 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  */
 
 #include <string.h>
@@ -34,7 +34,7 @@ int dbt_is_database(str *_s)
 {
 	DIR *dirp = NULL;
 	char buf[512];
-	
+
 	if(!_s || !_s->s || _s->len <= 0 || _s->len > 510)
 		return 0;
 	strncpy(buf, _s->s, _s->len);