Browse code

- fixed warning builder

Andrei Pelinescu-Onciul authored on 13/04/2003 17:19:10
Showing 3 changed files
... ...
@@ -21,7 +21,7 @@
21 21
 VERSION = 0
22 22
 PATCHLEVEL = 8
23 23
 SUBLEVEL =   11
24
-EXTRAVERSION = pre17
24
+EXTRAVERSION = pre18
25 25
 
26 26
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
27 27
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -100,6 +100,7 @@ optimizations:
100 100
 
101 101
 tcp stuff:
102 102
 x tcp disable nagle 
103
+- set TOS to minimize delay
103 104
 - tcp locking/atomic ops review
104 105
 - tcp fix simultaneous connects (ser process is blocked until connect timeouts
105 106
  => possible DOS)
... ...
@@ -47,6 +47,7 @@
47 47
  * 2003-04-02  added more subst lumps: SUBST_{SND,RCV}_ALL  
48 48
  *              => ip:port;transport=proto (andrei)
49 49
  * 2003-04-12  added FL_FORCE_RPORT support (andrei)
50
+ * 2003-04-13  updated warning builder -- fixed (andrei)
50 51
  *
51 52
  */
52 53
 /* Via special params:
... ...
@@ -197,22 +198,28 @@ static int check_via_address(struct ip_addr* ip, str *name,
197 197
 static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len)
198 198
 {
199 199
 	static char buf[MAX_WARNING_LEN];
200
-	static unsigned int fix_len=0;
201 200
 	str *foo;
202 201
 	int print_len, l;
203 202
 	int clen;
204 203
 	char* t;
205 204
 
206
-#define str_pair_print(string, string2, string2_len) \
205
+#define str_print(string, string_len) \
207 206
 		do{ \
208
-			l=strlen((string)); \
209
-		if ((clen+(string2_len)+l)>MAX_WARNING_LEN) \
210
-			goto error_overflow; \
211
-		memcpy(buf+clen, (string), l); \
212
-		clen+=l; \
213
-		memcpy(buf+clen, (string2), (string2_len)); \
214
-		clen+=(string2_len); }while(0)
215
-		
207
+			l=(string_len); \
208
+			if ((clen+l)>MAX_WARNING_LEN) \
209
+				goto error_overflow; \
210
+			memcpy(buf+clen, (string), l); \
211
+			clen+=l; \
212
+		}while(0)
213
+	
214
+#define str_lenpair_print(string, string_len, string2, string2_len) \
215
+		do{ \
216
+			str_print(string, string_len); \
217
+			str_print(string2, string2_len);\
218
+		}while(0)
219
+	
220
+#define str_pair_print( string, string2, string2_len) \
221
+		str_lenpair_print((string), strlen((string)), (string2), (string2_len))
216 222
 		
217 223
 #define str_int_print(string, intval)\
218 224
 		do{\
... ...
@@ -227,47 +234,39 @@ static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len)
227 227
 			str_pair_print(string, t, print_len);\
228 228
 		} while(0)
229 229
 	
230
-	if (!fix_len)
231
-	{
232
-		memcpy(buf+fix_len,WARNING, WARNING_LEN);
233
-		fix_len +=WARNING_LEN;
234
-		memcpy(buf+fix_len, bind_address->name.s,bind_address->name.len);
235
-		fix_len += bind_address->name.len;
236
-		*(buf+fix_len) = ':'; fix_len++;
237
-		memcpy(buf+fix_len,bind_address->port_no_str.s,
238
-			bind_address->port_no_str.len);
239
-		fix_len += bind_address->port_no_str.len;
240
-		memcpy(buf+fix_len, WARNING_PHRASE,WARNING_PHRASE_LEN);
241
-		fix_len += WARNING_PHRASE_LEN;
242
-	}
230
+	clen=0;
231
+	str_lenpair_print(WARNING, WARNING_LEN,
232
+						msg->rcv.bind_address->name.s,
233
+						msg->rcv.bind_address->name.len);
234
+	str_lenpair_print(":", 1, msg->rcv.bind_address->port_no_str.s,
235
+						msg->rcv.bind_address->port_no_str.len);
236
+	str_print(WARNING_PHRASE, WARNING_PHRASE_LEN);
243 237
 	
244 238
 	/*adding out_uri*/
245 239
 	if (msg->new_uri.s)
246 240
 		foo=&(msg->new_uri);
247 241
 	else
248 242
 		foo=&(msg->first_line.u.request.uri);
249
-		clen=fix_len;
243
+	/* pid= */
244
+	str_int_print(" pid=", my_pid());
245
+	/* req_src_ip= */
246
+	str_ipaddr_print(" req_src_ip=", &msg->rcv.src_ip);
247
+	str_int_print(" req_src_port=", msg->rcv.src_port);
248
+	str_pair_print(" in_uri=", msg->first_line.u.request.uri.s,
249
+								msg->first_line.u.request.uri.len);
250
+	str_pair_print(" out_uri=", foo->s, foo->len);
251
+	str_pair_print(" via_cnt", msg->parsed_flag & HDR_EOH ? "=" : ">", 1);
252
+	str_int_print("=", via_cnt);
253
+	if (clen<MAX_WARNING_LEN){ buf[clen]='"'; clen++; }
254
+	else goto error_overflow;
250 255
 		
251
-		/* pid= */
252
-		str_int_print("pid=", my_pid());
253
-		/* req_src_ip= */
254
-		str_ipaddr_print(" req_src_ip=", &msg->rcv.src_ip);
255
-		str_int_print(" req_src_port=", msg->rcv.src_port);
256
-		str_pair_print(" in_uri=", msg->first_line.u.request.uri.s,
257
-									msg->first_line.u.request.uri.len);
258
-		str_pair_print(" out_uri=", foo->s, foo->len);
259
-		str_pair_print(" via_cnt", msg->parsed_flag & HDR_EOH ? "=" : ">", 1);
260
-		str_int_print("=", via_cnt);
261
-		if (clen<MAX_WARNING_LEN){ buf[clen]='"'; clen++; }
262
-		else goto error_overflow;
263 256
 		
264
-		
265
-		*returned_len=clen;
266
-		return buf;
257
+	*returned_len=clen;
258
+	return buf;
267 259
 error_overflow:
268
-		LOG(L_ERR, "ERROR: warning_builder: buffer size exceeded\n");
269
-		*returned_len=0;
270
-		return 0;
260
+	LOG(L_ERR, "ERROR: warning_builder: buffer size exceeded\n");
261
+	*returned_len=0;
262
+	return 0;
271 263
 }
272 264
 
273 265