[sr-dev] git:sr_3.0: print line for fixing action error

Juha Heinanen jh at tutpro.com
Sun Nov 15 23:46:39 CET 2009


Module: sip-router
Branch: sr_3.0
Commit: c57e33e33b8b46ffb2d97fba55011b214dd4a4c1
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c57e33e33b8b46ffb2d97fba55011b214dd4a4c1

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Juha Heinanen <jh at tutpro.com>
Date:   Sun Nov 15 12:51:27 2009 +0100

print line for fixing action error

- reported by Juha Heinanen

---

 route.c |  109 ++++++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 70 insertions(+), 39 deletions(-)

diff --git a/route.c b/route.c
index 8d6f2c6..8887c8a 100644
--- a/route.c
+++ b/route.c
@@ -657,7 +657,8 @@ int fix_actions(struct action* a)
 							if (tmp==0){
 								LOG(L_CRIT, "ERROR: fix_actions:"
 										"memory allocation failure\n");
-								return E_OUT_OF_MEM;
+								ret = E_OUT_OF_MEM;
+								goto error;
 							}
 							t->val[0].type=STRING_ST;
 							t->val[0].u.string=tmp;
@@ -666,7 +667,7 @@ int fix_actions(struct action* a)
 							s.s = t->val[0].u.string;
 							s.len = strlen(s.s);
 							p=add_proxy(&s, t->val[1].u.number, 0); /* FIXME proto*/
-							if (p==0) return E_BAD_ADDRESS;
+							if (p==0) { ret =E_BAD_ADDRESS; goto error; }
 							t->val[0].u.data=p;
 							t->val[0].type=PROXY_ST;
 							break;
@@ -676,7 +677,8 @@ int fix_actions(struct action* a)
 							LOG(L_CRIT, "BUG: fix_actions: invalid type"
 									"%d (should be string or number)\n",
 										t->type);
-							return E_BUG;
+							ret = E_BUG;
+							goto error;
 					}
 					break;
 			case IF_T:
@@ -684,19 +686,22 @@ int fix_actions(struct action* a)
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
 								"%d for if (should be rval expr)\n",
 								t->val[0].type);
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}else if( (t->val[1].type!=ACTIONS_ST) &&
 							(t->val[1].type!=NOSUBTYPE) ){
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
 								"%d for if() {...} (should be action)\n",
 								t->val[1].type);
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}else if( (t->val[2].type!=ACTIONS_ST) &&
 							(t->val[2].type!=NOSUBTYPE) ){
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
 								"%d for if() {} else{...}(should be action)\n",
 								t->val[2].type);
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}
 				rve=(struct rval_expr*)t->val[0].u.data;
 				if (rve){
@@ -715,7 +720,8 @@ int fix_actions(struct action* a)
 							LOG(L_ERR, "fix_actions: invalid expression "
 									"(%d,%d): type mismatch?",
 									rve->fpos.s_line, rve->fpos.s_col);
-						return E_UNSPEC;
+						ret = E_UNSPEC;
+						goto error;
 					}
 					/* it's not an error anymore to have non-int in an if,
 					   only a script warning (to allow backward compat. stuff
@@ -728,16 +734,16 @@ int fix_actions(struct action* a)
 					}
 					*/
 					if ((ret=fix_rval_expr((void**)&rve))<0)
-						return ret;
+						goto error;
 				}
 				if ( (t->val[1].type==ACTIONS_ST)&&(t->val[1].u.data) ){
 					if ((ret=fix_actions((struct action*)t->val[1].u.data))<0)
-						return ret;
+						goto error;
 				}
 				if ( (t->val[2].type==ACTIONS_ST)&&(t->val[2].u.data) ){
 						if ((ret=fix_actions((struct action*)t->val[2].u.data))
 								<0)
-						return ret;
+						goto error;
 				}
 				break;
 			case SWITCH_T:
