Asterisk - The Open Source Telephony Project  GIT-master-44aef04
Data Structures | Functions | Variables
sip_to_pjsip Namespace Reference

Data Structures

class  Registration
 

Functions

def build_host (config, host, section='general', port_key=None)
 
def cli_options ()
 
def convert (sip, filename, non_mappings, include)
 
def create_tcp (sip, pjsip, nmapped)
 
def create_tls (sip, pjsip, nmapped)
 
def create_udp (sip, pjsip, nmapped)
 
def find_non_mapped (sections, nmapped)
 
def from_dtlsenable (key, val, section, pjsip, nmapped)
 
def from_encryption_taglen (key, val, section, pjsip, nmapped)
 
def from_host (key, val, section, pjsip, nmapped)
 
def from_mailbox (key, val, section, pjsip, nmapped)
 
def from_nat (key, val, section, pjsip, nmapped)
 
def from_progressinband (key, val, section, pjsip, nmapped)
 
def from_recordfeature (key, val, section, pjsip, nmapped)
 
def from_sendrpid (key, val, section, pjsip, nmapped)
 
def get_bind (sip, pjsip, protocol)
 
def ignore (key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
 
def info (msg)
 
def map_auth (sip, pjsip, nmapped)
 
def map_peer (sip, section, pjsip, nmapped)
 
def map_registrations (sip, pjsip, nmapped)
 
def map_setvars (sip, section, pjsip, nmapped)
 
def map_system (sip, pjsip, nmapped)
 
def map_transports (sip, pjsip, nmapped)
 
def merge_codec_value (key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint', section_to=None, key_to=None)
 
def merge_value (key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint', section_to=None, key_to=None)
 
def non_mapped (nmapped)
 
def section_by_type (section, pjsip, type)
 some utility functions More...
 
def set_direct_media (key, val, section, pjsip, nmapped)
 
def set_dtmfmode (key, val, section, pjsip, nmapped)
 mapping functions - define f(key, val, section) where key/val are the key/value pair to write to given section in pjsip.conf More...
 
def set_media_encryption (key, val, section, pjsip, nmapped)
 
def set_record_off_feature (key, val, section, pjsip, nmapped)
 
def set_record_on_feature (key, val, section, pjsip, nmapped)
 
def set_timers (key, val, section, pjsip, nmapped)
 
def set_tls_cafile (val, pjsip, section, nmapped)
 
def set_tls_capath (val, pjsip, section, nmapped)
 
def set_tls_cert_file (val, pjsip, section, nmapped)
 
def set_tls_cipher (val, pjsip, section, nmapped)
 
def set_tls_private_key (val, pjsip, section, nmapped)
 
def set_tls_verifyclient (val, pjsip, section, nmapped)
 
def set_tls_verifyserver (val, pjsip, section, nmapped)
 
def set_transport_common (section, sip, pjsip, protocol, nmapped)
 
def set_value (key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
 
def setup_auth (key, val, section, pjsip, nmapped)
 
def setup_ident (key, val, section, pjsip, nmapped)
 
def setup_udptl (section, pjsip, nmapped)
 
def split_hostport (addr)
 
def write_pjsip (filename, pjsip, non_mappings)
 

Variables

 non_mappings
 
list peer_map
 
 pjsip
 
 pjsip_filename
 
string PREFIX = 'pjsip_'
 
bool QUIET = False
 
 sip = astconfigparser.MultiOrderedConfigParser()
 
 sip_filename
 

Function Documentation

◆ build_host()

def sip_to_pjsip.build_host (   config,
  host,
  section = 'general',
  port_key = None 
)
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 overrides
a port in host, see parameter 'bindport' in chan_sip.

Definition at line 289 of file sip_to_pjsip.py.

Referenced by from_host(), and get_bind().

289 def build_host(config, host, section='general', port_key=None):
290  """
291  Returns a string composed of a host:port. This assumes that the host
292  may have a port as part of the initial value. The port_key overrides
293  a port in host, see parameter 'bindport' in chan_sip.
294  """
295  try:
296  socket.inet_pton(socket.AF_INET6, host)
297  if not host.startswith('['):
298  # SIP URI will need brackets.
299  host = '[' + host + ']'
300  except socket.error:
301  pass
302 
303  # Literal IPv6 (like [::]), IPv4, or hostname
304  # does not work for IPv6 without brackets; case catched above
305  url = urlparse('sip://' + host)
306 
307  if port_key:
308  try:
309  port = config.get(section, port_key)[0]
310  host = url.hostname # no port, but perhaps no brackets
311  try:
312  socket.inet_pton(socket.AF_INET6, host)
313  if not host.startswith('['):
314  # SIP URI will need brackets.
315  host = '[' + host + ']'
316  except socket.error:
317  pass
318  return host + ':' + port
319  except LookupError:
320  pass
321 
322  # Returns host:port, in brackets if required
323  # TODO Does not compress IPv6, for example 0:0:0:0:0:0:0:0 should get [::]
324  return url.netloc
325 
326 
def build_host(config, host, section='general', port_key=None)

◆ cli_options()

def sip_to_pjsip.cli_options ( )
Parse command line options and apply them. If invalid input is given,
print usage information

Definition at line 1279 of file sip_to_pjsip.py.

References len().

1279 def cli_options():
1280  """
1281  Parse command line options and apply them. If invalid input is given,
1282  print usage information
1283  """
1284  global PREFIX
1285  global QUIET
1286  usage = "usage: %prog [options] [input-file [output-file]]\n\n" \
1287  "Converts the chan_sip configuration input-file to the chan_pjsip output-file.\n" \
1288  "The input-file defaults to 'sip.conf'.\n" \
1289  "The output-file defaults to 'pjsip.conf'."
1290  parser = optparse.OptionParser(usage=usage)
1291  parser.add_option('-p', '--prefix', dest='prefix', default=PREFIX,
1292  help='output prefix for include files')
1293  parser.add_option('-q', '--quiet', dest='quiet', default=False, action='store_true',
1294  help="don't print messages to stdout")
1295 
1296  options, args = parser.parse_args()
1297  PREFIX = options.prefix
1298  if options.quiet:
1299  QUIET = True
1300 
1301  sip_filename = args[0] if len(args) else 'sip.conf'
1302  pjsip_filename = args[1] if len(args) == 2 else 'pjsip.conf'
1303 
1304  return sip_filename, pjsip_filename
1305 
1306 
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

◆ convert()

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 1223 of file sip_to_pjsip.py.

References find_non_mapped(), map_auth(), map_peer(), map_registrations(), map_setvars(), map_system(), map_transports(), and non_mapped().

1223 def convert(sip, filename, non_mappings, include):
1224  """
1225  Entry point for configuration file conversion. This
1226  function will create a pjsip.conf object and begin to
1227  map specific sections from sip.conf into it.
1228  Returns the new pjsip.conf object once completed
1229  """
1230  pjsip = sip.__class__()
1231  non_mappings[filename] = astdicts.MultiOrderedDict()
1232  nmapped = non_mapped(non_mappings[filename])
1233  if not include:
1234  # Don't duplicate transport and registration configs
1235  map_system(sip, pjsip, nmapped)
1236  map_transports(sip, pjsip, nmapped)
1237  map_registrations(sip, pjsip, nmapped)
1238  map_auth(sip, pjsip, nmapped)
1239  for section in sip.sections():
1240  if section == 'authentication':
1241  pass
1242  else:
1243  map_peer(sip, section, pjsip, nmapped)
1244  map_setvars(sip, section, pjsip, nmapped)
1245 
1246  find_non_mapped(sip.defaults(), nmapped)
1247  find_non_mapped(sip.sections(), nmapped)
1248 
1249  for key, val in sip.includes().iteritems():
1250  pjsip.add_include(PREFIX + key, convert(val, PREFIX + key,
1251  non_mappings, True)[0])
1252  return pjsip, non_mappings
1253 
1254 
def map_peer(sip, section, pjsip, nmapped)
def map_auth(sip, pjsip, nmapped)
def convert(sip, filename, non_mappings, include)
def map_system(sip, pjsip, nmapped)
def map_transports(sip, pjsip, nmapped)
def find_non_mapped(sections, nmapped)
def map_setvars(sip, section, pjsip, nmapped)
def non_mapped(nmapped)
def map_registrations(sip, pjsip, nmapped)

◆ create_tcp()

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 (or bindaddr)

Definition at line 744 of file sip_to_pjsip.py.

References get_bind(), set_transport_common(), and set_value().

Referenced by map_transports().

744 def create_tcp(sip, pjsip, nmapped):
745  """
746  Creates a 'transport-tcp' section in the pjsip.conf file based
747  on the following settings from sip.conf:
748 
749  tcpenable
750  tcpbindaddr (or bindaddr)
751  """
752  protocol = 'tcp'
753  bind, section = get_bind(sip, pjsip, protocol)
754  if not bind:
755  return
756 
757  set_value('protocol', protocol, section, pjsip, nmapped, 'transport')
758  set_value('bind', bind, section, pjsip, nmapped, 'transport')
759  set_transport_common(section, sip, pjsip, protocol, nmapped)
760 
761 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def set_transport_common(section, sip, pjsip, protocol, nmapped)
def get_bind(sip, pjsip, protocol)
def create_tcp(sip, pjsip, nmapped)

◆ create_tls()

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 or bindaddr)
tlsprivatekey (or sslprivatekey)
tlscipher (or sslcipher)
tlscafile
tlscapath (or tlscadir)
tlscertfile (or sslcert or tlscert)
tlsverifyclient
tlsdontverifyserver
tlsclientmethod (or sslclientmethod)

Definition at line 808 of file sip_to_pjsip.py.

References get_bind(), set_transport_common(), and set_value().

Referenced by map_transports().

808 def create_tls(sip, pjsip, nmapped):
809  """
810  Creates a 'transport-tls' section in pjsip.conf based on the following
811  settings from sip.conf:
812 
813  tlsenable (or sslenable)
814  tlsbindaddr (or sslbindaddr or bindaddr)
815  tlsprivatekey (or sslprivatekey)
816  tlscipher (or sslcipher)
817  tlscafile
818  tlscapath (or tlscadir)
819  tlscertfile (or sslcert or tlscert)
820  tlsverifyclient
821  tlsdontverifyserver
822  tlsclientmethod (or sslclientmethod)
823  """
824  protocol = 'tls'
825  bind, section = get_bind(sip, pjsip, protocol)
826  if not bind:
827  return
828 
829  set_value('protocol', protocol, section, pjsip, nmapped, 'transport')
830  set_value('bind', bind, section, pjsip, nmapped, 'transport')
831  set_transport_common(section, sip, pjsip, protocol, nmapped)
832 
833  tls_map = [
834  (['tlscertfile', 'sslcert', 'tlscert'], set_tls_cert_file),
835  (['tlsprivatekey', 'sslprivatekey'], set_tls_private_key),
836  (['tlscipher', 'sslcipher'], set_tls_cipher),
837  (['tlscafile'], set_tls_cafile),
838  (['tlscapath', 'tlscadir'], set_tls_capath),
839  (['tlsverifyclient'], set_tls_verifyclient),
840  (['tlsdontverifyserver'], set_tls_verifyserver)
841  ]
842 
843  for i in tls_map:
844  try:
845  i[1](sip.multi_get('general', i[0])[0], pjsip, section, nmapped)
846  except LookupError:
847  pass
848 
849  try:
850  method = sip.multi_get('general', ['tlsclientmethod',
851  'sslclientmethod'])[0]
852  if section != 'transport-' + protocol + '6': # print only once
853  print('In chan_sip, you specified the TLS version. With chan_sip,' \
854  ' this was just for outbound client connections. In' \
855  ' chan_pjsip, this value is for client and server. Instead,' \
856  ' consider not to specify \'tlsclientmethod\' for chan_sip' \
857  ' and \'method = sslv23\' for chan_pjsip.', file=sys.stderr)
858  except LookupError:
859  """
860  OpenSSL emerged during the 90s. SSLv2 and SSLv3 were the only
861  existing methods at that time. The OpenSSL project continued. And as
862  of today (OpenSSL 1.0.2) this does not start SSLv2 and SSLv3 anymore
863  but TLSv1.0 and v1.2. Or stated differently: This method should
864  have been called 'method = secure' or 'method = automatic' back in
865  the 90s. The PJProject did not realize this and uses 'tlsv1' as
866  default when unspecified, which disables TLSv1.2. chan_sip used
867  'sslv23' as default when unspecified, which gives TLSv1.0 and v1.2.
868  """
869  method = 'sslv23'
870  set_value('method', method, section, pjsip, nmapped, 'transport')
871 
872 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def create_tls(sip, pjsip, nmapped)
def set_transport_common(section, sip, pjsip, protocol, nmapped)
def get_bind(sip, pjsip, protocol)

◆ create_udp()

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

Definition at line 728 of file sip_to_pjsip.py.

References get_bind(), set_transport_common(), and set_value().

Referenced by map_transports().

728 def create_udp(sip, pjsip, nmapped):
729  """
730  Creates a 'transport-udp' section in the pjsip.conf file based
731  on the following settings from sip.conf:
732 
733  bindaddr (or udpbindaddr)
734  bindport
735  """
736  protocol = 'udp'
737  bind, section = get_bind(sip, pjsip, protocol)
738 
739  set_value('protocol', protocol, section, pjsip, nmapped, 'transport')
740  set_value('bind', bind, section, pjsip, nmapped, 'transport')
741  set_transport_common(section, sip, pjsip, protocol, nmapped)
742 
743 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def create_udp(sip, pjsip, nmapped)
def set_transport_common(section, sip, pjsip, protocol, nmapped)
def get_bind(sip, pjsip, protocol)

◆ find_non_mapped()

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 1159 of file sip_to_pjsip.py.

Referenced by convert().

1159 def find_non_mapped(sections, nmapped):
1160  """
1161  Determine sip.conf options that were not properly mapped to pjsip.conf
1162  options.
1163  """
1164  for section, sect in sections.iteritems():
1165  try:
1166  # since we are pulling from sip.conf this should always
1167  # be a single value list
1168  sect = sect[0]
1169  # loop through the section and store any values that were not
1170  # mapped
1171  for key in sect.keys(True):
1172  for i in peer_map:
1173  if i[0] == key:
1174  break
1175  else:
1176  nmapped(section, key, sect[key])
1177  except LookupError:
1178  pass
1179 
1180 
def find_non_mapped(sections, nmapped)

◆ from_dtlsenable()

def sip_to_pjsip.from_dtlsenable (   key,
  val,
  section,
  pjsip,
  nmapped 
)
Optionally sets media_encryption=dtls based on sip.conf dtlsenable

Definition at line 441 of file sip_to_pjsip.py.

References set_value().

441 def from_dtlsenable(key, val, section, pjsip, nmapped):
442  """Optionally sets media_encryption=dtls based on sip.conf dtlsenable"""
443  if val == 'yes':
444  set_value('media_encryption', 'dtls', section, pjsip, nmapped)
445 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def from_dtlsenable(key, val, section, pjsip, nmapped)

◆ from_encryption_taglen()

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 435 of file sip_to_pjsip.py.

References set_value().

435 def from_encryption_taglen(key, val, section, pjsip, nmapped):
436  """Sets the srtp_tag32 option based on sip.conf encryption_taglen"""
437  if val == '32':
438  set_value('srtp_tag_32', 'yes', section, pjsip, nmapped)
439 
440 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def from_encryption_taglen(key, val, section, pjsip, nmapped)

◆ from_host()

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 327 of file sip_to_pjsip.py.

References build_host(), and set_value().

327 def from_host(key, val, section, pjsip, nmapped):
328  """
329  Sets contact info in an AOR section in pjsip.conf using 'host'
330  and 'port' data from sip.conf
331  """
332  # all aors have the same name as the endpoint so makes
333  # it easy to set endpoint's 'aors' value
334  set_value('aors', section, section, pjsip, nmapped)
335  if val == 'dynamic':
336  # Easy case. Just set the max_contacts on the aor and we're done
337  set_value('max_contacts', 1, section, pjsip, nmapped, 'aor')
338  return
339 
340  result = 'sip:'
341 
342  # More difficult case. The host will be either a hostname or
343  # IP address and may or may not have a port specified. pjsip.conf
344  # expects the contact to be a SIP URI.
345 
346  user = None
347 
348  try:
349  user = sip.multi_get(section, ['defaultuser', 'username'])[0]
350  result += user + '@'
351  except LookupError:
352  # It's fine if there's no user name
353  pass
354 
355  result += build_host(sip, val, section, 'port')
356 
357  set_value('contact', result, section, pjsip, nmapped, 'aor')
358 
359 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def build_host(config, host, section='general', port_key=None)
def from_host(key, val, section, pjsip, nmapped)

◆ from_mailbox()

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-shallow/main/app.c.

Definition at line 360 of file sip_to_pjsip.py.

References set_value().

360 def from_mailbox(key, val, section, pjsip, nmapped):
361  """
362  Determines whether a mailbox configured in sip.conf should map to
363  an endpoint or aor in pjsip.conf. If subscribemwi is true, then the
364  mailboxes are set on an aor. Otherwise the mailboxes are set on the
365  endpoint.
366  """
367 
368  try:
369  subscribemwi = sip.get(section, 'subscribemwi')[0]
370  except LookupError:
371  # No subscribemwi option means default it to 'no'
372  subscribemwi = 'no'
373 
374  set_value('mailboxes', val, section, pjsip, nmapped, 'aor'
375  if subscribemwi == 'yes' else 'endpoint')
376 
377 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def from_mailbox(key, val, section, pjsip, nmapped)

◆ from_nat()

def sip_to_pjsip.from_nat (   key,
  val,
  section,
  pjsip,
  nmapped 
)
Sets values from nat into the appropriate pjsip.conf options.

Definition at line 191 of file sip_to_pjsip.py.

References set_value().

191 def from_nat(key, val, section, pjsip, nmapped):
192  """Sets values from nat into the appropriate pjsip.conf options."""
193  # nat from sip.conf can be comma separated list of values:
194  # yes/no, [auto_]force_rport, [auto_]comedia
195  if 'yes' in val:
196  set_value('rtp_symmetric', 'yes', section, pjsip, nmapped)
197  set_value('rewrite_contact', 'yes', section, pjsip, nmapped)
198  if 'comedia' in val:
199  set_value('rtp_symmetric', 'yes', section, pjsip, nmapped)
200  if 'force_rport' in val:
201  set_value('force_rport', 'yes', section, pjsip, nmapped)
202  set_value('rewrite_contact', 'yes', section, pjsip, nmapped)
203 
204 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def from_nat(key, val, section, pjsip, nmapped)

◆ from_progressinband()

def sip_to_pjsip.from_progressinband (   key,
  val,
  section,
  pjsip,
  nmapped 
)
Sets the inband_progress value in pjsip.conf

Definition at line 281 of file sip_to_pjsip.py.

References set_value().

281 def from_progressinband(key, val, section, pjsip, nmapped):
282  """Sets the inband_progress value in pjsip.conf"""
283  # progressinband can = yes/no/never
284  if val == 'never':
285  val = 'no'
286  set_value('inband_progress', val, section, pjsip, nmapped)
287 
288 
def from_progressinband(key, val, section, pjsip, nmapped)
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53

◆ from_recordfeature()

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 265 of file sip_to_pjsip.py.

References set_value().

Referenced by set_record_off_feature(), and set_record_on_feature().

265 def from_recordfeature(key, val, section, pjsip, nmapped):
266  """
267  If record on/off feature is set to automixmon then set
268  one_touch_recording, otherwise it can't be mapped.
269  """
270  set_value('one_touch_recording', 'yes', section, pjsip, nmapped)
271  set_value(key, val, section, pjsip, nmapped)
272 
def from_recordfeature(key, val, section, pjsip, nmapped)
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53

◆ from_sendrpid()

def sip_to_pjsip.from_sendrpid (   key,
  val,
  section,
  pjsip,
  nmapped 
)
Sets the send_rpid/pai values in pjsip.conf.

Definition at line 243 of file sip_to_pjsip.py.

References set_value().

243 def from_sendrpid(key, val, section, pjsip, nmapped):
244  """Sets the send_rpid/pai values in pjsip.conf."""
245  if val == 'yes' or val == 'rpid':
246  set_value('send_rpid', 'yes', section, pjsip, nmapped)
247  elif val == 'pai':
248  set_value('send_pai', 'yes', section, pjsip, nmapped)
249 
250 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def from_sendrpid(key, val, section, pjsip, nmapped)

◆ get_bind()

def sip_to_pjsip.get_bind (   sip,
  pjsip,
  protocol 
)
Given the protocol (udp, tcp, or tls), return
- the bind address, like [::] or 0.0.0.0
- name of the section to be created

Definition at line 663 of file sip_to_pjsip.py.

References build_host(), split_hostport(), and str.

Referenced by create_tcp(), create_tls(), and create_udp().

663 def get_bind(sip, pjsip, protocol):
664  """
665  Given the protocol (udp, tcp, or tls), return
666  - the bind address, like [::] or 0.0.0.0
667  - name of the section to be created
668  """
669  section = 'transport-' + protocol
670 
671  # UDP cannot be disabled in chan_sip
672  if protocol != 'udp':
673  try:
674  enabled = sip.get('general', protocol + 'enable')[0]
675  except LookupError:
676  # No value means disabled by default. Don't create this transport
677  return (None, section)
678  if enabled != 'yes':
679  return (None, section)
680 
681  try:
682  bind = pjsip.get(section, 'bind')[0]
683  # The first run created an transport already but this
684  # server was not configured for IPv4/IPv6 Dual Stack
685  return (None, section)
686  except LookupError:
687  pass
688 
689  try:
690  bind = pjsip.get(section + '6', 'bind')[0]
691  # The first run created an IPv6 transport, because
692  # the server was configured with :: as bindaddr.
693  # Now, re-use its port and create the IPv4 transport
694  host, port = split_hostport(bind)
695  bind = '0.0.0.0'
696  if port:
697  bind += ':' + str(port)
698  except LookupError:
699  # This is the first run, no transport in pjsip exists.
700  try:
701  bind = sip.get('general', protocol + 'bindaddr')[0]
702  except LookupError:
703  if protocol == 'udp':
704  try:
705  bind = sip.get('general', 'bindaddr')[0]
706  except LookupError:
707  bind = '0.0.0.0'
708  else:
709  try:
710  bind = pjsip.get('transport-udp6', 'bind')[0]
711  except LookupError:
712  bind = pjsip.get('transport-udp', 'bind')[0]
713  # Only TCP reuses host:port of UDP, others reuse just host
714  if protocol == 'tls':
715  bind, port = split_hostport(bind)
716  host, port = split_hostport(bind)
717  if host == '::':
718  section += '6'
719 
720  if protocol == 'udp':
721  host = build_host(sip, bind, 'general', 'bindport')
722  else:
723  host = build_host(sip, bind)
724 
725  return (host, section)
726 
727 
def split_hostport(addr)
const char * str
Definition: app_jack.c:147
def build_host(config, host, section='general', port_key=None)
def get_bind(sip, pjsip, protocol)

◆ ignore()

def sip_to_pjsip.ignore (   key = None,
  val = None,
  section = None,
  pjsip = None,
  nmapped = None,
  type = 'endpoint' 
)
Ignore a key and mark it as mapped

Definition at line 48 of file sip_to_pjsip.py.

Referenced by acl_handler(), endpoint_acl_handler(), find_unused_payload(), and section_by_type().

48  nmapped=None, type='endpoint'):
49  """Ignore a key and mark it as mapped"""
50 
51 

◆ info()

def sip_to_pjsip.info (   msg)

Definition at line 1307 of file sip_to_pjsip.py.

Referenced by __ast_datastore_alloc(), _jb_get(), acf_version_exec(), add_media_cb(), alloc_variant(), ami_outbound_registration_task(), append_mailbox(), apply_list_configuration(), ast_build_timing(), ast_datastores_alloc_datastore(), ast_dsp_get_threshold_from_settings(), ast_localtime_wakeup_monitor(), ast_media_get_variants(), ast_module_register(), ast_res_pjsip_initialize_configuration(), ast_sip_publish_client_alloc_datastore(), ast_sip_session_alloc_datastore(), ast_sip_threadpool(), ast_sockaddr_from_pj_sockaddr(), AST_TEST_DEFINE(), ast_utf8_validator_destroy(), asyncgoto_exec(), build_ami_notify(), build_cli_notify(), capture_info_dtor(), cdr_object_update_party_b_userfield_cb(), cdr_read_callback(), chanavail_exec(), complete_config_option(), complete_config_type(), conf_exec(), dbm_open(), device_state_info_dt(), dumpchan_exec(), find_variant(), get_calleridname(), get_device_state_causing_channels(), get_in_brackets(), get_name_and_number(), get_name_from_resource(), handle_cli_agi_show(), handle_client_registration(), handle_client_state_destruction(), handle_registration_response(), handle_show_function(), hcreate(), hepv3_create_capture_info(), keypad_cfg_read(), kqueue_timer_fd(), media_info_alloc(), media_info_destroy(), notify_ami_channel_data_create(), notify_ami_channel_data_destroy(), notify_ami_data_create(), notify_ami_data_destroy(), notify_ami_uri_data_create(), notify_ami_uri_data_destroy(), notify_cli_data_create(), notify_cli_uri_data_create(), notify_cli_uri_data_destroy(), parse_contact_header(), parse_name_andor_addr(), parse_sip_options(), parse_uri(), parse_uri_full(), parse_via(), presence_state_get_id(), refresh_list(), reregister_immediately_cb(), res_sdp_crypto_parse_offer(), schedule_registration(), session_outgoing_nat_hook(), sip_acf_channel_read(), sip_parse_host(), sip_parse_nat_option(), sip_parse_register_line(), sip_unregister_tests(), sorcery_memory_cache_ami_populate(), unbound_config_preapply_callback(), unregister_task(), and vmsayname_exec().

1307 def info(msg):
1308  if QUIET:
1309  return
1310  print(msg)
1311 
1312 
def info(msg)

◆ map_auth()

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 906 of file sip_to_pjsip.py.

References set_value().

Referenced by convert().

906 def map_auth(sip, pjsip, nmapped):
907  """
908  Creates auth sections based on entries in the authentication section of
909  sip.conf. pjsip.conf section names consist of "auth_" followed by the name
910  of the realm.
911  """
912  try:
913  auths = sip.get('authentication', 'auth')
914  except LookupError:
915  return
916 
917  for i in auths:
918  creds, at, realm = i.partition('@')
919  if not at and not realm:
920  # Invalid. Move on
921  continue
922  user, colon, secret = creds.partition(':')
923  if not secret:
924  user, sharp, md5 = creds.partition('#')
925  if not md5:
926  #Invalid. move on
927  continue
928  section = "auth_" + realm
929 
930  set_value('realm', realm, section, pjsip, nmapped, 'auth')
931  set_value('username', user, section, pjsip, nmapped, 'auth')
932  if secret:
933  set_value('password', secret, section, pjsip, nmapped, 'auth')
934  else:
935  set_value('md5_cred', md5, section, pjsip, nmapped, 'auth')
936  set_value('auth_type', 'md5', section, pjsip, nmapped, 'auth')
937 
938 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def map_auth(sip, pjsip, nmapped)

◆ map_peer()

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 1143 of file sip_to_pjsip.py.

References setup_udptl().

Referenced by convert().

1143 def map_peer(sip, section, pjsip, nmapped):
1144  """
1145  Map the options from a peer section in sip.conf into the appropriate
1146  sections in pjsip.conf
1147  """
1148  for i in peer_map:
1149  try:
1150  # coming from sip.conf the values should mostly be a list with a
1151  # single value. In the few cases that they are not a specialized
1152  # function (see merge_value) is used to retrieve the values.
1153  i[1](i[0], sip.get(section, i[0])[0], section, pjsip, nmapped)
1154  except LookupError:
1155  pass # key not found in sip.conf
1156 
1157  setup_udptl(section, pjsip, nmapped)
1158 
def map_peer(sip, section, pjsip, nmapped)
def setup_udptl(section, pjsip, nmapped)

◆ map_registrations()

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 1100 of file sip_to_pjsip.py.

Referenced by convert().

1100 def map_registrations(sip, pjsip, nmapped):
1101  """
1102  Gathers all necessary outbound registration data in sip.conf and creates
1103  corresponding registration sections in pjsip.conf
1104  """
1105  try:
1106  regs = sip.get('general', 'register')
1107  except LookupError:
1108  return
1109 
1110  try:
1111  retry_interval = sip.get('general', 'registertimeout')[0]
1112  except LookupError:
1113  retry_interval = '20'
1114 
1115  try:
1116  max_attempts = sip.get('general', 'registerattempts')[0]
1117  except LookupError:
1118  max_attempts = '10'
1119 
1120  try:
1121  outbound_proxy = sip.get('general', 'outboundproxy')[0]
1122  except LookupError:
1123  outbound_proxy = ''
1124 
1125  for i in regs:
1126  reg = Registration(i, retry_interval, max_attempts, outbound_proxy)
1127  reg.write(pjsip, nmapped)
1128 
1129 
def map_registrations(sip, pjsip, nmapped)

◆ map_setvars()

def sip_to_pjsip.map_setvars (   sip,
  section,
  pjsip,
  nmapped 
)
Map all setvar in peer section to the appropriate endpoint set_var

Definition at line 1130 of file sip_to_pjsip.py.

References set_value().

Referenced by convert().

1130 def map_setvars(sip, section, pjsip, nmapped):
1131  """
1132  Map all setvar in peer section to the appropriate endpoint set_var
1133  """
1134  try:
1135  setvars = sip.section(section)[0].get('setvar')
1136  except LookupError:
1137  return
1138 
1139  for setvar in setvars:
1140  set_value('set_var', setvar, section, pjsip, nmapped)
1141 
1142 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def map_setvars(sip, section, pjsip, nmapped)

◆ map_system()

def sip_to_pjsip.map_system (   sip,
  pjsip,
  nmapped 
)

Definition at line 1181 of file sip_to_pjsip.py.

References set_value().

Referenced by convert().

1181 def map_system(sip, pjsip, nmapped):
1182  section = 'system' # Just a label; you as user can change that
1183  type = 'system' # Not a label, therefore not the same as section
1184 
1185  try:
1186  user_agent = sip.get('general', 'useragent')[0]
1187  set_value('user_agent', user_agent, 'global', pjsip, nmapped, 'global')
1188  except LookupError:
1189  pass
1190 
1191 
1192  try:
1193  sipdebug = sip.get('general', 'sipdebug')[0]
1194  set_value('debug', sipdebug, 'global', pjsip, nmapped, 'global')
1195  except LookupError:
1196  pass
1197 
1198  try:
1199  useroption_parsing = sip.get('general', 'legacy_useroption_parsing')[0]
1200  set_value('ignore_uri_user_options', useroption_parsing, 'global', pjsip, nmapped, 'global')
1201  except LookupError:
1202  pass
1203 
1204  try:
1205  timer_t1 = sip.get('general', 'timert1')[0]
1206  set_value('timer_t1', timer_t1, section, pjsip, nmapped, type)
1207  except LookupError:
1208  pass
1209 
1210  try:
1211  timer_b = sip.get('general', 'timerb')[0]
1212  set_value('timer_b', timer_b, section, pjsip, nmapped, type)
1213  except LookupError:
1214  pass
1215 
1216  try:
1217  compact_headers = sip.get('general', 'compactheaders')[0]
1218  set_value('compact_headers', compact_headers, section, pjsip, nmapped, type)
1219  except LookupError:
1220  pass
1221 
1222 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def map_system(sip, pjsip, nmapped)

◆ map_transports()

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 for each IP version. As such, the mapping
into PJSIP can be made consistent by defining six sections:

transport-udp6
transport-udp
transport-tcp6
transport-tcp
transport-tls6
transport-tls

To accommodate the default behaviors in sip.conf, we'll need to
create the UDP transports first, followed by the TCP and TLS transports.

Definition at line 873 of file sip_to_pjsip.py.

References create_tcp(), create_tls(), and create_udp().

Referenced by convert().

873 def map_transports(sip, pjsip, nmapped):
874  """
875  Finds options in sip.conf general section pertaining to
876  transport configuration and creates appropriate transport
877  configuration sections in pjsip.conf.
878 
879  sip.conf only allows a single UDP transport, TCP transport,
880  and TLS transport for each IP version. As such, the mapping
881  into PJSIP can be made consistent by defining six sections:
882 
883  transport-udp6
884  transport-udp
885  transport-tcp6
886  transport-tcp
887  transport-tls6
888  transport-tls
889 
890  To accommodate the default behaviors in sip.conf, we'll need to
891  create the UDP transports first, followed by the TCP and TLS transports.
892  """
893 
894  # First create a UDP transport. Even if no bind parameters were provided
895  # in sip.conf, chan_sip would always bind to UDP 0.0.0.0:5060
896  create_udp(sip, pjsip, nmapped)
897  create_udp(sip, pjsip, nmapped)
898 
899  # TCP settings may be dependent on UDP settings, so do it second.
900  create_tcp(sip, pjsip, nmapped)
901  create_tcp(sip, pjsip, nmapped)
902  create_tls(sip, pjsip, nmapped)
903  create_tls(sip, pjsip, nmapped)
904 
905 
def create_tls(sip, pjsip, nmapped)
def map_transports(sip, pjsip, nmapped)
def create_udp(sip, pjsip, nmapped)
def create_tcp(sip, pjsip, nmapped)

◆ merge_codec_value()

def sip_to_pjsip.merge_codec_value (   key = None,
  val = None,
  section = None,
  pjsip = None,
  nmapped = None,
  type = 'endpoint',
  section_to = None,
  key_to = None 
)
Merge values from allow/deny with those from the default. Special treatment for all

Definition at line 93 of file sip_to_pjsip.py.

References merge_value(), and set_value().

Referenced by merge_value().

93  key_to=None):
94  """Merge values from allow/deny with those from the default. Special treatment for all"""
95  def _merge_codec_value(k, v, s, r, n):
96  merge_codec_value(key if key else k, v, s, r, n, type, section_to, key_to)
97 
98  # if no value or section return the merge_codec_value
99  # function with the enclosed key and type
100  if not val and not section:
101  return _merge_codec_value
102 
103  if key == 'allow':
104  try:
105  disallow = sip.get(section, 'disallow')[0]
106  if disallow == 'all':
107  #don't inherit
108  for i in sip.get(section, 'allow'):
109  set_value(key, i, section, pjsip, nmapped, type)
110  else:
111  merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)
112  except LookupError:
113  print("lookup error", file=sys.stderr)
114  merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)
115  return
116  elif key == 'disallow':
117  try:
118  allow = sip.get(section, 'allow')[0]
119  if allow == 'all':
120  #don't inherit
121  for i in sip.get(section, 'disallow'):
122  set_value(key, i, section, pjsip, nmapped, type)
123  else:
124  merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)
125  except LookupError:
126  merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)
127  return
128  else:
129  merge_value(key, val, section, pjsip, nmapped, type, section_to, key_to)
130 
131 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def merge_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint', section_to=None, key_to=None)
Definition: sip_to_pjsip.py:70
def merge_codec_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint', section_to=None, key_to=None)
Definition: sip_to_pjsip.py:93

