Sfoglia il codice sorgente

mtree: make log message on not maching character a debug instead of error

Daniel-Constantin Mierla 12 anni fa
parent
commit
862e267267
2 ha cambiato i file con 232 aggiunte e 232 eliminazioni
  1. 142 142
      modules/mtree/mtree.c
  2. 90 90
      modules/mtree/mtree_mod.c

+ 142 - 142
modules/mtree/mtree.c

@@ -133,16 +133,16 @@ m_tree_t* mt_init_tree(str* tname, str *dbtable, int type)
 	memset(pt->dbtable.s, 0, 1+dbtable->len);
 	memcpy(pt->dbtable.s, dbtable->s, dbtable->len);
 	pt->dbtable.len = dbtable->len;
-	
+
 	return pt;
 }
 
 int mt_add_to_tree(m_tree_t *pt, str *sp, str *svalue)
 {
-        int l, ivalue = 0;
+	int l, ivalue = 0;
 	mt_node_t *itn, *itn0;
 	mt_is_t *tvalues;
-	
+
 	if(pt==NULL || sp==NULL || sp->s==NULL
 			|| svalue==NULL || svalue->s==NULL)
 	{
@@ -157,8 +157,8 @@ int mt_add_to_tree(m_tree_t *pt, str *sp, str *svalue)
 	}
 
 	if ((pt->type == MT_TREE_IVAL) && (str2sint(svalue, &ivalue) != 0)) {
-	    LM_ERR("bad integer string <%.*s>\n", svalue->len, svalue->s);
-	    return -1;
+		LM_ERR("bad integer string <%.*s>\n", svalue->len, svalue->s);
+		return -1;
 	}
 
 	l = 0;
@@ -203,7 +203,7 @@ int mt_add_to_tree(m_tree_t *pt, str *sp, str *svalue)
 		if(_mt_char_table[(unsigned int)sp->s[l]]==255)
 		{
 			LM_ERR("invalid char %d in prefix [%c (0x%x)]\n",
-				l, sp->s[l], sp->s[l]);
+					l, sp->s[l], sp->s[l]);
 			return -1;			
 		}
 		itn0 = itn;
@@ -211,43 +211,43 @@ int mt_add_to_tree(m_tree_t *pt, str *sp, str *svalue)
 	}
 
 	if(itn0[_mt_char_table[(unsigned int)sp->s[l]]].tvalues != NULL) {
-	    if(_mt_ignore_duplicates != 0) {
-		LM_NOTICE("prefix already allocated [%.*s/%.*s]\n",
-			  sp->len, sp->s, svalue->len, svalue->s);
-		return 1;
-	    } else if (_mt_allow_duplicates == 0) {
-		LM_ERR("prefix already allocated [%.*s/%.*s]\n",
-		       sp->len, sp->s, svalue->len, svalue->s);
-		return -1;
-	    }
+		if(_mt_ignore_duplicates != 0) {
+			LM_NOTICE("prefix already allocated [%.*s/%.*s]\n",
+					sp->len, sp->s, svalue->len, svalue->s);
+			return 1;
+		} else if (_mt_allow_duplicates == 0) {
+			LM_ERR("prefix already allocated [%.*s/%.*s]\n",
+					sp->len, sp->s, svalue->len, svalue->s);
+			return -1;
+		}
 	}
 
 	tvalues = (mt_is_t *)shm_malloc(sizeof(mt_is_t));
 	if (tvalues == NULL) {
-	    LM_ERR("no more shm mem for tvalue\n");
-	    return -1;
+		LM_ERR("no more shm mem for tvalue\n");
+		return -1;
 	}
 	memset(tvalues, 0, sizeof(mt_is_t));
 
 	if (pt->type == MT_TREE_IVAL) {
-	    tvalues->tvalue.n = ivalue;
+		tvalues->tvalue.n = ivalue;
 	} else { /* pt->type == MT_TREE_SVAL or MT_TREE_DW */
-	    tvalues->tvalue.s.s = (char*)shm_malloc((svalue->len+1)*sizeof(char));
-	    if (tvalues->tvalue.s.s == NULL) {
-		LM_ERR("no more shm mem for string\n");
-		return -1;
-	    }
-	    tvalues->tvalue.s.len = svalue->len;
-	    pt->memsize +=  (svalue->len+1)*sizeof(char);
-	    pt->nritems++;
-	    strncpy(tvalues->tvalue.s.s, svalue->s, svalue->len);
-	    tvalues->tvalue.s.s[svalue->len] = '\0';
+		tvalues->tvalue.s.s = (char*)shm_malloc((svalue->len+1)*sizeof(char));
+		if (tvalues->tvalue.s.s == NULL) {
+			LM_ERR("no more shm mem for string\n");
+			return -1;
+		}
+		tvalues->tvalue.s.len = svalue->len;
+		pt->memsize +=  (svalue->len+1)*sizeof(char);
+		pt->nritems++;
+		strncpy(tvalues->tvalue.s.s, svalue->s, svalue->len);
+		tvalues->tvalue.s.s[svalue->len] = '\0';
 	}
 	tvalues->next = itn0[_mt_char_table[(unsigned int)sp->s[l]]].tvalues;
 	itn0[_mt_char_table[(unsigned int)sp->s[l]]].tvalues = tvalues;
 
 	mt_node_set_payload(&itn0[_mt_char_table[(unsigned int)sp->s[l]]],
-			    pt->type);
+			pt->type);
 	return 0;
 }
 
