[Serdev] how to access response body?

Juha Heinanen jh at tutpro.com
Sat Jan 3 14:48:23 UTC 2004


 > At 10:50 AM 12/29/2003, Juha Heinanen wrote:
 > >in order check the validity of a 301/302 response, i need to access from
 > >a failure route function the contact header of the response.  how can i
 > >refer to the body and headers of the response in the failure route
 > >function?
 > 
 > Actions for processing replies are very much same like for processing
 > requests -- accessing contacts should work similarly to how contacts
 > are accessed from request processing (say in registrar).

jiri,

welcome back from acation. i tried a few days ago by writing the move
function below, which i call from failure_route as follows:

	if (t_check_status("302") || t_check_status("301")) {
		if (move()) {
			log(1, "LOG: Diverting on 30x\n");
			route(6);
			break;
		} else {
			t_reply("400", "Bad contact in 30x response");
			break;
		};
    };

however, _m->contact in move doesn't refer to the contact header of the
reply, but to the contact header of the request to which is a reply.  i
know it because when i did a test, the request uri became the one that
was in the contact of the request, not the one in the contact of the
reply:

U 2004/01/03 16:37:19.902653 192.98.100.2:5060 -> 192.98.100.3:5060
INVITE sip:jh at 192.98.100.3;transport=udp SIP/2.0.
Max-Forwards: 10.
Record-Route: <sip:jh at 192.98.100.2;ftag=8EC7AA3;lr=on>.
Via: SIP/2.0/UDP 192.98.100.2;branch=z9hG4bK2379.8e3e25e.0.
Via: SIP/2.0/UDP 192.98.100.3:5062;rport=5062.
CSeq: 736 INVITE.
To: <sip:jh at tutpro.com>.
Content-Type: application/sdp.
From: "Juha Heinanen" <sip:jh at openxg.com>;tag=8EC7AA3.
Call-ID: 981923269 at 192.98.100.3.
Subject: sip:jh at openxg.com.
Content-Length: 185.
User-Agent: KPhone/3.13.
Contact: "Juha Heinanen" <sip:jh at 192.98.100.3:5062;transport=udp>.
.
v=0.
o=username 0 0 IN IP4 192.98.100.3.
s=The Funky Flow.
c=IN IP4 192.98.100.3.
t=0 0.
m=audio 32810 RTP/AVP 97 3 0.
a=rtpmap:0 PCMU/8000.
a=rtpmap:3 GSM/8000.
a=rtpmap:97 iLBC/8000.

#
U 2004/01/03 16:37:19.910393 192.98.100.3:5060 -> 192.98.100.2:5060
SIP/2.0 302 Moved Temporarily.
Via: SIP/2.0/UDP 192.98.100.2;branch=z9hG4bK2379.8e3e25e.0.
Via: SIP/2.0/UDP 192.98.100.3:5062;rport=5062.
From: "Juha Heinanen" <sip:jh at openxg.com>;tag=8EC7AA3.
To: <sip:jh at tutpro.com>.
CSeq: 736 INVITE.
Call-ID: 981923269 at 192.98.100.3.
Content-Type: text/plain.
Content-Length: 19.
User-Agent: KPhone/3.13.
Contact: <sip:0407058050 at tutpro.com>.
.
Forwarding to PSTN.
#
U 2004/01/03 16:37:19.910942 192.98.100.2:5060 -> 192.98.100.3:5060
ACK sip:jh at 192.98.100.3;transport=udp SIP/2.0.
Via: SIP/2.0/UDP 192.98.100.2;branch=z9hG4bK2379.8e3e25e.0.
From: "Juha Heinanen" <sip:jh at openxg.com>;tag=8EC7AA3.
Call-ID: 981923269 at 192.98.100.3.
To: <sip:jh at tutpro.com>.
CSeq: 736 ACK.
User-Agent: SIP EXpress Router(0.8.12-tcp_nonb (i386/linux)).
Content-Length: 0.
.

#
U 2004/01/03 16:37:19.911677 192.98.100.2:5060 -> 192.98.100.3:5062
INVITE sip:jh at 192.98.100.3:5062;transport=udp SIP/2.0.
Max-Forwards: 10.
Record-Route: <sip:jh at 192.98.100.2;ftag=8EC7AA3;lr=on>.
Via: SIP/2.0/UDP 192.98.100.2;branch=z9hG4bK2379.8e3e25e.1.
Via: SIP/2.0/UDP 192.98.100.3:5062;rport=5062.
CSeq: 736 INVITE.
To: <sip:jh at tutpro.com>.
Content-Type: application/sdp.
From: "Juha Heinanen" <sip:jh at openxg.com>;tag=8EC7AA3.
Call-ID: 981923269 at 192.98.100.3.
Subject: sip:jh at openxg.com.
Content-Length: 185.
User-Agent: KPhone/3.13.
Contact: "Juha Heinanen" <sip:jh at 192.98.100.3:5062;transport=udp>.
Remote-Party-ID: sip:+35864129450 at tutpro.com;privacy=off.
Proxy-Authorization: Digest username="jh at tutpro.com".
.
v=0.
o=username 0 0 IN IP4 192.98.100.3.
s=The Funky Flow.
c=IN IP4 192.98.100.3.
t=0 0.
m=audio 32810 RTP/AVP 97 3 0.
a=rtpmap:0 PCMU/8000.
a=rtpmap:3 GSM/8000.
a=rtpmap:97 iLBC/8000.

and that is why i asked you how can i refer to the contact of the reply.

-- juha

-------------------------------------------------------------------

/*
 * Appends a new branch to request using the first Contact URI of the (302/301)
 * reply (if any) as the Request URI.  Returns 1 if appending succeeded and -1
 * if it failed.
 */
int move(struct sip_msg* _m, char* _s1, char* _s2)
{
	contact_t* first;

	if (!_m->contact) {
		LOG(L_ERR, "move(): No contact header\n");
		return -1;
	}
	if (!_m->contact->parsed && parse_contact(_m->contact) < 0) {
		LOG(L_ERR, "move(): Error while parsing Contact body\n");
		return -1;
	}

	if (((contact_body_t*)_m->contact->parsed)->star == 1) {
		return -1;
	}

	first = ((contact_body_t*)_m->contact->parsed)->contacts;
	
	if (first) {
		if (append_branch(_m, first->uri.s, first->uri.len) == 1) {
			diversion.reason = "unconditional";
			set_diverter_info(_m);
			return 1;
		}
	}

	return -1;
}




More information about the Serdev mailing list