Asterisk - The Open Source Telephony Project GIT-master-f36a736
Public Member Functions | Data Fields
Registration Class Reference

Public Member Functions

def __init__ (self, line, retry_interval, max_attempts, outbound_proxy)
 
def parse (self, line)
 
def parse_host_part (self, host_part)
 
def parse_user_part (self, user_part)
 
def write (self, pjsip, nmapped)
 

Data Fields

 authuser
 
 domain
 
 expiry
 
 extension
 
 max_attempts
 
 outbound_proxy
 
 peer
 
 port
 
 protocol
 
 retry_interval
 
 secret
 

Detailed Description

Class for parsing and storing information in a register line in sip.conf.

Definition at line 945 of file sip_to_pjsip.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  line,
  retry_interval,
  max_attempts,
  outbound_proxy 
)

Definition at line 949 of file sip_to_pjsip.py.

949 def __init__(self, line, retry_interval, max_attempts, outbound_proxy):
950 self.retry_interval = retry_interval
951 self.max_attempts = max_attempts
952 self.outbound_proxy = outbound_proxy
953 self.parse(line)
954

Member Function Documentation

◆ parse()

def parse (   self,
  line 
)
Initial parsing routine for register lines in sip.conf.

This splits the line into the part before the host, and the part
after the '@' symbol. These two parts are then passed to their
own parsing routines

Definition at line 955 of file sip_to_pjsip.py.

955 def parse(self, line):
956 """
957 Initial parsing routine for register lines in sip.conf.
958
959 This splits the line into the part before the host, and the part
960 after the '@' symbol. These two parts are then passed to their
961 own parsing routines
962 """
963
964 # register =>
965 # [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry]
966
967 prehost, at, host_part = line.rpartition('@')
968 if not prehost:
969 raise
970
971 self.parse_host_part(host_part)
972 self.parse_user_part(prehost)
973

References Registration.parse_host_part(), and Registration.parse_user_part().

◆ parse_host_part()

def parse_host_part (   self,
  host_part 
)
Parsing routine for the part after the final '@' in a register line.
The strategy is to use partition calls to peel away the data starting
from the right and working to the left.

Definition at line 974 of file sip_to_pjsip.py.

974 def parse_host_part(self, host_part):
975 """
976 Parsing routine for the part after the final '@' in a register line.
977 The strategy is to use partition calls to peel away the data starting
978 from the right and working to the left.
979 """
980 pre_expiry, sep, expiry = host_part.partition('~')
981 pre_extension, sep, self.extension = pre_expiry.partition('/')
982 self.host, sep, self.port = pre_extension.partition(':')
983
984 self.expiry = expiry if expiry else '120'
985

Referenced by Registration.parse().

◆ parse_user_part()

def parse_user_part (   self,
  user_part 
)
Parsing routine for the part before the final '@' in a register line.
The only mandatory part of this line is the user portion. The strategy
here is to start by using partition calls to remove everything to
the right of the user, then finish by using rpartition calls to remove
everything to the left of the user.

Definition at line 986 of file sip_to_pjsip.py.

986 def parse_user_part(self, user_part):
987 """
988 Parsing routine for the part before the final '@' in a register line.
989 The only mandatory part of this line is the user portion. The strategy
990 here is to start by using partition calls to remove everything to
991 the right of the user, then finish by using rpartition calls to remove
992 everything to the left of the user.
993 """
994 self.peer = ''
995 self.protocol = 'udp'
996 protocols = ['udp', 'tcp', 'tls']
997 for protocol in protocols:
998 position = user_part.find(protocol + '://')
999 if -1 < position:
1000 post_transport = user_part[position + 6:]
1001 self.peer, sep, self.protocol = user_part[:position + 3].rpartition('?')
1002 user_part = post_transport
1003 break
1004
1005 colons = user_part.count(':')
1006 if (colons == 3):
1007 # :domainport:secret:authuser
1008 pre_auth, sep, port_auth = user_part.partition(':')
1009 self.domainport, sep, auth = port_auth.partition(':')
1010 self.secret, sep, self.authuser = auth.partition(':')
1011 elif (colons == 2):
1012 # :secret:authuser
1013 pre_auth, sep, auth = user_part.partition(':')
1014 self.secret, sep, self.authuser = auth.partition(':')
1015 elif (colons == 1):
1016 # :secret
1017 pre_auth, sep, self.secret = user_part.partition(':')
1018 elif (colons == 0):
1019 # No port, secret, or authuser
1020 pre_auth = user_part
1021 else:
1022 # Invalid setting
1023 raise
1024
1025 self.user, sep, self.domain = pre_auth.partition('@')
1026

