Browse code

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

Daniel-Constantin Mierla authored on 11/06/2013 16:47:54
Showing 2 changed files
... ...
@@ -133,16 +133,16 @@ m_tree_t* mt_init_tree(str* tname, str *dbtable, int type)
133 133
 	memset(pt->dbtable.s, 0, 1+dbtable->len);
134 134
 	memcpy(pt->dbtable.s, dbtable->s, dbtable->len);
135 135
 	pt->dbtable.len = dbtable->len;
136
-	
136
+
137 137
 	return pt;
138 138
 }
139 139
 
140 140
 int mt_add_to_tree(m_tree_t *pt, str *sp, str *svalue)
141 141
 {
142
-        int l, ivalue = 0;
142
+	int l, ivalue = 0;
143 143
 	mt_node_t *itn, *itn0;
144 144
 	mt_is_t *tvalues;
145
-	
145
+
146 146
 	if(pt==NULL || sp==NULL || sp->s==NULL
147 147
 			|| svalue==NULL || svalue->s==NULL)
148 148
 	{
... ...
@@ -157,8 +157,8 @@ int mt_add_to_tree(m_tree_t *pt, str *sp, str *svalue)
157 157
 	}
158 158
 
159 159
 	if ((pt->type == MT_TREE_IVAL) && (str2sint(svalue, &ivalue) != 0)) {
160
-	    LM_ERR("bad integer string <%.*s>\n", svalue->len, svalue->s);
161
-	    return -1;
160
+		LM_ERR("bad integer string <%.*s>\n", svalue->len, svalue->s);
161
+		return -1;
162 162
 	}
163 163
 
164 164
 	l = 0;
... ...
@@ -203,7 +203,7 @@ int mt_add_to_tree(m_tree_t *pt, str *sp, str *svalue)
203 203
 		if(_mt_char_table[(unsigned int)sp->s[l]]==255)
204 204
 		{
205 205
 			LM_ERR("invalid char %d in prefix [%c (0x%x)]\n",
206
-				l, sp->s[l], sp->s[l]);
206
+					l, sp->s[l], sp->s[l]);
207 207
 			return -1;			
208 208
 		}
209 209
 		itn0 = itn;
... ...
@@ -211,43 +211,43 @@ int mt_add_to_tree(m_tree_t *pt, str *sp, str *svalue)
211 211
 	}
212 212
 
213 213
 	if(itn0[_mt_char_table[(unsigned int)sp->s[l]]].tvalues != NULL) {
214
-	    if(_mt_ignore_duplicates != 0) {
215
-		LM_NOTICE("prefix already allocated [%.*s/%.*s]\n",
216
-			  sp->len, sp->s, svalue->len, svalue->s);
217
-		return 1;
218
-	    } else if (_mt_allow_duplicates == 0) {
219
-		LM_ERR("prefix already allocated [%.*s/%.*s]\n",
220
-		       sp->len, sp->s, svalue->len, svalue->s);
221
-		return -1;
222
-	    }
214
+		if(_mt_ignore_duplicates != 0) {
215
+			LM_NOTICE("prefix already allocated [%.*s/%.*s]\n",
216
+					sp->len, sp->s, svalue->len, svalue->s);
217
+			return 1;
218
+		} else if (_mt_allow_duplicates == 0) {
219
+			LM_ERR("prefix already allocated [%.*s/%.*s]\n",
220
+					sp->len, sp->s, svalue->len, svalue->s);
221
+			return -1;
222
+		}
223 223
 	}
224 224
 
225 225
 	tvalues = (mt_is_t *)shm_malloc(sizeof(mt_is_t));
226 226
 	if (tvalues == NULL) {
227
-	    LM_ERR("no more shm mem for tvalue\n");
228
-	    return -1;
227
+		LM_ERR("no more shm mem for tvalue\n");
228
+		return -1;
229 229
 	}
230 230
 	memset(tvalues, 0, sizeof(mt_is_t));
231 231
 
232 232
 	if (pt->type == MT_TREE_IVAL) {
233
-	    tvalues->tvalue.n = ivalue;
233
+		tvalues->tvalue.n = ivalue;
234 234
 	} else { /* pt->type == MT_TREE_SVAL or MT_TREE_DW */
235
-	    tvalues->tvalue.s.s = (char*)shm_malloc((svalue->len+1)*sizeof(char));
236
-	    if (tvalues->tvalue.s.s == NULL) {
237
-		LM_ERR("no more shm mem for string\n");
238
-		return -1;
239
-	    }
240
-	    tvalues->tvalue.s.len = svalue->len;
241
-	    pt->memsize +=  (svalue->len+1)*sizeof(char);
242
-	    pt->nritems++;
243
-	    strncpy(tvalues->tvalue.s.s, svalue->s, svalue->len);
244
-	    tvalues->tvalue.s.s[svalue->len] = '\0';
235
+		tvalues->tvalue.s.s = (char*)shm_malloc((svalue->len+1)*sizeof(char));
236
+		if (tvalues->tvalue.s.s == NULL) {
237
+			LM_ERR("no more shm mem for string\n");
238
+			return -1;
239
+		}
240
+		tvalues->tvalue.s.len = svalue->len;
241
+		pt->memsize +=  (svalue->len+1)*sizeof(char);
242
+		pt->nritems++;
243
+		strncpy(tvalues->tvalue.s.s, svalue->s, svalue->len);
244
+		tvalues->tvalue.s.s[svalue->len] = '\0';
245 245
 	}