◆ merge_value()

def sip_to_pjsip.merge_value (   key = None,
  val = None,
  section = None,
  pjsip = None,
  nmapped = None,
  type = 'endpoint',
  section_to = None,
  key_to = None 
)
Merge values from the given section with those from the default.

Definition at line 70 of file sip_to_pjsip.py.

References merge_codec_value(), and set_value().

Referenced by merge_codec_value(), set_transport_common(), and set_value().

70  key_to=None):
71  """Merge values from the given section with those from the default."""
72  def _merge_value(k, v, s, r, n):
73  merge_value(key if key else k, v, s, r, n, type, section_to, key_to)
74 
75  # if no value or section return the merge_value
76  # function with the enclosed key and type
77  if not val and not section:
78  return _merge_value
79 
80  # should return a single value section list
81  try:
82  sect = sip.section(section)[0]
83  except LookupError:
84  sect = sip.default(section)[0]
85  # for each merged value add it to pjsip.conf
86  for i in sect.get_merged(key):
87  set_value(key_to if key_to else key, i,
88  section_to if section_to else section,
89  pjsip, nmapped, type)
90 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def merge_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint', section_to=None, key_to=None)
Definition: sip_to_pjsip.py:70

◆ non_mapped()

def sip_to_pjsip.non_mapped (   nmapped)
Write non-mapped sip.conf values to the non-mapped object