@@ -255,7 +255,7 @@ m_tree_t* mt_get_tree(str *tname)
 {
 	m_tree_t *it;
 	int ret;
-			   
+
 	if(_ptree==NULL || *_ptree==NULL)
 		return NULL;
 
@@ -299,7 +299,7 @@ is_t* mt_get_tvalue(m_tree_t *pt, str *tomatch)
 		LM_ERR("bad parameters\n");
 		return NULL;
 	}
-	
+
 	l = 0;
 	itn = pt->head;
 	tvalue = NULL;
@@ -309,7 +309,7 @@ is_t* mt_get_tvalue(m_tree_t *pt, str *tomatch)
 		/* check validity */
 		if(_mt_char_table[(unsigned int)tomatch->s[l]]==255)
 		{
-			LM_ERR("invalid char at %d in [%.*s]\n",
+			LM_BG("not matching char at %d in [%.*s]\n",
 					l, tomatch->len, tomatch->s);
 			return NULL;
 		}
@@ -318,65 +318,65 @@ is_t* mt_get_tvalue(m_tree_t *pt, str *tomatch)
 		{
 			tvalue = &itn[_mt_char_table[(unsigned int)tomatch->s[l]]].tvalues->tvalue;
 		}
-		
+
 		itn = itn[_mt_char_table[(unsigned int)tomatch->s[l]]].child;
 		l++;	
 	}
