diff options
author | Joshua Colp <jcolp@digium.com> | 2017-10-17 09:38:52 -0500 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2017-10-17 09:38:52 -0500 |
commit | 0555cf8da1af0069ea4b711860d4a9eda57fcb93 (patch) | |
tree | 6c339e9c8dbfb7251b2c7a00cc5e8e6aa2a3b078 | |
parent | 4de4a4535993f8071f22bb907c62571c127d36e3 (diff) | |
parent | e682580df40a6ada9a3ba3d8a904966b393c8f8c (diff) |
Merge "contrib/script/sip_to_pjsip: implement 'all' for allow/disallow" into 15
-rwxr-xr-x | contrib/scripts/sip_to_pjsip/sip_to_pjsip.py | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py b/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py index eb3aab3b8..533e4baec 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 @@ def merge_value(key=None, val=None, section=None, pjsip=None, 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 @@ peer_map = [ ########################################################################### ['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')], |