Definition at line 132 of file sip_to_pjsip.py.

Referenced by convert().

132 def non_mapped(nmapped):
133  """Write non-mapped sip.conf values to the non-mapped object"""
134  def _non_mapped(section, key, val):
135  """Writes a non-mapped value from sip.conf to the non-mapped object."""
136  if section not in nmapped:
137  nmapped[section] = astconfigparser.Section()
138  if isinstance(val, list):
139  for v in val:
140  # since coming from sip.conf we can assume
141  # single section lists
142  nmapped[section][0][key] = v
143  else:
144  nmapped[section][0][key] = val
145  return _non_mapped
146 
def non_mapped(nmapped)

◆ section_by_type()

def sip_to_pjsip.section_by_type (   section,
  pjsip,
  type 
)

some utility functions

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

Definition at line 23 of file sip_to_pjsip.py.

References ignore().

Referenced by set_value().

23 def section_by_type(section, pjsip, type):
24  """Finds a section based upon the given type, adding it if not found."""
25  def __find_dict(mdicts, key, val):
26  """Given a list of multi-dicts, return the multi-dict that contains
27  the given key/value pair."""
28 
29  def found(d):
30  return key in d and val in d[key]
31 
32  try:
33  return [d for d in mdicts if found(d)][0]
34  except IndexError:
35  raise LookupError("Dictionary not located for key = %s, value = %s"
36  % (key, val))
37 
38  try:
39  return __find_dict(pjsip.section(section), 'type', type)
40  except LookupError:
41  # section for type doesn't exist, so add
42  sect = pjsip.add_section(section)
43  sect['type'] = type
44  return sect
45 
46 
def section_by_type(section, pjsip, type)
some utility functions
Definition: sip_to_pjsip.py:23