-	
+
 	return tvalue;
 }
 
 int mt_add_tvalues(struct sip_msg *msg, m_tree_t *pt, str *tomatch)
 {
-    int l;
-    mt_node_t *itn;
-    int_str val, values_avp_name;
-    unsigned short values_name_type;
-    mt_is_t *tvalues;
-
-    if (pt == NULL || tomatch == NULL || tomatch->s == NULL) {
-	LM_ERR("bad parameters\n");
-	return -1;
-    }
-    
-    if (pv_get_avp_name(msg, &pv_values.pvp, &values_avp_name,
-			&values_name_type) < 0) {
-	LM_ERR("cannot get values avp name\n");
-	return -1;
-    }
-	
-    l = 0;
-    itn = pt->head;
-
-    while (itn != NULL && l < tomatch->len && l < MT_MAX_DEPTH) {
-	/* check validity */
-	if(_mt_char_table[(unsigned int)tomatch->s[l]]==255) {
-	    LM_ERR("invalid char at %d in [%.*s]\n",
-		   l, tomatch->len, tomatch->s);
-	    return -1;
-	}
-	tvalues = itn[_mt_char_table[(unsigned int)tomatch->s[l]]].tvalues;
-	while (tvalues != NULL) {
-	    if (pt->type == MT_TREE_IVAL) {
-		val.n = tvalues->tvalue.n;
-		LM_DBG("adding avp <%.*s> with value <i:%d>\n",
-		       values_avp_name.s.len, values_avp_name.s.s, val.n);
-		add_avp(values_name_type, values_avp_name, val);
-	    } else {  /* pt->type == MT_TREE_SVAL */
-		val.s = tvalues->tvalue.s;
-		LM_DBG("adding avp <%.*s> with value <s:%.*s>\n",
-		       values_avp_name.s.len, values_avp_name.s.s, val.s.len,
-		       val.s.s);
-		add_avp(values_name_type|AVP_VAL_STR, values_avp_name, val);
-	    }
-	    tvalues = tvalues->next;
-	}
-		
-	itn = itn[_mt_char_table[(unsigned int)tomatch->s[l]]].child;
-	l++;	
-    }
-
-    return 0;
+	int l;
+	mt_node_t *itn;
+	int_str val, values_avp_name;
+	unsigned short values_name_type;
+	mt_is_t *tvalues;
+
+	if (pt == NULL || tomatch == NULL || tomatch->s == NULL) {
+		LM_ERR("bad parameters\n");
+		return -1;
+	}
+
+	if (pv_get_avp_name(msg, &pv_values.pvp, &values_avp_name,
+				&values_name_type) < 0) {
+		LM_ERR("cannot get values avp name\n");
+		return -1;
+	}
+
+	l = 0;
+	itn = pt->head;
+
+	while (itn != NULL && l < tomatch->len && l < MT_MAX_DEPTH) {
+		/* check validity */
+		if(_mt_char_table[(unsigned int)tomatch->s[l]]==255) {
+			LM_ERR("invalid char at %d in [%.*s]\n",
+					l, tomatch->len, tomatch->s);
+			return -1;
+		}
+		tvalues = itn[_mt_char_table[(unsigned int)tomatch->s[l]]].tvalues;
+		while (tvalues != NULL) {
+			if (pt->type == MT_TREE_IVAL) {
+				val.n = tvalues->tvalue.n;
+				LM_DBG("adding avp <%.*s> with value <i:%d>\n",
+						values_avp_name.s.len, values_avp_name.s.s, val.n);
+				add_avp(values_name_type, values_avp_name, val);
+			} else {  /* pt->type == MT_TREE_SVAL */
+				val.s = tvalues->tvalue.s;
+				LM_DBG("adding avp <%.*s> with value <s:%.*s>\n",
+						values_avp_name.s.len, values_avp_name.s.s, val.s.len,
+						val.s.s);
+				add_avp(values_name_type|AVP_VAL_STR, values_avp_name, val);
+			}
+			tvalues = tvalues->next;
+		}
+
+		itn = itn[_mt_char_table[(unsigned int)tomatch->s[l]]].child;
+		l++;	
+	}
+
+	return 0;
 }
 
 int mt_match_prefix(struct sip_msg *msg, m_tree_t *it,
@@ -407,30 +407,30 @@ int mt_match_prefix(struct sip_msg *msg, m_tree_t *it,
 	l = len = 0;
 	n = 0;
 	if ((it->type==MT_TREE_SVAL) || (it->type==MT_TREE_IVAL)) {
-	    if (mode == 2) 
-		return mt_add_tvalues(msg, it, tomatch);
-	    tvalue = mt_get_tvalue(it, tomatch);
-	    if (tvalue == NULL) {
-		LM_DBG("no match for: %.*s\n", tomatch->len, tomatch->s);
-		return -1;
-	    }
-	    memset(&val, 0, sizeof(pv_value_t));
-	    if (it->type==MT_TREE_SVAL) {
-		val.flags = PV_VAL_STR;
-		val.rs = tvalue->s;
-		if(pv_value.setf(msg, &pv_value.pvp, (int)EQ_T, &val)<0) {
-		    LM_ERR("setting PV failed\n");
-		    return -2;
+		if (mode == 2) 
+			return mt_add_tvalues(msg, it, tomatch);
+		tvalue = mt_get_tvalue(it, tomatch);
+		if (tvalue == NULL) {
+			LM_DBG("no match for: %.*s\n", tomatch->len, tomatch->s);
+			return -1;
 		}
-	    } else {
-		val.flags = PV_VAL_INT;
-		val.ri = tvalue->n;
-		if(pv_value.setf(msg, &pv_value.pvp, (int)EQ_T, &val)<0) {
-		    LM_ERR("setting PV failed\n");
-		    return -2;
+		memset(&val, 0, sizeof(pv_value_t));
+		if (it->type==MT_TREE_SVAL) {
+			val.flags = PV_VAL_STR;
+			val.rs = tvalue->s;
+			if(pv_value.setf(msg, &pv_value.pvp, (int)EQ_T, &val)<0) {
+				LM_ERR("setting PV failed\n");
+				return -2;
+			}
+		} else {
+			val.flags = PV_VAL_INT;
+			val.ri = tvalue->n;
+			if(pv_value.setf(msg, &pv_value.pvp, (int)EQ_T, &val)<0) {
+				LM_ERR("setting PV failed\n");
+				return -2;
+			}
 		}
-	    }
-	    return 0;
+		return 0;
 	}
 
 	if(it->type!=MT_TREE_DW)
@@ -477,11 +477,11 @@ int mt_match_prefix(struct sip_msg *msg, m_tree_t *it,
 		}
 		if(n==MT_MAX_DST_LIST)
 			break;
-		
+
 		itn = itn[_mt_char_table[(unsigned int)tomatch->s[l]]].child;
 		l++;	
 	}
-	
+
 	if(n==0)
 		return -1; /* no match */
 	/* invalidate duplicated dstid, keeping longest match */
@@ -521,40 +521,40 @@ int mt_match_prefix(struct sip_msg *msg, m_tree_t *it,
 			add_avp(dstid_name_type, dstid_avp_name, avp_value);
 		}
 	}
-	
+
 	return 0;
 }
 
 void mt_free_node(mt_node_t *pn, int type)
 {
 	int i;
-        mt_is_t *tvalues, *next;
+	mt_is_t *tvalues, *next;
 
 	if(pn==NULL)
 		return;
 
 	for(i=0; i<MT_NODE_SIZE; i++) {
-	    tvalues = pn[i].tvalues;
-	    while (tvalues != NULL) {
-		if ((type == MT_TREE_SVAL) && (tvalues->tvalue.s.s != NULL)) {
-		    shm_free(tvalues->tvalue.s.s);
-		    tvalues->tvalue.s.s   = NULL;
-		    tvalues->tvalue.s.len = 0;
+		tvalues = pn[i].tvalues;
+		while (tvalues != NULL) {
+			if ((type == MT_TREE_SVAL) && (tvalues->tvalue.s.s != NULL)) {
+				shm_free(tvalues->tvalue.s.s);
+				tvalues->tvalue.s.s   = NULL;
+				tvalues->tvalue.s.len = 0;
+			}
+			next = tvalues->next;
+			shm_free(tvalues);
+			tvalues = next;
+		}
+		if(type==MT_TREE_DW)
+			mt_node_unset_payload(&pn[i], type);
+		if(pn[i].child!=NULL) {
+			mt_free_node(pn[i].child, type);
+			pn[i].child = NULL;
 		}
-		next = tvalues->next;
-		shm_free(tvalues);
-		tvalues = next;
-	    }
-	    if(type==MT_TREE_DW)
-		mt_node_unset_payload(&pn[i], type);
-	    if(pn[i].child!=NULL) {
-		mt_free_node(pn[i].child, type);
-		pn[i].child = NULL;
-	    }
 	}
 	shm_free(pn);
 	pn = NULL;
-	
+
 	return;
 }
 
@@ -571,7 +571,7 @@ void mt_free_tree(m_tree_t *pt)
 		shm_free(pt->dbtable.s);
 	if(pt->tname.s!=NULL)
 		shm_free(pt->tname.s);
-	
+
 	shm_free(pt);
 	pt = NULL;
 	return;
@@ -584,19 +584,19 @@ int mt_print_node(mt_node_t *pn, char *code, int len, int type)
 
 	if(pn==NULL || code==NULL || len>=MT_MAX_DEPTH)
 		return 0;
-	
+
 	for(i=0; i<MT_NODE_SIZE; i++)
 	{
 		code[len]=mt_char_list.s[i];
 		tvalues = pn[i].tvalues;
 		while (tvalues != NULL) {
-		    if (type == MT_TREE_IVAL) {
-			LM_INFO("[%.*s] [i:%d]\n",	len+1, code, tvalues->tvalue.n);
-		    } else if (tvalues->tvalue.s.s != NULL) {
-			LM_INFO("[%.*s] [s:%.*s]\n",
-			       len+1, code, tvalues->tvalue.s.len, tvalues->tvalue.s.s);
-		    }
-		    tvalues = tvalues->next;
+			if (type == MT_TREE_IVAL) {
+				LM_INFO("[%.*s] [i:%d]\n",	len+1, code, tvalues->tvalue.n);
+			} else if (tvalues->tvalue.s.s != NULL) {
+				LM_INFO("[%.*s] [s:%.*s]\n",
+						len+1, code, tvalues->tvalue.s.len, tvalues->tvalue.s.s);
+			}
+			tvalues = tvalues->next;
 		}
 		mt_print_node(pn[i].child, code, len+1, type);
 	}
@@ -614,7 +614,7 @@ int mt_print_tree(m_tree_t *pt)
 		LM_DBG("tree is empty\n");
 		return 0;
 	}
-	
+
 	LM_INFO("[%.*s]\n", pt->tname.len, pt->tname.s);
 	len = 0;
 	mt_print_node(pt->head, mt_code_buf, len, pt->type);
@@ -695,7 +695,7 @@ int mt_table_spec(char* val)
 	m_tree_t tmp;
 	m_tree_t *it, *prev, *ndl;
 	str s;
-	
+
 	if(val==NULL)
 		return -1;
 
@@ -737,10 +737,10 @@ int mt_table_spec(char* val)
 		tmp.dbtable.len = 5;
 	}
 	if ((tmp.type != 0) && (tmp.type != 1) && (tmp.type != 2)) {
-	    LM_ERR("unknown tree type <%d>\n", tmp.type);
-	    goto error;
+		LM_ERR("unknown tree type <%d>\n", tmp.type);
+		goto error;
 	}