246 246
 	tvalues->next = itn0[_mt_char_table[(unsigned int)sp->s[l]]].tvalues;
247 247
 	itn0[_mt_char_table[(unsigned int)sp->s[l]]].tvalues = tvalues;
248 248
 
249 249
 	mt_node_set_payload(&itn0[_mt_char_table[(unsigned int)sp->s[l]]],
250
-			    pt->type);
250
+			pt->type);
251 251
 	return 0;
252 252
 }
253 253
 
... ...
@@ -255,7 +255,7 @@ m_tree_t* mt_get_tree(str *tname)
255 255
 {
256 256
 	m_tree_t *it;
257 257
 	int ret;
258
-			   
258
+
259 259
 	if(_ptree==NULL || *_ptree==NULL)
260 260
 		return NULL;
261 261
 
... ...
@@ -299,7 +299,7 @@ is_t* mt_get_tvalue(m_tree_t *pt, str *tomatch)
299 299
 		LM_ERR("bad parameters\n");
300 300
 		return NULL;
301 301
 	}
302
-	
302
+
303 303
 	l = 0;
304 304
 	itn = pt->head;
305 305
 	tvalue = NULL;
... ...
@@ -309,7 +309,7 @@ is_t* mt_get_tvalue(m_tree_t *pt, str *tomatch)
309 309
 		/* check validity */
310 310
 		if(_mt_char_table[(unsigned int)tomatch->s[l]]==255)
311 311
 		{
312
-			LM_ERR("invalid char at %d in [%.*s]\n",
312
+			LM_BG("not matching char at %d in [%.*s]\n",
313 313
 					l, tomatch->len, tomatch->s);
314 314
 			return NULL;
315 315
 		}
... ...
@@ -318,65 +318,65 @@ is_t* mt_get_tvalue(m_tree_t *pt, str *tomatch)
318 318
 		{
319 319
 			tvalue = &itn[_mt_char_table[(unsigned int)tomatch->s[l]]].tvalues->tvalue;
320 320
 		}
321
-		
321
+
322 322
 		itn = itn[_mt_char_table[(unsigned int)tomatch->s[l]]].child;
323 323
 		l++;	
324 324
 	}
325
-	
325
+
326 326
 	return tvalue;
327 327
 }
328 328
 
329 329
 int mt_add_tvalues(struct sip_msg *msg, m_tree_t *pt, str *tomatch)
330 330
 {
331
-    int l;
332
-    mt_node_t *itn;
333
-    int_str val, values_avp_name;
334
-    unsigned short values_name_type;
335
-    mt_is_t *tvalues;
336
-
337
-    if (pt == NULL || tomatch == NULL || tomatch->s == NULL) {
338
-	LM_ERR("bad parameters\n");
339
-	return -1;
340
-    }
341
-    
342
-    if (pv_get_avp_name(msg, &pv_values.pvp, &values_avp_name,
343
-			&values_name_type) < 0) {
344
-	LM_ERR("cannot get values avp name\n");
345
-	return -1;
346
-    }
347
-	
348
-    l = 0;
349
-    itn = pt->head;
350
-
351
-    while (itn != NULL && l < tomatch->len && l < MT_MAX_DEPTH) {
352
-	/* check validity */
353
-	if(_mt_char_table[(unsigned int)tomatch->s[l]]==255) {
354
-	    LM_ERR("invalid char at %d in [%.*s]\n",
355
-		   l, tomatch->len, tomatch->s);
356
-	    return -1;
357
-	}
358
-	tvalues = itn[_mt_char_table[(unsigned int)tomatch->s[l]]].tvalues;
359
-	while (tvalues != NULL) {
360
-	    if (pt->type == MT_TREE_IVAL) {
361
-		val.n = tvalues->tvalue.n;
362
-		LM_DBG("adding avp <%.*s> with value <i:%d>\n",
363
-		       values_avp_name.s.len, values_avp_name.s.s, val.n);
364
-		add_avp(values_name_type, values_avp_name, val);
365
-	    } else {  /* pt->type == MT_TREE_SVAL */
366
-		val.s = tvalues->tvalue.s;
367
-		LM_DBG("adding avp <%.*s> with value <s:%.*s>\n",
368
-		       values_avp_name.s.len, values_avp_name.s.s, val.s.len,
369
-		       val.s.s);
370
-		add_avp(values_name_type|AVP_VAL_STR, values_avp_name, val);
371
-	    }
372
-	    tvalues = tvalues->next;
373
-	}
374
-		
375
-	itn = itn[_mt_char_table[(unsigned int)tomatch->s[l]]].child;
376
-	l++;	
377
-    }
378
-
379
-    return 0;
331
+	int l;
332
+	mt_node_t *itn;
333
+	int_str val, values_avp_name;
334
+	unsigned short values_name_type;
335
+	mt_is_t *tvalues;
336
+
337
+	if (pt == NULL || tomatch == NULL || tomatch->s == NULL) {
338
+		LM_ERR("bad parameters\n");
339
+		return -1;
340
+	}
341
+
342
+	if (pv_get_avp_name(msg, &pv_values.pvp, &values_avp_name,
343
+				&values_name_type) < 0) {
344
+		LM_ERR("cannot get values avp name\n");
345
+		return -1;
346
+	}
347
+
348
+	l = 0;
349
+	itn = pt->head;
350
+
351
+	while (itn != NULL && l < tomatch->len && l < MT_MAX_DEPTH) {
352
+		/* check validity */
353
+		if(_mt_char_table[(unsigned int)tomatch->s[l]]==255) {
354
+			LM_ERR("invalid char at %d in [%.*s]\n",
355
+					l, tomatch->len, tomatch->s);
356
+			return -1;
357
+		}
358
+		tvalues = itn[_mt_char_table[(unsigned int)tomatch->s[l]]].tvalues;
359
+		while (tvalues != NULL) {
360
+			if (pt->type == MT_TREE_IVAL) {
361
+				val.n = tvalues->tvalue.n;
362
+				LM_DBG("adding avp <%.*s> with value <i:%d>\n",
363
+						values_avp_name.s.len, values_avp_name.s.s, val.n);
364
+				add_avp(values_name_type, values_avp_name, val);
365
+			} else {  /* pt->type == MT_TREE_SVAL */
366
+				val.s = tvalues->tvalue.s;
367
+				LM_DBG("adding avp <%.*s> with value <s:%.*s>\n",
368
+						values_avp_name.s.len, values_avp_name.s.s, val.s.len,
369
+						val.s.s);
370
+				add_avp(values_name_type|AVP_VAL_STR, values_avp_name, val);
371
+			}
372
+			tvalues = tvalues->next;
373
+		}
374
+
375
+		itn = itn[_mt_char_table[(unsigned int)tomatch->s[l]]].child;
376
+		l++;	
377
+	}
378
+
379
+	return 0;
380 380
 }
