sip_to_pjsip Namespace Reference


Data Structures

class  Registration

Functions

def add_localnet
def build_host
def cli_options
def convert
def create_tcp
def create_tls
def create_udp
def find_non_mapped
def from_dtlsenable
def from_encryption_taglen
def from_host
def from_mailbox
def from_nat
def from_progressinband
def from_recordfeature
def from_sendrpid
def map_auth
def map_peer
def map_registrations
def map_transports
def merge_value
def non_mapped
def section_by_type
def set_direct_media
def set_dtmfmode
def set_media_encryption
def set_record_off_feature
def set_record_on_feature
def set_timers
def set_tls_bindaddr
def set_tls_cafile
def set_tls_cipher
def set_tls_method
def set_tls_private_key
def set_tls_verifyclient
def set_tls_verifyserver
def set_transport_common
def set_value
def setup_auth
def setup_ident
def split_hostport
def write_pjsip

Variables

list peer_map
string PREFIX = 'pjsip_'
tuple sip = astconfigparser.MultiOrderedConfigParser()


Function Documentation

def sip_to_pjsip::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.

Definition at line 502 of file sip_to_pjsip.py.

00502                                          :
00503     """
00504     Adds localnet values from sip.conf's general section to a transport in
00505     pjsip.conf. Ideally, we would have just created a template with the
00506     localnet sections, but because this is a script, it's not hard to add
00507     the same thing on to every transport.
00508     """
00509     try:
00510         merge_value('local_net', sip.get('general', 'localnet')[0], 'general',
00511                     pjsip, nmapped, 'transport', section)
00512     except LookupError:
00513         # No localnet options configured. No biggie!
00514         pass
00515 
00516 
def set_transport_common(section, pjsip, nmapped):

def sip_to_pjsip::build_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

Definition at line 211 of file sip_to_pjsip.py.

00211                                                :
00212     """
00213     Returns a string composed of a host:port. This assumes that the host
00214     may have a port as part of the initial value. The port_key is only used
00215     if the host does not already have a port set on it.
00216     Throws a LookupError if the key does not exist
00217     """
00218     port = None
00219 
00220     try:
00221         socket.inet_pton(socket.AF_INET6, host)
00222         if not host.startswith('['):
00223             # SIP URI will need brackets.
00224             host = '[' + host + ']'
00225         else:
00226             # If brackets are present, there may be a port as well
00227             port = re.match('\[.*\]:(\d+)', host)
00228     except socket.error:
00229         # No biggie. It's just not an IPv6 address
00230         port = re.match('.*:(\d+)', host)
00231 
00232     result = host
00233 
00234     if not port:
00235         try:
00236             port = config.get(section, port_key)[0]
00237             result += ':' + port
00238         except LookupError:
00239             pass
00240 
00241     return result
00242 
00243 
def from_host(key, val, section, pjsip, nmapped):

def sip_to_pjsip::cli_options (  ) 

Parse command line options and apply them. If invalid input is given,
print usage information

Definition at line 1137 of file sip_to_pjsip.py.

01137                  :
01138     """
01139     Parse command line options and apply them. If invalid input is given,
01140     print usage information
01141     """
01142     global PREFIX
01143     usage = "usage: %prog [options] [input-file [output-file]]\n\n" \
01144       "Converts the chan_sip configuration input-file to the chan_pjsip output-file.\n"\
01145         "The input-file defaults to 'sip.conf'.\n" \
01146         "The output-file defaults to 'pjsip.conf'."
01147     parser = optparse.OptionParser(usage=usage)
01148     parser.add_option('-p', '--prefix', dest='prefix', default=PREFIX,
01149                       help='output prefix for include files')
01150 
01151     options, args = parser.parse_args()
01152     PREFIX = options.prefix
01153 
01154     sip_filename = args[0] if len(args) else 'sip.conf'
01155     pjsip_filename = args[1] if len(args) == 2 else 'pjsip.conf'
01156 
01157     return sip_filename, pjsip_filename
01158 
if __name__ == "__main__":

def sip_to_pjsip::convert (   sip,
  filename,
  non_mappings,
  include 
)

Entry point for configuration file conversion. This
function will create a pjsip.conf object and begin to
map specific sections from sip.conf into it.
Returns the new pjsip.conf object once completed

Definition at line 1083 of file sip_to_pjsip.py.

01083                                                  :
01084     """
01085     Entry point for configuration file conversion. This
01086     function will create a pjsip.conf object and begin to
01087     map specific sections from sip.conf into it.
01088     Returns the new pjsip.conf object once completed
01089     """
01090     pjsip = astconfigparser.MultiOrderedConfigParser()
01091     non_mappings[filename] = astdicts.MultiOrderedDict()
01092     nmapped = non_mapped(non_mappings[filename])
01093     if not include:
01094         # Don't duplicate transport and registration configs
01095         map_transports(sip, pjsip, nmapped)
01096         map_registrations(sip, pjsip, nmapped)
01097     map_auth(sip, pjsip, nmapped)
01098     for section in sip.sections():
01099         if section == 'authentication':
01100             pass
01101         else:
01102             map_peer(sip, section, pjsip, nmapped)
01103 
01104     find_non_mapped(sip.defaults(), nmapped)
01105     find_non_mapped(sip.sections(), nmapped)
01106 
01107     for key, val in sip.includes().iteritems():
01108         pjsip.add_include(PREFIX + key, convert(val, PREFIX + key,
01109                           non_mappings, True)[0])
01110     return pjsip, non_mappings
01111 
01112 
def write_pjsip(filename, pjsip, non_mappings):

