Index: extensions/rt_ereg/rtereg.c
===================================================================
--- extensions/rt_ereg/rtereg.c	(revision 1338)
+++ extensions/rt_ereg/rtereg.c	(revision 1387)
@@ -94,5 +94,5 @@
 		struct fd_list * c;
 
-		TRACE_DEBUG(ANNOYING, "Attempt pattern matching of '%.*s' with rule '%s'", (int)len, value, r->pattern);
+		LOG_D("[rt_ereg] attempting pattern matching of '%.*s' with rule '%s'", (int)len, value, r->pattern);
 
 		#ifdef HAVE_REG_STARTEND
@@ -119,5 +119,5 @@
 
 			/* Error while compiling the regex */
-			TRACE_DEBUG(INFO, "Error while executing the regular expression '%s':", r->pattern);
+			LOG_E("[rt_ereg] error while executing the regular expression '%s':", r->pattern);
 
 			/* Get the error message size */
@@ -129,5 +129,5 @@
 			/* Get the error message content */
 			regerror(err, &r->preg, errstr, bl);
-			TRACE_DEBUG(INFO, "\t%s", errstr);
+			LOG_E("\t%s", errstr);
 
 			/* Free the buffer, return the error */
@@ -138,10 +138,5 @@
 
 		/* From this point, the expression matched the AVP value */