◆ set_direct_media()

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 224 of file sip_to_pjsip.py.

References set_value().

224 def set_direct_media(key, val, section, pjsip, nmapped):
225  """
226  Maps values from the sip.conf comma separated direct_media option
227  into pjsip.conf direct_media options.
228  """
229  if 'yes' in val:
230  set_value('direct_media', 'yes', section, pjsip, nmapped)
231  if 'update' in val:
232  set_value('direct_media_method', 'update', section, pjsip, nmapped)
233  if 'outgoing' in val:
234  set_value('directed_media_glare_mitigation', 'outgoing', section,
235  pjsip, nmapped)
236  if 'nonat' in val:
237  set_value('disable_directed_media_on_nat', 'yes', section, pjsip,
238  nmapped)
239  if 'no' in val:
240  set_value('direct_media', 'no', section, pjsip, nmapped)
241 
242 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def set_direct_media(key, val, section, pjsip, nmapped)

◆ set_dtmfmode()

def sip_to_pjsip.set_dtmfmode (   key,
  val,
  section,
  pjsip,
  nmapped 
)

mapping functions - define f(key, val, section) where key/val are the key/value pair to write to given section in pjsip.conf

Sets the dtmfmode value.  If value matches allowable option in pjsip
then map it, otherwise set it to none.