def sip_to_pjsip::create_tcp (   sip,
  pjsip,
  nmapped 
)

Creates a 'transport-tcp' section in the pjsip.conf file based
on the following settings from sip.conf:

tcpenable
tcpbindaddr
externtcpport

Definition at line 614 of file sip_to_pjsip.py.

00614                                    :
00615     """
00616     Creates a 'transport-tcp' section in the pjsip.conf file based
00617     on the following settings from sip.conf:
00618 
00619     tcpenable
00620     tcpbindaddr
00621     externtcpport
00622     """
00623 
00624     try:
00625         enabled = sip.get('general', 'tcpenable')[0]
00626     except:
00627         # No value means disabled by default. No need for a tranport
00628         return
00629 
00630     if enabled == 'no':
00631         return
00632 
00633     try:
00634         bind = sip.get('general', 'tcpbindaddr')[0]
00635         bind = build_host(sip, bind, 'general', 'bindport')
00636     except LookupError:
00637         # No tcpbindaddr means to default to the udpbindaddr
00638         bind = pjsip.get('transport-udp', 'bind')[0]
00639 
00640     try:
00641         extern_addr = sip.multi_get('general', ['externaddr', 'externip',
00642                                     'externhost'])[0]
00643         host, port = split_hostport(extern_addr)
00644         try:
00645             tcpport = sip.get('general', 'externtcpport')[0]
00646         except:
00647             tcpport = port
00648         set_value('external_signaling_address', host, 'transport-tcp', pjsip,
00649                   nmapped, 'transport')
00650         if tcpport:
00651             set_value('external_signaling_port', tcpport, 'transport-tcp',
00652                       pjsip, nmapped, 'transport')
00653     except LookupError:
00654         pass
00655 
00656     set_value('protocol', 'tcp', 'transport-tcp', pjsip, nmapped, 'transport')
00657     set_value('bind', bind, 'transport-tcp', pjsip, nmapped, 'transport')
00658     set_transport_common('transport-tcp', pjsip, nmapped)
00659 
00660 
def set_tls_bindaddr(val, pjsip, nmapped):

def sip_to_pjsip::create_tls (   sip,
  pjsip,
  nmapped 
)

Creates a 'transport-tls' section in pjsip.conf based on the following
settings from sip.conf:

tlsenable (or sslenable)
tlsbindaddr (or sslbindaddr)
tlsprivatekey (or sslprivatekey)
tlscipher (or sslcipher)
tlscafile
tlscapath (or tlscadir)
tlscertfile (or sslcert or tlscert)
tlsverifyclient
tlsdontverifyserver
tlsclientmethod (or sslclientmethod)

Definition at line 739 of file sip_to_pjsip.py.

00739                                    :
00740     """
00741     Creates a 'transport-tls' section in pjsip.conf based on the following
00742     settings from sip.conf:
00743 
00744     tlsenable (or sslenable)
00745     tlsbindaddr (or sslbindaddr)
00746     tlsprivatekey (or sslprivatekey)
00747     tlscipher (or sslcipher)
00748     tlscafile
00749     tlscapath (or tlscadir)
00750     tlscertfile (or sslcert or tlscert)
00751     tlsverifyclient
00752     tlsdontverifyserver
00753     tlsclientmethod (or sslclientmethod)
00754     """
00755 
00756     tls_map = [
00757         (['tlsbindaddr', 'sslbindaddr'], set_tls_bindaddr),
00758         (['tlsprivatekey', 'sslprivatekey'], set_tls_private_key),
00759         (['tlscipher', 'sslcipher'], set_tls_cipher),
00760         (['tlscafile'], set_tls_cafile),
00761         (['tlsverifyclient'], set_tls_verifyclient),
00762         (['tlsdontverifyserver'], set_tls_verifyserver),
00763         (['tlsclientmethod', 'sslclientmethod'], set_tls_method)
00764     ]
00765 
00766     try:
00767         enabled = sip.multi_get('general', ['tlsenable', 'sslenable'])[0]
00768     except LookupError:
00769         # Not enabled. Don't create a transport
00770         return
00771 
00772     if enabled == 'no':
00773         return
00774 
00775     set_value('protocol', 'tls', 'transport-tls', pjsip, nmapped, 'transport')
00776 
00777     for i in tls_map:
00778         try:
00779             i[1](sip.multi_get('general', i[0])[0], pjsip, nmapped)
00780         except LookupError:
00781             pass
00782 
00783     set_transport_common('transport-tls', pjsip, nmapped)
00784     try:
00785         extern_addr = sip.multi_get('general', ['externaddr', 'externip',
00786                                     'externhost'])[0]
00787         host, port = split_hostport(extern_addr)
00788         try:
00789             tlsport = sip.get('general', 'externtlsport')[0]
00790         except:
00791             tlsport = port
00792         set_value('external_signaling_address', host, 'transport-tls', pjsip,
00793                   nmapped, 'transport')
00794         if tlsport:
00795             set_value('external_signaling_port', tlsport, 'transport-tls',
00796                       pjsip, nmapped, 'transport')
00797     except LookupError:
00798         pass
00799 
00800 
def map_transports(sip, pjsip, nmapped):