381 381
 
382 382
 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,
407 407
 	l = len = 0;
408 408
 	n = 0;
409 409
 	if ((it->type==MT_TREE_SVAL) || (it->type==MT_TREE_IVAL)) {
410
-	    if (mode == 2) 
411
-		return mt_add_tvalues(msg, it, tomatch);
412
-	    tvalue = mt_get_tvalue(it, tomatch);
413
-	    if (tvalue == NULL) {
414
-		LM_DBG("no match for: %.*s\n", tomatch->len, tomatch->s);
415
-		return -1;
416
-	    }
417
-	    memset(&val, 0, sizeof(pv_value_t));
418
-	    if (it->type==MT_TREE_SVAL) {
419
-		val.flags = PV_VAL_STR;
420
-		val.rs = tvalue->s;
421
-		if(pv_value.setf(msg, &pv_value.pvp, (int)EQ_T, &val)<0) {
422
-		    LM_ERR("setting PV failed\n");
423
-		    return -2;
410
+		if (mode == 2) 
411
+			return mt_add_tvalues(msg, it, tomatch);
412
+		tvalue = mt_get_tvalue(it, tomatch);
413
+		if (tvalue == NULL) {
414
+			LM_DBG("no match for: %.*s\n", tomatch->len, tomatch->s);
415
+			return -1;
424 416
 		}
425
-	    } else {
426
-		val.flags = PV_VAL_INT;
427
-		val.ri = tvalue->n;
428
-		if(pv_value.setf(msg, &pv_value.pvp, (int)EQ_T, &val)<0) {
429
-		    LM_ERR("setting PV failed\n");
430
-		    return -2;
417
+		memset(&val, 0, sizeof(pv_value_t));
418
+		if (it->type==MT_TREE_SVAL) {
419
+			val.flags = PV_VAL_STR;
420
+			val.rs = tvalue->s;
421
+			if(pv_value.setf(msg, &pv_value.pvp, (int)EQ_T, &val)<0) {
422
+				LM_ERR("setting PV failed\n");
423
+				return -2;
424
+			}
425
+		} else {
426
+			val.flags = PV_VAL_INT;
427
+			val.ri = tvalue->n;
428
+			if(pv_value.setf(msg, &pv_value.pvp, (int)EQ_T, &val)<0) {
429
+				LM_ERR("setting PV failed\n");
430
+				return -2;
431
+			}
431 432
 		}
432
-	    }
433
-	    return 0;
433
+		return 0;
434 434
 	}
435 435
 
436 436
 	if(it->type!=MT_TREE_DW)
... ...
@@ -477,11 +477,11 @@ int mt_match_prefix(struct sip_msg *msg, m_tree_t *it,
477 477
 		}
478 478
 		if(n==MT_MAX_DST_LIST)
479 479
 			break;
480
-		
480
+
481 481
 		itn = itn[_mt_char_table[(unsigned int)tomatch->s[l]]].child;
482 482
 		l++;	
483 483
 	}
484
-	
484
+
485 485
 	if(n==0)
486 486
 		return -1; /* no match */
487 487
 	/* invalidate duplicated dstid, keeping longest match */
... ...
@@ -521,40 +521,40 @@ int mt_match_prefix(struct sip_msg *msg, m_tree_t *it,
521 521
 			add_avp(dstid_name_type, dstid_avp_name, avp_value);
522 522
 		}
523 523
 	}
