[OpenSIPS-Users] Take the value of the newly added SIP X-header for the log

Oleg Podguyko podguiko at mail.ru
Thu Sep 26 18:30:45 EDT 2019


Hello Ben,
Thank you for your advices!
  
>Четверг, 26 сентября 2019, 21:16 +03:00 от Ben Newlin <ben.newlin at genesys.com>:
> 
>Oleg,
> 
>OpenSIPS stores all the changes you make to the INVITE and applies them all together right before sending it out. This is to be more efficient. So you cannot usually see these types of changes during processing. This means if you want to keep using those headers in your script you need to remember them yourself.
> 
>The easiest way to do this from your code is to just access the same $json variable in the BALANCE route. JSON variables in OpenSIPS are just like $var in that they are persistent within an OpenSIPS process [1] (so make sure you initialize!). So as long as you are not calling any async function in between, the values will all still be there.
> 
>Alternatively, you can store the values in AVPs [2]. Assuming you are using TM, AVPs are attached to the transaction and will persist through branches and replies, in case you need the values there as well. AVPs are stacks, so the model I have used for data like this is to have 2 AVPs – one for the keys and one for the values – and keep them in sync.
> 
>[1] -  https://opensips.org/html/docs/modules/2.4.x/json.html#pv_json
>[2] -  https://www.opensips.org/Documentation/Script-CoreVar-2-4#toc2
> 
>Ben Newlin 
> 
>From:  Users < users-bounces at lists.opensips.org > on behalf of Oleg Podguyko via Users < users at lists.opensips.org >
>Reply-To:  Oleg Podguyko < podguiko at mail.ru >, OpenSIPS users mailling list < users at lists.opensips.org >
>Date:  Thursday, September 26, 2019 at 1:49 PM
>To:  "users at lists.opensips.org" < users at lists.opensips.org >
>Subject:  [OpenSIPS-Users] Take the value of the newly added SIP X-header for the log
> 
>Hello everebody!
> 
>My opensips works as proxy. Get INVITE from one side and communicates with a remote web server via rest. Opensips sends a request to the web server and receives a lot of custom data, which it converts to SIP X-header. In the end I get 10 different SIP X-headers
> 
>$var(i) = 0; 
>            while( $json(resp/headers[$var(i)]) )
>            {
>                $var(header)=$json(resp/headers[$var(i)]/header);
>                $var(value)=$json(resp/headers[$var(i)]/value);
>                $var(i) = $var(i) + 1;           
>                # add sip headers
>                append_hf("$var(header):$var(value)\r\n");
>            } 
>        route(BALANCE);
>        route(RELAY);  
> 
> Everything works. Now, In the next route (BALANCE), I want to output the header that was just added to the log
>xlog("L_INFO", "$X-My-Custom-Header: $(hdr(X-My-Custom-Header))");
> 
>But in the log I always see null. Although in the INVITE wich opensips sends, all SIP X-header in place. 
>Does this mean I can't get the value of the newly added SIP X-header? What should I do to get these values?
> 
> 
> 
> 
> 
>--
>Олег Подгуйко 
 
 
--
Олег Подгуйко
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20190927/8354ff5e/attachment.html>


More information about the Users mailing list