[Serusers] SER Proxy with Redirect

mark wehberg mark.wehberg at clearviewcatv.net
Fri May 13 13:58:41 CEST 2005


Has there been any other development on this?  I am looking to do the
same thing upon receiving a 302 Moved Temporarily, send an invite rather
then relaying the 302 back upstream.

-Mark

-----Original Message-----
From: serusers-bounces at iptel.org [mailto:serusers-bounces at lists.iptel.org] On
Behalf Of Juha Heinanen
Sent: Friday, March 25, 2005 1:53 PM
To: Jan Janak
Cc: Eric Dean; serusers at lists.iptel.org
Subject: Re: [Serusers] SER Proxy with Redirect

Jan Janak writes:

 > This cannot be done in the current version bucause there is no way of
 > retrieving the information from contacts when a 3xx comes. Juha
Heinanen
 > <jh at tutpro.com> had it working, he might point you in the right
 > direction.

yes, i implemented a function called move that turned 302 to invite, but
that code relied on a patch to tm module that gave me access to contact
header of reply in reply route.

i found the function and it is below.  someone who needs this
functionality has to check if same kind of access to the contact header
of the reply is still possible or if the access method is now different
and modify the code accordingly.

also, all contacts would need to be taken from 302, not just the first.

contact_re was compiled during module initialization:

	regcomp(&contact_re, "^Contact:(.*)$",
REG_EXTENDED|REG_NEWLINE);

needless to say, i'm not proud of this code, but it gives an idea on how
it can be done.

-- juha

/*
 * Appends a new branch to request using the first Contact URI of the
(302)
 * 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)
{
	struct sip_msg* reply;
	regmatch_t pmatch[2];
	struct hdr_field hf;
	contact_t* first;

	reply = _m->final_reply;

	if (!reply) {
		LOG(L_ERR, "move(): No reply found\n");
		return -1;
	}

	LOG(L_ERR, "move(): unparsed part of reply: %s\n",
reply->unparsed);

	if ((regexec(&contact_re, reply->unparsed, 2, &(pmatch[0]), 0)
!= 0) ||
	    (pmatch[1].rm_so == -1)) {
		LOG(L_ERR, "move(): No Contact header found\n");
		return -1;
	}

	hf.type = HDR_CONTACT;
	hf.name.len = 0;
	hf.body.len = pmatch[1].rm_eo - pmatch[1].rm_so - 1;
	hf.body.s = &(reply->unparsed[pmatch[1].rm_so]);
	hf.len = hf.body.len + 2;
	hf.parsed = NULL;
	hf.next = NULL;
	
	LOG(L_ERR, "hf.body: '%.*s'\n", hf.body.len, hf.body.s);
 
	if (parse_contact(&hf) < 0) {
		LOG(L_ERR, "move(): Error while parsing Contact\n");
		goto failure;
	}
	
	if (((contact_body_t*)hf.parsed)->star == 1) {
		LOG(L_ERR, "move(): Contact is *\n");
		goto failure;
	}

	first = ((contact_body_t*)hf.parsed)->contacts;
	if (first) {
		if (append_branch(_m, first->uri.s, first->uri.len) ==
1) {
			goto success;
		} else {
			LOG(L_ERR, "move(): Appending branch failed\n");
		}
	} else {
		LOG(L_ERR, "move(): No contacts in Contact header\n");
	}

failure:
	if (hf.parsed) {
		free_contact((contact_body_t**)(&(hf.parsed)));
	}
	return -1;

success:
	free_contact((contact_body_t**)(&(hf.parsed)));
	return 1;
}

_______________________________________________
Serusers mailing list
serusers at lists.iptel.org
http://lists.iptel.org/mailman/listinfo/serusers




More information about the sr-users mailing list