-	
+
 	/* check for same tree */
 	if(_ptree == 0)
 	{
@@ -771,7 +771,7 @@ int mt_table_spec(char* val)
 	/* add new tname*/
 	if(it==NULL || str_strcmp(&it->tname, &tmp.tname)>0)
 	{
-                LM_DBG("adding new tname [%s]\n", tmp.tname.s);
+		LM_DBG("adding new tname [%s]\n", tmp.tname.s);
 
 		ndl = mt_init_tree(&tmp.tname, &tmp.dbtable, tmp.type);
 		if(ndl==NULL)
@@ -781,7 +781,7 @@ int mt_table_spec(char* val)
 		}
 
 		ndl->next = it;
-		
+
 		/* new tvalue must be added as first element */
 		if(prev==NULL)
 			*_ptree = ndl;

+ 90 - 90
modules/mtree/mtree_mod.c

@@ -58,19 +58,19 @@ static db_func_t mt_dbf;
 #if 0
 INSERT INTO version (table_name, table_version) values ('mtree','1');
 CREATE TABLE mtree (
-    id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
-    tprefix VARCHAR(32) NOT NULL,
-    tvalue VARCHAR(128) DEFAULT '' NOT NULL,
-    CONSTRAINT tprefix_idx UNIQUE (tprefix)
-) ENGINE=MyISAM;
+		id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
+		tprefix VARCHAR(32) NOT NULL,
+		tvalue VARCHAR(128) DEFAULT '' NOT NULL,
+		CONSTRAINT tprefix_idx UNIQUE (tprefix)
+		) ENGINE=MyISAM;
 INSERT INTO version (table_name, table_version) values ('mtrees','1');
 CREATE TABLE mtrees (
-    id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
-    tname VARCHAR(128) NOT NULL,
-    tprefix VARCHAR(32) NOT NULL,
-    tvalue VARCHAR(128) DEFAULT '' NOT NULL,
-    CONSTRAINT tname_tprefix_idx UNIQUE (tname, tprefix)
-) ENGINE=MyISAM;
+		id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
+		tname VARCHAR(128) NOT NULL,
+		tprefix VARCHAR(32) NOT NULL,
+		tvalue VARCHAR(128) DEFAULT '' NOT NULL,
+		CONSTRAINT tname_tprefix_idx UNIQUE (tname, tprefix)
+		) ENGINE=MyISAM;
 #endif
 
 /** parameters */