524
-	
524
+
525 525
 	return 0;
526 526
 }
527 527
 
528 528
 void mt_free_node(mt_node_t *pn, int type)
529 529
 {
530 530
 	int i;
531
-        mt_is_t *tvalues, *next;
531
+	mt_is_t *tvalues, *next;
532 532
 
533 533
 	if(pn==NULL)
534 534
 		return;
535 535
 
536 536
 	for(i=0; i<MT_NODE_SIZE; i++) {
537
-	    tvalues = pn[i].tvalues;
538
-	    while (tvalues != NULL) {
539
-		if ((type == MT_TREE_SVAL) && (tvalues->tvalue.s.s != NULL)) {
540
-		    shm_free(tvalues->tvalue.s.s);
541
-		    tvalues->tvalue.s.s   = NULL;
542
-		    tvalues->tvalue.s.len = 0;
537
+		tvalues = pn[i].tvalues;
538
+		while (tvalues != NULL) {
539
+			if ((type == MT_TREE_SVAL) && (tvalues->tvalue.s.s != NULL)) {
540
+				shm_free(tvalues->tvalue.s.s);
541
+				tvalues->tvalue.s.s   = NULL;
542
+				tvalues->tvalue.s.len = 0;
543
+			}
544
+			next = tvalues->next;
545
+			shm_free(tvalues);
546
+			tvalues = next;
547
+		}
548
+		if(type==MT_TREE_DW)
549
+			mt_node_unset_payload(&pn[i], type);
550
+		if(pn[i].child!=NULL) {
551
+			mt_free_node(pn[i].child, type);
552
+			pn[i].child = NULL;
543 553
 		}
544
-		next = tvalues->next;
545
-		shm_free(tvalues);
546
-		tvalues = next;
547
-	    }
548
-	    if(type==MT_TREE_DW)
549
-		mt_node_unset_payload(&pn[i], type);
550
-	    if(pn[i].child!=NULL) {
551
-		mt_free_node(pn[i].child, type);
552
-		pn[i].child = NULL;
553
-	    }
554 554
 	}
555 555
 	shm_free(pn);
556 556
 	pn = NULL;
557
-	
557
+
558 558
 	return;
559 559
 }
560 560
 
... ...
@@ -571,7 +571,7 @@ void mt_free_tree(m_tree_t *pt)
571 571
 		shm_free(pt->dbtable.s);
572 572
 	if(pt->tname.s!=NULL)
573 573
 		shm_free(pt->tname.s);
574
-	
574
+
575 575
 	shm_free(pt);
576 576
 	pt = NULL;
577 577
 	return;
... ...
@@ -584,19 +584,19 @@ int mt_print_node(mt_node_t *pn, char *code, int len, int type)
584 584
 
585 585
 	if(pn==NULL || code==NULL || len>=MT_MAX_DEPTH)
586 586
 		return 0;
587
-	
587
+
588 588
 	for(i=0; i<MT_NODE_SIZE; i++)
589 589
 	{
590 590
 		code[len]=mt_char_list.s[i];
591 591
 		tvalues = pn[i].tvalues;
592 592
 		while (tvalues != NULL) {
593
-		    if (type == MT_TREE_IVAL) {
594
-			LM_INFO("[%.*s] [i:%d]\n",	len+1, code, tvalues->tvalue.n);
595
-		    } else if (tvalues->tvalue.s.s != NULL) {
596
-			LM_INFO("[%.*s] [s:%.*s]\n",
597
-			       len+1, code, tvalues->tvalue.s.len, tvalues->tvalue.s.s);
598
-		    }
599
-		    tvalues = tvalues->next;
593
+			if (type == MT_TREE_IVAL) {
594
+				LM_INFO("[%.*s] [i:%d]\n",	len+1, code, tvalues->tvalue.n);
595
+			} else if (tvalues->tvalue.s.s != NULL) {
596
+				LM_INFO("[%.*s] [s:%.*s]\n",
597
+						len+1, code, tvalues->tvalue.s.len, tvalues->tvalue.s.s);
598
+			}
599
+			tvalues = tvalues->next;
600 600
 		}
601 601
 		mt_print_node(pn[i].child, code, len+1, type);
602 602
 	}
... ...
@@ -614,7 +614,7 @@ int mt_print_tree(m_tree_t *pt)
614 614
 		LM_DBG("tree is empty\n");
615 615
 		return 0;
616 616
 	}
617
-	
617
+
618 618
 	LM_INFO("[%.*s]\n", pt->tname.len, pt->tname.s);
619 619
 	len = 0;
