[Serusers] Rewriting URI in the Contact field

Maxim Sobolev sobomax at portaone.com
Tue Jan 14 22:17:54 CET 2003


Jiri Kuthan wrote:
> 
> I'm glad but surprised it works. There are two things I do not
> understand: registration and reply_route.
> 
> ad registration) I understood from your previous email you were
> wishing to save transport origin as user's contact in usrLoc DB.
> however, 'fix_nated_contact();save();' doesn't do that imho -- it
> creates a "diff list" and stores contacts from original message.

Yes and no. ;)

Call it dirty trick, or a smart workaround, but after patching the
contact in the message using del_lump/insert_new_lump(), I'm replacing
msg->contact->parsed->contacts->uri.s with the pointer to the
pkg_malloc'ed buffer passed to the insert_new_lump() and also
adjusting [...]->uri.len accordingly. Documentation says that buffers
passed to insert_new_lump() will be deallocated along with the message
itself, therefore memory isn't leaked and reference guranteed to be
valid during the lifetime of the message. Later on, registration
procedure checks that contact is already parsed (it is) and then takes
our replaced [...]->uri.s "as is", and voila, everything works. 8-)

Of course Bad Things[tm] will happen if some module invoked after
nathelper will try to calculate offset=[...]->contacts->uri.s -
msg->orig, or will try to scratch something in that buffer but no
modules do it yet.

> ad reply_route) I fear fix_nated_contact does not help here really.
>  From reply_route, you process original requests conserved in share
> memory now -- you don't affect replies.

Perhaps you are missing something, because my little old buddy gdb
disagrees[1] - I am definitely observing "200 OK" reply as msg
argument in fix_nated_contact() called from reply_route[].

-Maxim

[1]
(gdb) b on_positive_reply
Breakpoint 4 at 0x2a18dde2: file t_reply.c, line 939.
(gdb) c
Continuing.
Breakpoint 4, on_positive_reply (t=0x28304e24, msg=0x80b71b0,
code=200, param=0x0) at t_reply.c:939
939             if (!t->on_positive) {
(gdb) tb fix_nated_contact_f
Breakpoint 5 at 0x2a1b4bb3: file nathelper.c, line 145.
(gdb) c
Continuing.
fix_nated_contact_f (msg=0x80b71b0, str1=0x0, str2=0x0) at
nathelper.c:145
145             if ((parse_headers(msg, HDR_CONTACT, 0) == -1) ||
!msg->contact)
(gdb) bt
#0  fix_nated_contact_f (msg=0x80b71b0, str1=0x0, str2=0x0) at
nathelper.c:145
#1  0x0804de0a in do_action (a=0x81b1660, msg=0x80b71b0) at
action.c:511
#2  0x0804dff1 in run_actions (a=0x81b1660, msg=0x80b71b0) at
action.c:559
#3  0x0804dd97 in do_action (a=0x81b1680, msg=0x80b71b0) at
action.c:501
#4  0x0804dff1 in run_actions (a=0x81b1680, msg=0x80b71b0) at
action.c:559
#5  0x2a18de75 in on_positive_reply (t=0x28304e24, msg=0x80b71b0,
code=200, param=0x0)
    at t_reply.c:946
#6  0x2a18845e in callback_event (cbt=TMCB_REPLY_IN, trans=0x28304e24,
msg=0x80b71b0, code=200)
    at t_hooks.c:73
#7  0x2a18cee3 in relay_reply (t=0x28304e24, p_msg=0x80b71b0,
branch=0, msg_status=200,
    cancel_bitmap=0xbfbff09c) at t_reply.c:565