@@ -187,10 +187,10 @@ static int mod_init(void)
 		return -1;
 	}
 	if(mtree_init_rpc()!=0)
-        {
-                LM_ERR("failed to register RPC commands\n");
-                return -1;
-        }
+	{
+		LM_ERR("failed to register RPC commands\n");
+		return -1;
+	}
 
 	db_url.len = strlen(db_url.s);
 	db_table.len = strlen(db_table.s);
@@ -212,9 +212,9 @@ static int mod_init(void)
 	}
 
 	if (pv_parse_spec(&values_param, &pv_values) <0
-	    || pv_values.type != PVT_AVP) {
-	    LM_ERR("cannot parse values avp\n");
-	    return -1;
+			|| pv_values.type != PVT_AVP) {
+		LM_ERR("cannot parse values avp\n");
+		return -1;
 	}
 
 	if(pv_parse_spec(&dstid_param, &pv_dstid)<0
@@ -260,7 +260,7 @@ static int mod_init(void)
 	if (!DB_CAPABILITY(mt_dbf, DB_CAP_ALL))
 	{
 		LM_ERR("database module does not "
-		    "implement all functions needed by the module\n");
+				"implement all functions needed by the module\n");
 		return -1;
 	}
 
@@ -271,9 +271,9 @@ static int mod_init(void)
 		LM_ERR("failed to connect to the database\n");        
 		return -1;
 	}
