[SR-Users] Extracting P-Asserted-Identity value

Olle E. Johansson oej at edvina.net
Mon Apr 11 13:43:18 CEST 2016


> On 11 Apr 2016, at 12:35, Grant Bagdasarian <gb at cm.nl> wrote:
> 
> Hi Daniel,
>  
> I used the regexp sub, and it works!
>  
> If anyone is interested, here is the code:
>  
>                                                $var(p_asserted_identity) = $(hdr(P-Asserted-Identity)[*]);
>                                                xlog("L_INFO", "P-Asserted-Identity: $var(p_asserted_identity) \r\n”);
Did you see the $ai pseudo variable? Insted of using the hdr you could have grabbed the URI directly with $ai 
http://www.kamailio.org/wiki/cookbooks/4.4.x/pseudovariables#ai_-_uri_inp-asserted-identity_header <http://www.kamailio.org/wiki/cookbooks/4.4.x/pseudovariables#ai_-_uri_inp-asserted-identity_header>

/O

>                                                $var(caller_id) = $(var(p_asserted_identity){re.subst,/.*tel:(\+?[[:digit:]]+).*/\1/});
>                                                xlog("L_INFO", "Retrieved CallerId ($var(caller_id)) from P-Asserted-Identity header \r\n");
>  
> Debug log:
> P-Asserted-Identity: "Grant" <sip:grant at domain.com <sip:grant at domain.com>>,tel:+3101234567 <tel:+3101234567>
> Retrieved CallerId (+3101234567) from P-Asserted-Identity header
>  
> Regards,
>  
> Grant
>  
> From: Daniel-Constantin Mierla [mailto:miconda at gmail.com <mailto:miconda at gmail.com>] 
> Sent: Monday, April 11, 2016 11:25 AM
> To: Grant Bagdasarian <gb at cm.nl <mailto:gb at cm.nl>>; Kamailio (SER) - Users Mailing List <sr-users at lists.sip-router.org <mailto:sr-users at lists.sip-router.org>>
> Subject: Re: [SR-Users] Extracting P-Asserted-Identity value
>  
> Hello,
> 
> there is a transformation for regexp substitutions, see the transformations cookbook on kamailio.org/wiki <http://kamailio.org/wiki>.
> 
> Also, if you just want everything after 'tel:' <tel:'>, then you can use string transformations like substring or select.
> 
> Cheers,
> Daniel
> 
> On 11/04/16 11:13, Grant Bagdasarian wrote:
> Hi Daniel,
>  
> Yes, you are absolutely right! Thank you for pointing that out!
>  
> Is it possible to use regex inside the cfg script and use groups to extract the value?
>  
> Quick regex example (needs tweaking): tel:(\+\d{1,20}) <tel:%28%5C+%5Cd%7b1,20%7d%29> and then use a pseudo-variable to get the first group?
> https://regex101.com/r/dN7bY8/1 <https://regex101.com/r/dN7bY8/1>
>  
> P-Asserted-Identity: "Cullen Jennings" <sip:fluffy at cisco.com> <sip:fluffy at cisco.com>
> P-Asserted-Identity: tel:+14085264000 <tel:+14085264000>
>  
> Regards,
>  
> Grant
>  
> From: sr-users [mailto:sr-users-bounces at lists.sip-router.org <mailto:sr-users-bounces at lists.sip-router.org>] On Behalf Of Daniel-Constantin Mierla
> Sent: Monday, April 11, 2016 9:07 AM
> To: Kamailio (SER) - Users Mailing List <sr-users at lists.sip-router.org> <mailto:sr-users at lists.sip-router.org>
> Subject: Re: [SR-Users] Extracting P-Asserted-Identity value
>  
> Hello,
> 
> this should work unless there are parameters with the same name in userpart, or uri part or header body part.
> 
> Perhaps the safest mode is to apply first the tobody transformation to extract the part you want then apply the params transformation.
> 
> Cheers,
> Daniel
> 
> On 08/04/16 17:41, Grant Bagdasarian wrote:
> To answer my own question.
> This does parse:
>  
>                                                $var(p_asserted_identity) = $(hdr(P-Asserted-Identity)[*]);
>                                                $var(caller_id) = $(var(p_asserted_identity){param.value,'tel',:});
>  
> But, I’m not sure if this is the correct way to do this. Maybe someone else has a more elegant solution?
>  
>  
> From: sr-users [mailto:sr-users-bounces at lists.sip-router.org <mailto:sr-users-bounces at lists.sip-router.org>] On Behalf Of Grant Bagdasarian
> Sent: Friday, April 8, 2016 5:38 PM
> To: Kamailio (SER) - Users Mailing List (sr-users at lists.sip-router.org <mailto:sr-users at lists.sip-router.org>) <sr-users at lists.sip-router.org> <mailto:sr-users at lists.sip-router.org>
> Subject: [SR-Users] Extracting P-Asserted-Identity value
>  
> Hello,
>  
> How do I extract the value of “tel” from multiple P-Asserted-Identity headers?
>  
> Example:
>    P-Asserted-Identity: "Cullen Jennings" <sip:fluffy at cisco.com <sip:fluffy at cisco.com>>
>    P-Asserted-Identity: tel:+14085264000 <tel:+14085264000>
>  
> What I got so far is:
>                                                $var(p_asserted_identity) = $(hdr(P-Asserted-Identity)[*]);
>                                                $var(caller_id) = $var(p_asserted_identity){param.value,'tel',':'};
>  
> But this does not work. I keep getting parser errors when doing the transformation (2nd line of code example):
> I’m not sure how to format the line of code. I tried multiple ways, but none work.
>  
> Apr  8 18:35:20 kamailio: : <core> [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 400, column 47: syntax error
> Apr  8 18:35:20 kamailio: : <core> [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 400, column 47: bad command
> Apr  8 18:35:20 kamailio: : <core> [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 400, column 47: bad command
> Apr  8 18:35:20 kamailio: : <core> [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 400, column 53: '('')' expected (function call)
> Apr  8 18:35:20 kamailio: : <core> [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 400, column 53: bad command: missing ';'?
> Apr  8 18:35:20 kamailio: : <core> [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 400, column 59: '('')' expected (function call)
> Apr  8 18:35:20 kamailio: : <core> [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 400, column 59: bad command: missing ';'?
> Apr  8 18:35:20 kamailio: : <core> [cfg.y:3365]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 400, column 60-64: bad command
> Apr  8 18:35:20 kamailio: : <core> [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 400, column 65: bad command
> Apr  8 18:35:20 kamailio: : <core> [cfg.y:3365]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 400, column 66-68: bad command
> Apr  8 18:35:20 kamailio: : <core> [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 408, column 6: syntax error
> Apr  8 18:35:20 kamailio: : <core> [cfg.y:3368]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 408, column 6:
>  
> Regards,
>  
> Grant
> 
> 
> 
> 
> _______________________________________________
> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
> sr-users at lists.sip-router.org <mailto:sr-users at lists.sip-router.org>
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users <http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users>
> 
> 
> 
> -- 
> Daniel-Constantin Mierla
> http://www.asipto.com <http://www.asipto.com/>
> http://twitter.com/#!/miconda <http://twitter.com/#%21/miconda> - http://www.linkedin.com/in/miconda <http://www.linkedin.com/in/miconda>
> Kamailio World Conference, Berlin, May 18-20, 2016 - http://www.kamailioworld.com <http://www.kamailioworld.com/>
> 
> 
> -- 
> Daniel-Constantin Mierla
> http://www.asipto.com <http://www.asipto.com/>
> http://twitter.com/#!/miconda <http://twitter.com/#!/miconda> - http://www.linkedin.com/in/miconda <http://www.linkedin.com/in/miconda>
> Kamailio World Conference, Berlin, May 18-20, 2016 - http://www.kamailioworld.com <http://www.kamailioworld.com/>_______________________________________________
> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
> sr-users at lists.sip-router.org <mailto:sr-users at lists.sip-router.org>
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users <http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users>

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


More information about the sr-users mailing list