Browse code

bug_fix: route_set reversed

Jiri Kuthan authored on 01/03/2003 16:13:00
Showing 1 changed files
... ...
@@ -29,10 +29,11 @@
29 29
 # support REFER; dialog parser over-simplified (see inline) but 
30 30
 # quite functional (if there is something to be fixed, it is
31 31
 # richness of SIP syntax); an awk-only rewrite would be esthetically
32
-# nicer, imho 
32
+# nicer, imho. Never tested on solaris.
33 33
 #
34 34
 # History:
35 35
 # --------
36
+# 2003-03-01 bug_fix: route set reversed
36 37
 # 2003-02-27 dialog support completed (jiri)
37 38
 
38 39
 #--------------------------------
... ...
@@ -79,33 +80,41 @@ awk -F ' ' '
79 80
 BEGIN { IGNORECASE=1; rri=0; line=0; ret=1;eoh=0 }
80 81
 END { # print dialog information a la RFC3261, S. 12.2.1.1
81 82
 	# calculate route set 
83
+	sr=0
82 84
 	if (rri>0) { # route set not empty
83 85
 		# next-hop loose router?
84
-		if (match(rr[1], ";lr")) {
86
+		if (match(rr[rri], ";lr")) {
85 87
 			ruri=rcontact
86
-			nexthop=rr[1]
87
-			rrb=1 # begin from first
88
+			nexthop=rr[rri]
89
+			rre=rri # begin from first
88 90
 		} else { # next-hop strict router
89
-			ruri=rr[1]
90
-			rrb=2 # skip first
91
-			rri++
92
-			rr[rri]=rcontact
91
+			ruri=rr[rri]
92
+			rre=rri-1 # skip last
93
+			sr=1
94
+			#rri++
95
+			#rr[rri]=rcontact
93 96
 			nexthop="." # t_uac_dlg value for "use ruri"
94 97
 		}
95 98
 	} else { # no record-routing
96 99
 			ruri=rcontact
97 100
 			nexthop="."
98
-			rrb=1 # do not enter the loop
101
+			rre=0 # do not enter the loop
99 102
 	}
100 103
 	# print the FIFO request header
101 104
 	print ruri
102 105
 	print nexthop
103 106
 	print to
104
-	for(i=rrb; i<=rri; i++ ) {
105
-		if (i==rrb) printf "Route: "; else printf ", "
107
+	for(i=rre; i>=1; i-- ) { # reverse
108
+		if (i==rre) printf "Route: "; else printf ", "
106 109
 		printf("%s", rr[i])
107
-		if (i==rri) printf("\n")
108
-		
110
+		if (i==1) {
111
+			printf("\n")
112
+		}
113
+	}
114
+	if (sr==1) { 
115
+		printf "Route: "
116
+		printf  rcontact
117
+		printf "\n" 
109 118
 	}
110 119
 	exit ret
111 120
 }
... ...
@@ -113,7 +122,7 @@ END { # print dialog information a la RFC3261, S. 12.2.1.1
113 122
 # set true (0) to return value if transaction completed succesfully
114 123
 {line++; }
115 124
 line==1 && /^2[0-9][0-9] / { ret=0; next; }
116
-line==1 && /^[3-6][0-9][0-9] / { print; next; }
125
+line==1 && /^[3-6][0-9][0-9] / { print; print $0 > "/dev/stderr"; next; }
117 126
 line==1 { print "reply error"; print; next; } 
118 127
 
119 128
 # skip body