-	
+
 	LM_DBG("database connection opened successfully\n");
-	
+
 	if ( (mt_lock=lock_alloc())==0) {
 		LM_CRIT("failed to alloc lock\n");
 		goto error1;
@@ -282,7 +282,7 @@ static int mod_init(void)
 		LM_CRIT("failed to init lock\n");
 		goto error1;
 	}
-	
+
 	if(mt_defined_trees())
 	{
 		LM_DBG("static trees defined\n");
@@ -380,7 +380,7 @@ static void mod_destroy(void)
 	mt_destroy_trees();
 	if (db_con!=NULL && mt_dbf.close!=NULL)
 		mt_dbf.close(db_con);
-		/* destroy lock */
+	/* destroy lock */
 	if (mt_lock)
 	{
 		lock_destroy( mt_lock );
@@ -392,14 +392,14 @@ static void mod_destroy(void)
 
 static int fixup_mt_match(void** param, int param_no)
 {
-    if(param_no==1 || param_no==2) {
+	if(param_no==1 || param_no==2) {
 		return fixup_spve_null(param, 1);
-    }
-    if (param_no != 3)	{
+	}
+	if (param_no != 3)	{
 		LM_ERR("invalid parameter number %d\n", param_no);
 		return E_UNSPEC;
-    }
-    return fixup_igp_null(param, 1);
+	}
+	return fixup_igp_null(param, 1);
 }
 
 
@@ -411,7 +411,7 @@ static int mt_match(struct sip_msg *msg, gparam_t *tn, gparam_t *var,
 	str tomatch;
 	int mval;
 	m_tree_t *tr = NULL;
-	
+
 	if(msg==NULL)
 	{
 		LM_ERR("received null msg\n");
@@ -433,7 +433,7 @@ static int mt_match(struct sip_msg *msg, gparam_t *tn, gparam_t *var,
 		LM_ERR("cannot get the mode\n");
 		return -1;
 	}
-	
+
 again:
 	lock_get( mt_lock );
 	if (mt_reload_flag) {
@@ -458,7 +458,7 @@ again:
 				tomatch.len, tomatch.s);
 		goto error;
 	}
-	
+
 	lock_get( mt_lock );
 	mt_tree_refcnt--;
 	lock_release( mt_lock );
@@ -540,8 +540,8 @@ static int mt_load_db(str *tname)
 		}
 	} else {
 		if((ret=mt_dbf.query(db_con, NULL, NULL, NULL, db_cols,
-				0, 2, 0, &db_res))!=0
-			|| RES_ROW_N(db_res)<=0 )
+						0, 2, 0, &db_res))!=0
+				|| RES_ROW_N(db_res)<=0 )
 		{
 			mt_dbf.free_result(db_con, db_res);
 			if( ret==0)
@@ -559,23 +559,23 @@ static int mt_load_db(str *tname)
 			/* check for NULL values ?!?! */
 			tprefix.s = (char*)(RES_ROWS(db_res)[i].values[0].val.string_val);
 			tprefix.len = strlen(tprefix.s);
-			
+
 			tvalue.s = (char*)(RES_ROWS(db_res)[i].values[1].val.string_val);
 			tvalue.len = strlen(tvalue.s);
 
 			if(tprefix.s==NULL || tvalue.s==NULL
 					|| tprefix.len<=0 || tvalue.len<=0)
 			{
-				LM_ERR("Error - bad values in db\n");
+				LM_ERR("Error - bad values in db (%p:%p)\n", tprefix.s, tvalue.s);
 				continue;
 			}
-		
+
 			if(mt_add_to_tree(&new_tree, &tprefix, &tvalue)<0)
 			{
 				LM_ERR("Error adding info to tree\n");
 				goto error;
 			}
-	 	}
+		}
 		if (DB_CAPABILITY(mt_dbf, DB_CAP_FETCH)) {
 			if(mt_dbf.fetch_result(db_con, &db_res, mt_fetch_rows)<0) {
 				LM_ERR("Error while fetching!\n");
@@ -663,8 +663,8 @@ static int mt_load_db_trees()
 		}
 	} else {
 		if((ret=mt_dbf.query(db_con, NULL, NULL, NULL, db_cols,
-				0, 3, &tname_column, &db_res))!=0
-			|| RES_ROW_N(db_res)<=0 )
+						0, 3, &tname_column, &db_res))!=0
+				|| RES_ROW_N(db_res)<=0 )
 		{
 			mt_dbf.free_result(db_con, db_res);
 			if( ret==0)
@@ -690,7 +690,7 @@ static int mt_load_db_trees()
 			tvalue.len = strlen(tvalue.s);
 
 			if(tprefix.s==NULL || tvalue.s==NULL || tname.s==NULL ||
-				tprefix.len<=0 || tvalue.len<=0 || tname.len<=0)
+					tprefix.len<=0 || tvalue.len<=0 || tname.len<=0)
 			{
 				LM_ERR("Error - bad values in db\n");
 				continue;
@@ -787,12 +787,12 @@ static struct mi_root* mt_mi_reload(struct mi_root *cmd_tree, void *param)
 		}
 
 		pt = mt_get_first_tree();