Definition at line 154 of file sip_to_pjsip.py.

References set_value().

154 def set_dtmfmode(key, val, section, pjsip, nmapped):
155  """
156  Sets the dtmfmode value. If value matches allowable option in pjsip
157  then map it, otherwise set it to none.
158  """
159  key = 'dtmf_mode'
160  # available pjsip.conf values: rfc4733, inband, info, none
161  if val == 'inband' or val == 'info':
162  set_value(key, val, section, pjsip, nmapped)
163  elif val == 'rfc2833':
164  set_value(key, 'rfc4733', section, pjsip, nmapped)
165  else:
166  nmapped(section, key, val + " ; did not fully map - set to none")
167  set_value(key, 'none', section, pjsip, nmapped)
168 
169 
def set_dtmfmode(key, val, section, pjsip, nmapped)
mapping functions - define f(key, val, section) where key/val are the key/value pair to write to give...
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53

◆ set_media_encryption()

def sip_to_pjsip.set_media_encryption (   key,
  val,
  section,
  pjsip,
  nmapped 
)
Sets the media_encryption value in pjsip.conf

Definition at line 251 of file sip_to_pjsip.py.

References set_value().

251 def set_media_encryption(key, val, section, pjsip, nmapped):
252  """Sets the media_encryption value in pjsip.conf"""
253  try:
254  dtls = sip.get(section, 'dtlsenable')[0]
255  if dtls == 'yes':
256  # If DTLS is enabled, then that overrides SDES encryption.
257  return
258  except LookupError:
259  pass
260 
261  if val == 'yes':
262  set_value('media_encryption', 'sdes', section, pjsip, nmapped)
263 
264 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def set_media_encryption(key, val, section, pjsip, nmapped)

