Browse code

print line for fixing action error

- reported by Juha Heinanen

Daniel-Constantin Mierla authored on 15/11/2009 11:51:27
Showing 1 changed files
... ...
@@ -657,7 +657,8 @@ int fix_actions(struct action* a)
657 657
 							if (tmp==0){
658 658
 								LOG(L_CRIT, "ERROR: fix_actions:"
659 659
 										"memory allocation failure\n");
660
-								return E_OUT_OF_MEM;
660
+								ret = E_OUT_OF_MEM;
661
+								goto error;
661 662
 							}
662 663
 							t->val[0].type=STRING_ST;
663 664
 							t->val[0].u.string=tmp;
... ...
@@ -666,7 +667,7 @@ int fix_actions(struct action* a)
666 666
 							s.s = t->val[0].u.string;
667 667
 							s.len = strlen(s.s);
668 668
 							p=add_proxy(&s, t->val[1].u.number, 0); /* FIXME proto*/
669
-							if (p==0) return E_BAD_ADDRESS;
669
+							if (p==0) { ret =E_BAD_ADDRESS; goto error; }
670 670
 							t->val[0].u.data=p;
671 671
 							t->val[0].type=PROXY_ST;
672 672
 							break;
... ...
@@ -676,7 +677,8 @@ int fix_actions(struct action* a)
676 676
 							LOG(L_CRIT, "BUG: fix_actions: invalid type"
677 677
 									"%d (should be string or number)\n",
678 678
 										t->type);
679
-							return E_BUG;
679
+							ret = E_BUG;
680
+							goto error;
680 681
 					}
681 682
 					break;
682 683
 			case IF_T:
... ...
@@ -684,19 +686,22 @@ int fix_actions(struct action* a)
684 684
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
685 685
 								"%d for if (should be rval expr)\n",
686 686
 								t->val[0].type);
687
-					return E_BUG;
687
+					ret = E_BUG;
688
+					goto error;
688 689
 				}else if( (t->val[1].type!=ACTIONS_ST) &&
689 690
 							(t->val[1].type!=NOSUBTYPE) ){
690 691
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
691 692
 								"%d for if() {...} (should be action)\n",
692 693
 								t->val[1].type);
693
-					return E_BUG;
694
+					ret = E_BUG;
695
+					goto error;
694 696
 				}else if( (t->val[2].type!=ACTIONS_ST) &&
695 697
 							(t->val[2].type!=NOSUBTYPE) ){
696 698
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
697 699
 								"%d for if() {} else{...}(should be action)\n",
698 700
 								t->val[2].type);
699
-					return E_BUG;
701
+					ret = E_BUG;
702
+					goto error;
700 703
 				}
701 704
 				rve=(struct rval_expr*)t->val[0].u.data;
702 705
 				if (rve){
... ...
@@ -715,7 +720,8 @@ int fix_actions(struct action* a)
715 715
 							LOG(L_ERR, "fix_actions: invalid expression "
716 716
 									"(%d,%d): type mismatch?",
717 717
 									rve->fpos.s_line, rve->fpos.s_col);
718
-						return E_UNSPEC;
718
+						ret = E_UNSPEC;
719
+						goto error;
719 720
 					}
720 721
 					/* it's not an error anymore to have non-int in an if,
721 722
 					   only a script warning (to allow backward compat. stuff
... ...
@@ -728,16 +734,16 @@ int fix_actions(struct action* a)
728 728
 					}
729 729
 					*/
730 730
 					if ((ret=fix_rval_expr((void**)&rve))<0)
731
-						return ret;
731
+						goto error;
732 732
 				}
733 733
 				if ( (t->val[1].type==ACTIONS_ST)&&(t->val[1].u.data) ){
734 734
 					if ((ret=fix_actions((struct action*)t->val[1].u.data))<0)
735
-						return ret;
735
+						goto error;
736 736
 				}
737 737
 				if ( (t->val[2].type==ACTIONS_ST)&&(t->val[2].u.data) ){
738 738
 						if ((ret=fix_actions((struct action*)t->val[2].u.data))
739 739
 								<0)
740
-						return ret;
740
+						goto error;
741 741
 				}
742 742
 				break;
743 743
 			case SWITCH_T:
... ...
@@ -745,35 +751,40 @@ int fix_actions(struct action* a)
745 745
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
746 746
 								"%d for switch() (should be expr)\n",
747 747
 								t->val[0].type);
748
-					return E_BUG;
748
+					ret = E_BUG;
749
+					goto error;
749 750
 				}else if (t->val[1].type!=CASE_ST){
750 751
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
751 752
 								"%d for switch(...){...}(should be case)\n",
752 753
 								t->val[1].type);
753
-					return E_BUG;
754
+					ret = E_BUG;
755
+					goto error;
754 756
 				}
