User Tools

Site Tools


cookbooks:5.3.x:pseudovariables

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cookbooks:5.3.x:pseudovariables [2020/04/02 21:25]
miconda [$xavp(id) - XAVPs]
cookbooks:5.3.x:pseudovariables [2020/04/06 18:09] (current)
pojogas typo in xavp example
Line 722: Line 722:
 ===== $xavp(id) - XAVPs ===== ===== $xavp(id) - XAVPs =====
  
-**xavp** - eXtended AVPs - are structures that can store multiple values, which can be grouped in a structure-like fashion. They work like a stack, similar to AVPs, and are attached to SIP transactions. Each xavp has a name and can contain multiple named values, the structure name (or root list name) and the value name (or field name) are separated by <nowiki>=></nowiki> like <nowiki>$xavp(root=>field)</nowiki> where "root" is the name of the structure and "field" is the name of the value. To assign a value use:+**xavp** - eXtended AVPs - are variables that can store multiple values, which can also be grouped in a structure-like fashion. Their value can be a string, an integer number or a list of named values (child values). 
 + 
 +They work like a stack, similar to AVPs, and are attached to SIP transactions and automatically destroyed when the transaction is finished. 
 + 
 +Each xavp has a string name and can contain a string, and integer or a list of named values. The structure name (or root list name) and the value name (or field name, or child value name) are separated by <nowiki>=></nowiki> like <nowiki>$xavp(root=>field)</nowiki> where "root" is the name of the structure and "field" is the name of the (child) value. 
 + 
 +To assign a single value use: 
 + 
 +<code c> 
 +$xavp(root)="string value"; 
 +$xavp(root)=intnumber; 
 +</code> 
 + 
 +To assign a named value use:
  
 <code c> <code c>
Line 730: Line 743:
  
 Like avps, xavp act like a stack. To refer to an existing value, use an index. The newest xavp has index zero [0]. Like avps, xavp act like a stack. To refer to an existing value, use an index. The newest xavp has index zero [0].
 +
 <code c> <code c>
 $xavp(root[0]=>field)=12; $xavp(root[0]=>field)=12;
Line 737: Line 751:
  
 <code c> <code c>
-# new item (example => (name = "one")) +# new item (person => [(lastname = "Smith")]
-$xavp(example=>name)="one"; +$xavp(person=>lastname)="Smith"; 
-# add new item (example => (name = "two")) + 
-$xavp(example=>name)="two";+# add new item (person => [(lastname = "Doe")]
 +$xavp(person=>lastname)="Doe"; 
 # add another named value to the last example item # add another named value to the last example item
-$xavp(example[0]=>value)="John";+#   (person => [(firstname="John"), (lastname = "Doe")]) 
 +$xavp(person[0]=>firstname)="John"; 
 # add another named value to first example item # add another named value to first example item
-xavp(example[1]=>value)="Anna";+#   (person => [(firstname="Alice"), (lastname = "Smith")]) 
 +xavp(person[1]=>firstname)="Alice";
 </code> </code>
  
Line 750: Line 769:
 Another example: Another example:
 <code c> <code c>
-Create new xavp+create new (the first) root xavp with a named value of string type
 $xavp(sf=>uri)="sip:10.10.10.10"; $xavp(sf=>uri)="sip:10.10.10.10";
  
-#assign values+add named values (child values)
 $xavp(sf[0]=>fr_timer)=10; $xavp(sf[0]=>fr_timer)=10;
 $xavp(sf[0]=>fr_inv_timer)=15; $xavp(sf[0]=>fr_inv_timer)=15;
 $xavp(sf[0]=>headers)="X-CustomerID: 1234\r\n"; $xavp(sf[0]=>headers)="X-CustomerID: 1234\r\n";
  
-#create new xavp, moving previous one to sf[1]+# create new (the second) root xavp with a named value of string type, moving previous one to sf[1]
 $xavp(sf=>uri)="sip:10.10.10.11"; $xavp(sf=>uri)="sip:10.10.10.11";
 +# add named values (child values)
 $xavp(sf[0]=>fr_timer)=20; $xavp(sf[0]=>fr_timer)=20;
 $xavp(sf[0]=>fr_inv_timer)=35; $xavp(sf[0]=>fr_inv_timer)=35;
  
-#Create a third xavp+create new (the thirdxavp with a named value of string type, moving previous one to sf[1] and the other one to sf[2]
 $xavp(sf=>uri)="sip:10.10.10.12"; $xavp(sf=>uri)="sip:10.10.10.12";
 +# add named values (child values)
 $xavp(sf[0]=>fr_timer)=10; $xavp(sf[0]=>fr_timer)=10;
 $xavp(sf[0]=>fr_inv_timer)=15; $xavp(sf[0]=>fr_inv_timer)=15;
Line 770: Line 791:
 </code> </code>
  
-xavps are read and write variables. You can create multilevel xavps, as xavps may contain xavps.+xavps are read and write variables.
  
 ===== $hdr(name) - Headers ===== ===== $hdr(name) - Headers =====
cookbooks/5.3.x/pseudovariables.1585855558.txt.gz · Last modified: 2020/04/02 21:25 by miconda