1

sir,

I am trying to create stateful proxy in opensips 2.4.

I just wanted a variable to hold received message information and process it.

So i checked "core variable" in opensips manual.it says, script variable are process wise. So i should not use to hold header value in script value like $var(Ruri)=$ru?? it will be overwritten by other call??

$var(userName)=$rU;
$var(removePlus) = '+';
# Search the string starting at 0 index
if($(var(userName){s.index, $var(removePlus)})==0){ 
  $rU=$(var(userName){s.substr,1,0});
}

1 Answers1

1

$var variables are process-local, meaning that you can't share them with other SIP workers even if you wanted to! In fact, they are so optimized that their starting value will often be what the same process left-behind during a previous SIP message processing (tip: you can prove this by running opensips with children = 1 and making two calls).

On the other hand, variables such as $avp are shared between processes, but not in a "dangerous" way that you have to worry about two INVITE retransmissions processing in parallel, each overwriting the other one's $avp, etc. No! That is taken care of under the hood. The "sharing" only means that, for example, during a 200 OK reply processed by a different process than the one which relayed the initial INVITE, you will still be able to read and write to the same $avp which you set during request processing.

Finally, your code seems correct, but it can be greatly simplified:

if ($rU =~ "^+")
    strip(1);
Liviu Chircu
  • 1,000
  • 3
  • 11
  • 24
  • sir, do you mean that two thread at same process cannot share value right?? or only sharing would not happen threads between different process ?? – jagadeesh kalaiyarasan Feb 14 '19 at 13:16
  • 1
    opensips is multi-process, not multi-thread; different processes only share certain types of variables, such as `$avp` or `$dlg_val` – Liviu Chircu Feb 14 '19 at 16:36