755 757
 				if (t->val[0].u.data){
756 758
 					if ((ret=fix_rval_expr(&t->val[0].u.data))<0)
757
-						return ret;
759
+						goto error;
758 760
 				}else{
759 761
 					LOG(L_CRIT, "BUG: fix_actions: null switch()"
760 762
 							" expression\n");
761
-					return E_BUG;
763
+					ret = E_BUG;
764
+					goto error;
762 765
 				}
763 766
 				if ((ret=fix_switch(t))<0)
764
-					return ret;
767
+					goto error;
765 768
 				break;
766 769
 			case WHILE_T:
767 770
 				if (t->val[0].type!=RVE_ST){
768 771
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
769 772
 								"%d for while() (should be expr)\n",
770 773
 								t->val[0].type);
771
-					return E_BUG;
774
+					ret = E_BUG;
775
+					goto error;
772 776
 				}else if (t->val[1].type!=ACTIONS_ST){
773 777
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
774 778
 								"%d for while(...){...}(should be action)\n",
775 779
 								t->val[1].type);
776
-					return E_BUG;
780
+					ret = E_BUG;
781
+					goto error;
777 782
 				}
778 783
 				rve=(struct rval_expr*)t->val[0].u.data;
779 784
 				if (rve){
... ...
@@ -792,24 +803,27 @@ int fix_actions(struct action* a)
792 792
 							LOG(L_ERR, "fix_actions: invalid expression "
793 793
 									"(%d,%d): type mismatch?",
794 794
 									rve->fpos.s_line, rve->fpos.s_col);
795
-						return E_UNSPEC;
795
+						ret = E_UNSPEC;
796
+						goto error;
796 797
 					}
797 798
 					if (rve_type!=RV_INT && rve_type!=RV_NONE){
798 799
 						LOG(L_ERR, "fix_actions: invalid expression (%d,%d):"
799 800
 								" bad type, integer expected\n",
800 801
 								rve->fpos.s_line, rve->fpos.s_col);
801
-						return E_UNSPEC;
802
+						ret = E_UNSPEC;
803
+						goto error;
802 804
 					}
803 805
 					if ((ret=fix_rval_expr((void**)&rve))<0)
804
-						return ret;
806
+						goto error;
805 807
 				}else{
806 808
 					LOG(L_CRIT, "BUG: fix_actions: null while()"
807 809
 							" expression\n");
808
-					return E_BUG;
810
+					ret = E_BUG;
811
+					goto error;
809 812
 				}
810 813
 				if ( t->val[1].u.data && 
811 814
 					((ret= fix_actions((struct action*)t->val[1].u.data))<0)){
812
-					return ret;
815
+					goto error;
813 816
 				}
814 817
 				break;
815 818
 			case DROP_T:
... ...
@@ -833,20 +847,23 @@ int fix_actions(struct action* a)
833 833
 							LOG(L_ERR, "fix_actions: invalid expression "
834 834
 									"(%d,%d): type mismatch?",
835 835
 									rve->fpos.s_line, rve->fpos.s_col);
836
-						return E_UNSPEC;
836
+						ret = E_UNSPEC;
837
+						goto error;
837 838
 					}
838 839
 					if (rve_type!=RV_INT && rve_type!=RV_NONE){
839 840
 						LOG(L_ERR, "fix_actions: invalid expression (%d,%d):"
840 841
 								" bad type, integer expected\n",
841 842
 								rve->fpos.s_line, rve->fpos.s_col);
842
-						return E_UNSPEC;
843
+						ret = E_UNSPEC;
844
+						goto error;
843 845
 					}
844 846
 					if ((ret=fix_rval_expr((void**)&rve))<0)
845
-						return ret;
847
+						goto error;
846 848
 				}else{
847 849
 					LOG(L_CRIT, "BUG: fix_actions: null drop/return"
848 850
 							" expression\n");
849
-					return E_BUG;
851
+					ret = E_BUG;
852
+					goto error;
850 853
 				}
851 854
 				break;
852 855
 			case ASSIGN_T:
... ...
@@ -854,12 +871,14 @@ int fix_actions(struct action* a)
854 854
 				if (t->val[0].type !=LVAL_ST) {
855 855
 					LOG(L_CRIT, "BUG: fix_actions: Invalid left side of"
856 856
 								" assignment\n");
857
-					return E_BUG;
857
+					ret = E_BUG;
858
+					goto error;
858 859
 				}
859 860
 				if (t->val[1].type !=RVE_ST) {
860 861
 					LOG(L_CRIT, "BUG: fix_actions: Invalid right side of"
861 862
 								" assignment (%d)\n", t->val[1].type);
862
-					return E_BUG;
863
+					ret = E_BUG;
864
+					goto error;
863 865
 				}
864 866
 				lval=t->val[0].u.data;