def sip_to_pjsip::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

Definition at line 579 of file sip_to_pjsip.py.

00579                                    :
00580     """
00581     Creates a 'transport-udp' section in the pjsip.conf file based
00582     on the following settings from sip.conf:
00583 
00584     bindaddr (or udpbindaddr)
00585     bindport
00586     externaddr (or externip)
00587     externhost
00588     """
00589 
00590     try:
00591         bind = sip.multi_get('general', ['udpbindaddr', 'bindaddr'])[0]
00592     except LookupError:
00593         bind = ''
00594 
00595     bind = build_host(sip, bind, 'general', 'bindport')
00596 
00597     try:
00598         extern_addr = sip.multi_get('general', ['externaddr', 'externip',
00599                                     'externhost'])[0]
00600         host, port = split_hostport(extern_addr)
00601         set_value('external_signaling_address', host, 'transport-udp', pjsip,
00602                   nmapped, 'transport')
00603         if port:
00604             set_value('external_signaling_port', port, 'transport-udp', pjsip,
00605                       nmapped, 'transport')
00606     except LookupError:
00607         pass
00608 
00609     set_value('protocol', 'udp', 'transport-udp', pjsip, nmapped, 'transport')
00610     set_value('bind', bind, 'transport-udp', pjsip, nmapped, 'transport')
00611     set_transport_common('transport-udp', pjsip, nmapped)
00612 
00613 
def create_tcp(sip, pjsip, nmapped):

def sip_to_pjsip::find_non_mapped (   sections,
  nmapped 
)

Determine sip.conf options that were not properly mapped to pjsip.conf
options.

Definition at line 1061 of file sip_to_pjsip.py.

01061                                       :
01062     """
01063     Determine sip.conf options that were not properly mapped to pjsip.conf
01064     options.
01065     """
01066     for section, sect in sections.iteritems():
01067         try:
01068             # since we are pulling from sip.conf this should always
01069             # be a single value list
01070             sect = sect[0]
01071             # loop through the section and store any values that were not
01072             # mapped
01073             for key in sect.keys(True):
01074                 for i in peer_map:
01075                     if i[0] == key:
01076                         break
01077                 else:
01078                     nmapped(section, key, sect[key])
01079         except LookupError:
01080             pass
01081 
01082 
def convert(sip, filename, non_mappings, include):

def sip_to_pjsip::from_dtlsenable (   key,
  val,
  section,
  pjsip,
  nmapped 
)

Optionally sets media_encryption=dtls based on sip.conf dtlsenable

Definition at line 358 of file sip_to_pjsip.py.

00358                                                       :
00359     """Optionally sets media_encryption=dtls based on sip.conf dtlsenable"""
00360     if val == 'yes':
00361         set_value('media_encryption', 'dtls', section, pjsip, nmapped)
00362 
###############################################################################

def sip_to_pjsip::from_encryption_taglen (   key,
  val,
  section,
  pjsip,
  nmapped 
)

Sets the srtp_tag32 option based on sip.conf encryption_taglen

Definition at line 352 of file sip_to_pjsip.py.

00352                                                              :
00353     """Sets the srtp_tag32 option based on sip.conf encryption_taglen"""
00354     if val == '32':
00355         set_value('srtp_tag_32', 'yes', section, pjsip, nmapped)
00356 
00357 
def from_dtlsenable(key, val, section, pjsip, nmapped):

def sip_to_pjsip::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

Definition at line 244 of file sip_to_pjsip.py.

00244                                                 :
00245     """
00246     Sets contact info in an AOR section in pjsip.conf using 'host'
00247     and 'port' data from sip.conf
00248     """
00249     # all aors have the same name as the endpoint so makes
00250     # it easy to set endpoint's 'aors' value
00251     set_value('aors', section, section, pjsip, nmapped)
00252     if val == 'dynamic':
00253         # Easy case. Just set the max_contacts on the aor and we're done
00254         set_value('max_contacts', 1, section, pjsip, nmapped, 'aor')
00255         return
00256 
00257     result = 'sip:'
00258 
00259     # More difficult case. The host will be either a hostname or
00260     # IP address and may or may not have a port specified. pjsip.conf
00261     # expects the contact to be a SIP URI.
00262 
00263     user = None
00264 
00265     try:
00266         user = sip.multi_get(section, ['defaultuser', 'username'])[0]
00267         result += user + '@'
00268     except LookupError:
00269         # It's fine if there's no user name
00270         pass
00271 
00272     result += build_host(sip, val, section, 'port')
00273 
00274     set_value('contact', result, section, pjsip, nmapped, 'aor')
00275 
00276 
def from_mailbox(key, val, section, pjsip, nmapped):

def sip_to_pjsip::from_mailbox (   key,
  val,
  section,
  pjsip,
  nmapped 
)

Determines whether a mailbox configured in sip.conf should map to
an endpoint or aor in pjsip.conf. If subscribemwi is true, then the
mailboxes are set on an aor. Otherwise the mailboxes are set on the
endpoint.
Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 277 of file sip_to_pjsip.py.

