[SR-Users] Setting Kamailio User-Agent dynamically

Errol Samuels ewsamuels at gmail.com
Thu Oct 9 12:08:50 CEST 2014


Just found something interesting.

I just commented out the "user_agent_header" in the Global section and
restarted kamailio and now the REGISTER message seems to be completely
intact but now we have two occurrences of the User-Agent.  I tried doing
the remove_hf("User-Agent) but it doesn't seem to have any effect.

U 184.xx.xx.208:5060 -> 184.xx.xx.198:6060
REGISTER sip:184.xx.xx.198:6060 SIP/2.0.
Via: SIP/2.0/UDP 184.154.215.238;branch=z9hG4bK323.a0452631.0.
To: <sip:205 at pbx.mydomain.com>.
From: <sip:205 at pbx.mydomain.com>;tag=6f72f76f3402bf7cf11f6917529ca761-b489.
CSeq: 10 REGISTER.
Call-ID: 6ac0486a044f66e5-62858 at 184.xx.xx.208.
Max-Forwards: 70.
Content-Length: 0.
*User-Agent: kamailio (4.0.6 (x86_64/linux)).*
Contact: <sip:205 at pbx.mydomain.com;fs_path=sip:184.xx.xx.208:5060>.
*User-Agent: Yealink SIP-T46G 28.72.0.26.*
Expires: 120.
.

Any ideas?

BR

Errol

On Wed, Oct 8, 2014 at 6:25 PM, Errol Samuels <ewsamuels at gmail.com> 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>.
> From: <sip:1001 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;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?
>
> BR
>
> Errol
>
>
>
> On Wed, Oct 8, 2014 at 12:34 PM, Daniel-Constantin Mierla <
> 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
>>
>>
>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20141009/f1a8388a/attachment.html>


More information about the sr-users mailing list