From c97532fdbb5562369b3af79606f34c8599b959d3 Mon Sep 17 00:00:00 2001 From: Thomas Ries Date: Thu, 24 May 2007 18:38:59 +0000 Subject: [PATCH] - new feature: can masquerade User-agent header --- ChangeLog | 1 + doc/siproxd.conf.example | 11 +++++++++++ src/proxy.c | 39 +++++++++++++++++++++++++++++++++++---- src/readconf.c | 1 + src/siproxd.h | 2 ++ 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0511f89..8ad7cb5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 0.6.0 ===== + 24-May-2007: - new feature: can masquerade User-agent header 13-May-2007: - deal with locally running UAs on same host (inboud IF side) 07-May-2007: - Client-ID in RTP proxy is derived from Client IP address. This should fix an issue with unexpectedly timing-out RTP diff --git a/doc/siproxd.conf.example b/doc/siproxd.conf.example index b9193f4..777af75 100644 --- a/doc/siproxd.conf.example +++ b/doc/siproxd.conf.example @@ -232,6 +232,17 @@ debug_port = 0 # mask_host=10.0.1.1 -- inbound IP address of proxy # masked_host=my.public.host -- outbound hostname proxy +###################################################################### +# User Agent Masquerading +# +# Siproxd can masquerade the User Agent string of your local UAs. +# Useful for Providers that do not work with some specific UAs +# (e.g. sipcall.ch - it does not work if your outgoing SIP +# traffic contains an Asterisk UA string...) +# Default is to do no replacement. +# +#ua_string = Siproxd-UA + ###################################################################### # Outbound proxy # diff --git a/src/proxy.c b/src/proxy.c index 964a6a8..93a3d10 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -189,7 +189,6 @@ int proxy_request (sip_ticket_t *ticket) { /* 'i' still holds the valid index into the URLMAP table */ proxy_rewrite_request_uri(request, i); - /* if this is CANCEL/BYE request, stop RTP proxying */ if (MSG_IS_BYE(request) || MSG_IS_CANCEL(request)) { /* stop the RTP proxying stream(s) */ @@ -243,9 +242,12 @@ int proxy_request (sip_ticket_t *ticket) { } #endif - /* rewrite Contact header to represent the masqued address */ + /* Rewrite Contact header to represent the masqued address */ sip_rewrite_contact(ticket, DIR_OUTGOING); + /* Masquerade the User-Agent if configured to do so */ + proxy_rewrite_useragent(ticket); + /* if an INVITE, rewrite body */ if (MSG_IS_INVITE(request)) { sts = proxy_rewrite_invitation_body(ticket, DIR_OUTGOING); @@ -605,7 +607,7 @@ int proxy_response (sip_ticket_t *ticket) { * response merely indicates that the subscription has been * understood, and that authorization may or may not have been * granted), which then of course is forwarded back to the phone. - * Ans it seems that the Grandstream can *not* *handle* this + * And it seems that the Grandstream can *not* *handle* this * response, as it immediately sends another SUBSCRIBE request. * And this games goes on and on and on... * @@ -636,9 +638,12 @@ int proxy_response (sip_ticket_t *ticket) { response->from->url->host ? response->from->url->host : "*NULL*"); - /* rewrite Contact header to represent the masqued address */ + /* Rewrite Contact header to represent the masqued address */ sip_rewrite_contact(ticket, DIR_OUTGOING); + /* Masquerade the User-Agent if configured to do so */ + proxy_rewrite_useragent(ticket); + /* * If an 2xx OK or 1xx response, answer to an INVITE request, * rewrite body @@ -1204,3 +1209,29 @@ int proxy_rewrite_request_uri(osip_message_t *mymsg, int idx){ } return STS_SUCCESS; } + + +/* + * PROXY_REWRITE_USERAGENT + * + * rewrites the User Agent String + * + * RETURNS + * STS_SUCCESS on success + */ +int proxy_rewrite_useragent(sip_ticket_t *ticket){ + osip_header_t *ua_hdr=NULL; + char *useragent; + + osip_message_get_user_agent(ticket->sipmsg, 0, &ua_hdr); + + /* Configured? & Does User-Agent header exist? */ + if ((configuration.ua_string) && (ua_hdr && ua_hdr->hvalue)) { + DEBUGC(DBCLASS_PROXY,"proxy_rewrite_useragent: [%s] -> [%s]", + ua_hdr->hvalue, configuration.ua_string); + osip_free(ua_hdr->hvalue); + ua_hdr->hvalue=osip_malloc(strlen(configuration.ua_string)+1); + strcpy(ua_hdr->hvalue, configuration.ua_string); + } + return STS_SUCCESS; +} diff --git a/src/readconf.c b/src/readconf.c index 3de1960..a7b26f5 100644 --- a/src/readconf.c +++ b/src/readconf.c @@ -183,6 +183,7 @@ static int parse_config (FILE *configfile) { { "pi_shortdial_enable", TYP_INT4, &configuration.pi_shortdial }, { "pi_shortdial_akey", TYP_STRING, &configuration.pi_shortdial_akey }, { "pi_shortdial_entry", TYP_STRINGA,&configuration.pi_shortdial_entry }, + { "ua_string", TYP_STRING, &configuration.ua_string }, {0, 0, 0} }; diff --git a/src/siproxd.h b/src/siproxd.h index 84e6576..9f6917f 100644 --- a/src/siproxd.h +++ b/src/siproxd.h @@ -94,6 +94,7 @@ struct siproxd_config { int pi_shortdial; char *pi_shortdial_akey; stringa_t pi_shortdial_entry; + char *ua_string; }; /* @@ -143,6 +144,7 @@ int proxy_request (sip_ticket_t *ticket); /*X*/ int proxy_response (sip_ticket_t *ticket); /*X*/ int proxy_rewrite_invitation_body(sip_ticket_t *ticket, int direction); /*X*/ int proxy_rewrite_request_uri(osip_message_t *mymsg, int idx); /*X*/ +int proxy_rewrite_useragent(sip_ticket_t *ticket); /*X*/ /* route_preprocessing.c */ int route_preprocess(sip_ticket_t *ticket); /*X*/