Browse code

- exec_pre_cb fix backported from unstable

Andrei Pelinescu-Onciul authored on 30/04/2004 12:51:01
Showing 2 changed files
... ...
@@ -33,6 +33,8 @@
33 33
  * 2003-02-10 moved zero-term in the calling functions (udp_receive &
34 34
  *            tcp_read_req)
35 35
  * 2003-08-13 fixed exec_pre_cb returning 0 (backported from stable) (andrei)
36
+ * 2004-04-30 exec_pre_cb is called after basic sanity checks (at least one
37
+ *            via present & parsed ok)  (andrei)
36 38
  */
37 39
 
38 40
 
... ...
@@ -53,8 +55,6 @@
53 55
 #include "script_cb.h"
54 56
 #include "dset.h"
55 57
 
56
-#include "tcp_server.h" /* for tcpconn_add_alias */
57
-
58 58
 
59 59
 #ifdef DEBUG_DMALLOC
60 60
 #include <mem/dmalloc.h>
... ...
@@ -110,17 +110,8 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
110 110
 	}
111 111
 	DBG("After parse_msg...\n");
112 112
 
113
-	/* execute pre-script callbacks, if any; -jiri */
114
-	/* if some of the callbacks said not to continue with
115
-	   script processing, don't do so
116
-	*/
117
-	ret=exec_pre_cb(msg);
118
-	if (ret<=0){
119
-		if (ret<0) goto error;
120
-		else goto end; /* drop the message -- no error -- andrei */
121
-	}
122 113
 
123
-	/* ... and clear branches from previous message */
114
+	/* ... clear branches from previous message */
124 115
 	clear_branches();
125 116
 
126 117
 	if (msg->first_line.type==SIP_REQUEST){
... ...
@@ -131,30 +122,25 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
131 122
 			goto error;
132 123
 		}
133 124
 		/* check if neccesarry to add receive?->moved to forward_req */
134
-		/* check for the alias stuff */
135
-#ifdef USE_TCP
136
-		if (msg->via1->alias && tcp_accept_aliases && 
137
-				(((rcv_info->proto==PROTO_TCP) && !tcp_disable)
138
-#ifdef USE_TLS
139
-					|| ((rcv_info->proto==PROTO_TLS) && !tls_disable)
140
-#endif
141
-				)
142
-			){
143
-			if (tcpconn_add_alias(rcv_info->proto_reserved1, msg->via1->port,
144
-									rcv_info->proto)!=0){
145
-				LOG(L_ERR, " ERROR: receive_msg: tcp alias failed\n");
146
-				/* continue */
147
-			}
148
-		}
149
-#endif
150 125
 
151
-		/* exec routing script */
152 126
 		DBG("preparing to run routing scripts...\n");
153 127
 #ifdef  STATS
154 128
 		gettimeofday( & tvb, &tz );
155 129
 #endif
130
+		/* execute pre-script callbacks, if any; -jiri */
131
+		/* if some of the callbacks said not to continue with
132
+		   script processing, don't do so
133
+		   if we are here basic sanity checks are already done
134
+		   (like presence of at least one via), so you can count
135
+		   on via1 being parsed in a pre-script callback --andrei
136
+		*/
137
+		ret=exec_pre_cb(msg);
138
+		if (ret<=0){
139
+			if (ret<0) goto error;
140
+			else goto end; /* drop the message -- no error -- andrei */
141
+		}
142
+		/* exec the routing script */
156 143
 		if (run_actions(rlist[0], msg)<0){
157
-
158 144
 			LOG(L_WARN, "WARNING: receive_msg: "
159 145
 					"error while trying script\n");
160 146
 			goto error;
... ...
@@ -190,6 +176,19 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info)
190 176
 		STATS_RX_RESPONSE ( msg->first_line.u.reply.statuscode / 100 );
191 177
 #endif
192 178
 		
179
+		/* execute pre-script callbacks, if any; -jiri */
180
+		/* if some of the callbacks said not to continue with
181
+		   script processing, don't do so
182
+		   if we are here basic sanity checks are already done
183
+		   (like presence of at least one via), so you can count
184
+		   on via1 being parsed in a pre-script callback --andrei
185
+		*/
186
+		ret=exec_pre_cb(msg);
187
+		if (ret<=0){
188
+			if (ret<0) goto error;
189
+			else goto end; /* drop the message -- no error -- andrei */
190
+		}
191
+
193 192
 		/* send the msg */
194 193
 		forward_reply(msg);
195 194
 
... ...
@@ -48,7 +48,6 @@
48 48
 #include "globals.h"
49 49
 #include "crc.h"
50 50
 #include "str.h"
51
-#include "socket_info.h"
52 51
 
53 52
 #define TOTAG_VALUE_LEN (MD5_LEN+CRC16_LEN+1)
54 53
 
... ...
@@ -61,6 +60,7 @@ static inline void calc_crc_suffix( struct sip_msg *msg, char *tag_suffix)
61 60
 	str suffix_source[3];
62 61
 
63 62
 	ss_nr=2;
63
+	if (msg->via1==0) return; /* no via, bad message */
64 64
 	suffix_source[0]=msg->via1->host;
65 65
 	suffix_source[1]=msg->via1->port_str;
66 66
 	if (msg->via1->branch)
... ...
@@ -72,15 +72,12 @@ static void inline init_tags( char *tag, char **suffix,
72 72
 		char *signature, char separator )
73 73
 {
74 74
 	str src[3];
75
-	struct socket_info* si;
76
-	
77
-	si=get_first_socket();
75
+
78 76
 	src[0].s=signature; src[0].len=strlen(signature);
79
-	/* if we are not listening on anything we shouldn't be here */
80
-	src[1].s=si?si->address_str.s:"";
81
-	src[1].len=si?si->address_str.len:0;
82
-	src[2].s=si?si->port_no_str.s:"";
83
-	src[2].len=si?si->port_no_str.len:0;
77
+	src[1].s=sock_info[0].address_str.s;
78
+	src[1].len=sock_info[0].address_str.len;
79
+	src[2].s=sock_info[0].port_no_str.s;
80
+	src[2].len=sock_info[0].port_no_str.len;
84 81
 
85 82
 	MDStringArray( tag, src, 3 );
86 83