... | ... |
@@ -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 | 145 |
static char buf[MAX_WARNING_LEN]; |
145 | 146 |
static unsigned int fix_len=0; |
146 | 147 |
str *foo; |
147 |
- int print_len; |
|
148 |
- |
|
148 |
+ int print_len, l; |
|
149 |
+ int clen; |
|
150 |
+ char* t; |
|
151 |
+ |
|
152 |
+#define str_pair_print(string, string2, string2_len) \ |
|
153 |
+ do{ \ |
|
154 |
+ l=strlen((string)); \ |
|
155 |
+ if ((clen+(string2_len)+l)>MAX_WARNING_LEN) \ |
|
156 |
+ goto error_overflow; \ |
|
157 |
+ memcpy(buf+clen, (string), l); \ |
|
158 |
+ clen+=l; \ |
|
159 |
+ memcpy(buf+clen, (string2), (string2_len)); \ |
|
160 |
+ clen+=(string2_len); }while(0) |
|
161 |
+ |
|
162 |
+ |
|
163 |
+#define str_int_print(string, intval)\ |
|
164 |
+ do{\ |
|
165 |
+ t=int2str((intval), &print_len); \ |
|
166 |
+ str_pair_print(string, t, print_len);\ |
|
167 |
+ } while(0) |
|
168 |
+ |
|
169 |
+#define str_ipaddr_print(string, ipaddr_val)\ |
|
170 |
+ do{\ |
|
171 |
+ t=ip_addr2a((ipaddr_val)); \ |
|
172 |
+ print_len=strlen(t); \ |
|
173 |
+ str_pair_print(string, t, print_len);\ |
|
174 |
+ } while(0) |
|
175 |
+ |
|
149 | 176 |
if (!fix_len) |
150 | 177 |
{ |
151 | 178 |
memcpy(buf+fix_len,WARNING, WARNING_LEN); |
... | ... |
@@ -159,31 +186,34 @@ static char * warning_builder( struct sip_msg *msg, unsigned int *returned_len) |
159 | 186 |
memcpy(buf+fix_len, WARNING_PHRASE,WARNING_PHRASE_LEN); |
160 | 187 |
fix_len += WARNING_PHRASE_LEN; |
161 | 188 |
} |
162 |
- |
|
189 |
+ |
|
163 | 190 |
/*adding out_uri*/ |
164 | 191 |
if (msg->new_uri.s) |
165 | 192 |
foo=&(msg->new_uri); |
166 | 193 |
else |
167 | 194 |
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) { |
|
195 |
+ clen=fix_len; |
|
196 |
+ |
|
197 |
+ /* pid= */ |
|
198 |
+ str_int_print("pid=", my_pid()); |
|
199 |
+ /* req_src_ip= */ |
|
200 |
+ str_ipaddr_print(" req_src_ip=", &msg->rcv.src_ip); |
|
201 |
+ str_int_print(" req_src_port=", ntohs(msg->rcv.src_port)); |
|
202 |
+ str_pair_print(" in_uri=", msg->first_line.u.request.uri.s, |
|
203 |
+ msg->first_line.u.request.uri.len); |
|
204 |
+ str_pair_print(" out_uri=", foo->s, foo->len); |
|
205 |
+ str_pair_print(" via_cnt", msg->parsed_flag & HDR_EOH ? "=" : ">", 1); |
|
206 |
+ str_int_print("=", via_cnt); |
|
207 |
+ if (clen<MAX_WARNING_LEN){ buf[clen]='"'; clen++; } |
|
208 |
+ else goto error_overflow; |
|
209 |
+ |
|
210 |
+ |
|
211 |
+ *returned_len=clen; |
|
212 |
+ return buf; |
|
213 |
+error_overflow: |
|
180 | 214 |
LOG(L_ERR, "ERROR: warning_builder: buffer size exceeded\n"); |
181 | 215 |
*returned_len=0; |
182 | 216 |
return 0; |
183 |
- } else { |
|
184 |
- *returned_len=fix_len+print_len; |
|
185 |
- return buf; |
|
186 |
- } |
|
187 | 217 |
} |
188 | 218 |
|
189 | 219 |
|