620 620
 	mt_print_node(pt->head, mt_code_buf, len, pt->type);
... ...
@@ -695,7 +695,7 @@ int mt_table_spec(char* val)
695 695
 	m_tree_t tmp;
696 696
 	m_tree_t *it, *prev, *ndl;
697 697
 	str s;
698
-	
698
+
699 699
 	if(val==NULL)
700 700
 		return -1;
701 701
 
... ...
@@ -737,10 +737,10 @@ int mt_table_spec(char* val)
737 737
 		tmp.dbtable.len = 5;
738 738
 	}
739 739
 	if ((tmp.type != 0) && (tmp.type != 1) && (tmp.type != 2)) {
740
-	    LM_ERR("unknown tree type <%d>\n", tmp.type);
741
-	    goto error;
740
+		LM_ERR("unknown tree type <%d>\n", tmp.type);
741
+		goto error;
742 742
 	}
743
-	
743
+
744 744
 	/* check for same tree */
745 745
 	if(_ptree == 0)
746 746
 	{
... ...
@@ -771,7 +771,7 @@ int mt_table_spec(char* val)
771 771
 	/* add new tname*/
772 772
 	if(it==NULL || str_strcmp(&it->tname, &tmp.tname)>0)
773 773
 	{
774
-                LM_DBG("adding new tname [%s]\n", tmp.tname.s);
774
+		LM_DBG("adding new tname [%s]\n", tmp.tname.s);
775 775
 
776 776
 		ndl = mt_init_tree(&tmp.tname, &tmp.dbtable, tmp.type);
777 777
 		if(ndl==NULL)
... ...
@@ -781,7 +781,7 @@ int mt_table_spec(char* val)
781 781
 		}
782 782
 
783 783
 		ndl->next = it;
784
-		
784
+
785 785
 		/* new tvalue must be added as first element */
786 786
 		if(prev==NULL)
787 787
 			*_ptree = ndl;
... ...
@@ -58,19 +58,19 @@ static db_func_t mt_dbf;
58 58
 #if 0
59 59
 INSERT INTO version (table_name, table_version) values ('mtree','1');
60 60
 CREATE TABLE mtree (
61
-    id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
62
-    tprefix VARCHAR(32) NOT NULL,
63
-    tvalue VARCHAR(128) DEFAULT '' NOT NULL,
64
-    CONSTRAINT tprefix_idx UNIQUE (tprefix)
65
-) ENGINE=MyISAM;
61
+		id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
62
+		tprefix VARCHAR(32) NOT NULL,
63
+		tvalue VARCHAR(128) DEFAULT '' NOT NULL,
64
+		CONSTRAINT tprefix_idx UNIQUE (tprefix)
65
+		) ENGINE=MyISAM;
66 66
 INSERT INTO version (table_name, table_version) values ('mtrees','1');
67 67
 CREATE TABLE mtrees (
68
-    id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
69
-    tname VARCHAR(128) NOT NULL,
70
-    tprefix VARCHAR(32) NOT NULL,
71
-    tvalue VARCHAR(128) DEFAULT '' NOT NULL,
72
-    CONSTRAINT tname_tprefix_idx UNIQUE (tname, tprefix)
73
-) ENGINE=MyISAM;
68
+		id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
69
+		tname VARCHAR(128) NOT NULL,
70
+		tprefix VARCHAR(32) NOT NULL,
71
+		tvalue VARCHAR(128) DEFAULT '' NOT NULL,
72
+		CONSTRAINT tname_tprefix_idx UNIQUE (tname, tprefix)
73
+		) ENGINE=MyISAM;
74 74
 #endif
75 75
 
76 76
 /** parameters */
... ...
@@ -187,10 +187,10 @@ static int mod_init(void)
187 187
 		return -1;
188 188
 	}
189 189
 	if(mtree_init_rpc()!=0)
190
-        {
191
-                LM_ERR("failed to register RPC commands\n");
192
-                return -1;
193
-        }
190
+	{
191
+		LM_ERR("failed to register RPC commands\n");
192
+		return -1;
193
+	}
194 194
 
195 195
 	db_url.len = strlen(db_url.s);
196 196
 	db_table.len = strlen(db_table.s);
... ...
@@ -212,9 +212,9 @@ static int mod_init(void)
212 212
 	}
213 213
 
214 214
 	if (pv_parse_spec(&values_param, &pv_values) <0
215
-	    || pv_values.type != PVT_AVP) {
216
-	    LM_ERR("cannot parse values avp\n");
217
-	    return -1;
215
+			|| pv_values.type != PVT_AVP) {
216
+		LM_ERR("cannot parse values avp\n");
217
+		return -1;
218 218
 	}
219 219
 
220 220
 	if(pv_parse_spec(&dstid_param, &pv_dstid)<0
... ...
@@ -260,7 +260,7 @@ static int mod_init(void)
260 260
 	if (!DB_CAPABILITY(mt_dbf, DB_CAP_ALL))
261 261
 	{
262 262
 		LM_ERR("database module does not "
263
-		    "implement all functions needed by the module\n");
263
+				"implement all functions needed by the module\n");
264 264
 		return -1;
265 265
 	}