-	
+
 		while(pt!=NULL)
 		{
 			if(tname.s==NULL
-				|| (tname.s!=NULL && pt->tname.len>=tname.len
-					&& strncmp(pt->tname.s, tname.s, tname.len)==0))
+					|| (tname.s!=NULL && pt->tname.len>=tname.len
+						&& strncmp(pt->tname.s, tname.s, tname.len)==0))
 			{
 				/* re-loading table from database */
 				if(mt_load_db(&pt->tname)!=0)
@@ -804,7 +804,7 @@ static struct mi_root* mt_mi_reload(struct mi_root *cmd_tree, void *param)
 			pt = pt->next;
 		}
 	}
-	
+
 	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
 
 error:
@@ -823,7 +823,7 @@ int mt_print_mi_node(m_tree_t *tree, mt_node_t *pt, struct mi_node* rpl,
 
 	if(pt==NULL || len>=MT_MAX_DEPTH)
 		return 0;
-	
+
 	for(i=0; i<MT_NODE_SIZE; i++)
 	{
 		code[len]=mt_char_list.s[i];
@@ -838,23 +838,23 @@ int mt_print_mi_node(m_tree_t *tree, mt_node_t *pt, struct mi_node* rpl,
 			if(attr == NULL)
 				goto error;
 			attr = add_mi_attr(node, MI_DUP_VALUE, "TPREFIX", 7,
-						code, len+1);
+					code, len+1);
 			if(attr == NULL)
 				goto error;
 
 			while (tvalues != NULL) {
-			    if (tree->type == MT_TREE_IVAL) {
-				val.s = int2str(tvalues->tvalue.n, &val.len);
-				attr = add_mi_attr(node, MI_DUP_VALUE, "TVALUE", 6,
-						   val.s, val.len);
-			    } else {
-				attr = add_mi_attr(node, MI_DUP_VALUE, "TVALUE", 6,
-						   tvalues->tvalue.s.s,
-						   tvalues->tvalue.s.len);
-			    }
-			    if(attr == NULL)
-				goto error;
-			    tvalues = tvalues->next;
+				if (tree->type == MT_TREE_IVAL) {
+					val.s = int2str(tvalues->tvalue.n, &val.len);
+					attr = add_mi_attr(node, MI_DUP_VALUE, "TVALUE", 6,
+							val.s, val.len);
+				} else {
+					attr = add_mi_attr(node, MI_DUP_VALUE, "TVALUE", 6,
+							tvalues->tvalue.s.s,
+							tvalues->tvalue.s.len);
+				}
+				if(attr == NULL)
+					goto error;
+				tvalues = tvalues->next;
 			}
 		}
 		if(mt_print_mi_node(tree, pt[i].child, rpl, code, len+1)<0)
@@ -909,12 +909,12 @@ struct mi_root* mt_mi_list(struct mi_root* cmd_tree, void* param)
 	rpl = &rpl_tree->node;
 
 	pt = mt_get_first_tree();
-	
+
 	while(pt!=NULL)
 	{
 		if(tname.s==NULL || 
-			(tname.s!=NULL && pt->tname.len>=tname.len && 
-			 strncmp(pt->tname.s, tname.s, tname.len)==0))
+				(tname.s!=NULL && pt->tname.len>=tname.len && 
+				 strncmp(pt->tname.s, tname.s, tname.len)==0))
 		{
 			len = 0;
 			if(mt_print_mi_node(pt, pt->head, rpl, code_buf, len)<0)
@@ -922,7 +922,7 @@ struct mi_root* mt_mi_list(struct mi_root* cmd_tree, void* param)
 		}
 		pt = pt->next;
 	}
