[asterisk-commits] mmichelson: branch mmichelson/conversion_script r398876 - /team/mmichelson/co...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Sep 11 16:36:46 CDT 2013
Author: mmichelson
Date: Wed Sep 11 16:36:44 2013
New Revision: 398876
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=398876
Log:
Add docstrings for new functions.
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=398876&r1=398875&r2=398876
==============================================================================
--- 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 Wed Sep 11 16:36:44 2013
@@ -289,6 +289,11 @@
def setup_ident(key, val, section, pjsip, nmapped):
+ """
+ Examines the 'type' field for a sip.conf peer and creates an identify
+ section if the type is either 'peer' or 'friend'. The identify section uses
+ either the host or defaultip field of the sip.conf peer.
+ """
if val != 'peer' and val != 'friend':
return
@@ -308,11 +313,13 @@
def from_encryption_taglen(key, val, section, pjsip, nmapped):
+ """Sets the srtp_tag32 option based on sip.conf encryption_taglen"""
if val == '32':
set_value('srtp_tag_32', 'yes', section, pjsip, nmapped)
def from_dtlsenable(key, val, section, pjsip, nmapped):
+ """Optionally sets media_encryption=dtls based on sip.conf dtlsenable"""
if val == 'yes':
set_value('media_encryption', 'dtls', section, pjsip, nmapped)
@@ -605,6 +612,14 @@
def set_tls_bindaddr(val, pjsip, nmapped):
+ """
+ Creates the TCP bind address. This has two possible methods of
+ working:
+ Use the 'tlsbindaddr' option from sip.conf directly if it has both
+ an address and port. If no port is present, use 5061
+ If there is no 'tlsbindaddr' option present in sip.conf, use the
+ previously-established UDP bind address and port 5061
+ """
try:
bind = sip.get('general', 'tlsbindaddr')[0]
explicit = True
@@ -636,27 +651,31 @@
def set_tls_private_key(val, pjsip, nmapped):
+ """Sets privkey_file based on sip.conf tlsprivatekey or sslprivatekey"""
set_value('privkey_file', val, 'transport-tls', pjsip, nmapped,
'transport')
def set_tls_cipher(val, pjsip, nmapped):
+ """Sets cipher based on sip.conf tlscipher or sslcipher"""
set_value('cipher', val, 'transport-tls', pjsip, nmapped, 'transport')
def set_tls_cafile(val, pjsip, nmapped):
+ """Sets ca_list_file based on sip.conf tlscafile"""
set_value('ca_list_file', val, 'transport-tls', pjsip, nmapped,
'transport')
def set_tls_verifyclient(val, pjsip, nmapped):
+ """Sets verify_client based on sip.conf tlsverifyclient"""
set_value('verify_client', val, 'transport-tls', pjsip, nmapped,
'transport')
def set_tls_verifyserver(val, pjsip, nmapped):
- # sip.conf option is tlsdontverifyserver. pjsip.conf is verify_server.
- # So we need to set the value in pjsip.conf to the opposite of sip.conf
+ """Sets verify_server based on sip.conf tlsdontverifyserver"""
+
if val == 'no':
set_value('verify_server', 'yes', 'transport-tls', pjsip, nmapped,
'transport')
@@ -666,6 +685,7 @@
def set_tls_method(val, pjsip, nmapped):
+ """Sets method based on sip.conf tlsclientmethod or sslclientmethod"""
set_value('method', val, 'transport-tls', pjsip, nmapped, 'transport')
@@ -758,6 +778,11 @@
def map_auth(sip, pjsip, nmapped):
+ """
+ Creates auth sections based on entries in the authentication section of
+ sip.conf. pjsip.conf section names consist of "auth_" followed by the name
+ of the realm.
+ """
try:
auths = sip.get('authentication', 'auth')
except LookupError:
@@ -774,7 +799,7 @@
if not md5:
#Invalid. move on
continue
- section = realm
+ section = "auth_" + realm
set_value('realm', realm, section, pjsip, nmapped, 'auth')
set_value('username', user, section, pjsip, nmapped, 'auth')
@@ -786,6 +811,9 @@
class Registration:
+ """
+ Class for parsing and storing information in a register line in sip.conf.
+ """
def __init__(self, line, retry_interval, max_attempts, outbound_proxy):
self.retry_interval = retry_interval
self.max_attempts = max_attempts
@@ -793,6 +821,14 @@
self.parse(line)
def parse(self, line):
+ """
+ Initial parsing routine for register lines in sip.conf.
+
+ This splits the line into the part before the host, and the part
+ after the '@' symbol. These two parts are then passed to their
+ own parsing routines
+ """
+
# register =>
# [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry]
@@ -804,6 +840,11 @@
self.parse_user_part(prehost)
def parse_host_part(self, host_part):
+ """
+ Parsing routine for the part after the final '@' in a register line.
+ The strategy is to use partition calls to peel away the data starting
+ from the right and working to the left.
+ """
pre_expiry, sep, expiry = host_part.partition('~')
pre_extension, sep, self.extension = pre_expiry.partition('/')
self.host, sep, self.port = pre_extension.partition(':')
@@ -811,6 +852,13 @@
self.expiry = expiry if expiry else '120'
def parse_user_part(self, user_part):
+ """
+ Parsing routine for the part before the final '@' in a register line.
+ The only mandatory part of this line is the user portion. The strategy
+ here is to start by using partition calls to remove everything to
+ the right of the user, then finish by using rpartition calls to remove
+ everything to the left of the user.
+ """
colons = user_part.count(':')
if (colons == 3):
# :domainport:secret:authuser
@@ -838,20 +886,24 @@
self.protocol = transport if transport else 'udp'
def write(self, pjsip, nmapped):
- # Most of the data in self will get written to a registration section.
- # However, there will also need to be an auth section created if a
- # secret or authuser is present.
-
- # General mapping of values:
- # A combination of self.host and self.port is server_uri
- # A combination of self.user, self.domain, and self.domainport is
- # client_uri
- # self.expiry is expiration
- # self.extension is contact_user
- # self.protocol will map to one of the mapped transports
- # self.secret and self.authuser will result in a new auth section, and
- # outbound_auth will point to that section.
- # XXX self.peer really doesn't map to anything :(
+ """
+ Write parsed registration data into a section in pjsip.conf
+
+ Most of the data in self will get written to a registration section.
+ However, there will also need to be an auth section created if a
+ secret or authuser is present.
+
+ General mapping of values:
+ A combination of self.host and self.port is server_uri
+ A combination of self.user, self.domain, and self.domainport is
+ client_uri
+ self.expiry is expiration
+ self.extension is contact_user
+ self.protocol will map to one of the mapped transports
+ self.secret and self.authuser will result in a new auth section, and
+ outbound_auth will point to that section.
+ XXX self.peer really doesn't map to anything :(
+ """
section = 'reg_' + self.host
@@ -913,6 +965,10 @@
def map_registrations(sip, pjsip, nmapped):
+ """
+ Gathers all necessary outbound registration data in sip.conf and creates
+ corresponding registration sections in pjsip.conf
+ """
try:
regs = sip.get('general', 'register')
except LookupError:
@@ -936,6 +992,7 @@
for i in regs:
reg = Registration(i, retry_interval, max_attempts, outbound_proxy)
reg.write(pjsip, nmapped)
+
def map_peer(sip, section, pjsip, nmapped):
for i in peer_map:
More information about the asterisk-commits
mailing list