266 266
 
... ...
@@ -271,9 +271,9 @@ static int mod_init(void)
271 271
 		LM_ERR("failed to connect to the database\n");        
272 272
 		return -1;
273 273
 	}
274
-	
274
+
275 275
 	LM_DBG("database connection opened successfully\n");
276
-	
276
+
277 277
 	if ( (mt_lock=lock_alloc())==0) {
278 278
 		LM_CRIT("failed to alloc lock\n");
279 279
 		goto error1;
... ...
@@ -282,7 +282,7 @@ static int mod_init(void)
282 282
 		LM_CRIT("failed to init lock\n");
283 283
 		goto error1;
284 284
 	}
285
-	
285
+
286 286
 	if(mt_defined_trees())
287 287
 	{
288 288
 		LM_DBG("static trees defined\n");
... ...
@@ -380,7 +380,7 @@ static void mod_destroy(void)
380 380
 	mt_destroy_trees();
381 381
 	if (db_con!=NULL && mt_dbf.close!=NULL)
382 382
 		mt_dbf.close(db_con);
383
-		/* destroy lock */
383
+	/* destroy lock */
384 384
 	if (mt_lock)
385 385
 	{
386 386
 		lock_destroy( mt_lock );
... ...
@@ -392,14 +392,14 @@ static void mod_destroy(void)
392 392
 
393 393
 static int fixup_mt_match(void** param, int param_no)
394 394
 {
395
-    if(param_no==1 || param_no==2) {
395
+	if(param_no==1 || param_no==2) {
396 396
 		return fixup_spve_null(param, 1);
397
-    }
398
-    if (param_no != 3)	{
397
+	}
398
+	if (param_no != 3)	{
399 399
 		LM_ERR("invalid parameter number %d\n", param_no);
400 400
 		return E_UNSPEC;
401
-    }
402
-    return fixup_igp_null(param, 1);
401
+	}
402
+	return fixup_igp_null(param, 1);
403 403
 }
404 404
 
405 405
 
... ...
@@ -411,7 +411,7 @@ static int mt_match(struct sip_msg *msg, gparam_t *tn, gparam_t *var,
411 411
 	str tomatch;
412 412
 	int mval;
413 413
 	m_tree_t *tr = NULL;
414
-	
414
+
415 415
 	if(msg==NULL)
416 416
 	{
417 417
 		LM_ERR("received null msg\n");
... ...
@@ -433,7 +433,7 @@ static int mt_match(struct sip_msg *msg, gparam_t *tn, gparam_t *var,
433 433
 		LM_ERR("cannot get the mode\n");
434 434
 		return -1;
435 435
 	}
436
-	
436
+
437 437
 again:
438 438
 	lock_get( mt_lock );
439 439
 	if (mt_reload_flag) {
... ...
@@ -458,7 +458,7 @@ again:
458 458
 				tomatch.len, tomatch.s);
459 459
 		goto error;
460 460
 	}
461
-	
461
+
462 462
 	lock_get( mt_lock );
463 463
 	mt_tree_refcnt--;
464 464
 	lock_release( mt_lock );
... ...
@@ -540,8 +540,8 @@ static int mt_load_db(str *tname)
540 540
 		}
541 541
 	} else {
542 542
 		if((ret=mt_dbf.query(db_con, NULL, NULL, NULL, db_cols,
543
-				0, 2, 0, &db_res))!=0
544
-			|| RES_ROW_N(db_res)<=0 )
543
+						0, 2, 0, &db_res))!=0
544
+				|| RES_ROW_N(db_res)<=0 )
545 545
 		{
546 546
 			mt_dbf.free_result(db_con, db_res);
547 547
 			if( ret==0)
... ...
@@ -559,23 +559,23 @@ static int mt_load_db(str *tname)
559 559
 			/* check for NULL values ?!?! */
560 560
 			tprefix.s = (char*)(RES_ROWS(db_res)[i].values[0].val.string_val);
561 561
 			tprefix.len = strlen(tprefix.s);
562
-			
562
+
563 563
 			tvalue.s = (char*)(RES_ROWS(db_res)[i].values[1].val.string_val);
564 564
 			tvalue.len = strlen(tvalue.s);
565 565
 
566 566
 			if(tprefix.s==NULL || tvalue.s==NULL
567 567
 					|| tprefix.len<=0 || tvalue.len<=0)
568 568
 			{
569
-				LM_ERR("Error - bad values in db\n");
569
+				LM_ERR("Error - bad values in db (%p:%p)\n", tprefix.s, tvalue.s);
570 570
 				continue;
571 571
 			}
572
-		
572
+
573 573
 			if(mt_add_to_tree(&new_tree, &tprefix, &tvalue)<0)
574 574
 			{
575 575
 				LM_ERR("Error adding info to tree\n");
576 576
 				goto error;
577 577
 			}
578
-	 	}
578
+		}
579 579
 		if (DB_CAPABILITY(mt_dbf, DB_CAP_FETCH)) {
580 580
 			if(mt_dbf.fetch_result(db_con, &db_res, mt_fetch_rows)<0) {
581 581
 				LM_ERR("Error while fetching!\n");
... ...
@@ -663,8 +663,8 @@ static int mt_load_db_trees()
663 663
 		}
664 664
 	} else {
665 665
 		if((ret=mt_dbf.query(db_con, NULL, NULL, NULL, db_cols,
666
-				0, 3, &tname_column, &db_res))!=0
667
-			|| RES_ROW_N(db_res)<=0 )
666
+						0, 3, &tname_column, &db_res))!=0
667
+				|| RES_ROW_N(db_res)<=0 )
668 668
 		{
669 669
 			mt_dbf.free_result(db_con, db_res);
670 670
 			if( ret==0)
... ...
@@ -690,7 +690,7 @@ static int mt_load_db_trees()
690 690
 			tvalue.len = strlen(tvalue.s);
691 691
 
692 692
 			if(tprefix.s==NULL || tvalue.s==NULL || tname.s==NULL ||
693
-				tprefix.len<=0 || tvalue.len<=0 || tname.len<=0)
693
+					tprefix.len<=0 || tvalue.len<=0 || tname.len<=0)
694 694
 			{
695 695
 				LM_ERR("Error - bad values in db\n");
696 696
 				continue;
... ...
@@ -787,12 +787,12 @@ static struct mi_root* mt_mi_reload(struct mi_root *cmd_tree, void *param)
787 787
 		}