00277                                                    :
00278     """
00279     Determines whether a mailbox configured in sip.conf should map to
00280     an endpoint or aor in pjsip.conf. If subscribemwi is true, then the
00281     mailboxes are set on an aor. Otherwise the mailboxes are set on the
00282     endpoint.
00283     """
00284 
00285     try:
00286         subscribemwi = sip.get(section, 'subscribemwi')[0]
00287     except LookupError:
00288         # No subscribemwi option means default it to 'no'
00289         subscribemwi = 'no'
00290 
00291     set_value('mailboxes', val, section, pjsip, nmapped, 'aor'
00292               if subscribemwi == 'yes' else 'endpoint')
00293 
00294 
def setup_auth(key, val, section, pjsip, nmapped):

def sip_to_pjsip::from_nat (   key,
  val,
  section,
  pjsip,
  nmapped 
)

Sets values from nat into the appropriate pjsip.conf options.

Definition at line 116 of file sip_to_pjsip.py.

00116                                                :
00117     """Sets values from nat into the appropriate pjsip.conf options."""
00118     # nat from sip.conf can be comma separated list of values:
00119     # yes/no, [auto_]force_rport, [auto_]comedia
00120     if 'yes' in val:
00121         set_value('rtp_symmetric', 'yes', section, pjsip, nmapped)
00122         set_value('rewrite_contact', 'yes', section, pjsip, nmapped)
00123     if 'comedia' in val:
00124         set_value('rtp_symmetric', 'yes', section, pjsip, nmapped)
00125     if 'force_rport' in val:
00126         set_value('force_rport', 'yes', section, pjsip, nmapped)
00127         set_value('rewrite_contact', 'yes', section, pjsip, nmapped)
00128 
00129 
def set_timers(key, val, section, pjsip, nmapped):

def sip_to_pjsip::from_progressinband (   key,
  val,
  section,
  pjsip,
  nmapped 
)

Sets the inband_progress value in pjsip.conf

Definition at line 203 of file sip_to_pjsip.py.

00203                                                           :
00204     """Sets the inband_progress value in pjsip.conf"""
00205     # progressinband can = yes/no/never
00206     if val == 'never':
00207         val = 'no'
00208     set_value('inband_progress', val, section, pjsip, nmapped)
00209 
00210 
def build_host(config, host, section, port_key):

def sip_to_pjsip::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.

Definition at line 187 of file sip_to_pjsip.py.

00187                                                          :
00188     """
00189     If record on/off feature is set to automixmon then set
00190     one_touch_recording, otherwise it can't be mapped.
00191     """
00192     set_value('one_touch_recording', 'yes', section, pjsip, nmapped)
00193     set_value(key, val, section, pjsip, nmapped)
00194 
def set_record_on_feature(key, val, section, pjsip, nmapped):

def sip_to_pjsip::from_sendrpid (   key,
  val,
  section,
  pjsip,
  nmapped 
)

Sets the send_rpid/pai values in pjsip.conf.

Definition at line 165 of file sip_to_pjsip.py.

00165                                                     :
00166     """Sets the send_rpid/pai values in pjsip.conf."""
00167     if val == 'yes' or val == 'rpid':
00168         set_value('send_rpid', 'yes', section, pjsip, nmapped)
00169     elif val == 'pai':
00170         set_value('send_pai', 'yes', section, pjsip, nmapped)
00171 
00172 
def set_media_encryption(key, val, section, pjsip, nmapped):

def sip_to_pjsip::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.

Definition at line 828 of file sip_to_pjsip.py.

00828                                  :
00829     """
00830     Creates auth sections based on entries in the authentication section of
00831     sip.conf. pjsip.conf section names consist of "auth_" followed by the name
00832     of the realm.
00833     """
00834     try:
00835         auths = sip.get('authentication', 'auth')
00836     except LookupError:
00837         return
00838 
00839     for i in auths:
00840         creds, at, realm = i.partition('@')
00841         if not at and not realm:
00842             # Invalid. Move on
00843             continue
00844         user, colon, secret = creds.partition(':')
00845         if not secret:
00846             user, sharp, md5 = creds.partition('#')
00847             if not md5:
00848                 #Invalid. move on
00849                 continue
00850         section = "auth_" + realm
00851 
00852         set_value('realm', realm, section, pjsip, nmapped, 'auth')
00853         set_value('username', user, section, pjsip, nmapped, 'auth')
00854         if secret:
00855             set_value('password', secret, section, pjsip, nmapped, 'auth')
00856         else:
00857             set_value('md5_cred', md5, section, pjsip, nmapped, 'auth')
00858             set_value('auth_type', 'md5', section, pjsip, nmapped, 'auth')
00859 
00860 
class Registration:

def sip_to_pjsip::map_peer (   sip,
  section,
  pjsip,
  nmapped 
)

Map the options from a peer section in sip.conf into the appropriate
sections in pjsip.conf

Definition at line 1046 of file sip_to_pjsip.py.

01046                                           :
01047     """
01048     Map the options from a peer section in sip.conf into the appropriate
01049     sections in pjsip.conf
01050     """
01051     for i in peer_map:
01052         try:
01053             # coming from sip.conf the values should mostly be a list with a
01054             # single value.  In the few cases that they are not a specialized
01055             # function (see merge_value) is used to retrieve the values.
01056             i[1](i[0], sip.get(section, i[0])[0], section, pjsip, nmapped)
01057         except LookupError:
01058             pass  # key not found in sip.conf
01059 
01060 
def find_non_mapped(sections, nmapped):

def sip_to_pjsip::map_registrations (   sip,
  pjsip,
  nmapped 
)

