[SR-Users] Setting Kamailio User-Agent dynamically

Daniel-Constantin Mierla miconda at gmail.com
Thu Oct 9 13:09:25 CEST 2014


On 08/10/14 19:25, Errol Samuels wrote:
> I followed Daniel's instructions and made some progress but not 100% 
> there yet.
>
> -------[Global section]----------
>
> user_agent_header=""
>
> -------[Main Routing Logic]-------
>
> # handle registrations
>         if (is_method("REGISTER"))
>         {
>         $avp(new_user_agent) = $ua;
>         }
>         route(REGISTRAR);
> .
> .
>
> # Forward REGISTER to Freeswitch
> route[REGFWD] {
>
>         if(!is_method("REGISTER"))
>         {
>                 return;
>         }
>         route(DISPATCH);
>         $uac_req(method)="REGISTER";
>         $uac_req(ruri)=$du;
>         $uac_req(furi)=$fn + "<sip:" + $au + "@" + $ar + ">";
>         $uac_req(turi)=$tn + "<sip:" + $au + "@" + $ar + ">";
>         $uac_req(hdrs)="Contact: <sip:" + $au + "@"
>                                 + $ar
>                                 + ";fs_path=sip:"
>                                 + $sel(cfg_get.kamailio.bindip)
>                                 + ":" + $sel(cfg_get.kamailio.bindport)
>                                 + ">"
>                                 + "\r\n";
>         if($sel(contact.expires) != $null)
>                 $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + 
> $sel(contact.expires) + "\r\n";
>         else
>                 $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + 
> $hdr(Expires) + "\r\n";
>         $uac_req(hdrs)= $uac_req(hdrs) + "User-Agent: " + 
> $avp(new_user_agent) + "\r\n";
>         uac_req_send();
>         exit;
> }
> #!endif
>
> ------------
>
> Now the correct User-Agent appears in the REGISTER message but in 
> Freeswitch it shows as unknown.
>
> U 184.xx.xx.208:5060 -> 184.xx.xx.198:6060
> REGISTER sip:184.x.x.198:6060 SIP/2.0.
> Via: SIP/2.0/UDP 184.xx.xx.208;branch=z9hG4bKa764.668d6dc7.0.
> To: <sip:1001 at pbx.mydomain.com <mailto:sip%3A1001 at pbx.mydomain.com>>.
> From: <sip:1001 at pbx.mydomain.com 
> <mailto:sip%3A1001 at pbx.mydomain.com>>;tag=6f72f76f3402bf7cf11f6917529ca761-2ceb.
> CSeq: 10 REGISTER.
> Call-ID: 4570a277563cdffc-61869 at 184.xx.xx.208.
> Max-Forwards: 70.
> Content-Length: 0.
> .
> Contact: <sip:1001 at pbx.mydomain.com 
> <mailto:sip%3A1001 at pbx.mydomain.com>;fs_path=sip:184.xx.xx.208:5060>.
> Expires: 120.
> User-Agent: Yealink SIP-T46G 28.72.0.26.
> .
> ----------------
>
> Got some extra dots in there but not sure why they are there and how 
> they got there.
> Any ideas? Anything I missed?

Apparently by setting an empty user-agent header value in kamailio 
config file results in an empty line in headers, which means end of 
headers. So it kind of breaks the headers -- I will fix that in kamailio.

A solution for now will be to use:

user_agent_header = "X-Proxy: abc"

Or, in other words, set the value of the parameter to something that 
doesn't include User-Agent: as header name.

Cheers,
Daniel

>
> BR
>
> Errol
>
>
>
> On Wed, Oct 8, 2014 at 12:34 PM, Daniel-Constantin Mierla 
> <miconda at gmail.com <mailto:miconda at gmail.com>> wrote:
>
>     Perhaps you can get it with adding User-Agent header to
>     $uac_req(hdrs):
>
>     $uac_req(hdrs)= $uac_req(hdrs) + "User-Agent: " + $ua + "\r\n";
>
>     And sent the global parameter:
>
>     user_agent_header=""
>
>     But then no local generated request has user agent, which probably
>     is ok for you.
>
>     There are still ways to use event_route[tm:local-request] to set a
>     custom user agent header, but would require something like:
>     - add $us in $uac_req(hdrs) as X-UA header
>     - in event_route[tm:local-request], remove User-Agent and X-UA
>     headers and add again User-Agent taking the value from X-UA
>
>     Cheers,
>     Daniel
>
>
>
>
>

-- 
Daniel-Constantin Mierla
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20141009/dcaf98fa/attachment.html>


More information about the sr-users mailing list