788 788
 
789 789
 		pt = mt_get_first_tree();
790
-	
790
+
791 791
 		while(pt!=NULL)
792 792
 		{
793 793
 			if(tname.s==NULL
794
-				|| (tname.s!=NULL && pt->tname.len>=tname.len
795
-					&& strncmp(pt->tname.s, tname.s, tname.len)==0))
794
+					|| (tname.s!=NULL && pt->tname.len>=tname.len
795
+						&& strncmp(pt->tname.s, tname.s, tname.len)==0))
796 796
 			{
797 797
 				/* re-loading table from database */
798 798
 				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)
804 804
 			pt = pt->next;
805 805
 		}
806 806
 	}
807
-	
807
+
808 808
 	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
809 809
 
810 810
 error:
... ...
@@ -823,7 +823,7 @@ int mt_print_mi_node(m_tree_t *tree, mt_node_t *pt, struct mi_node* rpl,
823 823
 
824 824
 	if(pt==NULL || len>=MT_MAX_DEPTH)
825 825
 		return 0;
826
-	
826
+
827 827
 	for(i=0; i<MT_NODE_SIZE; i++)
828 828
 	{
829 829
 		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,
838 838
 			if(attr == NULL)
839 839
 				goto error;
840 840
 			attr = add_mi_attr(node, MI_DUP_VALUE, "TPREFIX", 7,
841
-						code, len+1);
841
+					code, len+1);
842 842
 			if(attr == NULL)
843 843
 				goto error;
844 844
 
845 845
 			while (tvalues != NULL) {
846
-			    if (tree->type == MT_TREE_IVAL) {
847
-				val.s = int2str(tvalues->tvalue.n, &val.len);
848
-				attr = add_mi_attr(node, MI_DUP_VALUE, "TVALUE", 6,
849
-						   val.s, val.len);
850
-			    } else {
851
-				attr = add_mi_attr(node, MI_DUP_VALUE, "TVALUE", 6,
852
-						   tvalues->tvalue.s.s,
853
-						   tvalues->tvalue.s.len);
854
-			    }
855
-			    if(attr == NULL)
856
-				goto error;
857
-			    tvalues = tvalues->next;
846
+				if (tree->type == MT_TREE_IVAL) {
847
+					val.s = int2str(tvalues->tvalue.n, &val.len);
848
+					attr = add_mi_attr(node, MI_DUP_VALUE, "TVALUE", 6,
849
+							val.s, val.len);
850
+				} else {
851
+					attr = add_mi_attr(node, MI_DUP_VALUE, "TVALUE", 6,
852
+							tvalues->tvalue.s.s,
853
+							tvalues->tvalue.s.len);
854
+				}
855
+				if(attr == NULL)
856
+					goto error;
857
+				tvalues = tvalues->next;
858 858
 			}
859 859
 		}
860 860
 		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)
909 909
 	rpl = &rpl_tree->node;
910 910
 
911 911
 	pt = mt_get_first_tree();
912
-	
912
+
913 913
 	while(pt!=NULL)
914 914
 	{
915 915
 		if(tname.s==NULL || 
916
-			(tname.s!=NULL && pt->tname.len>=tname.len && 
917
-			 strncmp(pt->tname.s, tname.s, tname.len)==0))
916
+				(tname.s!=NULL && pt->tname.len>=tname.len && 
917
+				 strncmp(pt->tname.s, tname.s, tname.len)==0))
918 918
 		{
919 919
 			len = 0;
920 920
 			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)
922 922
 		}
923 923
 		pt = pt->next;
924 924
 	}
925
-	
925
+
926 926
 	return rpl_tree;