Gathers all necessary outbound registration data in sip.conf and creates
corresponding registration sections in pjsip.conf

Definition at line 1016 of file sip_to_pjsip.py.

01016                                           :
01017     """
01018     Gathers all necessary outbound registration data in sip.conf and creates
01019     corresponding registration sections in pjsip.conf
01020     """
01021     try:
01022         regs = sip.get('general', 'register')
01023     except LookupError:
01024         return
01025 
01026     try:
01027         retry_interval = sip.get('general', 'registertimeout')[0]
01028     except LookupError:
01029         retry_interval = '20'
01030 
01031     try:
01032         max_attempts = sip.get('general', 'registerattempts')[0]
01033     except LookupError:
01034         max_attempts = '10'
01035 
01036     try:
01037         outbound_proxy = sip.get('general', 'outboundproxy')[0]
01038     except LookupError:
01039         outbound_proxy = ''
01040 
01041     for i in regs:
01042         reg = Registration(i, retry_interval, max_attempts, outbound_proxy)
01043         reg.write(pjsip, nmapped)
01044 
01045 
def map_peer(sip, section, pjsip, nmapped):

def sip_to_pjsip::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.

Definition at line 801 of file sip_to_pjsip.py.

00801                                        :
00802     """
00803     Finds options in sip.conf general section pertaining to
00804     transport configuration and creates appropriate transport
00805     configuration sections in pjsip.conf.
00806 
00807     sip.conf only allows a single UDP transport, TCP transport,
00808     and TLS transport. As such, the mapping into PJSIP can be made
00809     consistent by defining three sections:
00810 
00811     transport-udp
00812     transport-tcp
00813     transport-tls
00814 
00815     To accommodate the default behaviors in sip.conf, we'll need to
00816     create the UDP transport first, followed by the TCP and TLS transports.
00817     """
00818 
00819     # First create a UDP transport. Even if no bind parameters were provided
00820     # in sip.conf, chan_sip would always bind to UDP 0.0.0.0:5060
00821     create_udp(sip, pjsip, nmapped)
00822 
00823     # TCP settings may be dependent on UDP settings, so do it second.
00824     create_tcp(sip, pjsip, nmapped)
00825     create_tls(sip, pjsip, nmapped)
00826 
00827 
def map_auth(sip, pjsip, nmapped):

def sip_to_pjsip::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.

Definition at line 56 of file sip_to_pjsip.py.

00057                                                                :
00058     """Merge values from the given section with those from the default."""
00059     def _merge_value(k, v, s, r, n):
00060         merge_value(key if key else k, v, s, r, n, type, section_to)
00061 
00062     # if no value or section return the merge_value
00063     # function with the enclosed key and type
00064     if not val and not section:
00065         return _merge_value
00066 
00067     # should return a single value section list
00068     try:
00069         sect = sip.section(section)[0]
00070     except LookupError:
00071         sect = sip.default(section)[0]
00072     # for each merged value add it to pjsip.conf
00073     for i in sect.get_merged(key):
00074         set_value(key, i, section_to if section_to else section,
00075                   pjsip, nmapped, type)
00076 
00077 
def non_mapped(nmapped):

def sip_to_pjsip::non_mapped (   nmapped  ) 

Write non-mapped sip.conf values to the non-mapped object

Definition at line 78 of file sip_to_pjsip.py.

00078                        :
00079     """Write non-mapped sip.conf values to the non-mapped object"""
00080     def _non_mapped(section, key, val):
00081         """Writes a non-mapped value from sip.conf to the non-mapped object."""
00082         if section not in nmapped:
00083             nmapped[section] = astconfigparser.Section()
00084             if isinstance(val, list):
00085                 for v in val:
00086                     # since coming from sip.conf we can assume
00087                     # single section lists
00088                     nmapped[section][0][key] = v
00089             else:
00090                 nmapped[section][0][key] = val
00091     return _non_mapped
00092 
###############################################################################

def sip_to_pjsip::section_by_type (   section,
  pjsip,
  type 
)

Finds a section based upon the given type, adding it if not found.

Definition at line 16 of file sip_to_pjsip.py.