Referenced by Registration.parse().

◆ write()

def write (   self,
  pjsip,
  nmapped 
)
Write parsed registration data into a section in pjsip.conf

Most of the data in self will get written to a registration section.
However, there will also need to be an auth section created if a
secret or authuser is present.

General mapping of values:
A combination of self.host and self.port is server_uri
A combination of self.user, self.domain, and self.domainport is
  client_uri
self.expiry is expiration
self.extension is contact_user
self.protocol will map to one of the mapped transports
self.secret and self.authuser will result in a new auth section, and
  outbound_auth will point to that section.
XXX self.peer really doesn't map to anything :(

Definition at line 1027 of file sip_to_pjsip.py.

1027 def write(self, pjsip, nmapped):
1028 """
1029 Write parsed registration data into a section in pjsip.conf
1030
1031 Most of the data in self will get written to a registration section.
1032 However, there will also need to be an auth section created if a
1033 secret or authuser is present.
1034
1035 General mapping of values:
1036 A combination of self.host and self.port is server_uri
1037 A combination of self.user, self.domain, and self.domainport is
1038 client_uri
1039 self.expiry is expiration
1040 self.extension is contact_user
1041 self.protocol will map to one of the mapped transports
1042 self.secret and self.authuser will result in a new auth section, and
1043 outbound_auth will point to that section.
1044 XXX self.peer really doesn't map to anything :(
1045 """
1046
1047 section = 'reg_' + self.host
1048
1049 set_value('retry_interval', self.retry_interval, section, pjsip,
1050 nmapped, 'registration')
1051 set_value('max_retries', self.max_attempts, section, pjsip, nmapped,
1052 'registration')
1053 if self.extension:
1054 set_value('contact_user', self.extension, section, pjsip, nmapped,
1055 'registration')
1056
1057 set_value('expiration', self.expiry, section, pjsip, nmapped,
1058 'registration')
1059
1060 if self.protocol == 'udp':
1061 set_value('transport', 'transport-udp', section, pjsip, nmapped,
1062 'registration')
1063 elif self.protocol == 'tcp':
1064 set_value('transport', 'transport-tcp', section, pjsip, nmapped,
1065 'registration')
1066 elif self.protocol == 'tls':
1067 set_value('transport', 'transport-tls', section, pjsip, nmapped,
1068 'registration')
1069
1070 auth_section = 'auth_reg_' + self.host
1071
1072 if hasattr(self, 'secret') and self.secret:
1073 set_value('password', self.secret, auth_section, pjsip, nmapped,
1074 'auth')
1075 set_value('username', self.authuser if hasattr(self, 'authuser')
1076 else self.user, auth_section, pjsip, nmapped, 'auth')
1077 set_value('outbound_auth', auth_section, section, pjsip, nmapped,
1078 'registration')
1079
1080 client_uri = "sip:%s@" % self.user
1081 if self.domain:
1082 client_uri += self.domain
1083 else:
1084 client_uri += self.host
1085
1086 if hasattr(self, 'domainport') and self.domainport:
1087 client_uri += ":" + self.domainport
1088 elif self.port:
1089 client_uri += ":" + self.port
1090
1091 set_value('client_uri', client_uri, section, pjsip, nmapped,
1092 'registration')
1093
1094 server_uri = "sip:%s" % self.host
1095 if self.port:
1096 server_uri += ":" + self.port
1097
1098 set_value('server_uri', server_uri, section, pjsip, nmapped,
1099 'registration')
1100
1101 if self.outbound_proxy:
1102 set_value('outboundproxy', self.outbound_proxy, section, pjsip,
1103 nmapped, 'registration')
1104
1105
def set_value(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:53

References Registration.authuser, minivm_account.domain, Registration.domain, ast_sip_transport.domain, ast_sip_domain_alias.domain, ast_http_digest.domain, iax2_peer.expiry, chan_iax2_pvt.expiry, iax2_dpcache.expiry, Registration.expiry, gosub_stack_frame.extension, unistim_device.extension, Registration.extension, ast_cel_event_record.extension, rtp_extmap.extension, ast_ari_channels_originate_args.extension, ast_ari_channels_originate_with_id_args.extension, ast_ari_channels_continue_in_dialplan_args.extension, stasis_app_control_continue_data.extension, ooh323_pvt.host, chan_iax2_pvt.host, ast_dns_srv_record.host, ast_sip_transport_state.host, ast_sip_transport.host, srv_entry.host, ast_uri.host, websocket_client.host, acl.host, srv_record.host, Registration.max_attempts, Registration.outbound_proxy, ast_sip_contact.outbound_proxy, ast_sip_aor.outbound_proxy, ast_sip_endpoint.outbound_proxy, ast_sip_outbound_publish.outbound_proxy, sip_outbound_registration.outbound_proxy, ooh323_pvt.peer, chan_iax2_pvt.peer, parsed_dial_string.peer, Registration.peer, ast_cel_event_record.peer, oprmode.peer, ast_channel_snapshot.peer, ast_bridge_thread_obj.peer, ast_exten.peer, dial_target.peer, ooh323_pvt.port, ooh323_peer.port, iax2_registry.port, parsed_dial_string.port, iax_template.port, Registration.port, ast_dns_srv_record.port, srv_entry.port, stun_addr.port, ast_uri.port, multicast_control_packet.port, ast_xmpp_client_config.port, srv_record.port, sms_s.protocol, Registration.protocol, dundi_answer.protocol, ast_aeap_client_config.protocol, return_reason_data.protocol, Registration.retry_interval, sip_outbound_registration.retry_interval, sip_outbound_registration_client_state.retry_interval, iax2_user.secret, iax2_peer.secret, iax2_registry.secret, chan_iax2_pvt.secret, create_addr_info.secret, Registration.secret, ast_manager_user.secret, caldav_pvt.secret, ewscal_pvt.secret, exchangecal_pvt.secret, icalendar_pvt.secret, sip_to_pjsip.set_value(), ooh323_pvt.user, confbridge_hook_data.user, dtmf_menu_hook_pvt.user, iax_template.user, ast_calendar_tech.user, parking_limits_pvt.user, caldav_pvt.user, ewscal_pvt.user, exchangecal_pvt.user, icalendar_pvt.user, http_route.user, sip_outbound_publisher.user, and ast_xmpp_client_config.user.

Referenced by MultiOrderedConfigParser.write().

Field Documentation

◆ authuser

authuser

Definition at line 1010 of file sip_to_pjsip.py.

Referenced by Registration.write().

◆ domain

domain

Definition at line 1025 of file sip_to_pjsip.py.

Referenced by Registration.write().

◆ expiry

expiry

Definition at line 984 of file sip_to_pjsip.py.

Referenced by Registration.write().

◆ extension

Definition at line 981 of file sip_to_pjsip.py.

Referenced by Registration.write().

◆ max_attempts

max_attempts

Definition at line 951 of file sip_to_pjsip.py.

Referenced by Registration.write().

◆ outbound_proxy

outbound_proxy

Definition at line 952 of file sip_to_pjsip.py.

Referenced by Registration.write().

◆ peer

peer

Definition at line 994 of file sip_to_pjsip.py.

Referenced by Registration.write().

◆ port

port

Definition at line 982 of file sip_to_pjsip.py.

Referenced by Registration.write().

◆ protocol

protocol

Definition at line 995 of file sip_to_pjsip.py.

Referenced by Registration.write().

◆ retry_interval

retry_interval

Definition at line 950 of file sip_to_pjsip.py.

Referenced by Registration.write().

◆ secret

secret

Definition at line 1017 of file sip_to_pjsip.py.

Referenced by Registration.write().


The documentation for this class was generated from the following file: