[Asterisk-code-review] contrib/sip to pjsip: handle setvar in conversion (asterisk[16])

Pascal Cadotte Michaud asteriskteam at digium.com
Sat Oct 27 10:00:12 CDT 2018


Pascal Cadotte Michaud has uploaded this change for review. ( https://gerrit.asterisk.org/10554


Change subject: contrib/sip_to_pjsip: handle setvar in conversion
......................................................................

contrib/sip_to_pjsip: handle setvar in conversion

Given a sip.conf with the following content:

setvar FOO=1
setvar BAR=42

I want my generated pjsip.conf to containt the following set_vars

set_var FOO=1
set_var BAR=42

in the matching endpoint section.

Change-Id: I6c822401fda4133c3b44bf31e655b4eb939d4d26
---
M contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
1 file changed, 20 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/54/10554/1

diff --git a/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py b/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
index d05f97d..1860a31 100755
--- a/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
+++ b/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
@@ -40,6 +40,11 @@
         return sect
 
 
+def ignore(key=None, val=None, section=None, pjsip=None,
+           nmapped=None, type='endpoint'):
+    """Ignore a key and mark it as mapped"""
+
+
 def set_value(key=None, val=None, section=None, pjsip=None,
               nmapped=None, type='endpoint'):
     """Sets the key to the value within the section in pjsip.conf"""
@@ -508,6 +513,7 @@
     ['dtlscapath',         set_value('dtls_ca_path')],
     ['dtlssetup',          set_value('dtls_setup')],
     ['encryption_taglen',  from_encryption_taglen],
+    ['setvar',             ignore],
 
 ############################ maps to an aor ###################################
 
@@ -1117,6 +1123,19 @@
         reg.write(pjsip, nmapped)
 
 
+def map_setvars(sip, section, pjsip, nmapped):
+    """
+    Map all setvar in peer section to the appropriate endpoint set_var
+    """
+    try:
+        setvars = sip.section(section)[0].get('setvar')
+    except LookupError:
+        return
+
+    for setvar in setvars:
+        set_value('set_var', setvar, section, pjsip, nmapped)
+
+
 def map_peer(sip, section, pjsip, nmapped):
     """
     Map the options from a peer section in sip.conf into the appropriate
@@ -1218,6 +1237,7 @@
             pass
         else:
             map_peer(sip, section, pjsip, nmapped)
+            map_setvars(sip, section, pjsip, nmapped)
 
     find_non_mapped(sip.defaults(), nmapped)
     find_non_mapped(sip.sections(), nmapped)

-- 
To view, visit https://gerrit.asterisk.org/10554
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c822401fda4133c3b44bf31e655b4eb939d4d26
Gerrit-Change-Number: 10554
Gerrit-PatchSet: 1
Gerrit-Owner: Pascal Cadotte Michaud <pcm at wazo.io>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181027/8eab3f07/attachment.html>


More information about the asterisk-code-review mailing list