[Serdev] API question
Andrew Mee
andrew at healthshare.net.au
Mon Aug 23 23:40:27 UTC 2004
Ok let me explain. I am writing a patch to fix the MS strict/loose
routing issue, it's probably not a good piece of code but it looks like....
int fix_ms(struct sip_msg* _m, char* _s1, char* _s2)
{
int utod;
char *u;
char *uto;
char *uua;
char *umet;
umet = pkg_malloc(_m->first_line.u.request.method.len);
DBG ("fix_ms: Get Method\n");
memcpy(umet,
_m->first_line.u.request.method.s,_m->first_line.u.request.method.len);
DBG ("fix_ms: Check Method\n");
if (strstr(umet,"BYE")!=NULL || strstr(umet,"MESSAGE")!=NULL ||
strstr(umet,"INFO")!=NULL){
DBG ("fix_ms: Correct Method to fix\n");
}else{
pkg_free(umet);
return 1;
}
DBG ("fix_ms: Get RURI\n");
if (_m->new_uri.s){
u = pkg_malloc(_m->new_uri.len);
memcpy(u, _m->new_uri.s, _m->new_uri.len);
}else{
u = pkg_malloc(_m->first_line.u.request.uri.len);
memcpy(u,_m->first_line.u.request.uri.s,_m->first_line.u.request.uri.len);
}
DBG ("fix_ms: Get To\n");
if (!_m->to && ((parse_headers(_m, HDR_TO, 0) == -1) ||
(!_m->to))) {
LOG(L_ERR, "fix_ms: Can't get To header field\n");
return 1;
}
DBG ("fix_ms: Get To 2\n");
utod = get_to(_m)->uri.len;
DBG ("fix_ms: Get To 3\n");
uto = pkg_malloc(utod);
DBG ("fix_ms: Get To 4\n");
memcpy(uto, get_to(_m)->uri.s , get_to(_m)->uri.len);
DBG ("fix_ms: Checking to header: %d - %s\n", _m->to->body.len,
_m->to->body.s);
DBG ("fix_ms: Get UUA 0\n");
if (!_m->user_agent && ((parse_headers(_m, HDR_USERAGENT, 0) ==
-1) || (!_m->user_agent))) {
LOG(L_ERR, "fix_ms: Can't get user_agent header field\n");
return 1;
}
DBG ("fix_ms: Get UUA 1\n");
uua = pkg_malloc(_m->user_agent->body.len);
DBG ("fix_ms: Get UUA 2\n");
memcpy(uua,_m->user_agent->body.s, _m->user_agent->body.len);
DBG ("fix_ms: initiated [%s] [%s] [%s] [%s] \n", u , uto , uua,
umet);
if (strstr(u,uto)==NULL && strstr(uua,"RTC")!=NULL){
DBG ("fix_ms: Fixing To->RURI correct headers\n");
//change uri to go to
_m->new_uri.len=get_to(_m)->uri.len;
_m->new_uri.s= get_to(_m)->uri.s;
}
free_to(_m->to->parsed);
pkg_free (uto);
pkg_free (uua);
pkg_free(umet);
pkg_free(u);
return 1;
}
The code works, It grabs the correct URI and rewrites it to the RURI
however the output in Debug looks like....
11(11467) tcp_send: sending...
11(11467) tcp_send: after write: c= 0x40306228 n=549 fd=21
11(11467) tcp_send: buf=
BYE sip:192.168.2.11:8346;transport=tcp SIP/2.0
Record-Route:
<sip:test2 at 192.168.2.253;transport=tcp;ftag=81b38b55e7374086ae1d124ef71c4d28;lr=on>
Via: SIP/2.0/TCP 192.168.2.253;branch=z9hG4bKb65c.66dc51e6.0;i=5
Via: SIP/2.0/TCP 192.168.2.28:16774
Max-Forwards: 69
From: <sip:test2 at 192.168.2.253>;tag=81b38b55e7374086ae1d124ef71c4d28
To: "James Wes
11(11467) DEBUG: add_to_tail_of_timer[0]: 0x403045d4
11(11467) SER: new transaction fwd'ed
the NGREP looks like:
T 192.168.2.253:34230 -> 192.168.2.11:8346 [AP]
BYE sip:192.168.2.11:8346;transport=tcp SIP/2.0..Record-Route:
<sip:test2 at 1
92.168.2.253;transport=tcp;ftag=81b38b55e7374086ae1d124ef71c4d28;lr=on>..Vi
a: SIP/2.0/TCP 192.168.2.253;branch=z9hG4bKb65c.66dc51e6.0;i=5..Via:
SIP/2.
0/TCP 192.168.2.28:16774..Max-Forwards: 69..From:
<sip:test2 at 192.168.2.253>
;tag=81b38b55e7374086ae1d124ef71c4d28..To: "James
Wes....sip:support at 192.16
8.2.253>;tag=2d394725c2a846e4ae8908febf1e00bb;epid=18dddc6a32..Call-ID: d58
3c67c47924dacacea0d38c3f6f6a7 at 192.168.2.11..CSeq: 1 BYE..User-Agent:
RTC/1.
2..Content-Length: 0....
Now what I don't understand is that if I don't use this code, I have no
issue the To: stays as is and displays fine but if I parse To: it comes
out malformed, in fact so does the User-Agent. Perhaps there is some
kind of error in my code but I'm darned if I can see it. Is pasring the
headers mucking up the them up?
Any improvements to code welcome :)
Thanks
--
Andrew Mee
-------------- next part --------------
11(11467) After parse_msg...
11(11467) preparing to run routing scripts...
11(11467) DEBUG : is_maxfwd_present: searching for max_forwards header
11(11467) parse_headers: flags=128
11(11467) DEBUG: is_maxfwd_present: value = 70
11(11467) fix_ms: Get Method
11(11467) fix_ms: Check Method
11(11467) fix_ms: Correct Method to fix
11(11467) fix_ms: Get RURI
11(11467) fix_ms: Get To
11(11467) parse_headers: flags=4
11(11467) DEBUG: add_param: tag=2d394725c2a846e4ae8908febf1e00bb
11(11467) DEBUG: add_param: epid=18dddc6a32
11(11467) end of header reached, state=29
11(11467) DEBUG: get_hdr_field: <To> [95]; uri=[sip:support at 192.168.2.253]
11(11467) DEBUG: to body ["James West" <sip:support at 192.168.2.253>]
11(11467) fix_ms: Get To 2
11(11467) fix_ms: Get To 3
11(11467) fix_ms: Get To 4
11(11467) fix_ms: Checking to header: 93 - "James West" <sip:support at 192.168.2.253>;tag=2d394725c2a846e4ae8908febf1e00bb;epid=18dddc6a32
Call-ID: d583c67c47924dacacea0d38c3f6f6a7 at 192.168.2.11
CSeq: 1 BYE
Route: <sip:support at 192.168.2.253:8346;maddr=192.168.2.11;transport=tcp>
User-Agent: RTC/1.2
Content-Length: 0
11(11467) fix_ms: Get UUA 0
11(11467) parse_headers: flags=33554432
11(11467) get_hdr_field: cseq <CSeq>: <1> <BYE>
11(11467) fix_ms: Get UUA 1
11(11467) fix_ms: Get UUA 2
11(11467) fix_ms: initiated [sip:test2 at 192.168.2.253;transport=tcp;ftag=2d394725c2a846e4ae8908febf1e00bb;lr=on] [sip:support at 192.168.2.253] [RTC/1.2] [BYEITEE]
11(11467) fix_ms: Fixing To->RURI correct headers
11(11467) DEBUG: add_param: tag=81b38b55e7374086ae1d124ef71c4d28
11(11467) end of header reached, state=29
11(11467) parse_headers: flags=256
11(11467) check_self - checking if host==us: 13==13 && [192.168.2.253] == [192.168.2.253]
11(11467) check_self - checking if port 5060 matches port 5060
11(11467) check_self - checking if host==us: 13==13 && [192.168.2.253] == [192.168.2.253]
11(11467) check_self - checking if port 5060 matches port 8346
11(11467) parse_headers: flags=256
11(11467) DEBUG: get_hdr_body : content_length=0
11(11467) found end of header
11(11467) fnr(): No next Route HF found
11(11467) ras(): No next URI found
11(11467) check_self - checking if host==us: 13==13 && [192.168.2.253] == [192.168.2.253]
11(11467) check_self - checking if port 5060 matches port 5060
11(11467) rwrite(): Rewriting Request-URI with 'sip:192.168.2.11:8346;transport=tcp'
11(11467) ---------- PROCESSING BYE!!!!
11(11467) parse_headers: flags=-1
11(11467) parse_headers: flags=60
11(11467) DEBUG: MD5 calculated: 0e9167302f66096df38223cbcdaad599
11(11467) DEBUG: print_var: SIP_HF_CONTENT_LENGTH=0
11(11467) DEBUG: print_var: SIP_HF_USER_AGENT=RTC/1.2
11(11467) DEBUG: print_var: SIP_HF_ROUTE=<sip:support at 192.168.2.253:8346;maddr=192.168.2.11;transport=tcp>
11(11467) DEBUG: print_var: SIP_HF_CSEQ=1 BYE
11(11467) DEBUG: print_var: SIP_HF_CALLID=d583c67c47924dacacea0d38c3f6f6a7 at 192.168.2.11
11(11467) DEBUG: print_var: SIP_HF_TO="James Wes
11(11467) DEBUG: print_var: SIP_HF_FROM=<sip:test2 at 192.168.2.253>;tag=81b38b55e7374086ae1d124ef71c4d28
11(11467) DEBUG: print_var: SIP_HF_MAX_FORWARDS=69
11(11467) DEBUG: print_var: SIP_HF_VIA=SIP/2.0/TCP 192.168.2.28:16774
11(11467) INFO: SIGCHLD received: we do not worry about grand-children
11(11467) DEBUG: t_addifnew: msg id=13 , global msg id=12 , T on entrance=0xffffffff
11(11467) parse_headers: flags=-1
11(11467) parse_headers: flags=60
11(11467) t_lookup_request: start searching: hash=50539, isACK=0
11(11467) DEBUG: proceeding to pre-RFC3261 transaction matching
11(11467) DEBUG: t_lookup_request: no transaction found
11(11467) DEBUG: mk_proxy: doing DNS lookup...
11(11467) build_req_from_req: id added: <;i=5>, rcv proto=2
11(11467) parse_headers: flags=2048
11(11467) check_via_address(192.168.2.28, 192.168.2.28, 0)
11(11467) tcp_send: no open tcp connection found, opening new one
11(11467) tcpconn_new: new tcp connection: 192.168.2.11
11(11467) tcpconn_new: on port 8346, type 2
19(11477) tcp_main_loop: read response= 40306228, 2 from 11 (11467)
11(11467) tcp_send: sending...
11(11467) tcp_send: after write: c= 0x40306228 n=549 fd=21
11(11467) tcp_send: buf=
BYE sip:192.168.2.11:8346;transport=tcp SIP/2.0
Record-Route: <sip:test2 at 192.168.2.253;transport=tcp;ftag=81b38b55e7374086ae1d124ef71c4d28;lr=on>
Via: SIP/2.0/TCP 192.168.2.253;branch=z9hG4bKb65c.66dc51e6.0;i=5
Via: SIP/2.0/TCP 192.168.2.28:16774
Max-Forwards: 69
From: <sip:test2 at 192.168.2.253>;tag=81b38b55e7374086ae1d124ef71c4d28
To: "James Wes
11(11467) DEBUG: add_to_tail_of_timer[0]: 0x403045d4
11(11467) SER: new transaction fwd'ed
T 192.168.2.28:1097 -> 192.168.2.253:5060 [AP]
BYE sip:test2 at 192.168.2.253;transport=tcp;ftag=2d394725c2a846e4ae8908febf1e
00bb;lr=on SIP/2.0..Via: SIP/2.0/TCP 192.168.2.28:16774..Max-Forwards: 70..
From: <sip:test2 at 192.168.2.253>;tag=81b38b55e7374086ae1d124ef71c4d28..To: "
James West" <sip:support at 192.168.2.253>;tag=2d394725c2a846e4ae8908febf1e00b
b;epid=18dddc6a32..Call-ID: d583c67c47924dacacea0d38c3f6f6a7 at 192.168.2.11..
CSeq: 1 BYE..Route: <sip:support at 192.168.2.253:8346;maddr=192.168.2.11;tran
sport=tcp>..User-Agent: RTC/1.2..Content-Length: 0....
T 192.168.2.253:34230 -> 192.168.2.11:8346 [AP]
BYE sip:192.168.2.11:8346;transport=tcp SIP/2.0..Record-Route: <sip:test2 at 1
92.168.2.253;transport=tcp;ftag=81b38b55e7374086ae1d124ef71c4d28;lr=on>..Vi
a: SIP/2.0/TCP 192.168.2.253;branch=z9hG4bKb65c.66dc51e6.0;i=5..Via: SIP/2.
0/TCP 192.168.2.28:16774..Max-Forwards: 69..From: <sip:test2 at 192.168.2.253>
;tag=81b38b55e7374086ae1d124ef71c4d28..To: "James Wes....sip:support at 192.16
8.2.253>;tag=2d394725c2a846e4ae8908febf1e00bb;epid=18dddc6a32..Call-ID: d58
3c67c47924dacacea0d38c3f6f6a7 at 192.168.2.11..CSeq: 1 BYE..User-Agent: RTC/1.
2..Content-Length: 0....
More information about the Serdev
mailing list