[asterisk-commits] mmichelson: branch mmichelson/conversion_script r398224 - /team/mmichelson/co...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Sep 3 16:46:17 CDT 2013
Author: mmichelson
Date: Tue Sep 3 16:46:15 2013
New Revision: 398224
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=398224
Log:
Initial work towards creating transports in pjsip.conf.
This is now capable of creating a basic UDP transport. The
externaddr and its ilk are not handled yet, but they shouldn't
be too crazy-difficult to add.
Next I'll be working on creating basic TCP transport.
Modified:
team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
Modified: team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py?view=diff&rev=398224&r1=398223&r2=398224
==============================================================================
--- team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py (original)
+++ team/mmichelson/conversion_script/contrib/scripts/sip_to_pjsip/sip_to_pjsip.py Tue Sep 3 16:46:15 2013
@@ -28,6 +28,7 @@
except LookupError:
# section for type doesn't exist, so add
sect = pjsip.add_section(section)
+ print("Created new section called %s" % section)
sect['type'] = type
return sect
@@ -52,13 +53,22 @@
def _merge_value(k, v, s, r, n):
merge_value(key if key else k, v, s, r, n, type, section_to)
+ print ("Starting merge_value for %s: %s" % (key, val))
+
# if no value or section return the merge_value
# function with the enclosed key and type
if not val and not section:
return _merge_value
+ print("Made it past early return for %s: %s" % (key, val))
+
# should return a single value section list
- sect = sip.section(section)[0]
+ try:
+ sect = sip.section(section)[0]
+ except LookupError:
+ sect = sip.default(section)[0]
+
+ print("Got here for %s: %s" % (key, val))
# 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,
@@ -352,6 +362,108 @@
# match
]
+def add_localnet(section, pjsip, nmapped):
+ """
+ Adds localnet values from sip.conf's general section to a transport in
+ pjsip.conf. Ideally, we would have just created a template with the localnet
+ sections, but because this is a script, it's not hard to add the same thing
+ on to every transport.
+ """
+ try:
+ merge_value('localnet', sip.get('general', 'localnet')[0], 'general', pjsip,
+ nmapped, 'transport', section)
+ except LookupError:
+ # No localnet options configured. No biggie!
+ pass
+
+def create_udp(sip, pjsip, nmapped):
+ """
+ Creates a 'transport-udp' section in the pjsip.conf file based
+ on the following settings from sip.conf:
+
+ bindaddr (or udpbindaddr)
+ bindport
+ externaddr (or externip)
+ externhost
+ """
+ try:
+ bind = sip.get('general', 'udpbindaddr')[0]
+ except LookupError:
+ # Alternately, this can be called "bindaddr"
+ try:
+ bind = sip.get('general', 'bindaddr')[0]
+ except LookupError:
+ # No bindaddr or means no UDP transport
+ return
+
+ port = None
+
+ try:
+ socket.inet_pton(socket.AF_INET6, bind)
+ if not val.startswith('['):
+ # SIP URI will need brackets.
+ val = '[' + bind + ']'
+ else:
+ # If brackets are present, there may be a port as well
+ port = re.match('\[.*\]:(\d+)', bind)
+ except socket.error:
+ # No biggie. It's just not an IPv6 address
+ port = re.match('.*:(\d+)', bind)
+
+ if not port:
+ try:
+ port = sip.get('general', 'bindport')[0]
+ bind += ':' + port
+ except LookupError:
+ pass
+
+ set_value('protocol', 'udp', 'transport-udp', pjsip, nmapped, 'transport')
+ set_value('bind', bind, 'transport-udp', pjsip, nmapped, 'transport')
+ add_localnet('transport-udp', pjsip, nmapped)
+
+ #XXX Add externaddr, externip, externhost...
+
+def create_tcp(sip, pjsip, nmapped):
+ """
+ Creates a 'transport-tcp' section in the pjsip.conf file based
+ on the following settings from sip.conf:
+
+ tcpbindaddr
+ externtcpport
+ """
+ pass
+
+def create_tls(sip, pjsip, nmapped):
+ """
+ Add docs
+ """
+ pass
+
+def map_transports(sip, pjsip, nmapped):
+ """Finds options in sip.conf general section pertaining to
+ transport configuration and creates appropriate transport
+ configuration sections in pjsip.conf.
+
+ sip.conf only allows a single UDP transport, TCP transport,
+ and TLS transport. As such, the mapping into PJSIP can be made
+ consistent by defining three sections:
+
+ transport-udp
+ transport-tcp
+ transport-tls
+
+ To accommodate the default behaviors in sip.conf, we'll need to
+ create the UDP transport first, followed by the TCP and TLS transports.
+ """
+
+ # First create a UDP transport. Even if no bind parameters were provided
+ # in sip.conf, chan_sip would always bind to UDP 0.0.0.0:5060
+ create_udp(sip, pjsip, nmapped)
+
+ # TCP settings may be dependent on UDP settings, so do it second.
+ create_tcp(sip, pjsip, nmapped)
+ create_tls(sip, pjsip, nmapped)
+
def map_peer(sip, section, pjsip, nmapped):
for i in peer_map:
try:
@@ -382,6 +494,8 @@
pjsip = astconfigparser.MultiOrderedConfigParser()
non_mappings[filename] = astdicts.MultiOrderedDict()
nmapped = non_mapped(non_mappings[filename])
+ # First thing we need to do is establish transports.
+ map_transports(sip, pjsip, nmapped)
for section in sip.sections():
if section == 'authentication':
pass
More information about the asterisk-commits
mailing list