Browse Source

drouting: clang format the source code

Daniel-Constantin Mierla 7 years ago
parent
commit
e76a0acfcc

+ 217 - 211
src/modules/drouting/dr_load.c

@@ -41,12 +41,12 @@
 #include "parse.h"
 #include "parse.h"
 
 
 
 
-#define DST_ID_DRD_COL   "gwid"
-#define ADDRESS_DRD_COL  "address"
-#define STRIP_DRD_COL    "strip"
-#define PREFIX_DRD_COL   "pri_prefix"
-#define TYPE_DRD_COL     "type"
-#define ATTRS_DRD_COL    "attrs"
+#define DST_ID_DRD_COL "gwid"
+#define ADDRESS_DRD_COL "address"
+#define STRIP_DRD_COL "strip"
+#define PREFIX_DRD_COL "pri_prefix"
+#define TYPE_DRD_COL "type"
+#define ATTRS_DRD_COL "attrs"
 static str dst_id_drd_col = str_init(DST_ID_DRD_COL);
 static str dst_id_drd_col = str_init(DST_ID_DRD_COL);
 static str address_drd_col = str_init(ADDRESS_DRD_COL);
 static str address_drd_col = str_init(ADDRESS_DRD_COL);
 static str strip_drd_col = str_init(STRIP_DRD_COL);
 static str strip_drd_col = str_init(STRIP_DRD_COL);
@@ -54,13 +54,13 @@ static str prefix_drd_col = str_init(PREFIX_DRD_COL);
 static str type_drd_col = str_init(TYPE_DRD_COL);
 static str type_drd_col = str_init(TYPE_DRD_COL);
 static str attrs_drd_col = str_init(ATTRS_DRD_COL);
 static str attrs_drd_col = str_init(ATTRS_DRD_COL);
 
 
-#define RULE_ID_DRR_COL   "ruleid"
-#define GROUP_DRR_COL     "groupid"
-#define PREFIX_DRR_COL    "prefix"
-#define TIME_DRR_COL      "timerec"
-#define PRIORITY_DRR_COL  "priority"
-#define ROUTEID_DRR_COL   "routeid"
-#define DSTLIST_DRR_COL   "gwlist"
+#define RULE_ID_DRR_COL "ruleid"
+#define GROUP_DRR_COL "groupid"
+#define PREFIX_DRR_COL "prefix"
+#define TIME_DRR_COL "timerec"
+#define PRIORITY_DRR_COL "priority"
+#define ROUTEID_DRR_COL "routeid"
+#define DSTLIST_DRR_COL "gwlist"
 static str rule_id_drr_col = str_init(RULE_ID_DRR_COL);
 static str rule_id_drr_col = str_init(RULE_ID_DRR_COL);
 static str group_drr_col = str_init(GROUP_DRR_COL);
 static str group_drr_col = str_init(GROUP_DRR_COL);
 static str prefix_drr_col = str_init(PREFIX_DRR_COL);
 static str prefix_drr_col = str_init(PREFIX_DRR_COL);
@@ -69,59 +69,61 @@ static str priority_drr_col = str_init(PRIORITY_DRR_COL);
 static str routeid_drr_col = str_init(ROUTEID_DRR_COL);
 static str routeid_drr_col = str_init(ROUTEID_DRR_COL);
 static str dstlist_drr_col = str_init(DSTLIST_DRR_COL);
 static str dstlist_drr_col = str_init(DSTLIST_DRR_COL);
 
 
-#define ID_DRL_COL     "id"
+#define ID_DRL_COL "id"
 #define GWLIST_DRL_CAL "gwlist"
 #define GWLIST_DRL_CAL "gwlist"
 static str id_drl_col = str_init(ID_DRL_COL);
 static str id_drl_col = str_init(ID_DRL_COL);
 static str gwlist_drl_col = str_init(GWLIST_DRL_CAL);
 static str gwlist_drl_col = str_init(GWLIST_DRL_CAL);
 
 
-struct dr_gwl_tmp {
+struct dr_gwl_tmp
+{
 	unsigned int id;
 	unsigned int id;
 	char *gwlist;
 	char *gwlist;
 	struct dr_gwl_tmp *next;
 	struct dr_gwl_tmp *next;
 };
 };
 
 
 
 
-static struct dr_gwl_tmp* dr_gw_lists = NULL;
-
-#define check_val( _val, _type, _not_null, _is_empty_str) \
-	do{\
-		if ((_val)->type!=_type) { \
-			LM_ERR("bad colum type\n");\
-			goto error;\
-		} \
-		if (_not_null && (_val)->nul) { \
-			LM_ERR("nul column\n");\
-			goto error;\
-		} \
-		if (_is_empty_str && VAL_STRING(_val)==0) { \
-			LM_ERR("empty str column\n");\
-			goto error;\
-		} \
-	}while(0)
+static struct dr_gwl_tmp *dr_gw_lists = NULL;
+
+#define check_val(_val, _type, _not_null, _is_empty_str) \
+	do {                                                 \
+		if((_val)->type != _type) {                      \
+			LM_ERR("bad colum type\n");                  \
+			goto error;                                  \
+		}                                                \
+		if(_not_null && (_val)->nul) {                   \
+			LM_ERR("nul column\n");                      \
+			goto error;                                  \
+		}                                                \
+		if(_is_empty_str && VAL_STRING(_val) == 0) {     \
+			LM_ERR("empty str column\n");                \
+			goto error;                                  \
+		}                                                \
+	} while(0)
 
 
 
 
 #define TR_SEPARATOR '|'
 #define TR_SEPARATOR '|'
 
 
-#define load_TR_value( _p,_s, _tr, _func, _err, _done) \
-	do{ \
-		_s = strchr(_p, (int)TR_SEPARATOR); \
-		if (_s) \
-			*_s = 0; \
-		/*DBG("----parsing tr param <%s>\n",_p);*/\
-		if(_s != _p) {\
-			if( _func( _tr, _p)) {\
-				if (_s) *_s = TR_SEPARATOR; \
-				goto _err; \
-			} \
-		} \
-		if (_s) { \
-			*_s = TR_SEPARATOR; \
-			_p = _s+1;\
-			if ( *(_p)==0 ) \
-				goto _done; \
-		} else {\
-			goto _done; \
-		}\
+#define load_TR_value(_p, _s, _tr, _func, _err, _done) \
+	do {                                               \
+		_s = strchr(_p, (int)TR_SEPARATOR);            \
+		if(_s)                                         \
+			*_s = 0;                                   \
+		/*DBG("----parsing tr param <%s>\n",_p);*/     \
+		if(_s != _p) {                                 \
+			if(_func(_tr, _p)) {                       \
+				if(_s)                                 \
+					*_s = TR_SEPARATOR;                \
+				goto _err;                             \
+			}                                          \
+		}                                              \
+		if(_s) {                                       \
+			*_s = TR_SEPARATOR;                        \
+			_p = _s + 1;                               \
+			if(*(_p) == 0)                             \
+				goto _done;                            \
+		} else {                                       \
+			goto _done;                                \
+		}                                              \
 	} while(0)
 	} while(0)
 
 
 extern int dr_fetch_rows;
 extern int dr_fetch_rows;
@@ -134,13 +136,13 @@ static int add_tmp_gw_list(unsigned int id, char *list)
 	unsigned int list_len;
 	unsigned int list_len;
 
 
 	list_len = strlen(list) + 1;
 	list_len = strlen(list) + 1;
-	tmp = (struct dr_gwl_tmp*)pkg_malloc(sizeof(struct dr_gwl_tmp) + list_len);
-	if (tmp==NULL) {
+	tmp = (struct dr_gwl_tmp *)pkg_malloc(sizeof(struct dr_gwl_tmp) + list_len);
+	if(tmp == NULL) {
 		LM_ERR("no more pkg mem\n");
 		LM_ERR("no more pkg mem\n");
 		return -1;
 		return -1;
 	}
 	}
 	tmp->id = id;
 	tmp->id = id;
-	tmp->gwlist = (char*)(tmp+1);
+	tmp->gwlist = (char *)(tmp + 1);
 	memcpy(tmp->gwlist, list, list_len);
 	memcpy(tmp->gwlist, list, list_len);
 
 
 	tmp->next = dr_gw_lists;
 	tmp->next = dr_gw_lists;
@@ -148,12 +150,13 @@ static int add_tmp_gw_list(unsigned int id, char *list)
 	return 0;
 	return 0;
 }
 }
 
 
-static char* get_tmp_gw_list(unsigned int id)
+static char *get_tmp_gw_list(unsigned int id)
 {
 {
 	struct dr_gwl_tmp *tmp;
 	struct dr_gwl_tmp *tmp;
 
 
-	for( tmp=dr_gw_lists ; tmp ; tmp=tmp->next )
-		if (tmp->id == id) return tmp->gwlist;
+	for(tmp = dr_gw_lists; tmp; tmp = tmp->next)
+		if(tmp->id == id)
+			return tmp->gwlist;
 	return NULL;
 	return NULL;
 }
 }
 
 
