[SR-Users] Parsing Contact Port Field

Michael Iedema michael at kapsulate.com
Mon Nov 18 14:24:37 CET 2019


Hi Sergiu,

> @contact.uri.hostport might be what you are looking for.
> 
> For more:
> http://www.kamailio.org/wiki/cookbooks/devel/selects


That worked perfectly, thanks!

For the other beginners out there, here are two snippets for posterity:

== TO LOG ==

xlog("L_INFO", "contact.uri.host = $sel(@contact.uri.host)\n”);
xlog("L_INFO", "contact.uri.port = $sel(@contact.uri.port)\n”);


== TO COMPARE ==

#!define PORT_SERVICE_A 5062

if ( @contact.uri.port == PORT_SERVICE_A ) {
  xlog(“L_INFO", “Service A: sent $rm\n");
}



Regards,
-Michael



> On Nov 12, 2019, at 14:50, Sergiu Pojoga <pojogas at gmail.com> wrote:
> 
> Hi Michael,
> 
> @contact.uri.hostport might be what you are looking for.
> 
> For more:
> http://www.kamailio.org/wiki/cookbooks/devel/selects
> 
> Cheers.
> --Sergiu
> 
> On Tue, Nov 12, 2019 at 8:32 AM Michael Iedema <michael at kapsulate.com> wrote:
> Hello everyone,
> 
> I have a potentially silly beginners question: how can I parse the contact port field and act on it in my routing logic?
> 
> 
> I know that the $ct variable contains the entire contact header and I can print it in an xlog() call. However, I’d like to do something like the following in my routing logic:
> 
> 
> . . . SIP CONTENT
> 
> Contact: <sip:someaccount at 192.168.86.104:5062>;expires=1800
> 
> 
> . . . CONFIG LOGIC
> 
> #!define PORT_SERVICE1 5061
> #!define PORT_SERVICE2 5062
> 
> route {
>     if ( src_port == PORT_SERVICE1 ) {
>         xlog(“L_INFO”, “Received $rm from SERVICE1\n”);
>     } else if ( src_port == PORT_SERVICE2 ) {
>         xlog(“L_INFO”, “Received $rm from SERVICE2\n”);
>     }
> }
> 
> 
> I realize that src_port is not the correct value to compare against. I want to compare against the originating contact’s port value.
> 
> How can I extract the port field from $ct?
> 
> 
> Many thanks in advance and apologies for the beginners question. I’ve googled for what I think I’m trying to do without any real results on functions or tokenizers, etc. I’m using Kamailio 5.3.0.
> 
> Regards,
> -Michael
> 
> 
> _______________________________________________
> Kamailio (SER) - Users Mailing List
> sr-users at lists.kamailio.org
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
> _______________________________________________
> Kamailio (SER) - Users Mailing List
> sr-users at lists.kamailio.org
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users




More information about the sr-users mailing list