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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 27 10:34:11 CDT 2013


Author: mmichelson
Date: Tue Aug 27 10:34:09 2013
New Revision: 397707

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=397707
Log:
Fix how contact is generated for an AOR.

The host value was being copied verbatim. However, a full
SIP URI is expected for the contact. This means having to
construct a URI based on the username, host, and potentially
the port.

This also corrects an error where I had the parameters in the
wrong order for subscribemwi lookup.


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=397707&r1=397706&r2=397707
==============================================================================
--- 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 Aug 27 10:34:09 2013
@@ -12,6 +12,8 @@
 import optparse
 import astdicts
 import astconfigparser
+import socket
+import re
 
 PREFIX = 'pjsip_'
 
@@ -167,16 +169,59 @@
     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
+    """Sets contact info in an AOR section in pjsip.conf using 'host'
+       and 'port' data from sip.conf
     """
     # all aors have the same name as the endpoint so makes
-    # it easy to endpoint's 'aors' value
+    # it easy to set endpoint's 'aors' value
     set_value('aors', section, section, pjsip, nmapped)
-    if val != 'dynamic':
-        set_value('contact', val, section, pjsip, nmapped, 'aor')
-    else:
+    if val == 'dynamic':
+        # Easy case. Just set the max_contacts on the aor and we're done
         set_value('max_contacts', 1, section, pjsip, nmapped, 'aor')
+        return
+
+    result = 'sip:'
+
+    # More difficult case. The host will be either a hostname or
+    # IP address and may or may not have a port specified. pjsip.conf
+    # expects the contact to be a SIP URI.
+
+    user = None
+
+    try:
+        user = sip.get(section, 'defaultuser')[0]
+        result += user + '@'
+    except LookupError:
+        try:
+            user = sip.get(section, 'username')[0]
+            result += user + '@'
+        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
+
+    set_value('contact', result, section, pjsip, nmapped, 'aor')
 
 def from_mailbox(key, val, section, pjsip, nmapped):
     """Determines whether a mailbox configured in sip.conf should map to
@@ -186,7 +231,7 @@
     """
 
     try:
-        subscribemwi = sip.get('subscribemwi', section)
+        subscribemwi = sip.get(section, 'subscribemwi')
     except LookupError:
         # No subscribemwi option means default it to 'no'
         subscribemwi = 'no'




More information about the asterisk-commits mailing list