@@ -745,35 +751,40 @@ int fix_actions(struct action* a)
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
 								"%d for switch() (should be expr)\n",
 								t->val[0].type);
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}else if (t->val[1].type!=CASE_ST){
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
 								"%d for switch(...){...}(should be case)\n",
 								t->val[1].type);
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}
 				if (t->val[0].u.data){
 					if ((ret=fix_rval_expr(&t->val[0].u.data))<0)
-						return ret;
+						goto error;
 				}else{
 					LOG(L_CRIT, "BUG: fix_actions: null switch()"
 							" expression\n");
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}
 				if ((ret=fix_switch(t))<0)
-					return ret;
+					goto error;
 				break;
 			case WHILE_T:
 				if (t->val[0].type!=RVE_ST){
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
 								"%d for while() (should be expr)\n",
 								t->val[0].type);
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}else if (t->val[1].type!=ACTIONS_ST){
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
 								"%d for while(...){...}(should be action)\n",
 								t->val[1].type);
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}
 				rve=(struct rval_expr*)t->val[0].u.data;
 				if (rve){
@@ -792,24 +803,27 @@ int fix_actions(struct action* a)
 							LOG(L_ERR, "fix_actions: invalid expression "
 									"(%d,%d): type mismatch?",
 									rve->fpos.s_line, rve->fpos.s_col);
-						return E_UNSPEC;
+						ret = E_UNSPEC;
+						goto error;
 					}
 					if (rve_type!=RV_INT && rve_type!=RV_NONE){
 						LOG(L_ERR, "fix_actions: invalid expression (%d,%d):"
 								" bad type, integer expected\n",
 								rve->fpos.s_line, rve->fpos.s_col);
-						return E_UNSPEC;
+						ret = E_UNSPEC;
+						goto error;
 					}
 					if ((ret=fix_rval_expr((void**)&rve))<0)
-						return ret;
+						goto error;
 				}else{
 					LOG(L_CRIT, "BUG: fix_actions: null while()"
 							" expression\n");
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}
 				if ( t->val[1].u.data && 
 					((ret= fix_actions((struct action*)t->val[1].u.data))<0)){
-					return ret;
+					goto error;
 				}
 				break;
 			case DROP_T:
@@ -833,20 +847,23 @@ int fix_actions(struct action* a)
 							LOG(L_ERR, "fix_actions: invalid expression "
 									"(%d,%d): type mismatch?",
 									rve->fpos.s_line, rve->fpos.s_col);
-						return E_UNSPEC;
+						ret = E_UNSPEC;
+						goto error;
 					}
 					if (rve_type!=RV_INT && rve_type!=RV_NONE){
 						LOG(L_ERR, "fix_actions: invalid expression (%d,%d):"
 								" bad type, integer expected\n",
 								rve->fpos.s_line, rve->fpos.s_col);
-						return E_UNSPEC;
+						ret = E_UNSPEC;
+						goto error;
 					}
 					if ((ret=fix_rval_expr((void**)&rve))<0)
-						return ret;
+						goto error;
 				}else{
 					LOG(L_CRIT, "BUG: fix_actions: null drop/return"
 							" expression\n");
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}
 				break;
 			case ASSIGN_T:
@@ -854,12 +871,14 @@ int fix_actions(struct action* a)
 				if (t->val[0].type !=LVAL_ST) {
 					LOG(L_CRIT, "BUG: fix_actions: Invalid left side of"
 								" assignment\n");
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}
 				if (t->val[1].type !=RVE_ST) {
 					LOG(L_CRIT, "BUG: fix_actions: Invalid right side of"
 								" assignment (%d)\n", t->val[1].type);
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}
 				lval=t->val[0].u.data;
 				if (lval->type==LV_AVP){
@@ -867,16 +886,18 @@ int fix_actions(struct action* a)
 						LOG(L_ERR, "ERROR: You cannot change domain"
 									" attributes from the script, they are"
 									" read-only\n");
-						return E_BUG;
+						ret = E_BUG;
+						goto error;
 					} else if (lval->lv.avps.type & AVP_CLASS_GLOBAL) {
 						LOG(L_ERR, "ERROR: You cannot change global"
 								   " attributes from the script, they are"
 								   "read-only\n");
-						return E_BUG;
+						ret = E_BUG;
+						goto error;
 					}
 				}
 				if ((ret=fix_rval_expr(&t->val[1].u.data))<0)