00016                                          :
00017     """Finds a section based upon the given type, adding it if not found."""
00018     def __find_dict(mdicts, key, val):
00019         """Given a list of mult-dicts, return the multi-dict that contains
00020            the given key/value pair."""
00021 
00022         def found(d):
00023             return key in d and val in d[key]
00024 
00025         try:
00026             return [d for d in mdicts if found(d)][0]
00027         except IndexError:
00028             raise LookupError("Dictionary not located for key = %s, value = %s"
00029                               % (key, val))
00030 
00031     try:
00032         return __find_dict(pjsip.section(section), 'type', type)
00033     except LookupError:
00034         # section for type doesn't exist, so add
00035         sect = pjsip.add_section(section)
00036         sect['type'] = type
00037         return sect
00038 
00039 
def set_value(key=None, val=None, section=None, pjsip=None,

def sip_to_pjsip::set_direct_media (   key,
  val,
  section,
  pjsip,
  nmapped 
)

Maps values from the sip.conf comma separated direct_media option
into pjsip.conf direct_media options.

Definition at line 146 of file sip_to_pjsip.py.

00146                                                        :
00147     """
00148     Maps values from the sip.conf comma separated direct_media option
00149     into pjsip.conf direct_media options.
00150     """
00151     if 'yes' in val:
00152         set_value('direct_media', 'yes', section, pjsip, nmapped)
00153     if 'update' in val:
00154         set_value('direct_media_method', 'update', section, pjsip, nmapped)
00155     if 'outgoing' in val:
00156         set_value('directed_media_glare_mitigation', 'outgoing', section,
00157                   pjsip, nmapped)
00158     if 'nonat' in val:
00159         set_value('disable_directed_media_on_nat', 'yes', section, pjsip,
00160                   nmapped)
00161     if 'no' in val:
00162         set_value('direct_media', 'no', section, pjsip, nmapped)
00163 
00164 
def from_sendrpid(key, val, section, pjsip, nmapped):

def sip_to_pjsip::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.

Definition at line 100 of file sip_to_pjsip.py.

00100                                                    :
00101     """
00102     Sets the dtmfmode value.  If value matches allowable option in pjsip
00103     then map it, otherwise set it to none.
00104     """
00105     key = 'dtmf_mode'
00106     # available pjsip.conf values: rfc4733, inband, info, none
00107     if val == 'inband' or val == 'info':
00108         set_value(key, val, section, pjsip, nmapped)
00109     elif val == 'rfc2833':
00110         set_value(key, 'rfc4733', section, pjsip, nmapped)
00111     else:
00112         nmapped(section, key, val + " ; did not fully map - set to none")
00113         set_value(key, 'none', section, pjsip, nmapped)
00114 
00115 
def from_nat(key, val, section, pjsip, nmapped):

def sip_to_pjsip::set_media_encryption (   key,
  val,
  section,
  pjsip,
  nmapped 
)

Sets the media_encryption value in pjsip.conf

Definition at line 173 of file sip_to_pjsip.py.

00173                                                            :
00174     """Sets the media_encryption value in pjsip.conf"""
00175     try:
00176         dtls = sip.get(section, 'dtlsenable')[0]
00177         if dtls == 'yes':
00178             # If DTLS is enabled, then that overrides SDES encryption.
00179             return
00180     except LookupError:
00181         pass
00182 
00183     if val == 'yes':
00184         set_value('media_encryption', 'sdes', section, pjsip, nmapped)
00185 
00186 
def from_recordfeature(key, val, section, pjsip, nmapped):

def sip_to_pjsip::set_record_off_feature (   key,
  val,
  section,
  pjsip,
  nmapped 
)

Sets the record_off_feature in pjsip.conf

Definition at line 199 of file sip_to_pjsip.py.

00199                                                              :
00200     """Sets the record_off_feature in pjsip.conf"""
00201     from_recordfeature('record_off_feature', val, section, pjsip, nmapped)
00202 
def from_progressinband(key, val, section, pjsip, nmapped):

def sip_to_pjsip::set_record_on_feature (   key,
  val,
  section,
  pjsip,
  nmapped 
)

Sets the record_on_feature in pjsip.conf

Definition at line 195 of file sip_to_pjsip.py.

00195                                                             :
00196     """Sets the record_on_feature in pjsip.conf"""
00197     from_recordfeature('record_on_feature', val, section, pjsip, nmapped)
00198 
def set_record_off_feature(key, val, section, pjsip, nmapped):

def sip_to_pjsip::set_timers (   key,
  val,
  section,
  pjsip,
  nmapped 
)

Sets the timers in pjsip.conf from the session-timers option
found in sip.conf.

Definition at line 130 of file sip_to_pjsip.py.

00130                                                  :
00131     """
00132     Sets the timers in pjsip.conf from the session-timers option
00133     found in sip.conf.
00134     """
00135     # pjsip.conf values can be yes/no, required, always
00136     if val == 'originate':
00137         set_value('timers', 'always', section, pjsip, nmapped)
00138     elif val == 'accept':
00139         set_value('timers', 'required', section, pjsip, nmapped)
00140     elif val == 'never':
00141         set_value('timers', 'no', section, pjsip, nmapped)
00142     else:
00143         set_value('timers', 'yes', section, pjsip, nmapped)
00144 
00145 
def set_direct_media(key, val, section, pjsip, nmapped):

def sip_to_pjsip::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

Definition at line 661 of file sip_to_pjsip.py.

00661                                          :
00662     """
00663     Creates the TCP bind address. This has two possible methods of
00664     working:
00665     Use the 'tlsbindaddr' option from sip.conf directly if it has both
00666     an address and port. If no port is present, use 5061
00667     If there is no 'tlsbindaddr' option present in sip.conf, use the
00668     previously-established UDP bind address and port 5061
00669     """
00670     try:
00671         bind = sip.get('general', 'tlsbindaddr')[0]
00672         explicit = True
00673     except LookupError:
00674         # No tlsbindaddr means to default to the bindaddr but with standard TLS
00675         # port
00676         bind = pjsip.get('transport-udp', 'bind')[0]
00677         explicit = False
00678 
00679     matchv4 = re.match('\d+\.\d+\.\d+\.\d+:\d+', bind)
00680     matchv6 = re.match('\[.*\]:d+', bind)
00681     if matchv4 or matchv6:
00682         if explicit:
00683             # They provided a port. We'll just use it.
00684             set_value('bind', bind, 'transport-tls', pjsip, nmapped,
00685                       'transport')
00686             return
00687         else:
00688             # Need to strip the port from the UDP address
00689             index = bind.rfind(':')
00690             bind = bind[:index]
00691 
00692     # Reaching this point means either there was no port provided or we
00693     # stripped the port off. We need to add on the default 5061 port
00694 
00695     bind += ':5061'
00696 
00697     set_value('bind', bind, 'transport-tls', pjsip, nmapped, 'transport')
00698 
00699 
def set_tls_private_key(val, pjsip, nmapped):

def sip_to_pjsip::set_tls_cafile (   val,
  pjsip,
  nmapped 
)

Sets ca_list_file based on sip.conf tlscafile

Definition at line 711 of file sip_to_pjsip.py.

00711                                        :
00712     """Sets ca_list_file based on sip.conf tlscafile"""
00713     set_value('ca_list_file', val, 'transport-tls', pjsip, nmapped,
00714               'transport')
00715 
00716 
def set_tls_verifyclient(val, pjsip, nmapped):

def sip_to_pjsip::set_tls_cipher (   val,
  pjsip,
  nmapped 
)

Sets cipher based on sip.conf tlscipher or sslcipher

Definition at line 706 of file sip_to_pjsip.py.

00706                                        :
00707     """Sets cipher based on sip.conf tlscipher or sslcipher"""
00708     set_value('cipher', val, 'transport-tls', pjsip, nmapped, 'transport')
00709 
00710 
def set_tls_cafile(val, pjsip, nmapped):

def sip_to_pjsip::set_tls_method (   val,
  pjsip,
  nmapped 
)

Sets method based on sip.conf tlsclientmethod or sslclientmethod

Definition at line 734 of file sip_to_pjsip.py.

00734                                        :
00735     """Sets method based on sip.conf tlsclientmethod or sslclientmethod"""
00736     set_value('method', val, 'transport-tls', pjsip, nmapped, 'transport')
00737 
00738 
def create_tls(sip, pjsip, nmapped):

def sip_to_pjsip::set_tls_private_key (   val,
  pjsip,
  nmapped 
)

Sets privkey_file based on sip.conf tlsprivatekey or sslprivatekey

Definition at line 700 of file sip_to_pjsip.py.

00700                                             :
00701     """Sets privkey_file based on sip.conf tlsprivatekey or sslprivatekey"""
00702     set_value('priv_key_file', val, 'transport-tls', pjsip, nmapped,
00703               'transport')
00704 
00705 
def set_tls_cipher(val, pjsip, nmapped):

def sip_to_pjsip::set_tls_verifyclient (   val,
  pjsip,
  nmapped 
)

Sets verify_client based on sip.conf tlsverifyclient

Definition at line 717 of file sip_to_pjsip.py.

00717                                              :
00718     """Sets verify_client based on sip.conf tlsverifyclient"""
00719     set_value('verify_client', val, 'transport-tls', pjsip, nmapped,
00720               'transport')
00721 
00722 
def set_tls_verifyserver(val, pjsip, nmapped):

def sip_to_pjsip::set_tls_verifyserver (   val,
  pjsip,
  nmapped 
)

Sets verify_server based on sip.conf tlsdontverifyserver

Definition at line 723 of file sip_to_pjsip.py.

00723                                              :
00724     """Sets verify_server based on sip.conf tlsdontverifyserver"""
00725 
00726     if val == 'no':
00727         set_value('verify_server', 'yes', 'transport-tls', pjsip, nmapped,
00728                   'transport')
00729     else:
00730         set_value('verify_server', 'no', 'transport-tls', pjsip, nmapped,
00731                   'transport')
00732 
00733 
def set_tls_method(val, pjsip, nmapped):

def sip_to_pjsip::set_transport_common (   section,
  pjsip,
  nmapped 
)

sip.conf has several global settings that in pjsip.conf apply to individual
transports. This function adds these global settings to each individual
transport.

The settings included are:
localnet
tos_sip
cos_sip

Definition at line 517 of file sip_to_pjsip.py.

00517                                                  :
00518     """
00519     sip.conf has several global settings that in pjsip.conf apply to individual
00520     transports. This function adds these global settings to each individual
00521     transport.
00522 
00523     The settings included are:
00524     localnet
00525     tos_sip
00526     cos_sip
00527     """
00528 
00529     try:
00530         merge_value('local_net', sip.get('general', 'localnet')[0], 'general',
00531                     pjsip, nmapped, 'transport', section)
00532     except LookupError:
00533         # No localnet options configured. Move on.
00534         pass
00535 
00536     try:
00537         set_value('tos', sip.get('general', 'sip_tos')[0], 'general', pjsip,
00538                   nmapped, 'transport', section)
00539     except LookupError:
00540         pass
00541 
00542     try:
00543         set_value('cos', sip.get('general', 'sip_cos')[0], 'general', pjsip,
00544                   nmapped, 'transport', section)
00545     except LookupError:
00546         pass
00547 
00548 
def split_hostport(addr):

def sip_to_pjsip::set_value (   key = None,
  val = None,
  section = None,
  pjsip = None,
  nmapped = None,
  type = 'endpoint' 
)

Sets the key to the value within the section in pjsip.conf

Definition at line 40 of file sip_to_pjsip.py.

00041                                             :
00042     """Sets the key to the value within the section in pjsip.conf"""
00043     def _set_value(k, v, s, r, n):
00044         set_value(key if key else k, v, s, r, n, type)
00045 
00046     # if no value or section return the set_value
00047     # function with the enclosed key and type
00048     if not val and not section:
00049         return _set_value
00050 
00051     # otherwise try to set the value
00052     section_by_type(section, pjsip, type)[key] = \
00053         val[0] if isinstance(val, list) else val
00054 
00055 
def merge_value(key=None, val=None, section=None, pjsip=None,

def sip_to_pjsip::setup_auth (   key,
  val,
  section,
  pjsip,
  nmapped 
)

Sets up authentication information for a specific endpoint based on the
'secret' setting on a peer in sip.conf

Definition at line 295 of file sip_to_pjsip.py.

00295                                                  :
00296     """
00297     Sets up authentication information for a specific endpoint based on the
00298     'secret' setting on a peer in sip.conf
00299     """
00300     set_value('username', section, section, pjsip, nmapped, 'auth')
00301     # In chan_sip, if a secret and an md5secret are both specified on a peer,
00302     # then in practice, only the md5secret is used. If both are encountered
00303     # then we build an auth section that has both an md5_cred and password.
00304     # However, the auth_type will indicate to authenticators to use the
00305     # md5_cred, so like with sip.conf, the password will be there but have
00306     # no purpose.
00307     if key == 'secret':
00308         set_value('password', val, section, pjsip, nmapped, 'auth')
00309     else:
00310         set_value('md5_cred', val, section, pjsip, nmapped, 'auth')
00311         set_value('auth_type', 'md5', section, pjsip, nmapped, 'auth')
00312 
00313     realms = [section]
00314     try:
00315         auths = sip.get('authentication', 'auth')
00316         for i in auths:
00317             user, at, realm = i.partition('@')
00318             realms.append(realm)
00319     except LookupError:
00320         pass
00321 
00322     realm_str = ','.join(realms)
00323 
00324     set_value('auth', section, section, pjsip, nmapped)
00325     set_value('outbound_auth', realm_str, section, pjsip, nmapped)
00326 
00327 
def setup_ident(key, val, section, pjsip, nmapped):

def sip_to_pjsip::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.

Definition at line 328 of file sip_to_pjsip.py.

00328                                                   :
00329     """
00330     Examines the 'type' field for a sip.conf peer and creates an identify
00331     section if the type is either 'peer' or 'friend'. The identify section uses
00332     either the host or defaultip field of the sip.conf peer.
00333     """
00334     if val != 'peer' and val != 'friend':
00335         return
00336 
00337     try:
00338         ip = sip.get(section, 'host')[0]
00339     except LookupError:
00340         return
00341 
00342     if ip == 'dynamic':
00343         try:
00344             ip = sip.get(section, 'defaultip')[0]
00345         except LookupError:
00346             return
00347 
00348     set_value('endpoint', section, section, pjsip, nmapped, 'identify')
00349     set_value('match', ip, section, pjsip, nmapped, 'identify')
00350 
00351 
def from_encryption_taglen(key, val, section, pjsip, nmapped):

def sip_to_pjsip::split_hostport (   addr  ) 

Given an address in the form 'addr:port' separate the addr and port
components.
Returns a two-tuple of strings, (addr, port). If no port is present in the
string, then the port section of the tuple is None.

Definition at line 549 of file sip_to_pjsip.py.

Referenced by load_module(), and unload_module().

00549                         :
00550     """
00551     Given an address in the form 'addr:port' separate the addr and port
00552     components.
00553     Returns a two-tuple of strings, (addr, port). If no port is present in the
00554     string, then the port section of the tuple is None.
00555     """
00556     try:
00557         socket.inet_pton(socket.AF_INET6, addr)
00558         if not addr.startswith('['):
00559             return (addr, None)
00560         else:
00561             # If brackets are present, there may be a port as well
00562             match = re.match('\[(.*\)]:(\d+)', addr)
00563             if match:
00564                 return (match.group(1), match.group(2))
00565             else:
00566                 return (addr, None)
00567     except socket.error:
00568         pass
00569 
00570     # IPv4 address or hostname
00571     host, sep, port = addr.rpartition(':')
00572 
00573     if not sep and not port:
00574         return (host, None)
00575     else:
00576         return (host, port)
00577 
00578 
def create_udp(sip, pjsip, nmapped):

def sip_to_pjsip::write_pjsip (   filename,
  pjsip,
  non_mappings 
)

Write pjsip.conf file to disk

Definition at line 1113 of file sip_to_pjsip.py.

01113                                               :
01114     """
01115     Write pjsip.conf file to disk
01116     """
01117     try:
01118         with open(filename, 'wt') as fp:
01119             fp.write(';--\n')
01120             fp.write(';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n')
01121             fp.write('Non mapped elements start\n')
01122             fp.write(';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\n')
01123             astconfigparser.write_dicts(fp, non_mappings[filename])
01124             fp.write(';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n')
01125             fp.write('Non mapped elements end\n')
01126             fp.write(';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n')
01127             fp.write('--;\n\n')
01128             # write out include file(s)
01129             pjsip.write(fp)
01130 
01131     except IOError:
01132         print "Could not open file ", filename, " for writing"
01133 
###############################################################################


Variable Documentation

list peer_map

Definition at line 370 of file sip_to_pjsip.py.

string PREFIX = 'pjsip_'

Definition at line 9 of file sip_to_pjsip.py.

Definition at line 1162 of file sip_to_pjsip.py.


Generated on Thu Apr 16 06:41:38 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6