[asterisk-commits] mmichelson: branch mmichelson/conversion_script r397662 - in /team/mmichelson...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Aug 26 13:33:02 CDT 2013
Author: mmichelson
Date: Mon Aug 26 13:33:00 2013
New Revision: 397662
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=397662
Log:
Get rid of references to "res_sip"
This converts the script name to "sip_to_pjsip" as well as its
parent directory. This also changes the text in the script not to
refer to res_sip anywhere.
Added:
team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/
- copied from r397661, team/mmichelson/conversion_script/contrib/scripts/sip_to_res_sip/
team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
- copied, changed from r397661, team/mmichelson/conversion_script/contrib/scripts/sip_to_res_sip/sip_to_res_sip.py
Removed:
team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_res_sip.py
team/mmichelson/conversion_script/contrib/scripts/sip_to_res_sip/
Copied: team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py (from r397661, team/mmichelson/conversion_script/contrib/scripts/sip_to_res_sip/sip_to_res_sip.py)
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py?view=diff&rev=397662&p1=team/mmichelson/conversion_script/contrib/scripts/sip_to_res_sip/sip_to_res_sip.py&r1=397661&p2=team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py&r2=397662
==============================================================================
--- team/mmichelson/conversion_script/contrib/scripts/sip_to_res_sip/sip_to_res_sip.py (original)
+++ team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py Mon Aug 26 13:33:00 2013
@@ -13,25 +13,25 @@
import astdicts
import astconfigparser
-PREFIX = 'res_sip_'
+PREFIX = 'pjsip_'
###############################################################################
### some utility functions
###############################################################################
-def section_by_type(section, res_sip, type):
+def section_by_type(section, pjsip, type):
"""Finds a section based upon the given type, adding it if not found."""
try:
return astconfigparser.find_dict(
- res_sip.section(section), 'type', type)
+ pjsip.section(section), 'type', type)
except LookupError:
# section for type doesn't exist, so add
- sect = res_sip.add_section(section)
+ sect = pjsip.add_section(section)
sect['type'] = type
return sect
-def set_value(key=None, val=None, section=None, res_sip=None,
+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 res_sip.conf"""
+ """Sets the key to the value within the section in pjsip.conf"""
def _set_value(k, v, s, r, n):
set_value(key if key else k, v, s, r, n, type)
@@ -41,10 +41,10 @@
return _set_value
# otherwise try to set the value
- section_by_type(section, res_sip, type)[key] = \
+ section_by_type(section, pjsip, type)[key] = \
val[0] if isinstance(val, list) else val
-def merge_value(key=None, val=None, section=None, res_sip=None,
+def merge_value(key=None, val=None, section=None, pjsip=None,
nmapped=None, type='endpoint', section_to=None):
"""Merge values from the given section with those from the default."""
def _merge_value(k, v, s, r, n):
@@ -57,10 +57,10 @@
# should return a single value section list
sect = sip.section(section)[0]
- # for each merged value add it to res_sip.conf
+ # for each merged value add it to pjsip.conf
for i in sect.get_merged(key):
set_value(key, i, section_to if section_to else section,
- res_sip, nmapped, type)
+ pjsip, nmapped, type)
def is_in(s, sub):
"""Returns true if 'sub' is in 's'"""
@@ -83,119 +83,119 @@
###############################################################################
### mapping functions -
### define f(key, val, section) where key/val are the key/value pair to
-### write to given section in res_sip.conf
-###############################################################################
-
-def set_dtmfmode(key, val, section, res_sip, nmapped):
- """Sets the dtmfmode value. If value matches allowable option in res_sip
+### write to given section in pjsip.conf
+###############################################################################
+
+def set_dtmfmode(key, val, section, pjsip, nmapped):
+ """Sets the dtmfmode value. If value matches allowable option in pjsip
then map it, otherwise set it to none.
"""
- # available res_sip.conf values: frc4733, inband, info, none
+ # available pjsip.conf values: frc4733, inband, info, none
if val != 'inband' or val != 'info':
nmapped(section, key, val + " ; did not fully map - set to none")
val = 'none'
- set_value(key, val, section, res_sip, nmapped)
-
-def from_nat(key, val, section, res_sip, nmapped):
- """Sets values from nat into the appropriate res_sip.conf options."""
+ set_value(key, val, section, pjsip, nmapped)
+
+def from_nat(key, val, section, pjsip, nmapped):
+ """Sets values from nat into the appropriate pjsip.conf options."""
# nat from sip.conf can be comma separated list of values:
# yes/no, [auto_]force_rport, [auto_]comedia
if is_in(val, 'yes'):
- set_value('rtp_symmetric', 'yes', section, res_sip, nmapped)
- set_value('rewrite_contact', 'yes', section, res_sip, nmapped)
+ set_value('rtp_symmetric', 'yes', section, pjsip, nmapped)
+ set_value('rewrite_contact', 'yes', section, pjsip, nmapped)
if is_in(val, 'comedia'):
- set_value('rtp_symmetric', 'yes', section, res_sip, nmapped)
+ set_value('rtp_symmetric', 'yes', section, pjsip, nmapped)
if is_in(val, 'force_rport'):
- set_value('force_rport', 'yes', section, res_sip, nmapped)
- set_value('rewrite_contact', 'yes', section, res_sip, nmapped)
-
-def set_timers(key, val, section, res_sip, nmapped):
- """Sets the timers in res_sip.conf from the session-timers option
+ set_value('force_rport', 'yes', section, pjsip, nmapped)
+ set_value('rewrite_contact', 'yes', section, pjsip, nmapped)
+
+def set_timers(key, val, section, pjsip, nmapped):
+ """Sets the timers in pjsip.conf from the session-timers option
found in sip.conf.
"""
- # res_sip.conf values can be yes/no, required, always
+ # pjsip.conf values can be yes/no, required, always
if val == 'originate':
- set_value('timers', 'always', section, res_sip, nmapped)
+ set_value('timers', 'always', section, pjsip, nmapped)
elif val == 'accept':
- set_value('timers', 'required', section, res_sip, nmapped)
+ set_value('timers', 'required', section, pjsip, nmapped)
elif val == 'never':
- set_value('timers', 'no', section, res_sip, nmapped)
+ set_value('timers', 'no', section, pjsip, nmapped)
else:
- set_value('timers', 'yes', section, res_sip, nmapped)
-
-def set_direct_media(key, val, section, res_sip, nmapped):
+ set_value('timers', 'yes', section, pjsip, nmapped)
+
+def set_direct_media(key, val, section, pjsip, nmapped):
"""Maps values from the sip.conf comma separated direct_media option
- into res_sip.conf direct_media options.
+ into pjsip.conf direct_media options.
"""
if is_in(val, 'yes'):
- set_value('direct_media', 'yes', section, res_sip, nmapped)
+ set_value('direct_media', 'yes', section, pjsip, nmapped)
if is_in(val, 'update'):
- set_value('direct_media_method', 'update', section, res_sip, nmapped)
+ set_value('direct_media_method', 'update', section, pjsip, nmapped)
if is_in(val, 'outgoing'):
- set_value('directed_media_glare_mitigation', 'outgoing', section, res_sip, nmapped)
+ set_value('directed_media_glare_mitigation', 'outgoing', section, pjsip, nmapped)
if is_in(val, 'nonat'):
- set_value('disable_directed_media_on_nat','yes', section, res_sip, nmapped)
+ set_value('disable_directed_media_on_nat','yes', section, pjsip, nmapped)
if (val == 'no'):
- set_value('direct_media', 'no', section, res_sip, nmapped)
-
-def from_sendrpid(key, val, section, res_sip, nmapped):
- """Sets the send_rpid/pai values in res_sip.conf."""
+ set_value('direct_media', 'no', section, pjsip, nmapped)
+
+def from_sendrpid(key, val, section, pjsip, nmapped):
+ """Sets the send_rpid/pai values in pjsip.conf."""
if val == 'yes' or val == 'rpid':
- set_value('send_rpid', 'yes', section, res_sip, nmapped)
+ set_value('send_rpid', 'yes', section, pjsip, nmapped)
elif val == 'pai':
- set_value('send_pai', 'yes', section, res_sip, nmapped)
-
-def set_media_encryption(key, val, section, res_sip, nmapped):
- """Sets the media_encryption value in res_sip.conf"""
+ set_value('send_pai', 'yes', section, pjsip, nmapped)
+
+def set_media_encryption(key, val, section, pjsip, nmapped):
+ """Sets the media_encryption value in pjsip.conf"""
if val == 'yes':
- set_value('media_encryption', 'sdes', section, res_sip, nmapped)
-
-def from_recordfeature(key, val, section, res_sip, nmapped):
+ set_value('media_encryption', 'sdes', section, pjsip, nmapped)
+
+def from_recordfeature(key, val, section, pjsip, nmapped):
"""If record on/off feature is set to automixmon then set
one_touch_recording, otherwise it can't be mapped.
"""
if val == 'automixmon':
- set_value('one_touch_recording', 'yes', section, res_sip, nmapped)
+ set_value('one_touch_recording', 'yes', section, pjsip, nmapped)
else:
nmapped(section, key, val + " ; could not be fully mapped")
-def from_progressinband(key, val, section, res_sip, nmapped):
- """Sets the inband_progress value in res_sip.conf"""
+def from_progressinband(key, val, section, pjsip, nmapped):
+ """Sets the inband_progress value in pjsip.conf"""
# progressinband can = yes/no/never
if val == 'never':
val = 'no'
- set_value('inband_progress', val, section, res_sip, nmapped)
-
-def from_host(key, val, section, res_sip, nmapped):
- """Sets contact info in an AOR section in in res_sip.conf using 'host'
+ set_value('inband_progress', val, section, pjsip, nmapped)
+
+def from_host(key, val, section, pjsip, nmapped):
+ """Sets contact info in an AOR section in in pjsip.conf using 'host'
data from sip.conf
"""
# all aors have the same name as the endpoint so makes
# it easy to endpoint's 'aors' value
- set_value('aors', section, section, res_sip, nmapped)
+ set_value('aors', section, section, pjsip, nmapped)
if val != 'dynamic':
- set_value('contact', val, section, res_sip, nmapped, 'aor')
+ set_value('contact', val, section, pjsip, nmapped, 'aor')
else:
- set_value('max_contacts', 1, section, res_sip, nmapped, 'aor')
-
-def from_subscribemwi(key, val, section, res_sip, nmapped):
+ set_value('max_contacts', 1, section, pjsip, nmapped, 'aor')
+
+def from_subscribemwi(key, val, section, pjsip, nmapped):
"""Checks the subscribemwi value in sip.conf. If yes places the
mailbox value in mailboxes within the endpoint, otherwise puts
it in the aor.
"""
- mailboxes = sip.get('mailbox', section, res_sip)
+ mailboxes = sip.get('mailbox', section, pjsip)
type = 'endpoint' if val == 'yes' else 'aor'
- set_value('mailboxes', mailboxes, section, res_sip, nmapped, type)
-
-###############################################################################
-
-# options in res_sip.conf on an endpoint that have no sip.conf equivalent:
+ set_value('mailboxes', mailboxes, section, pjsip, nmapped, type)
+
+###############################################################################
+
+# options in pjsip.conf on an endpoint that have no sip.conf equivalent:
# type, rtp_ipv6, 100rel, trust_id_outbound, aggregate_mwi,
# connected_line_method
-# known sip.conf peer keys that can be mapped to a res_sip.conf section/key
+# known sip.conf peer keys that can be mapped to a pjsip.conf section/key
peer_map = [
- # sip.conf option mapping function res_sip.conf option(s)
+ # sip.conf option mapping function pjsip.conf option(s)
###########################################################################
['context', set_value],
['dtmfmode', set_dtmfmode],
@@ -297,13 +297,13 @@
# match
]
-def map_peer(sip, section, res_sip, nmapped):
+def map_peer(sip, section, pjsip, nmapped):
for i in peer_map:
try:
# coming from sip.conf the values should mostly be a list with a
# single value. In the few cases that they are not a specialized
# function (see merge_value) is used to retrieve the values.
- i[1](i[0], sip.get(section, i[0])[0], section, res_sip, nmapped)
+ i[1](i[0], sip.get(section, i[0])[0], section, pjsip, nmapped)
except LookupError:
pass # key not found in sip.conf
@@ -324,23 +324,23 @@
pass
def convert(sip, filename, non_mappings):
- res_sip = astconfigparser.MultiOrderedConfigParser()
+ pjsip = astconfigparser.MultiOrderedConfigParser()
non_mappings[filename] = astdicts.MultiOrderedDict()
nmapped = non_mapped(non_mappings[filename])
for section in sip.sections():
if section == 'authentication':
pass
else:
- map_peer(sip, section, res_sip, nmapped)
+ map_peer(sip, section, pjsip, nmapped)
find_non_mapped(sip.defaults(), nmapped)
find_non_mapped(sip.sections(), nmapped)
for key, val in sip.includes().iteritems():
- res_sip.add_include(PREFIX + key, convert(val, PREFIX + key, non_mappings)[0])
- return res_sip, non_mappings
-
-def write_res_sip(filename, res_sip, non_mappings):
+ pjsip.add_include(PREFIX + key, convert(val, PREFIX + key, non_mappings)[0])
+ return pjsip, non_mappings
+
+def write_pjsip(filename, pjsip, non_mappings):
try:
with open(filename, 'wt') as fp:
fp.write(';--\n')
@@ -353,13 +353,13 @@
fp.write(';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n')
fp.write('--;\n\n')
# write out include file(s)
- for key, val in res_sip.includes().iteritems():
- write_res_sip(key, val, non_mappings)
+ for key, val in pjsip.includes().iteritems():
+ write_pjsip(key, val, non_mappings)
fp.write('#include "%s"\n' % key)
fp.write('\n')
# write out mapped data elements
- astconfigparser.write_dicts(fp, res_sip.defaults())
- astconfigparser.write_dicts(fp, res_sip.sections())
+ astconfigparser.write_dicts(fp, pjsip.defaults())
+ astconfigparser.write_dicts(fp, pjsip.sections())
except IOError:
print "Could not open file ", filename, " for writing"
@@ -370,7 +370,7 @@
global PREFIX
usage = "usage: %prog [options] [input-file [output-file]]\n\n" \
"input-file defaults to 'sip.conf'\n" \
- "output-file defaults to 'res_sip.conf'"
+ "output-file defaults to 'pjsip.conf'"
parser = optparse.OptionParser(usage=usage)
parser.add_option('-p', '--prefix', dest='prefix', default=PREFIX,
help='output prefix for include files')
@@ -379,14 +379,14 @@
PREFIX = options.prefix
sip_filename = args[0] if len(args) else 'sip.conf'
- res_sip_filename = args[1] if len(args) == 2 else 'res_sip.conf'
-
- return sip_filename, res_sip_filename
+ pjsip_filename = args[1] if len(args) == 2 else 'pjsip.conf'
+
+ return sip_filename, pjsip_filename
if __name__ == "__main__":
- sip_filename, res_sip_filename = cli_options()
+ sip_filename, pjsip_filename = cli_options()
# configuration parser for sip.conf
sip = astconfigparser.MultiOrderedConfigParser()
sip.read(sip_filename)
- res_sip, non_mappings = convert(sip, res_sip_filename, dict())
- write_res_sip(res_sip_filename, res_sip, non_mappings)
+ pjsip, non_mappings = convert(sip, pjsip_filename, dict())
+ write_pjsip(pjsip_filename, pjsip, non_mappings)
More information about the asterisk-commits
mailing list