◆ set_record_off_feature()

def sip_to_pjsip.set_record_off_feature (   key,
  val,
  section,
  pjsip,
  nmapped 
)
Sets the record_off_feature in pjsip.conf

Definition at line 277 of file sip_to_pjsip.py.

References from_recordfeature().

277 def set_record_off_feature(key, val, section, pjsip, nmapped):
278  """Sets the record_off_feature in pjsip.conf"""
279  from_recordfeature('record_off_feature', val, section, pjsip, nmapped)
280 
def from_recordfeature(key, val, section, pjsip, nmapped)
def set_record_off_feature(key, val, section, pjsip, nmapped)

◆ set_record_on_feature()

def sip_to_pjsip.set_record_on_feature (   key,
  val,
  section,
  pjsip,
  nmapped 
)
Sets the record_on_feature in pjsip.conf

Definition at line 273 of file sip_to_pjsip.py.

References from_recordfeature().

273 def set_record_on_feature(key, val, section, pjsip, nmapped):
274  """Sets the record_on_feature in pjsip.conf"""
275  from_recordfeature('record_on_feature', val, section, pjsip, nmapped)
276 
def from_recordfeature(key, val, section, pjsip, nmapped)
def set_record_on_feature(key, val, section, pjsip, nmapped)

◆ set_timers()

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 205 of file sip_to_pjsip.py.

References set_value().