-		TRACE_DEBUG(FULL, "[rt_ereg] Match: '%s' to value '%.*s' => '%s' += %d",
-					r->pattern,
-					(int)len,
-					value,
-					r->server,
-					r->score);
+		LOG_D("[rt_ereg] Match: '%s' to value '%.*s' => '%s' += %d", r->pattern, (int)len, value, r->server, r->score);
 
 		for (c = candidates->next; c != candidates; c = c->next) {
@@ -168,5 +163,5 @@
 //	for (i = 0; i<rtereg_conf[j].level; i++) {
 	if (level > rtereg_conf[conf_index].level) {
-		TRACE_DEBUG(INFO, "internal error, dug too deep");
+		LOG_E("internal error, dug too deep");
 		return 1;
 	}
@@ -179,9 +174,13 @@
 		if ((avp_hdr->avp_code == dictdata.avp_code) && (avp_hdr->avp_vendor == dictdata.avp_vendor)) {
 			if (level != rtereg_conf[conf_index].level - 1) {
-				TRACE_DEBUG(INFO, "[rt_ereg] found grouped AVP %d (vendor %d), digging deeper", avp_hdr->avp_code, avp_hdr->avp_vendor);
+				LOG_D("[rt_ereg] found grouped AVP %d (vendor %d), digging deeper", avp_hdr->avp_code, avp_hdr->avp_vendor);
 				CHECK_FCT(find_avp(nextavp, conf_index, level+1, candidates));
 			} else {
-				TRACE_DEBUG(INFO, "[rt_ereg] found AVP %d (vendor %d)", avp_hdr->avp_code, avp_hdr->avp_vendor);
+				struct dictionary * dict;
+				LOG_D("[rt_ereg] found AVP %d (vendor %d)", avp_hdr->avp_code, avp_hdr->avp_vendor);
+				CHECK_FCT(fd_dict_getdict(what, &dict));
+				CHECK_FCT_DO(fd_msg_parse_dict(nextavp, dict, NULL), /* nothing */);
 				if (avp_hdr->avp_value != NULL) {
+					LOG_A("avp_hdr->avp_value NOT NULL, matching");
 #ifndef HAVE_REG_STARTEND
 					int ret;
@@ -224,5 +223,5 @@
 	int j, ret;
 
-	TRACE_ENTRY("%p %p %p", cbdata, *pmsg, candidates);
+	LOG_A("[rt_ereg] rtereg_out arguments: %p %p %p", cbdata, *pmsg, candidates);
 
 	CHECK_PARAMS(pmsg && *pmsg && candidates);
@@ -239,5 +238,5 @@
 		for (j=0; j<rtereg_conf_size; j++) {
 			where = *pmsg;
-			TRACE_DEBUG(INFO, "[rt_ereg] iterating over AVP group %d", j);
+			LOG_D("[rt_ereg] iterating over AVP group %d", j);
 			if ((ret=find_avp(where, j, 0, candidates)) != 0) {
 				break;
@@ -302,10 +301,10 @@
 static int rtereg_entry(char * conffile)
 {
-	TRACE_ENTRY("%p", conffile);
+	LOG_A("[rt_ereg] started with conffile '%p'", conffile);
 
 	rt_ereg_config_file = conffile;
 
 	if (rtereg_init() != 0) {
-	    return 1;
+		return 1;
 	}
 
@@ -322,6 +321,6 @@
 	/* Initialize the configuration */
 	if ((rtereg_conf=malloc(sizeof(*rtereg_conf))) == NULL) {
-	    TRACE_DEBUG(INFO, "malloc failured");
-	    return 1;
+		LOG_E("[rt_ereg] malloc failured");
+		return 1;
 	}
 	rtereg_conf_size = 1;
@@ -367,17 +366,25 @@
 static void rtereg_fini(void)
 {
-	TRACE_ENTRY();
-
 	/* Unregister the cb */
 	CHECK_FCT_DO( fd_rt_out_unregister ( rtereg_hdl, NULL ), /* continue */ );
 
+#ifndef HAVE_REG_STARTEND
+	free(buf);
+	buf = NULL;
+#endif /* HAVE_REG_STARTEND */
+
+	if (pthread_rwlock_wrlock(&rte_lock) != 0) {
+		fd_log_error("%s: write-locking failed in fini, giving up", MODULE_NAME);
+		return;
+	}
 	/* Destroy the data */
 	rtereg_conf_free(rtereg_conf, rtereg_conf_size);
 	rtereg_conf = NULL;
 	rtereg_conf_size = 0;
-#ifndef HAVE_REG_STARTEND
-	free(buf);
-	buf = NULL;
-#endif /* HAVE_REG_STARTEND */
+
+	if (pthread_rwlock_unlock(&rte_lock) != 0) {
+		fd_log_error("%s: write-unlocking failed in fini", MODULE_NAME);
+		return;
+	}
 
 	/* Done */
Index: extensions/rt_ereg/rtereg_conf.l
===================================================================
--- extensions/rt_ereg/rtereg_conf.l	(revision 1127)
+++ extensions/rt_ereg/rtereg_conf.l	(revision 1387)
@@ -81,5 +81,5 @@
 				CHECK_MALLOC_DO( yylval->string = strdup(yytext+1), 
 				{
-					TRACE_DEBUG(INFO, "Unable to copy the string '%s': %s", yytext, strerror(errno));
+					LOG_E("[rt_ereg] unable to copy the string '%s': %s", yytext, strerror(errno));
 					return LEX_ERROR; /* trig an error in yacc parser */
 				} );
Index: extensions/rt_ereg/rtereg_conf.y
===================================================================
--- extensions/rt_ereg/rtereg_conf.y	(revision 1342)
+++ extensions/rt_ereg/rtereg_conf.y	(revision 1387)
@@ -62,7 +62,5 @@
 	int ret;
 
-	TRACE_ENTRY("%p", conffile);
-
-	TRACE_DEBUG (FULL, "Parsing configuration file: %s...", conffile);
+	LOG_D("[rt_ereg] parsing configuration file '%s'", conffile);
 
 	rtereg_confin = fopen(conffile, "r");
@@ -70,5 +68,5 @@
 		ret = errno;
 		fd_log_debug("Unable to open extension configuration file %s for reading: %s", conffile, strerror(ret));
-		TRACE_DEBUG (INFO, "rt_ereg: error occurred, message logged -- configuration file.");
+		LOG_E("[rt_ereg] error occurred, message logged -- configuration file.");
 		return ret;
 	}
@@ -80,10 +78,10 @@
 
 	if (rtereg_conf[rtereg_conf_size-1].finished == 0) {
-		TRACE_DEBUG(INFO, "rt_ereg: configuration invalid, AVP ended without OCTETSTRING AVP");
+		LOG_E("[rt_ereg] configuration invalid, AVP ended without OCTETSTRING AVP");
 		return EINVAL;
 	}
 
 	if (ret != 0) {
-		TRACE_DEBUG(INFO, "rt_ereg: unable to parse the configuration file.");
+		LOG_E("[rt_ereg] unable to parse the configuration file.");
 		return EINVAL;
 	} else {
@@ -92,5 +90,5 @@
 			sum += rtereg_conf[i].rules_nb;
 		}
-		TRACE_DEBUG(FULL, "[rt-ereg] Added %d rules successfully.", sum);
+		LOG_D("[rt-ereg] Added %d rules successfully.", sum);
 	}
 
@@ -105,5 +103,5 @@
 	if (rtereg_conf[rtereg_conf_size-1].finished) {
 		if ((ret = realloc(rtereg_conf, sizeof(*rtereg_conf)*(rtereg_conf_size+1))) == NULL) {
-			TRACE_DEBUG(INFO, "rt_ereg: realloc failed");
+			LOG_E("[rt_ereg] realloc failed");
 			return -1;
 		}
@@ -111,10 +109,10 @@
 		rtereg_conf = ret;
 		memset(&rtereg_conf[rtereg_conf_size-1], 0, sizeof(*rtereg_conf));
-		TRACE_DEBUG(INFO, "rt_ereg: New AVP group found starting with %s", name);
+		LOG_D("[rt_ereg] New AVP group found starting with %s", name);
 	}
 	level = rtereg_conf[rtereg_conf_size-1].level + 1;
 
 	if ((ret = realloc(rtereg_conf[rtereg_conf_size-1].avps, sizeof(*rtereg_conf[rtereg_conf_size-1].avps)*level)) == NULL) {
-		TRACE_DEBUG(INFO, "rt_ereg: realloc failed");
+		LOG_E("[rt_ereg] realloc failed");
 		return -1;
 	}
@@ -123,5 +121,5 @@
 	CHECK_FCT_DO( fd_dict_search ( fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME_ALL_VENDORS, name, &rtereg_conf[rtereg_conf_size-1].avps[level-1], ENOENT ),
 		      {
-			      TRACE_DEBUG(INFO, "rt_ereg: Unable to find '%s' AVP in the loaded dictionaries.", name);
+			      LOG_E("[rt_ereg] Unable to find '%s' AVP in the loaded dictionaries.", name);
 			      return -1;
 		      } );
@@ -134,5 +132,5 @@
 			rtereg_conf[rtereg_conf_size-1].finished = 1;
 		} else if (data.avp_basetype != AVP_TYPE_GROUPED) {
-			TRACE_DEBUG(INFO, "rt_ereg: '%s' AVP is not an OCTETSTRING nor GROUPED AVP (%d).", name, data.avp_basetype);
+			LOG_E("[rt_ereg] '%s' AVP is not an OCTETSTRING nor GROUPED AVP (%d).", name, data.avp_basetype);
 			return -1;
 		}
@@ -148,5 +146,5 @@
 void yyerror (YYLTYPE *ploc, char * conffile, char const *s)
 {
-	TRACE_DEBUG(INFO, "rt_ereg: error in configuration parsing");
+	LOG_E("[rt_ereg] error in configuration parsing");
 
 	if (ploc->first_line != ploc->last_line)
@@ -223,5 +221,5 @@
 
 						/* Error while compiling the regex */
-						TRACE_DEBUG(INFO, "rt_ereg: error while compiling the regular expression '%s':", new->pattern);
+						LOG_E("[rt_ereg] error while compiling the regular expression '%s':", new->pattern);
 
 						/* Get the error message size */
@@ -233,5 +231,5 @@
 						/* Get the error message content */
 						regerror(err, &new->preg, buf, bl);
-						TRACE_DEBUG(INFO, "\t%s", buf);
+						LOG_E("\t%s", buf);
 
 						/* Free the buffer, return the error */
