[asterisk-commits] mmichelson: branch mmichelson/conversion_script r398225 - /team/mmichelson/co...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 3 17:30:46 CDT 2013


Author: mmichelson
Date: Tue Sep  3 17:30:44 2013
New Revision: 398225

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=398225
Log:
Add basic method for adding TCP transports.


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=398225&r1=398224&r2=398225
==============================================================================
--- 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 17:30:44 2013
@@ -181,6 +181,39 @@
         val = 'no'
     set_value('inband_progress', val, section, pjsip, nmapped)
 
+def get_host(config, host, section, port_key):
+    """
+    Returns a string composed of a host:port. This assumes that the host
+    may have a port as part of the initial value. The port_key is only used
+    if the host does not already have a port set on it.
+    Throws a LookupError if the key does not exist
+    """
+    port = None
+
+    try:
+        socket.inet_pton(socket.AF_INET6, host)
+        if not host.startswith('['):
+            # SIP URI will need brackets.
+            host = '[' + host + ']'
+        else:
+            # If brackets are present, there may be a port as well
+            port = re.match('\[.*\]:(\d+)', host)
+    except socket.error:
+        # No biggie. It's just not an IPv6 address
+        port = re.match('.*:(\d+)', host)
+
+    result = host
+
+    if not port:
+        try:
+            port = config.get(section, port_key)[0]
+            result += ':' + port
+        except LookupError:
+            pass
+
+    return result
+
+
 def from_host(key, val, section, pjsip, nmapped):
     """Sets contact info in an AOR section in pjsip.conf using 'host'
        and 'port' data from sip.conf
@@ -211,28 +244,7 @@
         except LookupError:
             pass
 
-    port = None
-
-    try:
-        socket.inet_pton(socket.AF_INET6, val)
-        if not val.startswith('['):
-            # SIP URI will need brackets.
-            val = '[' + val + ']'
-        else:
-            # If brackets are present, there may be a port as well
-            port = re.match('\[.*\]:(\d+)', val)
-    except socket.error:
-        # No biggie. It's just not an IPv6 address
-        port = re.match('.*:(\d+)', val)
-
-    result += val
-
-    if not port:
-        try:
-            port = sip.get(section, 'port')[0]
-            result += ':' + port
-        except LookupError:
-            pass
+    result += get_host(sip, val, section, 'port')
 
     set_value('contact', result, section, pjsip, nmapped, 'aor')
 
@@ -395,27 +407,8 @@
         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
+    
+    bind = get_host(sip, bind, 'general', 'bindport')
 
     set_value('protocol', 'udp', 'transport-udp', pjsip, nmapped, 'transport')
     set_value('bind', bind, 'transport-udp', pjsip, nmapped, 'transport')
@@ -431,7 +424,28 @@
     tcpbindaddr
     externtcpport
     """
-    pass
+
+    try:
+        enabled = sip.get('general', 'tcpenable')[0]
+    except:
+        # No value means disabled by default. No need for a tranport
+        return
+
+    if enabled == 'no':
+        return
+
+    try:
+        bind = sip.get('general', 'tcpbindaddr')[0]
+        bind = get_host(sip, bind, 'general', 'bindport')
+    except LookupError:
+        # No tcpbindaddr means to default to the udpbindaddr
+        bind = pjsip.get('transport-udp', 'bind')[0]
+
+    set_value('protocol', 'tcp', 'transport-tcp', pjsip, nmapped, 'transport')
+    set_value('bind', bind, 'transport-tcp', pjsip, nmapped, 'transport')
+    add_localnet('transport-tcp', pjsip, nmapped)
+
+    #XXX Add externtcpport...
 
 def create_tls(sip, pjsip, nmapped):
     """




More information about the asterisk-commits mailing list