#8  0x2a18d995 in t_on_reply (p_msg=0x80b71b0) at t_reply.c:812
#9  0x08052af7 in forward_reply (msg=0x80b71b0) at forward.c:343
#10 0x0805dec5 in receive_msg (buf=0x809a6c0 "SIP/2.0", len=733,
src_su=0x81b1220) at receive.c:161
#11 0x08064127 in udp_rcv_loop () at udp_server.c:332
#12 main_loop () at main.c:582
#13 0x080571df in main (argc=3, argv=0xbfbff74c) at main.c:1383
#14 0x0804c679 in _start ()
(gdb) print *msg
$2 = {id = 49, first_line = {type = 2, u = {request = {method = {s =
0x809a6c0 "SIP/2.0",
	  len = 7}, uri = {s = 0x809a6c8 "200", len = 3}, version = {s =
0x809a6cc "OK", len = 2},
	method_value = 200}, reply = {version = {s = 0x809a6c0 "SIP/2.0", len
= 7}, status = {
	  s = 0x809a6c8 "200", len = 3}, reason = {s = 0x809a6cc "OK", len =
2},
	statuscode = 200}}}, via1 = 0x80b7540, via2 = 0x80b8180, headers =
0x80b77a4,
  last_header = 0x80b78d4, parsed_flag = 575, h_via1 = 0x80b77a4,
h_via2 = 0x80b7888,
  callid = 0x80b7b40, to = 0x80b79f0, cseq = 0x80b78d4, from =
0x80b76c8, contact = 0x0,
  maxforwards = 0x0, route = 0x0, record_route = 0x80b7714,
content_type = 0x0,
  content_length = 0x0, authorization = 0x0, expires = 0x0, proxy_auth
= 0x0, www_auth = 0x0,
  supported = 0x0, require = 0x0, proxy_require = 0x0, unsupported =
0x0, allow = 0x0,
  event = 0x0, eoh = 0x0,
  unparsed = 0x809a82b "Contact: 
<sip:380442466396 at 192.168.0.9:5060;user=phone;transport=udp>\r\nSe
rver: Cisco ATA  v2.15 ata18x (020927a)\r\nContent-Length:
201\r\nContent-Type: application/sdp\r\n\
r\nv=0\r\no=380442466396 76117 76117"..., src_ip = {af = 2, len = 4, u
= {addr32 = {838969536, 0,
	0, 0}, addr16 = {43200, 12801, 0, 0, 0, 0, 0, 0},
      addr = "(\0012", '\0' <repeats 11 times>}}, src_port_no = 5060,
dst_ip = {af = 2, len = 4,
    u = {addr32 = {1677830336, 0, 0, 0}, addr16 = {43200, 25601, 0, 0,
0, 0, 0, 0},
      addr = "(\001d", '\0' <repeats 11 times>}},
  orig = 0x80b8a5c "SIP/2.0 200 OK\r\nVia: SIP/2.0/UDP
192.168.1.100;branch=z9hG4bK61d8.02d66d15.0\r
\nVia: SIP/2.0/UDP 192.168.1.1:5063\r\nRecord-Route:
<sip:380442466396 at 192.168.1.100;branch=0>\r\nFr
om: Maxim <sip:380442466397@"..., buf = 0x809a6c0 "SIP/2.0", len =
733, new_uri = {s = 0x0,
    len = 0}, parsed_uri_ok = 0, parsed_uri = {user = {s = 0x0, len =
0}, passwd = {s = 0x0,
      len = 0}, host = {s = 0x0, len = 0}, port = {s = 0x0, len = 0},
params = {s = 0x0, len = 0},
    headers = {s = 0x0, len = 0}, port_no = 0}, add_rm = 0x0,
repl_add_rm = 0x0, reply_lump = 0x0,
  add_to_branch_s = '\0' <repeats 54 times>, add_to_branch_len = 0,
hash_index = 0, flags = 0}
(gdb) print msg->orig
$3 = 0x80b8a5c "SIP/2.0 200 OK\r\nVia: SIP/2.0/UDP
192.168.1.100;branch=z9hG4bK61d8.02d66d15.0\r\nVi
a: SIP/2.0/UDP 192.168.1.1:5063\r\nRecord-Route:
<sip:380442466396 at 192.168.1.100;branch=0>\r\nFrom:
Maxim <sip:380442466397@"...



More information about the sr-users mailing list