-	
+
 	return rpl_tree;
 
 error:
@@ -961,7 +961,7 @@ struct mi_root* mt_mi_summary(struct mi_root* cmd_tree, void* param)
 			goto error;
 		val.s = int2str(pt->type, &val.len);
 		attr = add_mi_attr(node, MI_DUP_VALUE, "TTYPE", 5,
-				   val.s, val.len);
+				val.s, val.len);
 		if(attr == NULL)
 			goto error;
 		val.s = int2str(pt->memsize, &val.len);
@@ -998,7 +998,7 @@ void rpc_mtree_summary(rpc_t* rpc, void* c)
 	if(!mt_defined_trees())
 	{
 		rpc->fault(c, 500, "Empty tree list.");
-                return;
+		return;
 	}
 
 	if (rpc->add(c, "{", &th) < 0)
@@ -1011,29 +1011,29 @@ void rpc_mtree_summary(rpc_t* rpc, void* c)
 	while(pt!=NULL)
 	{
 		if(rpc->struct_add(th, "s{",
-				"table", pt->tname.s,
-				"item", &ih) < 0)
-			{
-				rpc->fault(c, 500, "Internal error creating rpc ih");
-				return;
-			}
+					"table", pt->tname.s,
+					"item", &ih) < 0)
+		{
+			rpc->fault(c, 500, "Internal error creating rpc ih");
+			return;
+		}
 
 		if(rpc->struct_add(ih, "d", "ttype", pt->type) < 0 ) {
-                                rpc->fault(c, 500, "Internal error adding type");
-                                return;
-                }
+			rpc->fault(c, 500, "Internal error adding type");
+			return;
+		}
 		if(rpc->struct_add(ih, "d", "memsize", pt->memsize) < 0 ) {
-                                rpc->fault(c, 500, "Internal error adding memsize");
-                                return;
-                }
+			rpc->fault(c, 500, "Internal error adding memsize");
+			return;
+		}
 		if(rpc->struct_add(ih, "d", "nrnodes", pt->nrnodes) < 0 ) {
-                                rpc->fault(c, 500, "Internal error adding nodes");
-                                return;
-                }
+			rpc->fault(c, 500, "Internal error adding nodes");
+			return;
+		}
 		if(rpc->struct_add(ih, "d", "nritems", pt->nritems) < 0 ) {
-                                rpc->fault(c, 500, "Internal error adding items");
-                                return;
-                }
+			rpc->fault(c, 500, "Internal error adding items");
+			return;
+		}
 		pt = pt->next;
 	}
 	return;
@@ -1066,17 +1066,17 @@ void rpc_mtree_reload(rpc_t* rpc, void* c)
 
 		/* read tree name */
 		if (rpc->scan(c, "S", &tname) != 1) {
-		    rpc->fault(c, 500, "Failed to get table name parameter");
-		    return;
+			rpc->fault(c, 500, "Failed to get table name parameter");
+			return;
 		}
 
 		pt = mt_get_first_tree();
-	
+
 		while(pt!=NULL)
 		{
 			if(tname.s==NULL
-				|| (tname.s!=NULL && pt->tname.len>=tname.len
-					&& strncmp(pt->tname.s, tname.s, tname.len)==0))
+					|| (tname.s!=NULL && pt->tname.len>=tname.len
+						&& strncmp(pt->tname.s, tname.s, tname.len)==0))
 			{
 				/* re-loading table from database */
 				if(mt_load_db(&pt->tname)!=0)
@@ -1088,7 +1088,7 @@ void rpc_mtree_reload(rpc_t* rpc, void* c)
 			pt = pt->next;
 		}
 	}
-	
+
 	return;
 
 error:
@@ -1096,8 +1096,8 @@ error:
 }
 
 static const char* rpc_mtree_reload_doc[2] = {
-    "Reload mtrees from database to memory",
-    0
+	"Reload mtrees from database to memory",
+	0
 };
 
 rpc_export_t mtree_rpc[] = {