From fb744b6ba4a06616963fe69134572d13f72cb623 Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Mon, 3 Oct 2005 18:12:33 +0000 Subject: [PATCH] - handle multiple Contact headers (e.g. in REGISTER response) --- src/register.c | 18 ++++++++++++++---- src/sip_utils.c | 21 +++++++++++++-------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/register.c b/src/register.c index 3c1b7d4..c72ba8e 100644 --- a/src/register.c +++ b/src/register.c @@ -175,6 +175,7 @@ int register_client(sip_ticket_t *ticket, int force_lcl_masq) { int i, j, n, sts; int expires; time_t time_now; + osip_contact_t *contact; osip_uri_t *url1_to, *url1_contact=NULL; osip_uri_t *url2_to; osip_header_t *expires_hdr; @@ -235,20 +236,29 @@ int register_client(sip_ticket_t *ticket, int force_lcl_masq) { * (gdb) p *((osip_contact_t*)(sip->contacts->node->element)) * $5 = {displayname = 0x8af8848 "*", url = 0x0, gen_params = 0x8af8838} */ - if (ticket->sipmsg->contacts && ticket->sipmsg->contacts->node && +/* + if (ticket->sipmsg->contacts && + (ticket->sipmsg->contacts->nb_elt != 0) && + ticket->sipmsg->contacts->node && ticket->sipmsg->contacts->node->element) { url1_contact=((osip_contact_t*) (ticket->sipmsg->contacts->node->element))->url; } - - if ((url1_contact == NULL) || (url1_contact->host == NULL)) { +*/ + osip_message_get_contact(ticket->sipmsg, 0, &contact); + if ((contact == NULL) || + (contact->url == NULL) || + (contact->url->host == NULL)) { /* Don't have required Contact fields. This may be a Registration query. We should simply forward this request to its destination. */ - ERROR("empty Contact header - seems to be a registration query"); + DEBUGC(DBCLASS_REG, "empty Contact header - " + "seems to be a registration query"); return STS_SUCCESS; } + url1_contact=contact->url; + /* evaluate Expires Header field */ osip_message_get_expires(ticket->sipmsg, 0, &expires_hdr); diff --git a/src/sip_utils.c b/src/sip_utils.c index 3e40c13..d635ff3 100644 --- a/src/sip_utils.c +++ b/src/sip_utils.c @@ -681,6 +681,19 @@ int sip_rewrite_contact (sip_ticket_t *ticket, int direction) { /* found a mapping entry */ if (i %s@%s", + (contact->url->username)? contact->url->username : "*NULL*", + (contact->url->host)? contact->url->host : "*NULL*", + urlmap[i].masq_url->username, urlmap[i].masq_url->host); + } else { + DEBUGC(DBCLASS_PROXY, "rewriting Contact header %s@%s -> %s@%s", + (contact->url->username)? contact->url->username : "*NULL*", + (contact->url->host)? contact->url->host : "*NULL*", + urlmap[i].true_url->username, urlmap[i].true_url->host); + } + /* remove old entry */ osip_list_remove(sip_msg->contacts,j); osip_contact_to_str(contact, &tmp); @@ -694,17 +707,9 @@ int sip_rewrite_contact (sip_ticket_t *ticket, int direction) { if (direction == DIR_OUTGOING) { /* outgoing, use masqueraded url */ osip_uri_clone(urlmap[i].masq_url, &contact->url); - DEBUGC(DBCLASS_PROXY, "rewrote Contact header %s@%s -> %s@%s", - (contact->url->username)? contact->url->username : "*NULL*", - (contact->url->host)? contact->url->host : "*NULL*", - urlmap[i].masq_url->username, urlmap[i].masq_url->host); } else { /* incoming, use true url */ osip_uri_clone(urlmap[i].true_url, &contact->url); - DEBUGC(DBCLASS_PROXY, "rewrote Contact header %s@%s -> %s@%s", - (contact->url->username)? contact->url->username : "*NULL*", - (contact->url->host)? contact->url->host : "*NULL*", - urlmap[i].true_url->username, urlmap[i].true_url->host); } osip_list_add(sip_msg->contacts,contact,j);