-					return ret;
+					goto error;
 				break;
 
 			case MODULE_T:
@@ -891,7 +912,7 @@ int fix_actions(struct action* a)
 					if (t->val[1].u.number==0) {
 						ret = cmd->c.fixup(0, 0);
 						if (ret < 0)
-							return ret;
+							goto error;
 					}
 					/* type cast NUMBER to STRING, old modules may expect
 					 * all STRING params during fixup */
@@ -904,7 +925,8 @@ int fix_actions(struct action* a)
 							if (!t->val[i+2].u.string) {
 								LOG(L_CRIT, "ERROR: cannot translate NUMBER"
 											" to STRING\n");
-								return E_OUT_OF_MEM;
+								ret = E_OUT_OF_MEM;
+								goto error;
 							}
 							strcpy(t->val[i+2].u.string, buf);
 							t->val[i+2].type = STRING_ST;
@@ -917,7 +939,7 @@ int fix_actions(struct action* a)
 						if (t->val[i+2].u.data != p)
 							t->val[i+2].type = MODFIXUP_ST;
 						if (ret < 0)
-							return ret;
+							goto error;
 					}
 				}
 				break;
@@ -926,7 +948,8 @@ int fix_actions(struct action* a)
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
 								"%d for force_send_socket\n",
 								t->val[0].type);
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}
 				he=resolvehost(
 						((struct socket_id*)t->val[0].u.data)->addr_lst->name
@@ -935,7 +958,8 @@ int fix_actions(struct action* a)
 					LOG(L_ERR, "ERROR: fix_actions: force_send_socket:"
 								" could not resolve %s\n",
 						((struct socket_id*)t->val[0].u.data)->addr_lst->name);
-					return E_BAD_ADDRESS;
+					ret = E_BAD_ADDRESS;
+					goto error;
 				}
 				hostent2ip_addr(&ip, he, 0);
 				si=find_si(&ip, ((struct socket_id*)t->val[0].u.data)->port,
@@ -945,7 +969,8 @@ int fix_actions(struct action* a)
 							" argument: %s:%d (ser doesn't listen on it)\n",
 						((struct socket_id*)t->val[0].u.data)->addr_lst->name,
 							((struct socket_id*)t->val[0].u.data)->port);
-					return E_BAD_ADDRESS;
+					ret = E_BAD_ADDRESS;
+					goto error;
 				}
 				t->val[0].u.data=si;
 				t->val[0].type=SOCKETINFO_ST;
@@ -955,7 +980,8 @@ int fix_actions(struct action* a)
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
 								"%d for udp_mtu_try_proto\n",
 								t->val[0].type);
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}
 				switch(t->val[0].u.number){
 					case PROTO_UDP:
@@ -980,7 +1006,8 @@ int fix_actions(struct action* a)
 				if (t->val[0].type!=STRING_ST){
 					BUG("invalid subtype%d for append_branch_t\n",
 								t->val[0].type);
-					return E_BUG;
+					ret = E_BUG;
+					goto error;
 				}
 				s.s=t->val[0].u.string;
 				s.len=(s.s)?strlen(s.s):0;
@@ -993,6 +1020,10 @@ int fix_actions(struct action* a)
 		}
 	}
 	return 0;
+
+error:
+	LM_ERR("fixing failed (code=%d) at cfg line %d\n", ret, t->cline);
+	return ret;
 }
 
 




More information about the sr-dev mailing list