205 def set_timers(key, val, section, pjsip, nmapped):
206  """
207  Sets the timers in pjsip.conf from the session-timers option
208  found in sip.conf.
209  """
210  # pjsip.conf values can be yes/no, required, always
211  # 'required' is a new feature of chan_pjsip, which rejects
212  # all SIP clients not supporting Session Timers
213  # 'Accept' is the default value of chan_sip and maps to 'yes'
214  # chan_sip ignores the case, for example 'session-timers=Refuse'
215  val = val.lower()
216  if val == 'originate':
217  set_value('timers', 'always', section, pjsip, nmapped)
218  elif val == 'refuse':
219  set_value('timers', 'no', section, pjsip, nmapped)
220  else:
221  set_value('timers', 'yes', section, pjsip, nmapped)
222 
223 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def set_timers(key, val, section, pjsip, nmapped)

◆ set_tls_cafile()

def sip_to_pjsip.set_tls_cafile (   val,
  pjsip,
  section,
  nmapped 
)
Sets ca_list_file based on sip.conf tlscafile

Definition at line 779 of file sip_to_pjsip.py.

References set_value().

779 def set_tls_cafile(val, pjsip, section, nmapped):
780  """Sets ca_list_file based on sip.conf tlscafile"""
781  set_value('ca_list_file', val, section, pjsip, nmapped,
782  'transport')
783 
784 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def set_tls_cafile(val, pjsip, section, nmapped)

◆ set_tls_capath()

def sip_to_pjsip.set_tls_capath (   val,
  pjsip,
  section,
  nmapped 
)
Sets ca_list_path based on sip.conf tlscapath

Definition at line 785 of file sip_to_pjsip.py.

References set_value().

785 def set_tls_capath(val, pjsip, section, nmapped):
786  """Sets ca_list_path based on sip.conf tlscapath"""
787  set_value('ca_list_path', val, section, pjsip, nmapped,
788  'transport')
789 
790 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def set_tls_capath(val, pjsip, section, nmapped)

◆ set_tls_cert_file()

def sip_to_pjsip.set_tls_cert_file (   val,
  pjsip,
  section,
  nmapped 
)
Sets cert_file based on sip.conf tlscertfile

Definition at line 762 of file sip_to_pjsip.py.

References set_value().

762 def set_tls_cert_file(val, pjsip, section, nmapped):
763  """Sets cert_file based on sip.conf tlscertfile"""
764  set_value('cert_file', val, section, pjsip, nmapped,
765  'transport')
766 
767 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def set_tls_cert_file(val, pjsip, section, nmapped)

◆ set_tls_cipher()

def sip_to_pjsip.set_tls_cipher (   val,
  pjsip,
  section,
  nmapped 
)
Sets cipher based on sip.conf tlscipher or sslcipher

Definition at line 774 of file sip_to_pjsip.py.

References set_value().

774 def set_tls_cipher(val, pjsip, section, nmapped):
775  """Sets cipher based on sip.conf tlscipher or sslcipher"""
776  set_value('cipher', val, section, pjsip, nmapped, 'transport')
777 
778 
def set_tls_cipher(val, pjsip, section, nmapped)
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53

◆ set_tls_private_key()

def sip_to_pjsip.set_tls_private_key (   val,
  pjsip,
  section,
  nmapped 
)
Sets privkey_file based on sip.conf tlsprivatekey or sslprivatekey

Definition at line 768 of file sip_to_pjsip.py.

References set_value().

768 def set_tls_private_key(val, pjsip, section, nmapped):
769  """Sets privkey_file based on sip.conf tlsprivatekey or sslprivatekey"""
770  set_value('priv_key_file', val, section, pjsip, nmapped,
771  'transport')
772 
773 
def set_tls_private_key(val, pjsip, section, nmapped)
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53

◆ set_tls_verifyclient()

def sip_to_pjsip.set_tls_verifyclient (   val,
  pjsip,
  section,
  nmapped 
)
Sets verify_client based on sip.conf tlsverifyclient

Definition at line 791 of file sip_to_pjsip.py.

References set_value().

791 def set_tls_verifyclient(val, pjsip, section, nmapped):
792  """Sets verify_client based on sip.conf tlsverifyclient"""
793  set_value('verify_client', val, section, pjsip, nmapped,
794  'transport')
795 
796 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def set_tls_verifyclient(val, pjsip, section, nmapped)

◆ set_tls_verifyserver()

def sip_to_pjsip.set_tls_verifyserver (   val,
  pjsip,
  section,
  nmapped 
)
Sets verify_server based on sip.conf tlsdontverifyserver

Definition at line 797 of file sip_to_pjsip.py.

References set_value().

797 def set_tls_verifyserver(val, pjsip, section, nmapped):
798  """Sets verify_server based on sip.conf tlsdontverifyserver"""
799 
800  if val == 'no':
801  set_value('verify_server', 'yes', section, pjsip, nmapped,
802  'transport')
803  else:
804  set_value('verify_server', 'no', section, pjsip, nmapped,
805  'transport')
806 
807 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def set_tls_verifyserver(val, pjsip, section, nmapped)

◆ set_transport_common()

def sip_to_pjsip.set_transport_common (   section,
  sip,
  pjsip,
  protocol,
  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:
externaddr (or externip)
externhost
externtcpport for TCP
externtlsport for TLS
localnet
tos_sip
cos_sip

Definition at line 610 of file sip_to_pjsip.py.

References merge_value(), set_value(), and split_hostport().

Referenced by create_tcp(), create_tls(), and create_udp().

610 def set_transport_common(section, sip, pjsip, protocol, nmapped):
611  """
612  sip.conf has several global settings that in pjsip.conf apply to individual
613  transports. This function adds these global settings to each individual
614  transport.
615 
616  The settings included are:
617  externaddr (or externip)
618  externhost
619  externtcpport for TCP
620  externtlsport for TLS
621  localnet
622  tos_sip
623  cos_sip
624  """
625  try:
626  extern_addr = sip.multi_get('general', ['externaddr', 'externip',
627  'externhost'])[0]
628  host, port = split_hostport(extern_addr)
629  try:
630  port = sip.get('general', 'extern' + protocol + 'port')[0]
631  except LookupError:
632  pass
633  set_value('external_media_address', host, section, pjsip,
634  nmapped, 'transport')
635  set_value('external_signaling_address', host, section, pjsip,
636  nmapped, 'transport')
637  if port:
638  set_value('external_signaling_port', port, section, pjsip,
639  nmapped, 'transport')
640  except LookupError:
641  pass
642 
643  try:
644  merge_value('localnet', sip.get('general', 'localnet')[0], 'general',
645  pjsip, nmapped, 'transport', section, "local_net")
646  except LookupError:
647  # No localnet options configured. Move on.
648  pass
649 
650  try:
651  set_value('tos', sip.get('general', 'tos_sip')[0], section, pjsip,
652  nmapped, 'transport')
653  except LookupError:
654  pass
655 
656  try:
657  set_value('cos', sip.get('general', 'cos_sip')[0], section, pjsip,
658  nmapped, 'transport')
659  except LookupError:
660  pass
661 
662 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def split_hostport(addr)
def merge_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint', section_to=None, key_to=None)
Definition: sip_to_pjsip.py:70
def set_transport_common(section, sip, pjsip, protocol, nmapped)

◆ set_value()

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 53 of file sip_to_pjsip.py.

References merge_value(), and section_by_type().

Referenced by create_tcp(), create_tls(), create_udp(), from_dtlsenable(), from_encryption_taglen(), from_host(), from_mailbox(), from_nat(), from_progressinband(), from_recordfeature(), from_sendrpid(), map_auth(), map_setvars(), map_system(), merge_codec_value(), merge_value(), set_direct_media(), set_dtmfmode(), set_media_encryption(), set_timers(), set_tls_cafile(), set_tls_capath(), set_tls_cert_file(), set_tls_cipher(), set_tls_private_key(), set_tls_verifyclient(), set_tls_verifyserver(), set_transport_common(), setup_auth(), setup_ident(), setup_udptl(), and Registration.write().

53  nmapped=None, type='endpoint'):
54  """Sets the key to the value within the section in pjsip.conf"""
55  def _set_value(k, v, s, r, n):
56  set_value(key if key else k, v, s, r, n, type)
57 
58  # if no value or section return the set_value
59  # function with the enclosed key and type
60  if not val and not section:
61  return _set_value
62 
63  # otherwise try to set the value
64  section_by_type(section, pjsip, type)[key] = \
65  val[0] if isinstance(val, list) else val
66 
67 
def section_by_type(section, pjsip, type)
some utility functions
Definition: sip_to_pjsip.py:23
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53