@@ -161,7 +164,7 @@ static void free_tmp_gw_list(void)
 {
 {
 	struct dr_gwl_tmp *tmp, *tmp1;
 	struct dr_gwl_tmp *tmp, *tmp1;
 
 
-	for( tmp=dr_gw_lists ; tmp ; ) {
+	for(tmp = dr_gw_lists; tmp;) {
 		tmp1 = tmp;
 		tmp1 = tmp;
 		tmp = tmp->next;
 		tmp = tmp->next;
 		pkg_free(tmp1);
 		pkg_free(tmp1);
@@ -170,88 +173,88 @@ static void free_tmp_gw_list(void)
 }
 }
 
 
 
 
-static inline tmrec_t* parse_time_def(char *time_str)
+static inline tmrec_t *parse_time_def(char *time_str)
 {
 {
 	tmrec_t *time_rec;
 	tmrec_t *time_rec;
-	char *p,*s;
+	char *p, *s;
 
 
 	p = time_str;
 	p = time_str;
 	time_rec = 0;
 	time_rec = 0;
 
 
-	time_rec = (tmrec_t*)shm_malloc(sizeof(tmrec_t));
-	if (time_rec==0) {
+	time_rec = (tmrec_t *)shm_malloc(sizeof(tmrec_t));
+	if(time_rec == 0) {
 		LM_ERR("no more pkg mem\n");
 		LM_ERR("no more pkg mem\n");
 		goto error;
 		goto error;
 	}
 	}
-	memset( time_rec, 0, sizeof(tmrec_t));
+	memset(time_rec, 0, sizeof(tmrec_t));
 
 
 	/* empty definition? */
 	/* empty definition? */
-	if ( time_str==0 || *time_str==0 )
+	if(time_str == 0 || *time_str == 0)
 		goto done;
 		goto done;
 
 
-	load_TR_value( p, s, time_rec, tr_parse_dtstart, parse_error, done);
-	load_TR_value( p, s, time_rec, tr_parse_duration, parse_error, done);
-	load_TR_value( p, s, time_rec, tr_parse_freq, parse_error, done);
-	load_TR_value( p, s, time_rec, tr_parse_until, parse_error, done);
-	load_TR_value( p, s, time_rec, tr_parse_interval, parse_error, done);
-	load_TR_value( p, s, time_rec, tr_parse_byday, parse_error, done);
-	load_TR_value( p, s, time_rec, tr_parse_bymday, parse_error, done);
-	load_TR_value( p, s, time_rec, tr_parse_byyday, parse_error, done);
-	load_TR_value( p, s, time_rec, tr_parse_byweekno, parse_error, done);
-	load_TR_value( p, s, time_rec, tr_parse_bymonth, parse_error, done);
-
-	/* success */
+	load_TR_value(p, s, time_rec, tr_parse_dtstart, parse_error, done);
+	load_TR_value(p, s, time_rec, tr_parse_duration, parse_error, done);
+	load_TR_value(p, s, time_rec, tr_parse_freq, parse_error, done);
+	load_TR_value(p, s, time_rec, tr_parse_until, parse_error, done);
+	load_TR_value(p, s, time_rec, tr_parse_interval, parse_error, done);
+	load_TR_value(p, s, time_rec, tr_parse_byday, parse_error, done);
+	load_TR_value(p, s, time_rec, tr_parse_bymday, parse_error, done);
+	load_TR_value(p, s, time_rec, tr_parse_byyday, parse_error, done);
+	load_TR_value(p, s, time_rec, tr_parse_byweekno, parse_error, done);
+	load_TR_value(p, s, time_rec, tr_parse_bymonth, parse_error, done);
+
+/* success */
 done:
 done:
 	return time_rec;
 	return time_rec;
 parse_error:
 parse_error:
-	LM_ERR("parse error in <%s> around position %i\n",
-		time_str, (int)(long)(p-time_str));
+	LM_ERR("parse error in <%s> around position %i\n", time_str,
+			(int)(long)(p - time_str));
 error:
 error:
-	if (time_rec)
-		tmrec_free( time_rec );
+	if(time_rec)
+		tmrec_free(time_rec);
 	return 0;
 	return 0;
 }
 }
 
 
 
 
-static int add_rule(rt_data_t *rdata, char *grplst, str *prefix, rt_info_t *rule)
+static int add_rule(
+		rt_data_t *rdata, char *grplst, str *prefix, rt_info_t *rule)
 {
 {
 	long int t;
 	long int t;
 	char *tmp;
 	char *tmp;
 	char *ep;
 	char *ep;
 	int n;
 	int n;
 
 
-	tmp=grplst;
-	n=0;
+	tmp = grplst;
+	n = 0;
 	/* parse the grplst */
 	/* parse the grplst */
-	while(tmp && (*tmp!=0)) {
+	while(tmp && (*tmp != 0)) {
 		errno = 0;
 		errno = 0;
 		t = strtol(tmp, &ep, 10);
 		t = strtol(tmp, &ep, 10);
-		if (ep == tmp) {
-			LM_ERR("bad grp id '%c' (%d)[%s]\n",
-				*ep, (int)(ep-grplst), grplst);
+		if(ep == tmp) {
+			LM_ERR("bad grp id '%c' (%d)[%s]\n", *ep, (int)(ep - grplst),
+					grplst);
 			goto error;
 			goto error;
 		}
 		}
-		if ((!IS_SPACE(*ep)) && (*ep != SEP) && (*ep != SEP1) && (*ep!=0)) {
-			LM_ERR("bad char %c (%d) [%s]\n",
-					*ep, (int)(ep-grplst), grplst);
+		if((!IS_SPACE(*ep)) && (*ep != SEP) && (*ep != SEP1) && (*ep != 0)) {
+			LM_ERR("bad char %c (%d) [%s]\n", *ep, (int)(ep - grplst), grplst);
 			goto error;
 			goto error;
 		}
 		}
-		if (errno == ERANGE && (t== LONG_MAX || t== LONG_MIN)) {
+		if(errno == ERANGE && (t == LONG_MAX || t == LONG_MIN)) {
 			LM_ERR("out of bounds\n");
 			LM_ERR("out of bounds\n");
 			goto error;
 			goto error;
 		}
 		}
 		n++;
 		n++;
 		/* add rule -> has prefix? */
 		/* add rule -> has prefix? */
-		if (prefix->len) {
+		if(prefix->len) {
 			/* add the routing rule */
 			/* add the routing rule */
-			if ( add_prefix(rdata->pt, prefix, rule, (unsigned int)t)!=0 ) {
+			if(add_prefix(rdata->pt, prefix, rule, (unsigned int)t) != 0) {
 				LM_ERR("failed to add prefix route\n");
 				LM_ERR("failed to add prefix route\n");
-					goto error;
+				goto error;
 			}
 			}
 		} else {
 		} else {
-			if ( add_rt_info( &rdata->noprefix, rule, (unsigned int)t)!=0 ) {
+			if(add_rt_info(&rdata->noprefix, rule, (unsigned int)t) != 0) {
 				LM_ERR("failed to add prefixless route\n");
 				LM_ERR("failed to add prefixless route\n");
-					goto error;
+				goto error;
 			}
 			}
 		}
 		}
 		/* keep parsing */
 		/* keep parsing */
@@ -262,9 +265,8 @@ static int add_rule(rt_data_t *rdata, char *grplst, str *prefix, rt_info_t *rule
 		tmp = ep;
 		tmp = ep;
 	}
 	}
 
 
-	if(n==0) {
-		LM_ERR("no id in grp list [%s]\n",
-			grplst);
+	if(n == 0) {
+		LM_ERR("no id in grp list [%s]\n", grplst);
 		goto error;
 		goto error;
 	}
 	}
 
 
@@ -274,35 +276,35 @@ error:
 }
 }
 
 
 
 
-rt_data_t* dr_load_routing_info( db_func_t *dr_dbf, db1_con_t* db_hdl,
-							str *drd_table, str *drl_table, str* drr_table )
+rt_data_t *dr_load_routing_info(db_func_t *dr_dbf, db1_con_t *db_hdl,
+		str *drd_table, str *drl_table, str *drr_table)
 {
 {
-	int    int_vals[4];
-	char * str_vals[5];
+	int int_vals[4];
+	char *str_vals[5];
 	str tmp;
 	str tmp;
 	db_key_t columns[7];
 	db_key_t columns[7];
-	db1_res_t* res;
-	db_row_t* row;
+	db1_res_t *res;
+	db_row_t *row;
 	rt_info_t *ri;
 	rt_info_t *ri;
 	rt_data_t *rdata;
 	rt_data_t *rdata;
-	tmrec_t   *time_rec;
+	tmrec_t *time_rec;
 	unsigned int id;
 	unsigned int id;
 	str s_id;
 	str s_id;
-	int i,n;
+	int i, n;
 
 
 	res = 0;
 	res = 0;
 	ri = 0;
 	ri = 0;
 	rdata = 0;
 	rdata = 0;
 
 
 	/* init new data structure */
 	/* init new data structure */
-	if ( (rdata=build_rt_data())==0 ) {
+	if((rdata = build_rt_data()) == 0) {
 		LM_ERR("failed to build rdata\n");
 		LM_ERR("failed to build rdata\n");
 		goto error;
 		goto error;
 	}
 	}
 
 
 	/* read the destinations */
 	/* read the destinations */
-	if (dr_dbf->use_table( db_hdl, drd_table) < 0) {
-		LM_ERR("cannot select table \"%.*s\"\n", drd_table->len,drd_table->s);
+	if(dr_dbf->use_table(db_hdl, drd_table) < 0) {
+		LM_ERR("cannot select table \"%.*s\"\n", drd_table->len, drd_table->s);
 		goto error;
 		goto error;
 	}
 	}
 
 
@@ -313,138 +315,139 @@ rt_data_t* dr_load_routing_info( db_func_t *dr_dbf, db1_con_t* db_hdl,
 	columns[4] = &type_drd_col;
 	columns[4] = &type_drd_col;
 	columns[5] = &attrs_drd_col;
 	columns[5] = &attrs_drd_col;
 
 
-	if (DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {
-		if ( dr_dbf->query( db_hdl, 0, 0, 0, columns, 0, 6, 0, 0 ) < 0) {
+	if(DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {
+		if(dr_dbf->query(db_hdl, 0, 0, 0, columns, 0, 6, 0, 0) < 0) {
 			LM_ERR("DB query failed\n");
 			LM_ERR("DB query failed\n");
 			goto error;
 			goto error;
 		}
 		}
-		if(dr_dbf->fetch_result(db_hdl, &res, dr_fetch_rows)<0) {
+		if(dr_dbf->fetch_result(db_hdl, &res, dr_fetch_rows) < 0) {
 			LM_ERR("Error fetching rows\n");
 			LM_ERR("Error fetching rows\n");
 			goto error;
 			goto error;
 		}
 		}
 	} else {
 	} else {
-		if ( dr_dbf->query( db_hdl, 0, 0, 0, columns, 0, 6, 0, &res) < 0) {
+		if(dr_dbf->query(db_hdl, 0, 0, 0, columns, 0, 6, 0, &res) < 0) {
 			LM_ERR("DB query failed\n");
 			LM_ERR("DB query failed\n");
 			goto error;
 			goto error;
 		}
 		}
 	}
 	}
 
 
-	if (RES_ROW_N(res) == 0) {
-		LM_WARN("table \"%.*s\" empty\n", drd_table->len,drd_table->s );
+	if(RES_ROW_N(res) == 0) {
+		LM_WARN("table \"%.*s\" empty\n", drd_table->len, drd_table->s);
 	}
 	}
-	LM_DBG("%d records found in %.*s\n",
-		RES_ROW_N(res), drd_table->len,drd_table->s);
+	LM_DBG("%d records found in %.*s\n", RES_ROW_N(res), drd_table->len,
+			drd_table->s);
 	n = 0;
 	n = 0;
 	do {
 	do {
-		for(i=0; i < RES_ROW_N(res); i++) {
+		for(i = 0; i < RES_ROW_N(res); i++) {
 			row = RES_ROWS(res) + i;
 			row = RES_ROWS(res) + i;
 			/* DST_ID column */
 			/* DST_ID column */
-			check_val( ROW_VALUES(row), DB1_INT, 1, 0);
-			int_vals[0] = VAL_INT   (ROW_VALUES(row));
+			check_val(ROW_VALUES(row), DB1_INT, 1, 0);
+			int_vals[0] = VAL_INT(ROW_VALUES(row));
 			/* ADDRESS column */
 			/* ADDRESS column */
-			check_val( ROW_VALUES(row)+1, DB1_STRING, 1, 1);
-			str_vals[0] = (char*)VAL_STRING(ROW_VALUES(row)+1);
+			check_val(ROW_VALUES(row) + 1, DB1_STRING, 1, 1);
+			str_vals[0] = (char *)VAL_STRING(ROW_VALUES(row) + 1);
 			/* STRIP column */
 			/* STRIP column */
-			check_val( ROW_VALUES(row)+2, DB1_INT, 1, 0);
-			int_vals[1] = VAL_INT   (ROW_VALUES(row)+2);
+			check_val(ROW_VALUES(row) + 2, DB1_INT, 1, 0);
+			int_vals[1] = VAL_INT(ROW_VALUES(row) + 2);
 			/* PREFIX column */
 			/* PREFIX column */
-			check_val( ROW_VALUES(row)+3, DB1_STRING, 0, 0);
-			str_vals[1] = (char*)VAL_STRING(ROW_VALUES(row)+3);
+			check_val(ROW_VALUES(row) + 3, DB1_STRING, 0, 0);
+			str_vals[1] = (char *)VAL_STRING(ROW_VALUES(row) + 3);
 			/* TYPE column */
 			/* TYPE column */
-			check_val( ROW_VALUES(row)+4, DB1_INT, 1, 0);
-			int_vals[2] = VAL_INT(ROW_VALUES(row)+4);
+			check_val(ROW_VALUES(row) + 4, DB1_INT, 1, 0);
+			int_vals[2] = VAL_INT(ROW_VALUES(row) + 4);
 			/* ATTRS column */
 			/* ATTRS column */
-			check_val( ROW_VALUES(row)+5, DB1_STRING, 0, 0);
-			str_vals[2] = (char*)VAL_STRING(ROW_VALUES(row)+5);
+			check_val(ROW_VALUES(row) + 5, DB1_STRING, 0, 0);
+			str_vals[2] = (char *)VAL_STRING(ROW_VALUES(row) + 5);
 
 
 			/* add the destinaton definition in */
 			/* add the destinaton definition in */
-			if ( add_dst( rdata, int_vals[0], str_vals[0], int_vals[1],
-					str_vals[1], int_vals[2], str_vals[2])<0 ) {
+			if(add_dst(rdata, int_vals[0], str_vals[0], int_vals[1],
+					   str_vals[1], int_vals[2], str_vals[2])
+					< 0) {
 				LM_ERR("failed to add destination id %d -> skipping\n",
 				LM_ERR("failed to add destination id %d -> skipping\n",
-					int_vals[0]);
+						int_vals[0]);
 				continue;
 				continue;
 			}
 			}
 			n++;
 			n++;
 		}
 		}
-		if (DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {
-			if(dr_dbf->fetch_result(db_hdl, &res, dr_fetch_rows)<0) {
-				LM_ERR( "fetching rows (1)\n");
+		if(DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {
+			if(dr_dbf->fetch_result(db_hdl, &res, dr_fetch_rows) < 0) {
+				LM_ERR("fetching rows (1)\n");
 				goto error;
 				goto error;
 			}
 			}
 		} else {
 		} else {
 			break;
 			break;
 		}
 		}
-	} while(RES_ROW_N(res)>0);
+	} while(RES_ROW_N(res) > 0);
 
 
 	dr_dbf->free_result(db_hdl, res);
 	dr_dbf->free_result(db_hdl, res);
 	res = 0;
 	res = 0;
 
 
-	if (n==0) {
+	if(n == 0) {
 		LM_WARN("no valid "
 		LM_WARN("no valid "
-			"destinations set -> ignoring the routing rules\n");
+				"destinations set -> ignoring the routing rules\n");
 		return rdata;
 		return rdata;
 	}
 	}
 
 
 	/* read the gw lists, if any */
 	/* read the gw lists, if any */
-	if (dr_dbf->use_table( db_hdl, drl_table) < 0) {
-		LM_ERR("cannot select table \"%.*s\"\n", drl_table->len,drl_table->s);
+	if(dr_dbf->use_table(db_hdl, drl_table) < 0) {
+		LM_ERR("cannot select table \"%.*s\"\n", drl_table->len, drl_table->s);
 		goto error;
 		goto error;
 	}
 	}
 
 
 	columns[0] = &id_drl_col;
 	columns[0] = &id_drl_col;
 	columns[1] = &gwlist_drl_col;
 	columns[1] = &gwlist_drl_col;
 
 
-	if (DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {
-		if ( dr_dbf->query( db_hdl, 0, 0, 0, columns, 0, 2, 0, 0 ) < 0) {
+	if(DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {
+		if(dr_dbf->query(db_hdl, 0, 0, 0, columns, 0, 2, 0, 0) < 0) {
 			LM_ERR("DB query failed\n");
 			LM_ERR("DB query failed\n");
 			goto error;
 			goto error;
 		}
 		}
-		if(dr_dbf->fetch_result(db_hdl, &res, dr_fetch_rows)<0) {
+		if(dr_dbf->fetch_result(db_hdl, &res, dr_fetch_rows) < 0) {
 			LM_ERR("Error fetching rows\n");
 			LM_ERR("Error fetching rows\n");
 			goto error;
 			goto error;
 		}
 		}
 	} else {
 	} else {
-		if ( dr_dbf->query( db_hdl, 0, 0, 0, columns, 0, 2, 0, &res) < 0) {
+		if(dr_dbf->query(db_hdl, 0, 0, 0, columns, 0, 2, 0, &res) < 0) {
 			LM_ERR("DB query failed\n");
 			LM_ERR("DB query failed\n");
 			goto error;
 			goto error;
 		}
 		}
 	}
 	}
 
 
-	if (RES_ROW_N(res) == 0) {
-		LM_DBG("table \"%.*s\" empty\n", drl_table->len,drl_table->s );
+	if(RES_ROW_N(res) == 0) {
+		LM_DBG("table \"%.*s\" empty\n", drl_table->len, drl_table->s);
 	} else {
 	} else {
-		LM_DBG("%d records found in %.*s\n",
-			RES_ROW_N(res), drl_table->len,drl_table->s);
+		LM_DBG("%d records found in %.*s\n", RES_ROW_N(res), drl_table->len,
+				drl_table->s);
 		do {
 		do {
-			for(i=0; i < RES_ROW_N(res); i++) {
+			for(i = 0; i < RES_ROW_N(res); i++) {
 				row = RES_ROWS(res) + i;
 				row = RES_ROWS(res) + i;
 				/* ID column */
 				/* ID column */
-				check_val( ROW_VALUES(row), DB1_INT, 1, 0);
-				int_vals[0] = VAL_INT   (ROW_VALUES(row));
+				check_val(ROW_VALUES(row), DB1_INT, 1, 0);
+				int_vals[0] = VAL_INT(ROW_VALUES(row));
 				/* GWLIST column */
 				/* GWLIST column */
-				check_val( ROW_VALUES(row)+1, DB1_STRING, 1, 1);
-				str_vals[0] = (char*)VAL_STRING(ROW_VALUES(row)+1);
+				check_val(ROW_VALUES(row) + 1, DB1_STRING, 1, 1);
+				str_vals[0] = (char *)VAL_STRING(ROW_VALUES(row) + 1);
 
 
-				if (add_tmp_gw_list(int_vals[0], str_vals[0])!=0) {
+				if(add_tmp_gw_list(int_vals[0], str_vals[0]) != 0) {
 					LM_ERR("failed to add temporary GW list\n");
 					LM_ERR("failed to add temporary GW list\n");
 					goto error;
 					goto error;
 				}
 				}
 			}
 			}
-			if (DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {
-				if(dr_dbf->fetch_result(db_hdl, &res, dr_fetch_rows)<0) {
-					LM_ERR( "fetching rows (1)\n");
+			if(DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {
+				if(dr_dbf->fetch_result(db_hdl, &res, dr_fetch_rows) < 0) {
+					LM_ERR("fetching rows (1)\n");
 					goto error;
 					goto error;
 				}
 				}
 			} else {
 			} else {
 				break;
 				break;
 			}
 			}
-		} while(RES_ROW_N(res)>0);
+		} while(RES_ROW_N(res) > 0);
 	}
 	}
 	dr_dbf->free_result(db_hdl, res);
 	dr_dbf->free_result(db_hdl, res);
 	res = 0;
 	res = 0;
 
 
 	/* read the routing rules */
 	/* read the routing rules */
-	if (dr_dbf->use_table( db_hdl, drr_table) < 0) {
+	if(dr_dbf->use_table(db_hdl, drr_table) < 0) {
 		LM_ERR("cannot select table \"%.*s\"\n", drr_table->len, drr_table->s);
 		LM_ERR("cannot select table \"%.*s\"\n", drr_table->len, drr_table->s);
 		goto error;
 		goto error;
 	}
 	}
@@ -457,130 +460,133 @@ rt_data_t* dr_load_routing_info( db_func_t *dr_dbf, db1_con_t* db_hdl,
 	columns[5] = &routeid_drr_col;
 	columns[5] = &routeid_drr_col;
 	columns[6] = &dstlist_drr_col;
 	columns[6] = &dstlist_drr_col;
 
 
-	if (DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {
-		if ( dr_dbf->query( db_hdl, 0, 0, 0, columns, 0, 7, 0, 0) < 0) {
+	if(DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {
+		if(dr_dbf->query(db_hdl, 0, 0, 0, columns, 0, 7, 0, 0) < 0) {
 			LM_ERR("DB query failed\n");
 			LM_ERR("DB query failed\n");
 			goto error;
 			goto error;
 		}
 		}
-		if(dr_dbf->fetch_result(db_hdl, &res, dr_fetch_rows)<0) {
+		if(dr_dbf->fetch_result(db_hdl, &res, dr_fetch_rows) < 0) {
 			LM_ERR("Error fetching rows\n");
 			LM_ERR("Error fetching rows\n");
 			goto error;
 			goto error;
 		}
 		}
 	} else {
 	} else {
-		if ( dr_dbf->query( db_hdl, 0, 0, 0, columns, 0, 7, 0, &res) < 0) {
+		if(dr_dbf->query(db_hdl, 0, 0, 0, columns, 0, 7, 0, &res) < 0) {
 			LM_ERR("DB query failed\n");
 			LM_ERR("DB query failed\n");
 			goto error;
 			goto error;
 		}
 		}
 	}
 	}
 
 
-	if (RES_ROW_N(res) == 0) {
+	if(RES_ROW_N(res) == 0) {
 		LM_WARN("table \"%.*s\" is empty\n", drr_table->len, drr_table->s);
 		LM_WARN("table \"%.*s\" is empty\n", drr_table->len, drr_table->s);
 	}
 	}
 
 
-	LM_DBG("%d records found in %.*s\n", RES_ROW_N(res),
-		drr_table->len, drr_table->s);
+	LM_DBG("%d records found in %.*s\n", RES_ROW_N(res), drr_table->len,
+			drr_table->s);
 
 
 	n = 0;
 	n = 0;
 	do {
 	do {
-		for(i=0; i < RES_ROW_N(res); i++) {
+		for(i = 0; i < RES_ROW_N(res); i++) {
 			row = RES_ROWS(res) + i;
 			row = RES_ROWS(res) + i;
 			/* RULE_ID column */
 			/* RULE_ID column */
-			check_val( ROW_VALUES(row), DB1_INT, 1, 0);
-			int_vals[0] = VAL_INT (ROW_VALUES(row));
+			check_val(ROW_VALUES(row), DB1_INT, 1, 0);
+			int_vals[0] = VAL_INT(ROW_VALUES(row));
 			/* GROUP column */
 			/* GROUP column */
-			check_val( ROW_VALUES(row)+1, DB1_STRING, 1, 1);
-			str_vals[0] = (char*)VAL_STRING(ROW_VALUES(row)+1);
+			check_val(ROW_VALUES(row) + 1, DB1_STRING, 1, 1);
+			str_vals[0] = (char *)VAL_STRING(ROW_VALUES(row) + 1);
 			/* PREFIX column - it may be null or empty */
 			/* PREFIX column - it may be null or empty */
-			check_val( ROW_VALUES(row)+2, DB1_STRING, 0, 0);
-			if ((ROW_VALUES(row)+2)->nul || VAL_STRING(ROW_VALUES(row)+2)==0){
+			check_val(ROW_VALUES(row) + 2, DB1_STRING, 0, 0);
+			if((ROW_VALUES(row) + 2)->nul
+					|| VAL_STRING(ROW_VALUES(row) + 2) == 0) {
 				tmp.s = NULL;
 				tmp.s = NULL;
 				tmp.len = 0;
 				tmp.len = 0;
 			} else {
 			} else {
-				str_vals[1] = (char*)VAL_STRING(ROW_VALUES(row)+2);
+				str_vals[1] = (char *)VAL_STRING(ROW_VALUES(row) + 2);
 				tmp.s = str_vals[1];
 				tmp.s = str_vals[1];
 				tmp.len = strlen(str_vals[1]);
 				tmp.len = strlen(str_vals[1]);
 			}
 			}
 			/* TIME column */
 			/* TIME column */
-			check_val( ROW_VALUES(row)+3, DB1_STRING, 1, 1);
-			str_vals[2] = (char*)VAL_STRING(ROW_VALUES(row)+3);
+			check_val(ROW_VALUES(row) + 3, DB1_STRING, 1, 1);
+			str_vals[2] = (char *)VAL_STRING(ROW_VALUES(row) + 3);
 			/* PRIORITY column */
 			/* PRIORITY column */
-			check_val( ROW_VALUES(row)+4, DB1_INT, 1, 0);
-			int_vals[2] = VAL_INT   (ROW_VALUES(row)+4);
+			check_val(ROW_VALUES(row) + 4, DB1_INT, 1, 0);
+			int_vals[2] = VAL_INT(ROW_VALUES(row) + 4);
 			/* ROUTE_ID column */
 			/* ROUTE_ID column */
-			check_val( ROW_VALUES(row)+5, DB1_STRING, 1, 0);
-			str_vals[3] = (char*)VAL_STRING(ROW_VALUES(row)+5);
+			check_val(ROW_VALUES(row) + 5, DB1_STRING, 1, 0);
+			str_vals[3] = (char *)VAL_STRING(ROW_VALUES(row) + 5);
 			/* DSTLIST column */
 			/* DSTLIST column */
-			check_val( ROW_VALUES(row)+6, DB1_STRING, 1, 1);
-			str_vals[4] = (char*)VAL_STRING(ROW_VALUES(row)+6);
+			check_val(ROW_VALUES(row) + 6, DB1_STRING, 1, 1);
+			str_vals[4] = (char *)VAL_STRING(ROW_VALUES(row) + 6);
 			/* parse the time definition */
 			/* parse the time definition */
-			if ((time_rec=parse_time_def(str_vals[2]))==0) {
+			if((time_rec = parse_time_def(str_vals[2])) == 0) {
 				LM_ERR("bad time definition <%s> for rule id %d -> skipping\n",
 				LM_ERR("bad time definition <%s> for rule id %d -> skipping\n",
-					str_vals[2], int_vals[0]);
+						str_vals[2], int_vals[0]);
 				continue;
 				continue;
 			}
 			}
 			/* lookup for the script route ID */
 			/* lookup for the script route ID */
-			if (str_vals[3][0] && str_vals[3][0]!='0') {
-				int_vals[3] =  route_lookup(&main_rt, str_vals[3]);
-				if (int_vals[3]==-1) {
-					LM_WARN("route <%s> does not exist\n",str_vals[3]);
+			if(str_vals[3][0] && str_vals[3][0] != '0') {
+				int_vals[3] = route_lookup(&main_rt, str_vals[3]);
+				if(int_vals[3] == -1) {
+					LM_WARN("route <%s> does not exist\n", str_vals[3]);
 					int_vals[3] = 0;
 					int_vals[3] = 0;
 				}
 				}
 			} else {
 			} else {
 				int_vals[3] = 0;
 				int_vals[3] = 0;
 			}
 			}
 			/* is gw_list a list or a list id? */
 			/* is gw_list a list or a list id? */
-			if (str_vals[4][0]=='#') {
-				s_id.s = str_vals[4]+1;
+			if(str_vals[4][0] == '#') {
+				s_id.s = str_vals[4] + 1;
 				s_id.len = strlen(s_id.s);
 				s_id.len = strlen(s_id.s);
-				if ( str2int( &s_id, &id)!=0 ||
-				(str_vals[4]=get_tmp_gw_list(id))==NULL ) {
+				if(str2int(&s_id, &id) != 0
+						|| (str_vals[4] = get_tmp_gw_list(id)) == NULL) {
 					LM_ERR("invalid reference to a GW list <%s> -> skipping\n",
 					LM_ERR("invalid reference to a GW list <%s> -> skipping\n",
-						str_vals[4]);
+							str_vals[4]);
 					continue;
 					continue;
 				}
 				}
 			}
 			}
 			/* build the routing rule */
 			/* build the routing rule */
-			if ((ri = build_rt_info( int_vals[2], time_rec, int_vals[3],
-					str_vals[4], rdata->pgw_l))== 0 ) {
+			if((ri = build_rt_info(int_vals[2], time_rec, int_vals[3],
+						str_vals[4], rdata->pgw_l))
+					== 0) {
 				LM_ERR("failed to add routing info for rule id %d -> "
 				LM_ERR("failed to add routing info for rule id %d -> "
-					"skipping\n", int_vals[0]);
-				tmrec_free( time_rec );
+					   "skipping\n",
+						int_vals[0]);
+				tmrec_free(time_rec);
 				continue;
 				continue;
 			}
 			}
 			/* add the rule */
 			/* add the rule */
-			if (add_rule( rdata, str_vals[0], &tmp, ri)!=0) {
+			if(add_rule(rdata, str_vals[0], &tmp, ri) != 0) {
 				LM_ERR("failed to add rule id %d -> skipping\n", int_vals[0]);
 				LM_ERR("failed to add rule id %d -> skipping\n", int_vals[0]);
-				free_rt_info( ri );
+				free_rt_info(ri);
 				continue;
 				continue;
 			}
 			}
 			n++;
 			n++;
 		}
 		}
-		if (DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {
-			if(dr_dbf->fetch_result(db_hdl, &res, dr_fetch_rows)<0) {
-				LM_ERR( "fetching rows (1)\n");
+		if(DB_CAPABILITY(*dr_dbf, DB_CAP_FETCH)) {
+			if(dr_dbf->fetch_result(db_hdl, &res, dr_fetch_rows) < 0) {
+				LM_ERR("fetching rows (1)\n");
 				goto error;
 				goto error;
 			}
 			}
 		} else {
 		} else {
 			break;
 			break;
 		}
 		}
-	} while(RES_ROW_N(res)>0);
+	} while(RES_ROW_N(res) > 0);
 
 
 	dr_dbf->free_result(db_hdl, res);
 	dr_dbf->free_result(db_hdl, res);
 	res = 0;
 	res = 0;
 
 
 	free_tmp_gw_list();
 	free_tmp_gw_list();
 
 
-	if (n==0) {
+	if(n == 0) {
 		LM_WARN("no valid routing rules -> discarding all destinations\n");
 		LM_WARN("no valid routing rules -> discarding all destinations\n");
-		free_rt_data( rdata, 0 );
+		free_rt_data(rdata, 0);
 	}
 	}
 
 
 	return rdata;
 	return rdata;
 error:
 error:
-	if (res)
+	if(res)
 		dr_dbf->free_result(db_hdl, res);
 		dr_dbf->free_result(db_hdl, res);
-	if (rdata)
-		free_rt_data( rdata, 1 );
+	if(rdata)
+		free_rt_data(rdata, 1);
 	rdata = NULL;
 	rdata = NULL;
 	return 0;
 	return 0;
 }
 }

+ 2 - 2
src/modules/drouting/dr_load.h

@@ -27,7 +27,7 @@
 #include "../../lib/srdb1/db.h"
 #include "../../lib/srdb1/db.h"
 #include "routing.h"
 #include "routing.h"
 
 
-rt_data_t* dr_load_routing_info( db_func_t *dr_dbf, db1_con_t* db_hdl,
-							str *drd_table, str *drl_table, str* str_table);
+rt_data_t *dr_load_routing_info(db_func_t *dr_dbf, db1_con_t *db_hdl,
+		str *drd_table, str *drl_table, str *str_table);
 
 
 #endif
 #endif

File diff suppressed because it is too large
+ 260 - 268
src/modules/drouting/dr_time.c


+ 32 - 34
src/modules/drouting/dr_time.h

@@ -35,14 +35,15 @@
 */
 */
 
 
 #ifndef USE_YWEEK_U
 #ifndef USE_YWEEK_U
-# ifndef USE_YWEEK_V
-#  ifndef USE_YWEEK_W
-#   define USE_YWEEK_W
-#  endif
-# endif
+#ifndef USE_YWEEK_V
+#ifndef USE_YWEEK_W
+#define USE_YWEEK_W
+#endif
+#endif
 #endif
 #endif
 
 
-#define is_leap_year(yyyy) ((((yyyy)%400))?(((yyyy)%100)?(((yyyy)%4)?0:1):0):1)
+#define is_leap_year(yyyy) \
+	((((yyyy) % 400)) ? (((yyyy) % 100) ? (((yyyy) % 4) ? 0 : 1) : 0) : 1)
 
 
 
 
 typedef struct _ac_maxval
 typedef struct _ac_maxval
@@ -73,24 +74,22 @@ int ac_tm_set_time(ac_tm_p, time_t);
 int ac_tm_reset(ac_tm_p);
 int ac_tm_reset(ac_tm_p);
 int ac_tm_free(ac_tm_p);
 int ac_tm_free(ac_tm_p);
 
 
-int ac_get_mweek(struct tm*);
-int ac_get_yweek(struct tm*);
+int ac_get_mweek(struct tm *);
+int ac_get_yweek(struct tm *);
 ac_maxval_p ac_get_maxval(ac_tm_p);
 ac_maxval_p ac_get_maxval(ac_tm_p);
 int ac_get_wkst();
 int ac_get_wkst();
 
 
 int ac_print(ac_tm_p);
 int ac_print(ac_tm_p);
 
 
 
 
-
-
 /************************ imported from "tmrec.h"  ***************************/
 /************************ imported from "tmrec.h"  ***************************/
 
 
 
 
-#define FREQ_NOFREQ  0
-#define FREQ_YEARLY  1
+#define FREQ_NOFREQ 0
+#define FREQ_YEARLY 1
 #define FREQ_MONTHLY 2
 #define FREQ_MONTHLY 2
-#define FREQ_WEEKLY  3
-#define FREQ_DAILY   4
+#define FREQ_WEEKLY 3
+#define FREQ_DAILY 4
 
 
 #define WDAY_SU 0
 #define WDAY_SU 0
 #define WDAY_MO 1
 #define WDAY_MO 1
@@ -101,8 +100,8 @@ int ac_print(ac_tm_p);
 #define WDAY_SA 6
 #define WDAY_SA 6
 #define WDAY_NU 7
 #define WDAY_NU 7
 
 
-#define TSW_TSET	1
-#define TSW_RSET	2
+#define TSW_TSET 1
+#define TSW_RSET 2
 
 
 typedef struct _tr_byxxx
 typedef struct _tr_byxxx
 {
 {
@@ -141,29 +140,28 @@ int tr_byxxx_free(tr_byxxx_p);
 tmrec_p tmrec_new();
 tmrec_p tmrec_new();
 int tmrec_free(tmrec_p);
 int tmrec_free(tmrec_p);
 
 
-int tr_parse_dtstart(tmrec_p, char*);
-int tr_parse_dtend(tmrec_p, char*);
-int tr_parse_duration(tmrec_p, char*);
-int tr_parse_until(tmrec_p, char*);
-int tr_parse_freq(tmrec_p, char*);
-int tr_parse_interval(tmrec_p, char*);
-int tr_parse_byday(tmrec_p, char*);
-int tr_parse_bymday(tmrec_p, char*);
-int tr_parse_byyday(tmrec_p, char*);
-int tr_parse_bymonth(tmrec_p, char*);
-int tr_parse_byweekno(tmrec_p, char*);
-int tr_parse_wkst(tmrec_p, char*);
+int tr_parse_dtstart(tmrec_p, char *);
+int tr_parse_dtend(tmrec_p, char *);
+int tr_parse_duration(tmrec_p, char *);
+int tr_parse_until(tmrec_p, char *);
+int tr_parse_freq(tmrec_p, char *);
+int tr_parse_interval(tmrec_p, char *);
+int tr_parse_byday(tmrec_p, char *);
+int tr_parse_bymday(tmrec_p, char *);
+int tr_parse_byyday(tmrec_p, char *);
+int tr_parse_bymonth(tmrec_p, char *);
+int tr_parse_byweekno(tmrec_p, char *);
+int tr_parse_wkst(tmrec_p, char *);
 
 
 int tr_print(tmrec_p);
 int tr_print(tmrec_p);
-time_t ic_parse_datetime(char*,struct tm*);
-time_t ic_parse_duration(char*);
+time_t ic_parse_datetime(char *, struct tm *);
+time_t ic_parse_duration(char *);
 
 
-tr_byxxx_p ic_parse_byday(char*);
-tr_byxxx_p ic_parse_byxxx(char*);
-int ic_parse_wkst(char*);
+tr_byxxx_p ic_parse_byday(char *);
+tr_byxxx_p ic_parse_byxxx(char *);
+int ic_parse_wkst(char *);
 
 
 int check_tmrec(tmrec_p, ac_tm_p, tr_res_p);
 int check_tmrec(tmrec_p, ac_tm_p, tr_res_p);
 
 
 
 
 #endif
 #endif
-

File diff suppressed because it is too large
+ 281 - 276
src/modules/drouting/drouting.c


+ 4 - 4
src/modules/drouting/parse.h

@@ -28,11 +28,11 @@
 #define SEP1 ','
 #define SEP1 ','
 #define SEP_GRP ';'
 #define SEP_GRP ';'
 
 
-#define IS_SPACE(s)\
-	((s)==' ' || (s)=='\t' || (s)=='\r' || (s)=='\n')
+#define IS_SPACE(s) ((s) == ' ' || (s) == '\t' || (s) == '\r' || (s) == '\n')
 
 
-#define EAT_SPACE(s)\
-	while((s) && IS_SPACE(*(s))) (s)++
+#define EAT_SPACE(s)             \
+	while((s) && IS_SPACE(*(s))) \
+	(s)++
 
 
 
 
 #endif
 #endif

+ 68 - 111
src/modules/drouting/prefix_tree.c

@@ -34,57 +34,49 @@ extern int inode;
 extern int unode;
 extern int unode;
 
 
 
 
-
-static inline int
-check_time(
-		tmrec_t *time_rec
-		)
+static inline int check_time(tmrec_t *time_rec)
 {
 {
 	ac_tm_t att;
 	ac_tm_t att;
 
 
 	/* shortcut: if there is no dstart, timerec is valid */
 	/* shortcut: if there is no dstart, timerec is valid */
-	if (time_rec->dtstart==0)
+	if(time_rec->dtstart == 0)
 		return 1;
 		return 1;
 
 
-	memset( &att, 0, sizeof(att));
+	memset(&att, 0, sizeof(att));
 
 
 	/* set current time */
 	/* set current time */
-	if ( ac_tm_set_time( &att, time(0) ) )
+	if(ac_tm_set_time(&att, time(0)))
 		return 0;
 		return 0;
 
 
 	/* does the recv_time match the specified interval?  */
 	/* does the recv_time match the specified interval?  */
-	if (check_tmrec( time_rec, &att, 0)!=0)
+	if(check_tmrec(time_rec, &att, 0) != 0)
 		return 0;
 		return 0;
 
 
 	return 1;
 	return 1;
 }
 }
 
 
 
 
-static inline rt_info_t*
-internal_check_rt(
-		ptree_node_t *ptn,
-		unsigned int rgid
-		)
+static inline rt_info_t *internal_check_rt(ptree_node_t *ptn, unsigned int rgid)
 {
 {
 	int i;
 	int i;
-	int rg_pos=0;
-	rg_entry_t* rg=NULL;
-	rt_info_wrp_t* rtlw=NULL;
+	int rg_pos = 0;
+	rg_entry_t *rg = NULL;
+	rt_info_wrp_t *rtlw = NULL;
 
 
-	if((NULL==ptn) || (NULL==ptn->rg))
+	if((NULL == ptn) || (NULL == ptn->rg))
 		return NULL;
 		return NULL;
 
 
 	rg_pos = ptn->rg_pos;
 	rg_pos = ptn->rg_pos;
-	rg=ptn->rg;
-	for(i=0;(i<rg_pos) && (rg[i].rgid!=rgid);i++);
-	if(i<rg_pos) {
-		LM_DBG("found rgid %d (rule list %p)\n",
-				rgid, rg[i].rtlw);
-		rtlw=rg[i].rtlw;
-		while(rtlw!=NULL) {
+	rg = ptn->rg;
+	for(i = 0; (i < rg_pos) && (rg[i].rgid != rgid); i++)
+		;
+	if(i < rg_pos) {
+		LM_DBG("found rgid %d (rule list %p)\n", rgid, rg[i].rtlw);
+		rtlw = rg[i].rtlw;
+		while(rtlw != NULL) {
 			if(check_time(rtlw->rtl->time_rec))
 			if(check_time(rtlw->rtl->time_rec))
 				return rtlw->rtl;
 				return rtlw->rtl;
-			rtlw=rtlw->next;
+			rtlw = rtlw->next;
 		}
 		}
 	}
 	}
 
 
@@ -92,26 +84,17 @@ internal_check_rt(
 }
 }
 
 
 
 
-rt_info_t*
-check_rt(
-	ptree_node_t *ptn,
-	unsigned int rgid
-	)
+rt_info_t *check_rt(ptree_node_t *ptn, unsigned int rgid)
 {
 {
-	return internal_check_rt( ptn, rgid);
+	return internal_check_rt(ptn, rgid);
 }
 }
 
 
 
 
-rt_info_t*
-get_prefix(
-	ptree_t *ptree,
-	str* prefix,
-	unsigned int rgid
-	)
+rt_info_t *get_prefix(ptree_t *ptree, str *prefix, unsigned int rgid)
 {
 {
 	rt_info_t *rt = NULL;
 	rt_info_t *rt = NULL;
-	char *tmp=NULL;
-	int idx=0;
+	char *tmp = NULL;
+	int idx = 0;
 
 
 	if(NULL == ptree)
 	if(NULL == ptree)
 		goto err_exit;
 		goto err_exit;
@@ -120,17 +103,17 @@ get_prefix(
 	tmp = prefix->s;
 	tmp = prefix->s;
 	/* go the tree down to the last digit in the
 	/* go the tree down to the last digit in the
 	 * prefix string or down to a leaf */
 	 * prefix string or down to a leaf */
-	while(tmp< (prefix->s+prefix->len)) {
+	while(tmp < (prefix->s + prefix->len)) {
 		idx = get_node_index(*tmp);
 		idx = get_node_index(*tmp);
-		if (idx == -1){
+		if(idx == -1) {
 			/* unknown character in the prefix string */
 			/* unknown character in the prefix string */
 			goto err_exit;
 			goto err_exit;
 		}
 		}
-		if( tmp == (prefix->s+prefix->len-1) ) {
+		if(tmp == (prefix->s + prefix->len - 1)) {
 			/* last digit in the prefix string */
 			/* last digit in the prefix string */
 			break;
 			break;
 		}
 		}
-		if( NULL == ptree->ptnode[idx].next) {
+		if(NULL == ptree->ptnode[idx].next) {
 			/* this is a leaf */
 			/* this is a leaf */
 			break;
 			break;
 		}
 		}
@@ -138,12 +121,12 @@ get_prefix(
 		tmp++;
 		tmp++;
 	}
 	}
 	/* go in the tree up to the root trying to match the prefix */
 	/* go in the tree up to the root trying to match the prefix */
-	while(ptree !=NULL ) {
+	while(ptree != NULL) {
 		/* is it a real node or an intermediate one */
 		/* is it a real node or an intermediate one */
 		idx = get_node_index(*tmp);
 		idx = get_node_index(*tmp);
-		if(idx!=-1 && NULL != ptree->ptnode[idx].rg) {
+		if(idx != -1 && NULL != ptree->ptnode[idx].rg) {
 			/* real node; check the constraints on the routing info*/
 			/* real node; check the constraints on the routing info*/
-			if( NULL != (rt = internal_check_rt( &(ptree->ptnode[idx]), rgid)))
+			if(NULL != (rt = internal_check_rt(&(ptree->ptnode[idx]), rgid)))
 				break;
 				break;
 		}
 		}
 		tmp--;
 		tmp--;
@@ -156,13 +139,9 @@ err_exit:
 }
 }
 
 
 
 
-pgw_t*
-get_pgw(
-		pgw_t* pgw_l,
-		long id
-		)
+pgw_t *get_pgw(pgw_t *pgw_l, long id)
 {
 {
-	if(NULL==pgw_l)
+	if(NULL == pgw_l)
 		goto err_exit;
 		goto err_exit;
 	while(NULL != pgw_l) {
 	while(NULL != pgw_l) {
 		if(id == pgw_l->id) {
 		if(id == pgw_l->id) {
@@ -175,34 +154,29 @@ err_exit:
 }
 }
 
 
 
 
-int
-add_prefix(
-	ptree_t *ptree,
-	str* prefix,
-	rt_info_t *r,
-	unsigned int rg
-	)
+int add_prefix(ptree_t *ptree, str *prefix, rt_info_t *r, unsigned int rg)
 {
 {
-	char* tmp=NULL;
+	char *tmp = NULL;
 	int res = 0;
 	int res = 0;
-	if(NULL==ptree)
+	if(NULL == ptree)
 		goto err_exit;
 		goto err_exit;
 	tmp = prefix->s;
 	tmp = prefix->s;
-	while(tmp < (prefix->s+prefix->len)) {
+	while(tmp < (prefix->s + prefix->len)) {
 		if(NULL == tmp)
 		if(NULL == tmp)
 			goto err_exit;
 			goto err_exit;
 		int insert_index = get_node_index(*tmp);
 		int insert_index = get_node_index(*tmp);
-		if (insert_index == -1){
+		if(insert_index == -1) {
 			/* unknown character in the prefix string */
 			/* unknown character in the prefix string */
 			goto err_exit;
 			goto err_exit;
 		}
 		}
-		if( tmp == (prefix->s+prefix->len-1) ) {
+		if(tmp == (prefix->s + prefix->len - 1)) {
 			/* last symbol in the prefix string */
 			/* last symbol in the prefix string */
 
 
 			LM_DBG("adding info %p, %d at: "
 			LM_DBG("adding info %p, %d at: "
-				"%p (%d)\n", r, rg, &(ptree->ptnode[insert_index]), insert_index);
-			res = add_rt_info(&(ptree->ptnode[insert_index]), r,rg);
-			if(res < 0 )
+				   "%p (%d)\n",
+					r, rg, &(ptree->ptnode[insert_index]), insert_index);
+			res = add_rt_info(&(ptree->ptnode[insert_index]), r, rg);
+			if(res < 0)
 				goto err_exit;
 				goto err_exit;
 			unode++;
 			unode++;
 			res = 1;
 			res = 1;
@@ -212,7 +186,7 @@ add_prefix(
 		if(NULL == ptree->ptnode[insert_index].next) {
 		if(NULL == ptree->ptnode[insert_index].next) {
 			/* allocate new node */
 			/* allocate new node */
 			INIT_PTREE_NODE(ptree, ptree->ptnode[insert_index].next);
 			INIT_PTREE_NODE(ptree, ptree->ptnode[insert_index].next);
-			inode+=PTREE_CHILDREN;
+			inode += PTREE_CHILDREN;
 #if 0
 #if 0
 			printf("new tree node: %p (bp: %p)\n",
 			printf("new tree node: %p (bp: %p)\n",
 					ptree->ptnode[insert_index].next,
 					ptree->ptnode[insert_index].next,
@@ -231,21 +205,18 @@ err_exit:
 	return -1;
 	return -1;
 }
 }
 
 
-int
-del_tree(
-		ptree_t* t
-		)
+int del_tree(ptree_t *t)
 {
 {
-	int i,j;
+	int i, j;
 	if(NULL == t)
 	if(NULL == t)
 		goto exit;
 		goto exit;
 	/* delete all the children */
 	/* delete all the children */
-	for(i=0; i< PTREE_CHILDREN; i++) {
+	for(i = 0; i < PTREE_CHILDREN; i++) {
 		/* shm_free the rg array of rt_info */
 		/* shm_free the rg array of rt_info */
-		if(NULL!=t->ptnode[i].rg) {
-			for(j=0;j<t->ptnode[i].rg_pos;j++) {
+		if(NULL != t->ptnode[i].rg) {
+			for(j = 0; j < t->ptnode[i].rg_pos; j++) {
 				/* if non intermediate delete the routing info */
 				/* if non intermediate delete the routing info */
-				if(t->ptnode[i].rg[j].rtlw !=NULL)
+				if(t->ptnode[i].rg[j].rtlw != NULL)
 					del_rt_list(t->ptnode[i].rg[j].rtlw);
 					del_rt_list(t->ptnode[i].rg[j].rtlw);
 			}
 			}
 			shm_free(t->ptnode[i].rg);
 			shm_free(t->ptnode[i].rg);
@@ -259,61 +230,47 @@ exit:
 	return 0;
 	return 0;
 }
 }
 
 
-void
-del_rt_list(
-		rt_info_wrp_t *rwl
-		)
+void del_rt_list(rt_info_wrp_t *rwl)
 {
 {
-	rt_info_wrp_t* t=rwl;
-	while(rwl!=NULL) {
-		t=rwl;
-		rwl=rwl->next;
-		if ( (--t->rtl->ref_cnt)==0)
+	rt_info_wrp_t *t = rwl;
+	while(rwl != NULL) {
+		t = rwl;
+		rwl = rwl->next;
+		if((--t->rtl->ref_cnt) == 0)
 			free_rt_info(t->rtl);
 			free_rt_info(t->rtl);
 		shm_free(t);
 		shm_free(t);
 	}
 	}
 }
 }
 
 
-void
-free_rt_info(
-		rt_info_t *rl
-		)
+void free_rt_info(rt_info_t *rl)
 {
 {
 	if(NULL == rl)
 	if(NULL == rl)
 		return;
 		return;
-	if(NULL!=rl->pgwl)
+	if(NULL != rl->pgwl)
 		shm_free(rl->pgwl);
 		shm_free(rl->pgwl);
-	if(NULL!=rl->time_rec)
+	if(NULL != rl->time_rec)
 		tmrec_free(rl->time_rec);
 		tmrec_free(rl->time_rec);
 	shm_free(rl);
 	shm_free(rl);
 	return;
 	return;
 }
 }
 
 
-void
-print_rt(
-		rt_info_t*rt
-		)
+void print_rt(rt_info_t *rt)
 {
 {
-	int i=0;
-	if(NULL==rt)
+	int i = 0;
+	if(NULL == rt)
 		return;
 		return;
 	printf("priority:%d list of gw:\n", rt->priority);
 	printf("priority:%d list of gw:\n", rt->priority);
-	for(i=0;i<rt->pgwa_len;i++)
-		if(NULL!=rt->pgwl[i].pgw) 
-			printf("  id:%ld pri:%.*s ip:%.*s \n",
-				rt->pgwl[i].pgw->id, 
-				rt->pgwl[i].pgw->pri.len, rt->pgwl[i].pgw->pri.s,
-				rt->pgwl[i].pgw->ip.len, rt->pgwl[i].pgw->ip.s);
+	for(i = 0; i < rt->pgwa_len; i++)
+		if(NULL != rt->pgwl[i].pgw)
+			printf("  id:%ld pri:%.*s ip:%.*s \n", rt->pgwl[i].pgw->id,
+					rt->pgwl[i].pgw->pri.len, rt->pgwl[i].pgw->pri.s,
+					rt->pgwl[i].pgw->ip.len, rt->pgwl[i].pgw->ip.s);
 }
 }
 
 
 
 
-int
-get_node_index(
-		char ch
-		)
+int get_node_index(char ch)
 {
 {
-	switch (ch)
-	{
+	switch(ch) {
 		case '0':
 		case '0':
 		case '1':
 		case '1':
 		case '2':
 		case '2':

+ 55 - 90
src/modules/drouting/prefix_tree.h

@@ -20,7 +20,6 @@
  */
  */
 
 
 
 
-
 #ifndef prefix_tree_h
 #ifndef prefix_tree_h
 #define prefix_tree_h
 #define prefix_tree_h
 
 
@@ -29,32 +28,34 @@
 #include "../keepalive/api.h"
 #include "../keepalive/api.h"
 #include "dr_time.h"
 #include "dr_time.h"
 
 
-#define PTREE_CHILDREN 13  //decimal digits, '*', '#',  '+'
+#define PTREE_CHILDREN 13 //decimal digits, '*', '#',  '+'
 
 
 extern int tree_size;
 extern int tree_size;
 
 
-#define INIT_PTREE_NODE(p, n) \
-do {\
-	(n) = (ptree_t*)shm_malloc(sizeof(ptree_t));\
-	if(NULL == (n))\
-		goto err_exit;\
-	tree_size+=sizeof(ptree_t);\
-	memset((n), 0, sizeof(ptree_t));\
-	(n)->bp=(p);\
-}while(0);
+#define INIT_PTREE_NODE(p, n)                         \
+	do {                                              \
+		(n) = (ptree_t *)shm_malloc(sizeof(ptree_t)); \
+		if(NULL == (n))                               \
+			goto err_exit;                            \
+		tree_size += sizeof(ptree_t);                 \
+		memset((n), 0, sizeof(ptree_t));              \
+		(n)->bp = (p);                                \
+	} while(0);
 
 
 
 
 /* list of PSTN gw */
 /* list of PSTN gw */
-typedef struct pgw_addr_ {
+typedef struct pgw_addr_
+{
 	struct ip_addr ip;
 	struct ip_addr ip;
 	unsigned short port;
 	unsigned short port;
 	int type;
 	int type;
 	int strip;
 	int strip;
 	struct pgw_addr_ *next;
 	struct pgw_addr_ *next;
-}pgw_addr_t;
+} pgw_addr_t;
 
 
 /* list of PSTN gw */
 /* list of PSTN gw */
-typedef struct pgw_ {
+typedef struct pgw_
+{
 	/* id matching the one in db */
 	/* id matching the one in db */
 	long id;
 	long id;
 	str pri;
 	str pri;
@@ -66,16 +67,18 @@ typedef struct pgw_ {
 	ka_state state;
 	ka_state state;
 
 
 	struct pgw_ *next;
 	struct pgw_ *next;
-}pgw_t;
+} pgw_t;
 
 
 /**/
 /**/
-typedef struct pgw_list_ {
+typedef struct pgw_list_
+{
 	pgw_t *pgw;
 	pgw_t *pgw;
-	int    grpid;
-}pgw_list_t;
+	int grpid;
+} pgw_list_t;
 
 
 /* element containing routing information */
 /* element containing routing information */
-typedef struct rt_info_ {
+typedef struct rt_info_
+{
 	unsigned int priority;
 	unsigned int priority;
 	tmrec_t *time_rec;
 	tmrec_t *time_rec;
 	/* array of pointers into the PSTN gw list */
 	/* array of pointers into the PSTN gw list */
@@ -88,93 +91,55 @@ typedef struct rt_info_ {
 	int route_idx;
 	int route_idx;
 } rt_info_t;
 } rt_info_t;
 
 
-typedef struct rt_info_wrp_ {
-	rt_info_t     *rtl;
-	struct rt_info_wrp_  *next;
+typedef struct rt_info_wrp_
+{
+	rt_info_t *rtl;
+	struct rt_info_wrp_ *next;
 } rt_info_wrp_t;
 } rt_info_wrp_t;
 
 
-typedef struct rg_entry_ {
+typedef struct rg_entry_
+{
 	unsigned int rgid;
 	unsigned int rgid;
 	rt_info_wrp_t *rtlw;
 	rt_info_wrp_t *rtlw;
 } rg_entry_t;
 } rg_entry_t;
 
 
-typedef struct ptree_node_ {
+typedef struct ptree_node_
+{
 	unsigned int rg_len;
 	unsigned int rg_len;
 	unsigned int rg_pos;
 	unsigned int rg_pos;
 	rg_entry_t *rg;
 	rg_entry_t *rg;
 	struct ptree_ *next;
 	struct ptree_ *next;
 } ptree_node_t;
 } ptree_node_t;
 
 
-typedef struct ptree_ {
+typedef struct ptree_
+{
 	/* backpointer */
 	/* backpointer */
 	struct ptree_ *bp;
 	struct ptree_ *bp;
 	ptree_node_t ptnode[PTREE_CHILDREN];
 	ptree_node_t ptnode[PTREE_CHILDREN];
 } ptree_t;
 } ptree_t;
 
 
-void 
-print_interim(
-		int,
-		int,
-		ptree_t*
-		);
-
-int
-del_tree(
-	ptree_t *
-	);
-
-int
-add_prefix(
-	ptree_t*,
-	/* prefix */
-	str*,
-	rt_info_t *,
-	unsigned int
-	);
-
-rt_info_t*
-get_prefix(
-	ptree_t *ptree,
-	str* prefix,
-	unsigned int rgid
-	);
-
-int
-add_rt_info(
-	ptree_node_t*, 
-	rt_info_t*,
-	unsigned int
-	);
-
-pgw_t*
-get_pgw(
-	pgw_t*,
-	long
-	);
-
-void
-del_rt_list(
-	rt_info_wrp_t *rl
-	);
-
-void print_rt(
-	rt_info_t*
-	);
-
-void
-free_rt_info(
-	rt_info_t*
-	);
-
-rt_info_t*
-check_rt(
-	ptree_node_t *ptn,
-	unsigned int rgid
-	);
-
-int
-get_node_index(
-	char ch
-	);
+void print_interim(int, int, ptree_t *);
+
+int del_tree(ptree_t *);
+
+int add_prefix(ptree_t *,
+		/* prefix */
+		str *, rt_info_t *, unsigned int);
+
+rt_info_t *get_prefix(ptree_t *ptree, str *prefix, unsigned int rgid);
+
+int add_rt_info(ptree_node_t *, rt_info_t *, unsigned int);
+
+pgw_t *get_pgw(pgw_t *, long);
+
+void del_rt_list(rt_info_wrp_t *rl);
+
+void print_rt(rt_info_t *);
+
+void free_rt_info(rt_info_t *);
+
+rt_info_t *check_rt(ptree_node_t *ptn, unsigned int rgid);
+
+int get_node_index(char ch);
 
 
 #endif
 #endif

+ 149 - 175
src/modules/drouting/routing.c

@@ -38,12 +38,11 @@
 
 
 extern int dr_force_dns;
 extern int dr_force_dns;
 
 
-rt_data_t*
-build_rt_data( void )
+rt_data_t *build_rt_data(void)
 {
 {
 	rt_data_t *rdata;
 	rt_data_t *rdata;
 
 
-	if( NULL==(rdata=shm_malloc(sizeof(rt_data_t)))) {
+	if(NULL == (rdata = shm_malloc(sizeof(rt_data_t)))) {
 		LM_ERR("no more shm mem\n");
 		LM_ERR("no more shm mem\n");
 		goto err_exit;
 		goto err_exit;
 	}
 	}
@@ -57,78 +56,72 @@ err_exit:
 }
 }
 
 
 
 
-rt_info_t*
-build_rt_info(
-	int priority,
-	tmrec_t *trec,
-	/* script routing table index */
-	int route_idx,
-	/* list of destinations indexes */
-	char* dstlst,
-	pgw_t* pgw_l
-	) 
+rt_info_t *build_rt_info(int priority, tmrec_t *trec,
+		/* script routing table index */
+		int route_idx,
+		/* list of destinations indexes */
+		char *dstlst, pgw_t *pgw_l)
 {
 {
-	char *tmp=NULL;
-	char *ep=NULL;
-	rt_info_t* rt = NULL;
-	int *idx = NULL, *t_idx=NULL;
-	int n=0, idx_size=0,i, grp_idx=0;
-	long t=0;
-	pgw_t *pgw=NULL;
-
-	if(NULL == (rt = (rt_info_t*)shm_malloc(sizeof(rt_info_t)))) {
+	char *tmp = NULL;
+	char *ep = NULL;
+	rt_info_t *rt = NULL;
+	int *idx = NULL, *t_idx = NULL;
+	int n = 0, idx_size = 0, i, grp_idx = 0;
+	long t = 0;
+	pgw_t *pgw = NULL;
+
+	if(NULL == (rt = (rt_info_t *)shm_malloc(sizeof(rt_info_t)))) {
 		LM_ERR("no more shm mem(1)\n");
 		LM_ERR("no more shm mem(1)\n");
 		goto err_exit;
 		goto err_exit;
 	}
 	}
 	memset(rt, 0, sizeof(rt_info_t));
 	memset(rt, 0, sizeof(rt_info_t));
 
 
 	idx_size = IDX_SIZE;
 	idx_size = IDX_SIZE;
-	if( NULL == (idx = (int*)shm_malloc(2*idx_size*sizeof(int)))) {
+	if(NULL == (idx = (int *)shm_malloc(2 * idx_size * sizeof(int)))) {
 		LM_ERR("no more shm mem(2)\n");
 		LM_ERR("no more shm mem(2)\n");
 		goto err_exit;
 		goto err_exit;
 	}
 	}
-	memset(idx, 0, 2*idx_size*sizeof(int));
+	memset(idx, 0, 2 * idx_size * sizeof(int));
 
 
 	rt->priority = priority;
 	rt->priority = priority;
 	rt->time_rec = trec;
 	rt->time_rec = trec;
 	rt->route_idx = route_idx;
 	rt->route_idx = route_idx;
-	tmp=dstlst;
-	n=0;
+	tmp = dstlst;
+	n = 0;
 	/* parse the dstlst */
 	/* parse the dstlst */
-	while(tmp && (*tmp!=0)) {
+	while(tmp && (*tmp != 0)) {
 		errno = 0;
 		errno = 0;
 		t = strtol(tmp, &ep, 10);
 		t = strtol(tmp, &ep, 10);
-		if (ep == tmp) {
-			LM_ERR("bad id '%c' (%d)[%s]\n",
-					*ep, (int)(ep-dstlst), dstlst);
+		if(ep == tmp) {
+			LM_ERR("bad id '%c' (%d)[%s]\n", *ep, (int)(ep - dstlst), dstlst);
 			goto err_exit;
 			goto err_exit;
 		}
 		}
-		if ((!IS_SPACE(*ep)) && (*ep != SEP) && (*ep != SEP1)
-				&& (*ep != SEP_GRP) && (*ep!=0)) {
-			LM_ERR("bad char %c (%d) [%s]\n",
-					*ep, (int)(ep-dstlst), dstlst);
+		if((!IS_SPACE(*ep)) && (*ep != SEP) && (*ep != SEP1) && (*ep != SEP_GRP)
+				&& (*ep != 0)) {
+			LM_ERR("bad char %c (%d) [%s]\n", *ep, (int)(ep - dstlst), dstlst);
 			goto err_exit;
 			goto err_exit;
 		}
 		}
-		if (errno == ERANGE && (t== LONG_MAX || t== LONG_MIN)) {
+		if(errno == ERANGE && (t == LONG_MAX || t == LONG_MIN)) {
 			LM_ERR("out of bounds\n");
 			LM_ERR("out of bounds\n");
 			goto err_exit;
 			goto err_exit;
 		}
 		}
-		idx[2*n]=t;
-		idx[2*n+1]=grp_idx;
+		idx[2 * n] = t;
+		idx[2 * n + 1] = grp_idx;
 		if(*ep == SEP_GRP)
 		if(*ep == SEP_GRP)
 			grp_idx++;
 			grp_idx++;
 		n++;
 		n++;
 		/* reallocate the array which keeps the parsed indexes */
 		/* reallocate the array which keeps the parsed indexes */
-		if(n>=idx_size){
-			if(NULL==((t_idx)=(int*)shm_malloc((idx_size*2*2)*sizeof(int)))) {
+		if(n >= idx_size) {
+			if(NULL == ((t_idx) = (int *)shm_malloc(
+								(idx_size * 2 * 2) * sizeof(int)))) {
 				LM_ERR("out of shm\n");
 				LM_ERR("out of shm\n");
 				goto err_exit;
 				goto err_exit;
 			}
 			}
-			memset(t_idx+(2*idx_size), 0, 2*idx_size*sizeof(int));
-			memcpy(t_idx, idx, 2*idx_size*sizeof(int));
+			memset(t_idx + (2 * idx_size), 0, 2 * idx_size * sizeof(int));
+			memcpy(t_idx, idx, 2 * idx_size * sizeof(int));
 			shm_free(idx);
 			shm_free(idx);
-			idx_size*=2;
-			idx=t_idx;
+			idx_size *= 2;
+			idx = t_idx;
 		}
 		}
 		if(IS_SPACE(*ep))
 		if(IS_SPACE(*ep))
 			EAT_SPACE(ep);
 			EAT_SPACE(ep);
@@ -136,26 +129,25 @@ build_rt_info(
 			ep++;
 			ep++;
 		tmp = ep;
 		tmp = ep;
 	}
 	}
-	if(n==0) {
+	if(n == 0) {
 		LM_ERR("invalid n\n");
 		LM_ERR("invalid n\n");
 		goto err_exit;
 		goto err_exit;
 	}
 	}
 	/* create the pgwl */
 	/* create the pgwl */
 	rt->pgwa_len = n;
 	rt->pgwa_len = n;
-	if(NULL ==
-		(rt->pgwl=(pgw_list_t*)shm_malloc(rt->pgwa_len*sizeof(pgw_list_t)))) {
+	if(NULL == (rt->pgwl = (pgw_list_t *)shm_malloc(
+						rt->pgwa_len * sizeof(pgw_list_t)))) {
 		goto err_exit;
 		goto err_exit;
 	}
 	}
-	memset(rt->pgwl, 0, rt->pgwa_len*sizeof(pgw_list_t));
+	memset(rt->pgwl, 0, rt->pgwa_len * sizeof(pgw_list_t));
 	/* translate GW ids to GW pointers */
 	/* translate GW ids to GW pointers */
-	for(i=0;i<n; i++){
-		if ( NULL == (pgw = get_pgw(pgw_l, idx[2*i]))) {
-			LM_ERR("invalid GW id %d\n",
-				idx[2*i]);
+	for(i = 0; i < n; i++) {
+		if(NULL == (pgw = get_pgw(pgw_l, idx[2 * i]))) {
+			LM_ERR("invalid GW id %d\n", idx[2 * i]);
 			goto err_exit;
 			goto err_exit;
 		}
 		}
-		rt->pgwl[i].pgw=pgw;
-		rt->pgwl[i].grpid=idx[2*i+1];
+		rt->pgwl[i].pgw = pgw;
+		rt->pgwl[i].grpid = idx[2 * i + 1];
 		/* LM_DBG("added to gwlist [%d/%d/%p]\n",
 		/* LM_DBG("added to gwlist [%d/%d/%p]\n",
 				idx[2*i], idx[2*i+1], pgw); */
 				idx[2*i], idx[2*i+1], pgw); */
 	}
 	}
@@ -164,81 +156,76 @@ build_rt_info(
 	return rt;
 	return rt;
 
 
 err_exit:
 err_exit:
-	if(NULL!=idx)
+	if(NULL != idx)
 		shm_free(idx);
 		shm_free(idx);
-	if((NULL != rt) && 
-		(NULL!=rt->pgwl))
-		shm_free(rt->pgwl); 
-	if(NULL!=rt)
+	if((NULL != rt) && (NULL != rt->pgwl))
+		shm_free(rt->pgwl);
+	if(NULL != rt)
 		shm_free(rt);
 		shm_free(rt);
 	return NULL;
 	return NULL;
 }
 }
 
 
-int
-add_rt_info(
-	ptree_node_t *pn,
-	rt_info_t* r,
-	unsigned int rgid
-	)
+int add_rt_info(ptree_node_t *pn, rt_info_t *r, unsigned int rgid)
 {
 {
-	rg_entry_t    *trg=NULL;
-	rt_info_wrp_t *rtl_wrp=NULL;
-	rt_info_wrp_t *rtlw=NULL;
-	int i=0;
+	rg_entry_t *trg = NULL;
+	rt_info_wrp_t *rtl_wrp = NULL;
+	rt_info_wrp_t *rtlw = NULL;
+	int i = 0;
 
 
 	if((NULL == pn) || (NULL == r))
 	if((NULL == pn) || (NULL == r))
 		goto err_exit;
 		goto err_exit;
 
 
-	if (NULL == (rtl_wrp = (rt_info_wrp_t*)shm_malloc(sizeof(rt_info_wrp_t)))) {
+	if(NULL == (rtl_wrp = (rt_info_wrp_t *)shm_malloc(sizeof(rt_info_wrp_t)))) {
 		LM_ERR("no more shm mem\n");
 		LM_ERR("no more shm mem\n");
 		goto err_exit;
 		goto err_exit;
 	}
 	}
-	memset( rtl_wrp, 0, sizeof(rt_info_wrp_t));
+	memset(rtl_wrp, 0, sizeof(rt_info_wrp_t));
 	rtl_wrp->rtl = r;
 	rtl_wrp->rtl = r;
 
 
-	if(NULL==pn->rg) {
+	if(NULL == pn->rg) {
 		/* allocate the routing groups array */
 		/* allocate the routing groups array */
 		pn->rg_len = RG_INIT_LEN;
 		pn->rg_len = RG_INIT_LEN;
-		if(NULL == (pn->rg = (rg_entry_t*)shm_malloc(
-						pn->rg_len*sizeof(rg_entry_t)))) {
+		if(NULL == (pn->rg = (rg_entry_t *)shm_malloc(
+							pn->rg_len * sizeof(rg_entry_t)))) {
 			/* recover the old pointer to be able to shm_free mem */
 			/* recover the old pointer to be able to shm_free mem */
 			goto err_exit;
 			goto err_exit;
 		}
 		}
-		memset( pn->rg, 0, pn->rg_len*sizeof(rg_entry_t));
-		pn->rg_pos=0;
+		memset(pn->rg, 0, pn->rg_len * sizeof(rg_entry_t));
+		pn->rg_pos = 0;
 	}
 	}
 	/* search for the rgid up to the rg_pos */
 	/* search for the rgid up to the rg_pos */
-	for(i=0; (i<pn->rg_pos) && (pn->rg[i].rgid!=rgid); i++);
-	if((i==pn->rg_len-1)&&(pn->rg[i].rgid!=rgid)) {
+	for(i = 0; (i < pn->rg_pos) && (pn->rg[i].rgid != rgid); i++)
+		;
+	if((i == pn->rg_len - 1) && (pn->rg[i].rgid != rgid)) {
 		/* realloc & copy the old rg */
 		/* realloc & copy the old rg */
 		trg = pn->rg;
 		trg = pn->rg;
-		if(NULL == (pn->rg = (rg_entry_t*)shm_malloc(
-						2*pn->rg_len*sizeof(rg_entry_t)))) {
+		if(NULL == (pn->rg = (rg_entry_t *)shm_malloc(
+							2 * pn->rg_len * sizeof(rg_entry_t)))) {
 			/* recover the old pointer to be able to shm_free mem */
 			/* recover the old pointer to be able to shm_free mem */
 			pn->rg = trg;
 			pn->rg = trg;
 			goto err_exit;
 			goto err_exit;
 		}
 		}
-		memset(pn->rg+pn->rg_len, 0, pn->rg_len*sizeof(rg_entry_t));
-		memcpy(pn->rg, trg, pn->rg_len*sizeof(rg_entry_t));
-		pn->rg_len*=2;
-		shm_free( trg );
+		memset(pn->rg + pn->rg_len, 0, pn->rg_len * sizeof(rg_entry_t));
+		memcpy(pn->rg, trg, pn->rg_len * sizeof(rg_entry_t));
+		pn->rg_len *= 2;
+		shm_free(trg);
 	}
 	}
 	/* insert into list */
 	/* insert into list */
 	r->ref_cnt++;
 	r->ref_cnt++;
-	if(NULL==pn->rg[i].rtlw){
+	if(NULL == pn->rg[i].rtlw) {
 		pn->rg[i].rtlw = rtl_wrp;
 		pn->rg[i].rtlw = rtl_wrp;
 		pn->rg[i].rgid = rgid;
 		pn->rg[i].rgid = rgid;
 		pn->rg_pos++;
 		pn->rg_pos++;
 		goto ok_exit;
 		goto ok_exit;
 	}
 	}
-	if( r->priority > pn->rg[i].rtlw->rtl->priority) {
+	if(r->priority > pn->rg[i].rtlw->rtl->priority) {
 		/* change the head of the list */
 		/* change the head of the list */
 		rtl_wrp->next = pn->rg[i].rtlw;
 		rtl_wrp->next = pn->rg[i].rtlw;
 		pn->rg[i].rtlw = rtl_wrp;
 		pn->rg[i].rtlw = rtl_wrp;
 		goto ok_exit;
 		goto ok_exit;
 	}
 	}
 	rtlw = pn->rg[i].rtlw;
 	rtlw = pn->rg[i].rtlw;
-	while( rtlw->next !=NULL) {
+	while(rtlw->next != NULL) {
 		if(r->priority > rtlw->next->rtl->priority) {
 		if(r->priority > rtlw->next->rtl->priority) {
 			rtl_wrp->next = rtlw->next;
 			rtl_wrp->next = rtlw->next;
 			rtlw->next = rtl_wrp;
 			rtlw->next = rtl_wrp;
@@ -247,72 +234,70 @@ add_rt_info(
 		rtlw = rtlw->next;
 		rtlw = rtlw->next;
 	}
 	}
 	/* the smallest priority is linked at the end */
 	/* the smallest priority is linked at the end */
-	rtl_wrp->next=NULL;
-	rtlw->next=rtl_wrp;
+	rtl_wrp->next = NULL;
+	rtlw->next = rtl_wrp;
 ok_exit:
 ok_exit:
 	return 0;
 	return 0;
 
 
 err_exit:
 err_exit:
-	if (rtl_wrp) shm_free(rtl_wrp);
+	if(rtl_wrp)
+		shm_free(rtl_wrp);
 	return -1;
 	return -1;
 }
 }
 
 
-int
-add_dst(
-	rt_data_t *r,
-	/* id */
-	int id,
-	/* ip address */ 
-	char* ip,
-	/* strip len */
-	int strip,
-	/* pri prefix */
-	char* pri,
-	/* dst type*/
-	int type,
-	/* dst attrs*/
-	char* attrs
-	)
+int add_dst(rt_data_t *r,
+		/* id */
+		int id,
+		/* ip address */
+		char *ip,
+		/* strip len */
+		int strip,
+		/* pri prefix */
+		char *pri,
+		/* dst type*/
+		int type,
+		/* dst attrs*/
+		char *attrs)
 {
 {
-	pgw_t *pgw=NULL, *tmp=NULL;
-	pgw_addr_t *tmpa=NULL;
-	struct hostent* he;
+	pgw_t *pgw = NULL, *tmp = NULL;
+	pgw_addr_t *tmpa = NULL;
+	struct hostent *he;
 	struct sip_uri uri;
 	struct sip_uri uri;
 	struct ip_addr ipa;
 	struct ip_addr ipa;
-	int l_ip,l_pri,l_attrs;
-#define GWABUF_MAX_SIZE	512
+	int l_ip, l_pri, l_attrs;
+#define GWABUF_MAX_SIZE 512
 	char gwabuf[GWABUF_MAX_SIZE];
 	char gwabuf[GWABUF_MAX_SIZE];
 	str gwas;
 	str gwas;
 
 
-	if (NULL==r || NULL==ip) {
+	if(NULL == r || NULL == ip) {
 		LM_ERR("invalid parametres\n");
 		LM_ERR("invalid parametres\n");
 		goto err_exit;
 		goto err_exit;
 	}
 	}
 
 
 	l_ip = strlen(ip);
 	l_ip = strlen(ip);
-	l_pri = pri?strlen(pri):0;
-	l_attrs = attrs?strlen(attrs):0;
+	l_pri = pri ? strlen(pri) : 0;
+	l_attrs = attrs ? strlen(attrs) : 0;
 
 
-	pgw = (pgw_t*)shm_malloc(sizeof(pgw_t) + l_ip + l_pri + l_attrs);
-	if (NULL==pgw) {
+	pgw = (pgw_t *)shm_malloc(sizeof(pgw_t) + l_ip + l_pri + l_attrs);
+	if(NULL == pgw) {
 		LM_ERR("no more shm mem (%u)\n",
 		LM_ERR("no more shm mem (%u)\n",
-			(unsigned int)(sizeof(pgw_t)+l_ip+l_pri +l_attrs));
+				(unsigned int)(sizeof(pgw_t) + l_ip + l_pri + l_attrs));
 		goto err_exit;
 		goto err_exit;
 	}
 	}
-	memset(pgw,0,sizeof(pgw_t));
+	memset(pgw, 0, sizeof(pgw_t));
 
 
-	pgw->ip.len= l_ip;
-	pgw->ip.s = (char*)(pgw+1);
+	pgw->ip.len = l_ip;
+	pgw->ip.s = (char *)(pgw + 1);
 	memcpy(pgw->ip.s, ip, l_ip);
 	memcpy(pgw->ip.s, ip, l_ip);
 
 
-	if (pri) {
+	if(pri) {
 		pgw->pri.len = l_pri;
 		pgw->pri.len = l_pri;
-		pgw->pri.s = ((char*)(pgw+1))+l_ip;
+		pgw->pri.s = ((char *)(pgw + 1)) + l_ip;
 		memcpy(pgw->pri.s, pri, l_pri);
 		memcpy(pgw->pri.s, pri, l_pri);
 	}
 	}
-	if (attrs) {
+	if(attrs) {
 		pgw->attrs.len = l_attrs;
 		pgw->attrs.len = l_attrs;
-		pgw->attrs.s = ((char*)(pgw+1))+l_ip+l_pri;
+		pgw->attrs.s = ((char *)(pgw + 1)) + l_ip + l_pri;
 		memcpy(pgw->attrs.s, attrs, l_attrs);
 		memcpy(pgw->attrs.s, attrs, l_attrs);
 	}
 	}
 	pgw->id = id;
 	pgw->id = id;
@@ -322,60 +307,57 @@ add_dst(
 	pgw->state = KA_STATE_UP;
 	pgw->state = KA_STATE_UP;
 
 
 	/* add address in the list */
 	/* add address in the list */
-	if(pgw->ip.len<5 || (strncasecmp("sip:", ip, 4)
-			&&strncasecmp("sips:", ip, 5)))
-	{
-		if(pgw->ip.len+4>=GWABUF_MAX_SIZE) {
+	if(pgw->ip.len < 5
+			|| (strncasecmp("sip:", ip, 4) && strncasecmp("sips:", ip, 5))) {
+		if(pgw->ip.len + 4 >= GWABUF_MAX_SIZE) {
 			LM_ERR("GW address (%d) longer "
 			LM_ERR("GW address (%d) longer "
-				"than %d\n",pgw->ip.len+4,GWABUF_MAX_SIZE);
+				   "than %d\n",
+					pgw->ip.len + 4, GWABUF_MAX_SIZE);
 			goto err_exit;
 			goto err_exit;
 		}
 		}
 		memcpy(gwabuf, "sip:", 4);
 		memcpy(gwabuf, "sip:", 4);
-		memcpy(gwabuf+4, ip, pgw->ip.len);
+		memcpy(gwabuf + 4, ip, pgw->ip.len);
 		gwas.s = gwabuf;
 		gwas.s = gwabuf;
-		gwas.len = 4+pgw->ip.len;
+		gwas.len = 4 + pgw->ip.len;
 	} else {
 	} else {
 		gwas.s = ip;
 		gwas.s = ip;
 		gwas.len = pgw->ip.len;
 		gwas.len = pgw->ip.len;
 	}
 	}
 
 
 	memset(&uri, 0, sizeof(struct sip_uri));
 	memset(&uri, 0, sizeof(struct sip_uri));
-	if(parse_uri(gwas.s, gwas.len, &uri)!=0) {
-		LM_ERR("invalid uri <%.*s>\n",
-			gwas.len, gwas.s);
+	if(parse_uri(gwas.s, gwas.len, &uri) != 0) {
+		LM_ERR("invalid uri <%.*s>\n", gwas.len, gwas.s);
 		goto err_exit;
 		goto err_exit;
 	}
 	}
 	/* note we discard the port discovered by the resolve function - we are
 	/* note we discard the port discovered by the resolve function - we are
 	interested only in the port that was actually configured. */
 	interested only in the port that was actually configured. */
-	if ((he=sip_resolvehost( &uri.host, NULL, (char*)(void*)&uri.proto))==0 ) {
-		if(dr_force_dns)
-		{
-			LM_ERR("cannot resolve <%.*s>\n",
-				uri.host.len, uri.host.s);
+	if((he = sip_resolvehost(&uri.host, NULL, (char *)(void *)&uri.proto))
+			== 0) {
+		if(dr_force_dns) {
+			LM_ERR("cannot resolve <%.*s>\n", uri.host.len, uri.host.s);
 			goto err_exit;
 			goto err_exit;
 		} else {
 		} else {
 			LM_DBG("cannot resolve <%.*s> - won't be used"
 			LM_DBG("cannot resolve <%.*s> - won't be used"
-					" by is_from_gw()\n", uri.host.len, uri.host.s);
+				   " by is_from_gw()\n",
+					uri.host.len, uri.host.s);
 			goto done;
 			goto done;
 		}
 		}
 	}
 	}
 	hostent2ip_addr(&ipa, he, 0);
 	hostent2ip_addr(&ipa, he, 0);
 	tmpa = r->pgw_addr_l;
 	tmpa = r->pgw_addr_l;
 	while(tmpa) {
 	while(tmpa) {
-		if(tmpa->type==type && uri.port_no==tmpa->port
-		&& ip_addr_cmp(&ipa, &tmpa->ip)) {
-			LM_DBG("gw ip addr [%s]:%d loaded\n",
-				ip_addr2a(&ipa), uri.port_no);
+		if(tmpa->type == type && uri.port_no == tmpa->port
+				&& ip_addr_cmp(&ipa, &tmpa->ip)) {
+			LM_DBG("gw ip addr [%s]:%d loaded\n", ip_addr2a(&ipa), uri.port_no);
 			goto done;
 			goto done;
 		}
 		}
 		tmpa = tmpa->next;
 		tmpa = tmpa->next;
 	}
 	}
-	
+
 	LM_DBG("new gw ip addr [%s]\n", ip);
 	LM_DBG("new gw ip addr [%s]\n", ip);
-	tmpa = (pgw_addr_t*)shm_malloc(sizeof(pgw_addr_t));
-	if(tmpa==NULL) {
-		LM_ERR("no more shm mem (%u)\n",
-			(unsigned int)sizeof(pgw_addr_t));
+	tmpa = (pgw_addr_t *)shm_malloc(sizeof(pgw_addr_t));
+	if(tmpa == NULL) {
+		LM_ERR("no more shm mem (%u)\n", (unsigned int)sizeof(pgw_addr_t));
 		goto err_exit;
 		goto err_exit;
 	}
 	}
 	memset(tmpa, 0, sizeof(pgw_addr_t));
 	memset(tmpa, 0, sizeof(pgw_addr_t));
@@ -387,7 +369,7 @@ add_dst(
 	r->pgw_addr_l = tmpa;
 	r->pgw_addr_l = tmpa;
 
 
 done:
 done:
-	if(NULL==r->pgw_l)
+	if(NULL == r->pgw_l)
 		r->pgw_l = pgw;
 		r->pgw_l = pgw;
 	else {
 	else {
 		tmp = r->pgw_l;
 		tmp = r->pgw_l;
@@ -398,57 +380,47 @@ done:
 	return 0;
 	return 0;
 
 
 err_exit:
 err_exit:
-	if(NULL!=pgw)
+	if(NULL != pgw)
 		shm_free(pgw);
 		shm_free(pgw);
 	return -1;
 	return -1;
 }
 }
 
 
-void
-del_pgw_list(
-		pgw_t *pgw_l
-		)
+void del_pgw_list(pgw_t *pgw_l)
 {
 {
 	pgw_t *t;
 	pgw_t *t;
-	while(NULL!=pgw_l){
+	while(NULL != pgw_l) {
 		t = pgw_l;
 		t = pgw_l;
-		pgw_l=pgw_l->next;
+		pgw_l = pgw_l->next;
 		shm_free(t);
 		shm_free(t);
 	}
 	}
 }
 }
 
 
-void
-del_pgw_addr_list(
-		pgw_addr_t *pgw_addr_l
-		)
+void del_pgw_addr_list(pgw_addr_t *pgw_addr_l)
 {
 {
 	pgw_addr_t *t;
 	pgw_addr_t *t;
-	while(NULL!=pgw_addr_l){
+	while(NULL != pgw_addr_l) {
 		t = pgw_addr_l;
 		t = pgw_addr_l;
-		pgw_addr_l=pgw_addr_l->next;
+		pgw_addr_l = pgw_addr_l->next;
 		shm_free(t);
 		shm_free(t);
 	}
 	}
 }
 }
 
 
-void 
-free_rt_data(
-		rt_data_t* rt_data,
-		int all
-		)
+void free_rt_data(rt_data_t *rt_data, int all)
 {
 {
 	int j;
 	int j;
-	if(NULL!=rt_data) {
+	if(NULL != rt_data) {
 		/* del GW list */
 		/* del GW list */
 		del_pgw_list(rt_data->pgw_l);
 		del_pgw_list(rt_data->pgw_l);
-		rt_data->pgw_l = 0 ;
+		rt_data->pgw_l = 0;
 		/* del GW addr list */
 		/* del GW addr list */
 		del_pgw_addr_list(rt_data->pgw_addr_l);
 		del_pgw_addr_list(rt_data->pgw_addr_l);
-		rt_data->pgw_addr_l =0;
+		rt_data->pgw_addr_l = 0;
 		/* del prefix tree */
 		/* del prefix tree */
 		del_tree(rt_data->pt);
 		del_tree(rt_data->pt);
 		/* del prefixless rules */
 		/* del prefixless rules */
-		if(NULL!=rt_data->noprefix.rg) {
-			for(j=0;j<rt_data->noprefix.rg_pos;j++) {
-				if(rt_data->noprefix.rg[j].rtlw !=NULL) {
+		if(NULL != rt_data->noprefix.rg) {
+			for(j = 0; j < rt_data->noprefix.rg_pos; j++) {
+				if(rt_data->noprefix.rg[j].rtlw != NULL) {
 					del_rt_list(rt_data->noprefix.rg[j].rtlw);
 					del_rt_list(rt_data->noprefix.rg[j].rtlw);
 					rt_data->noprefix.rg[j].rtlw = 0;
 					rt_data->noprefix.rg[j].rtlw = 0;
 				}
 				}
@@ -457,7 +429,9 @@ free_rt_data(
 			rt_data->noprefix.rg = 0;
 			rt_data->noprefix.rg = 0;
 		}
 		}
 		/* del top level or reset to 0 it's content */
 		/* del top level or reset to 0 it's content */
-		if (all) shm_free(rt_data);
-		else memset(rt_data, 0, sizeof(rt_data_t));
+		if(all)
+			shm_free(rt_data);
+		else
+			memset(rt_data, 0, sizeof(rt_data_t));
 	}
 	}
 }
 }

+ 35 - 46
src/modules/drouting/routing.h

@@ -32,10 +32,11 @@
 #define RG_INIT_LEN 4;
 #define RG_INIT_LEN 4;
 
 
 /* the buckets for the rt_data rg_hash */
 /* the buckets for the rt_data rg_hash */
-typedef struct hb_ {
+typedef struct hb_
+{
 	int rgid;
 	int rgid;
 	ptree_t *pt;
 	ptree_t *pt;
-	struct hb_*next;
+	struct hb_ *next;
 } hb_t;
 } hb_t;
 
 
 /* routing data is comprised of:
 /* routing data is comprised of:
@@ -43,7 +44,8 @@ typedef struct hb_ {
 	- a hash over routing groups containing
 	- a hash over routing groups containing
 	pointers to the coresponding prefix trees
 	pointers to the coresponding prefix trees
 */
 */
-typedef struct rt_data_ {
+typedef struct rt_data_
+{
 	/* list of PSTN gw */
 	/* list of PSTN gw */
 	pgw_t *pgw_l;
 	pgw_t *pgw_l;
 	/* list of IP addr for PSTN gw */
 	/* list of IP addr for PSTN gw */
@@ -52,63 +54,50 @@ typedef struct rt_data_ {
 	ptree_node_t noprefix;
 	ptree_node_t noprefix;
 	/* hash table with routing prefixes */
 	/* hash table with routing prefixes */
 	ptree_t *pt;
 	ptree_t *pt;
-}rt_data_t;
+} rt_data_t;
 
 
-typedef struct _dr_group {
+typedef struct _dr_group
+{
 	/* 0 - use grp ; 1 - use AVP */
 	/* 0 - use grp ; 1 - use AVP */
 	int type;
 	int type;
-	union {
+	union
+	{
 		unsigned int grp_id;
 		unsigned int grp_id;
-		struct _avp_id{
+		struct _avp_id
+		{
 			int_str name;
 			int_str name;
 			unsigned short type;
 			unsigned short type;
-		}avp_id;
-	}u;
+		} avp_id;
+	} u;
 } dr_group_t;
 } dr_group_t;
 
 
 /* init new rt_data structure */
 /* init new rt_data structure */
-rt_data_t*
-build_rt_data( void );
+rt_data_t *build_rt_data(void);
 
 
 
 
 /* add a PSTN gw in the list */
 /* add a PSTN gw in the list */
-int
-add_dst(
-	rt_data_t*,
-	/* id */
-	int ,
-	/* ip address */
-	char*,
-	/* strip len */
-	int,
-	/* pri prefix */
-	char*,
-	/* dst type*/
-	int,
-	/* dst attrs*/
-	char*
-	);
+int add_dst(rt_data_t *,
+		/* id */
+		int,
+		/* ip address */
+		char *,
+		/* strip len */
+		int,
+		/* pri prefix */
+		char *,
+		/* dst type*/
+		int,
+		/* dst attrs*/
+		char *);
 
 
 /* build a routing info list element */
 /* build a routing info list element */
-rt_info_t*
-build_rt_info(
-	int priority,
-	tmrec_t* time,
-	/* ser routing table id */
-	int route_id,
-	/* list of destinations indexes */
-	char* dstlst,
-	pgw_t* pgw_l
-);
+rt_info_t *build_rt_info(int priority, tmrec_t *time,
+		/* ser routing table id */
+		int route_id,
+		/* list of destinations indexes */
+		char *dstlst, pgw_t *pgw_l);
 
 
-void
-del_pgw_list(
-		pgw_t *pgw_l
-		);
+void del_pgw_list(pgw_t *pgw_l);
 
 
-void
-free_rt_data(
-		rt_data_t*,
-		int
-		);
+void free_rt_data(rt_data_t *, int);
 #endif
 #endif

Some files were not shown because too many files changed in this diff