927 927
 
928 928
 error:
... ...
@@ -961,7 +961,7 @@ struct mi_root* mt_mi_summary(struct mi_root* cmd_tree, void* param)
961 961
 			goto error;
962 962
 		val.s = int2str(pt->type, &val.len);
963 963
 		attr = add_mi_attr(node, MI_DUP_VALUE, "TTYPE", 5,
964
-				   val.s, val.len);
964
+				val.s, val.len);
965 965
 		if(attr == NULL)
966 966
 			goto error;
967 967
 		val.s = int2str(pt->memsize, &val.len);
... ...
@@ -998,7 +998,7 @@ void rpc_mtree_summary(rpc_t* rpc, void* c)
998 998
 	if(!mt_defined_trees())
999 999
 	{
1000 1000
 		rpc->fault(c, 500, "Empty tree list.");
1001
-                return;
1001
+		return;
1002 1002
 	}
1003 1003
 
1004 1004
 	if (rpc->add(c, "{", &th) < 0)
... ...
@@ -1011,29 +1011,29 @@ void rpc_mtree_summary(rpc_t* rpc, void* c)
1011 1011
 	while(pt!=NULL)
1012 1012
 	{
1013 1013
 		if(rpc->struct_add(th, "s{",
1014
-				"table", pt->tname.s,
1015
-				"item", &ih) < 0)
1016
-			{
1017
-				rpc->fault(c, 500, "Internal error creating rpc ih");
1018
-				return;
1019
-			}
1014
+					"table", pt->tname.s,
1015
+					"item", &ih) < 0)
1016
+		{
1017
+			rpc->fault(c, 500, "Internal error creating rpc ih");
1018
+			return;
1019
+		}
1020 1020
 
1021 1021
 		if(rpc->struct_add(ih, "d", "ttype", pt->type) < 0 ) {
1022
-                                rpc->fault(c, 500, "Internal error adding type");
1023
-                                return;
1024
-                }
1022
+			rpc->fault(c, 500, "Internal error adding type");
1023
+			return;
1024
+		}
1025 1025
 		if(rpc->struct_add(ih, "d", "memsize", pt->memsize) < 0 ) {
1026
-                                rpc->fault(c, 500, "Internal error adding memsize");
1027
-                                return;
1028
-                }
1026
+			rpc->fault(c, 500, "Internal error adding memsize");
1027
+			return;
1028
+		}
1029 1029
 		if(rpc->struct_add(ih, "d", "nrnodes", pt->nrnodes) < 0 ) {
1030
-                                rpc->fault(c, 500, "Internal error adding nodes");
1031
-                                return;
1032
-                }
1030
+			rpc->fault(c, 500, "Internal error adding nodes");
1031
+			return;
1032
+		}
1033 1033
 		if(rpc->struct_add(ih, "d", "nritems", pt->nritems) < 0 ) {
1034
-                                rpc->fault(c, 500, "Internal error adding items");
1035
-                                return;
1036
-                }
1034
+			rpc->fault(c, 500, "Internal error adding items");
1035
+			return;
1036
+		}
1037 1037
 		pt = pt->next;
1038 1038
 	}
1039 1039
 	return;
... ...
@@ -1066,17 +1066,17 @@ void rpc_mtree_reload(rpc_t* rpc, void* c)
1066 1066
 
1067 1067
 		/* read tree name */
1068 1068
 		if (rpc->scan(c, "S", &tname) != 1) {
1069
-		    rpc->fault(c, 500, "Failed to get table name parameter");
1070
-		    return;
1069
+			rpc->fault(c, 500, "Failed to get table name parameter");
1070
+			return;
1071 1071
 		}
1072 1072
 
1073 1073
 		pt = mt_get_first_tree();
1074
-	
1074
+
1075 1075
 		while(pt!=NULL)
1076 1076
 		{
1077 1077
 			if(tname.s==NULL
1078
-				|| (tname.s!=NULL && pt->tname.len>=tname.len
1079
-					&& strncmp(pt->tname.s, tname.s, tname.len)==0))
1078
+					|| (tname.s!=NULL && pt->tname.len>=tname.len
1079
+						&& strncmp(pt->tname.s, tname.s, tname.len)==0))
1080 1080
 			{
1081 1081
 				/* re-loading table from database */
1082 1082
 				if(mt_load_db(&pt->tname)!=0)
... ...
@@ -1088,7 +1088,7 @@ void rpc_mtree_reload(rpc_t* rpc, void* c)
1088 1088
 			pt = pt->next;
1089 1089
 		}
1090 1090
 	}
1091
-	
1091
+
1092 1092
 	return;
1093 1093
 
1094 1094
 error:
... ...
@@ -1096,8 +1096,8 @@ error:
1096 1096
 }
1097 1097
 
1098 1098
 static const char* rpc_mtree_reload_doc[2] = {
1099
-    "Reload mtrees from database to memory",
1100
-    0
1099
+	"Reload mtrees from database to memory",
1100
+	0
1101 1101
 };
1102 1102
 
1103 1103
 rpc_export_t mtree_rpc[] = {