Browse code

- killed the last snprintf used in non-init code from core (build_warning)

Andrei Pelinescu-Onciul authored on 18/03/2003 17:32:02
Showing 1 changed files
... ...
@@ -28,17 +28,18 @@
28 28
  *
29 29
  * History:
30 30
  * --------
31
- * 2003-03-01 VOICE_MAIL defs removed (jiri)
32
- * 2003-02-28 scratchpad compatibility abandoned (jiri)
33
- * 2003-01-20 bug_fix: use of return value of snprintf aligned to C99 (jiri)
34
- * 2003-01-23 added rport patches, contributed by 
35
- *             Maxim Sobolev <sobomax@FreeBSD.org> and heavily modified by me
36
- *             (andrei)
37
- * 2003-01-24 added i param to via of outgoing requests (used by tcp),
38
- *             modified via_builder params (andrei)
39
- * 2003-01-27 more rport fixes (make use of new via_param->start)  (andrei)
40
- * 2003-01-27 next baby-step to removing ZT - PRESERVE_ZT (jiri)
41
- * 2003-01-29 scratchpad removed (jiri)
31
+ * 2003-03-01  VOICE_MAIL defs removed (jiri)
32
+ * 2003-02-28  scratchpad compatibility abandoned (jiri)
33
+ * 2003-01-20  bug_fix: use of return value of snprintf aligned to C99 (jiri)
34
+ * 2003-01-23  added rport patches, contributed by 
35
+ *              Maxim Sobolev <sobomax@FreeBSD.org> and heavily modified by me
36
+ *              (andrei)
37
+ * 2003-01-24  added i param to via of outgoing requests (used by tcp),
38
+ *              modified via_builder params (andrei)
39
+ * 2003-01-27  more rport fixes (make use of new via_param->start)  (andrei)
40
+ * 2003-01-27  next baby-step to removing ZT - PRESERVE_ZT (jiri)
41
+ * 2003-01-29  scratchpad removed (jiri)
42
+ * 2003-03-18  killed the build_warning snprintf (andrei)
42 43
  *
43 44
  */
44 45
 
... ...
@@ -144,8 +145,34 @@ static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len)
144 144
 	static char buf[MAX_WARNING_LEN];
145 145
 	static unsigned int fix_len=0;
146 146
 	str *foo;
147
-	int print_len;
148
-
147
+	int print_len, l;
148
+	int clen;
149
+	char* t;
150
+
151
+#define str_pair_print(string, string2, string2_len) \
152
+		do{ \
153
+			l=strlen((string)); \
154
+		if ((clen+(string2_len)+l)>MAX_WARNING_LEN) \
155
+			goto error_overflow; \
156
+		memcpy(buf+clen, (string), l); \
157
+		clen+=l; \
158
+		memcpy(buf+clen, (string2), (string2_len)); \
159
+		clen+=(string2_len); }while(0)
160
+		
161
+		
162
+#define str_int_print(string, intval)\
163
+		do{\
164
+			t=int2str((intval), &print_len); \
165
+			str_pair_print(string, t, print_len);\
166
+		} while(0)
167
+		
168
+#define str_ipaddr_print(string, ipaddr_val)\
169
+		do{\
170
+			t=ip_addr2a((ipaddr_val)); \
171
+			print_len=strlen(t); \
172
+			str_pair_print(string, t, print_len);\
173
+		} while(0)
174
+	
149 175
 	if (!fix_len)
150 176
 	{
151 177
 		memcpy(buf+fix_len,WARNING, WARNING_LEN);
... ...
@@ -159,31 +186,34 @@ static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len)
159 159
 		memcpy(buf+fix_len, WARNING_PHRASE,WARNING_PHRASE_LEN);
160 160
 		fix_len += WARNING_PHRASE_LEN;
161 161
 	}
162
-
162
+	
163 163
 	/*adding out_uri*/
164 164
 	if (msg->new_uri.s)
165 165
 		foo=&(msg->new_uri);
166 166
 	else
167 167
 		foo=&(msg->first_line.u.request.uri);
168
-	print_len=snprintf(buf+fix_len, MAX_WARNING_LEN-fix_len,
169
-		"pid=%d req_src_ip=%s req_src_port=%d in_uri=%.*s out_uri=%.*s"
170
-		" via_cnt%c=%d\"",
171
-		my_pid(),
172
-		ip_addr2a(&msg->rcv.src_ip),
173
-		ntohs(msg->rcv.src_port),
174
-		msg->first_line.u.request.uri.len, msg->first_line.u.request.uri.s,
175
-		foo->len, foo->s, 
176
-		msg->parsed_flag & HDR_EOH ? '=' : '>', /* should be = */
177
-		via_cnt );
178
-
179
-	if (print_len==-1 || print_len>=MAX_WARNING_LEN-fix_len) {
168
+		clen=fix_len;
169
+		
170
+		/* pid= */
171
+		str_int_print("pid=", my_pid());
172
+		/* req_src_ip= */
173
+		str_ipaddr_print(" req_src_ip=", &msg->rcv.src_ip);
174
+		str_int_print(" req_src_port=", ntohs(msg->rcv.src_port));
175
+		str_pair_print(" in_uri=", msg->first_line.u.request.uri.s,
176
+									msg->first_line.u.request.uri.len);
177
+		str_pair_print(" out_uri=", foo->s, foo->len);
178
+		str_pair_print(" via_cnt", msg->parsed_flag & HDR_EOH ? "=" : ">", 1);
179
+		str_int_print("=", via_cnt);
180
+		if (clen<MAX_WARNING_LEN){ buf[clen]='"'; clen++; }
181
+		else goto error_overflow;
182
+		
183
+		
184
+		*returned_len=clen;
185
+		return buf;
186
+error_overflow:
180 187
 		LOG(L_ERR, "ERROR: warning_builder: buffer size exceeded\n");
181 188
 		*returned_len=0;
182 189
 		return 0;
183
-	} else {
184
-		*returned_len=fix_len+print_len;
185
-		return buf;
186
-	}
187 190
 }
188 191
 
189 192