◆ setup_auth()

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 378 of file sip_to_pjsip.py.

References set_value().

378 def setup_auth(key, val, section, pjsip, nmapped):
379  """
380  Sets up authentication information for a specific endpoint based on the
381  'secret' setting on a peer in sip.conf
382  """
383  set_value('username', section, section, pjsip, nmapped, 'auth')
384  # In chan_sip, if a secret and an md5secret are both specified on a peer,
385  # then in practice, only the md5secret is used. If both are encountered
386  # then we build an auth section that has both an md5_cred and password.
387  # However, the auth_type will indicate to authenticators to use the
388  # md5_cred, so like with sip.conf, the password will be there but have
389  # no purpose.
390  if key == 'secret':
391  set_value('password', val, section, pjsip, nmapped, 'auth')
392  else:
393  set_value('md5_cred', val, section, pjsip, nmapped, 'auth')
394  set_value('auth_type', 'md5', section, pjsip, nmapped, 'auth')
395 
396  realms = [section]
397  try:
398  auths = sip.get('authentication', 'auth')
399  for i in auths:
400  user, at, realm = i.partition('@')
401  realms.append(realm)
402  except LookupError:
403  pass
404 
405  realm_str = ','.join(realms)
406 
407  set_value('auth', section, section, pjsip, nmapped)
408  set_value('outbound_auth', realm_str, section, pjsip, nmapped)
409 
410 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def setup_auth(key, val, section, pjsip, nmapped)

◆ setup_ident()

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 411 of file sip_to_pjsip.py.

References set_value().

411 def setup_ident(key, val, section, pjsip, nmapped):
412  """
413  Examines the 'type' field for a sip.conf peer and creates an identify
414  section if the type is either 'peer' or 'friend'. The identify section uses
415  either the host or defaultip field of the sip.conf peer.
416  """
417  if val != 'peer' and val != 'friend':
418  return
419 
420  try:
421  ip = sip.get(section, 'host')[0]
422  except LookupError:
423  return
424 
425  if ip == 'dynamic':
426  try:
427  ip = sip.get(section, 'defaultip')[0]
428  except LookupError:
429  return
430 
431  set_value('endpoint', section, section, pjsip, nmapped, 'identify')
432  set_value('match', ip, section, pjsip, nmapped, 'identify')
433 
434 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def setup_ident(key, val, section, pjsip, nmapped)

◆ setup_udptl()

def sip_to_pjsip.setup_udptl (   section,
  pjsip,
  nmapped 
)
Sets values from udptl into the appropriate pjsip.conf options.

Definition at line 170 of file sip_to_pjsip.py.

References set_value().

Referenced by map_peer().

170 def setup_udptl(section, pjsip, nmapped):
171  """Sets values from udptl into the appropriate pjsip.conf options."""
172  try:
173  val = sip.get(section, 't38pt_udptl')[0]
174  except LookupError:
175  try:
176  val = sip.get('general', 't38pt_udptl')[0]
177  except LookupError:
178  return
179 
180  ec = 'none'
181  if 'yes' in val:
182  set_value('t38_udptl', 'yes', section, pjsip, nmapped)
183  if 'no' in val:
184  set_value('t38_udptl', 'no', section, pjsip, nmapped)
185  if 'redundancy' in val:
186  ec = 'redundancy'
187  if 'fec' in val:
188  ec = 'fec'
189  set_value('t38_udptl_ec', ec, section, pjsip, nmapped)
190 
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53
def setup_udptl(section, pjsip, nmapped)

◆ split_hostport()

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

Definition at line 589 of file sip_to_pjsip.py.

Referenced by get_bind(), load_module(), set_transport_common(), and unload_module().

589 def split_hostport(addr):
590  """
591  Given an address in the form 'host:port' separate the host and port
592  components.
593  Returns a two-tuple of strings, (host, port). If no port is present in the
594  string, then the port section of the tuple is None.
595  """
596  try:
597  socket.inet_pton(socket.AF_INET6, addr)
598  if not addr.startswith('['):
599  return (addr, None)
600  except socket.error:
601  pass
602 
603  # Literal IPv6 (like [::]), IPv4, or hostname
604  # does not work for IPv6 without brackets; case catched above
605  url = urlparse('sip://' + addr)
606  # TODO Does not compress IPv6, for example 0:0:0:0:0:0:0:0 should get [::]
607  return (url.hostname, url.port)
608 
609 
def split_hostport(addr)

◆ write_pjsip()

def sip_to_pjsip.write_pjsip (   filename,
  pjsip,
  non_mappings 
)
Write pjsip.conf file to disk

Definition at line 1255 of file sip_to_pjsip.py.

References astconfigparser.write_dicts().

1255 def write_pjsip(filename, pjsip, non_mappings):
1256  """
1257  Write pjsip.conf file to disk
1258  """
1259  try:
1260  with open(filename, 'wt') as fp:
1261  fp.write(';--\n')
1262  fp.write(';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n')
1263  fp.write('Non mapped elements start\n')
1264  fp.write(';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n\n')
1265  astconfigparser.write_dicts(fp, non_mappings[filename])
1266  fp.write(';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n')
1267  fp.write('Non mapped elements end\n')
1268  fp.write(';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n')
1269  fp.write('--;\n\n')
1270  # write out include file(s)
1271  pjsip.write(fp)
1272 
1273  except IOError:
1274  print("Could not open file " + filename + " for writing", file=sys.stderr)
1275 
def write_pjsip(filename, pjsip, non_mappings)
def write_dicts(config_file, mdicts)

Variable Documentation

◆ non_mappings

non_mappings

Definition at line 1322 of file sip_to_pjsip.py.

◆ peer_map

list peer_map

Definition at line 452 of file sip_to_pjsip.py.

◆ pjsip

pjsip

Definition at line 1322 of file sip_to_pjsip.py.

◆ pjsip_filename

pjsip_filename

Definition at line 1314 of file sip_to_pjsip.py.

◆ PREFIX

string PREFIX = 'pjsip_'

Definition at line 15 of file sip_to_pjsip.py.

◆ QUIET

bool QUIET = False

Definition at line 16 of file sip_to_pjsip.py.

◆ sip

Definition at line 1316 of file sip_to_pjsip.py.

◆ sip_filename

sip_filename

Definition at line 1314 of file sip_to_pjsip.py.