865 867
 				if (lval->type==LV_AVP){
... ...
@@ -867,16 +886,18 @@ int fix_actions(struct action* a)
867 867
 						LOG(L_ERR, "ERROR: You cannot change domain"
868 868
 									" attributes from the script, they are"
869 869
 									" read-only\n");
870
-						return E_BUG;
870
+						ret = E_BUG;
871
+						goto error;
871 872
 					} else if (lval->lv.avps.type & AVP_CLASS_GLOBAL) {
872 873
 						LOG(L_ERR, "ERROR: You cannot change global"
873 874
 								   " attributes from the script, they are"
874 875
 								   "read-only\n");
875
-						return E_BUG;
876
+						ret = E_BUG;
877
+						goto error;
876 878
 					}
877 879
 				}
878 880
 				if ((ret=fix_rval_expr(&t->val[1].u.data))<0)
879
-					return ret;
881
+					goto error;
880 882
 				break;
881 883
 
882 884
 			case MODULE_T:
... ...
@@ -891,7 +912,7 @@ int fix_actions(struct action* a)
891 891
 					if (t->val[1].u.number==0) {
892 892
 						ret = cmd->c.fixup(0, 0);
893 893
 						if (ret < 0)
894
-							return ret;
894
+							goto error;
895 895
 					}
896 896
 					/* type cast NUMBER to STRING, old modules may expect
897 897
 					 * all STRING params during fixup */
... ...
@@ -904,7 +925,8 @@ int fix_actions(struct action* a)
904 904
 							if (!t->val[i+2].u.string) {
905 905
 								LOG(L_CRIT, "ERROR: cannot translate NUMBER"
906 906
 											" to STRING\n");
907
-								return E_OUT_OF_MEM;
907
+								ret = E_OUT_OF_MEM;
908
+								goto error;
908 909
 							}
909 910
 							strcpy(t->val[i+2].u.string, buf);
910 911
 							t->val[i+2].type = STRING_ST;
... ...
@@ -917,7 +939,7 @@ int fix_actions(struct action* a)
917 917
 						if (t->val[i+2].u.data != p)
918 918
 							t->val[i+2].type = MODFIXUP_ST;
919 919
 						if (ret < 0)
920
-							return ret;
920
+							goto error;
921 921
 					}
922 922
 				}
923 923
 				break;
... ...
@@ -926,7 +948,8 @@ int fix_actions(struct action* a)
926 926
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
927 927
 								"%d for force_send_socket\n",
928 928
 								t->val[0].type);
929
-					return E_BUG;
929
+					ret = E_BUG;
930
+					goto error;
930 931
 				}
931 932
 				he=resolvehost(
932 933
 						((struct socket_id*)t->val[0].u.data)->addr_lst->name
... ...
@@ -935,7 +958,8 @@ int fix_actions(struct action* a)
935 935
 					LOG(L_ERR, "ERROR: fix_actions: force_send_socket:"
936 936
 								" could not resolve %s\n",
937 937
 						((struct socket_id*)t->val[0].u.data)->addr_lst->name);
938
-					return E_BAD_ADDRESS;
938
+					ret = E_BAD_ADDRESS;
939
+					goto error;
939 940
 				}
940 941
 				hostent2ip_addr(&ip, he, 0);
941 942
 				si=find_si(&ip, ((struct socket_id*)t->val[0].u.data)->port,
... ...
@@ -945,7 +969,8 @@ int fix_actions(struct action* a)
945 945
 							" argument: %s:%d (ser doesn't listen on it)\n",
946 946
 						((struct socket_id*)t->val[0].u.data)->addr_lst->name,
947 947
 							((struct socket_id*)t->val[0].u.data)->port);
948
-					return E_BAD_ADDRESS;
948
+					ret = E_BAD_ADDRESS;
949
+					goto error;
949 950
 				}
950 951
 				t->val[0].u.data=si;
951 952
 				t->val[0].type=SOCKETINFO_ST;
... ...
@@ -955,7 +980,8 @@ int fix_actions(struct action* a)
955 955
 					LOG(L_CRIT, "BUG: fix_actions: invalid subtype"
956 956
 								"%d for udp_mtu_try_proto\n",
957 957
 								t->val[0].type);
958
-					return E_BUG;
958
+					ret = E_BUG;
959
+					goto error;
959 960
 				}
960 961
 				switch(t->val[0].u.number){
961 962
 					case PROTO_UDP:
... ...
@@ -980,7 +1006,8 @@ int fix_actions(struct action* a)
980 980
 				if (t->val[0].type!=STRING_ST){
981 981
 					BUG("invalid subtype%d for append_branch_t\n",
982 982
 								t->val[0].type);
983
-					return E_BUG;
983
+					ret = E_BUG;
984
+					goto error;
984 985
 				}
985 986
 				s.s=t->val[0].u.string;
986 987
 				s.len=(s.s)?strlen(s.s):0;
... ...
@@ -993,6 +1020,10 @@ int fix_actions(struct action* a)
993 993
 		}
994 994
 	}
995 995
 	return 0;
996
+
997
+error:
998
+	LM_ERR("fixing failed (code=%d) at cfg line %d\n", ret, t->cline);
999
+	return ret;
996 1000
 }
997 1001
 
998 1002