[asterisk-commits] contrib/script/sip to pjsip: implement 'all' for allow/disallow (asterisk[15])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Oct 17 09:38:52 CDT 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/6810 )

Change subject: contrib/script/sip_to_pjsip: implement 'all' for allow/disallow
......................................................................

contrib/script/sip_to_pjsip: implement 'all' for allow/disallow

when 'all' is specified in an allow or disallow section, it should erase
all values from the inverse section in the default config. E.G.
allow=all should erase any deny values from default config &
vice-versa

ASTERISK-27333 #close

Change-Id: I99219478fb98f08751d769daaee0b7795118a5a6
---
M contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
1 file changed, 42 insertions(+), 2 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  George Joseph: Looks good to me, approved



diff --git a/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py b/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
index eb3aab3..533e4ba 100755
--- a/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
+++ b/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
@@ -77,6 +77,46 @@
                   section_to if section_to else section,
                   pjsip, nmapped, type)
 
+def merge_codec_value(key=None, val=None, section=None, pjsip=None,
+                nmapped=None, type='endpoint', section_to=None,
+                key_to=None):
+    """Merge values from allow/deny with those from the default. Special treatment for all"""
+    def _merge_codec_value(k, v, s, r, n):
+        merge_codec_value(key if key else k, v, s, r, n, type, section_to, key_to)
+
+    # if no value or section return the merge_codec_value
+    # function with the enclosed key and type
+    if not val and not section:
+        return _merge_codec_value
+
+    if key == 'allow':
+	    try:
+		disallow = sip.get(section, 'disallow')[0]
+		if disallow == 'all':
+		    #don't inherit
+                    for i in sip.get(section, 'allow'):
+		        set_value(key, i, section, pjsip, nmapped, type)
+	        else:
+		    merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)
+	    except LookupError:
+	        print "lookup error"
+		merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)
+		return
+    elif key == 'disallow':
+	    try:
+		allow = sip.get(section, 'allow')[0]
+		if allow == 'all':
+		    #don't inherit
+                    for i in sip.get(section, 'disallow'):
+		        set_value(key, i, section, pjsip, nmapped, type)
+	        else:
+		    merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)
+	    except LookupError:
+		merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)
+		return
+    else:
+	merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)
+
 
 def non_mapped(nmapped):
     """Write non-mapped sip.conf values to the non-mapped object"""
@@ -404,8 +444,8 @@
     ###########################################################################
     ['context',            set_value],
     ['dtmfmode',           set_dtmfmode],
-    ['disallow',           merge_value],
-    ['allow',              merge_value],
+    ['disallow',           merge_codec_value],
+    ['allow',              merge_codec_value],
     ['nat',                from_nat],            # rtp_symmetric, force_rport,
                                                  # rewrite_contact
     ['rtptimeout',         set_value('rtp_timeout')],

-- 
To view, visit https://gerrit.asterisk.org/6810
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: I99219478fb98f08751d769daaee0b7795118a5a6
Gerrit-Change-Number: 6810
Gerrit-PatchSet: 1
Gerrit-Owner: Torrey Searle <tsearle at gmail.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-commits/attachments/20171017/7045c287/attachment-0001.html>


More information about the asterisk-commits mailing list