def _create_account_on_server(self, account, refcfg): vtable = {} tmp_identity = account.modified_identity.clone() vtable['registration_state_changed'] = AccountManager.account_created_on_server_cb vtable['auth_info_requested'] = AccountManager.account_created_auth_requested_cb lc = CoreManager.configure_lc_from(vtable, tester_resources_path, None, account) lc.sip_transports = linphone.SipTransports(-1, -1, -1, -1) cfg = lc.create_proxy_config() tmp_identity.secure = False tmp_identity.password = account.password tmp_identity.set_header("X-Create-Account", "yes") cfg.identity_address = tmp_identity server_addr = linphone.Address.new(refcfg.server_addr) server_addr.secure = False server_addr.transport = linphone.TransportType.Tcp; server_addr.port = 0 cfg.server_addr = server_addr.as_string() cfg.expires = 3 * 3600 # Accounts are valid 3 hours lc.add_proxy_config(cfg) if AccountManager.wait_for_until(lc, None, lambda lc: lc.user_data().created == True, 10000) != True: linphonetester_logger.critical("[TESTER] Account for {identity} could not be created on server.".format(identity=refcfg.identity_address.as_string())) sys.exit(-1) cfg.edit() cfg.identity_address = account.modified_identity.clone() cfg.identity_address.secure = False cfg.done() ai = linphone.AuthInfo.new(account.modified_identity.username, None, account.password, None, None, account.modified_identity.domain) lc.add_auth_info(ai) if AccountManager.wait_for_until(lc, None, lambda lc: lc.user_data().registered == True, 3000) != True: linphonetester_logger.critical("[TESTER] Account for {identity} is not working on server.".format(identity=refcfg.identity_address.as_string())) sys.exit(-1) lc.remove_proxy_config(cfg) if AccountManager.wait_for_until(lc, None, lambda lc: lc.user_data().done == True, 3000) != True: linphonetester_logger.critical("[TESTER] Account creation could not clean the registration context.") sys.exit(-1)
def test_simple_tcp_register_compatibility_mode(self): cm = RegisterCoreManager() cm.register_with_refresh(False, test_domain, "sip:{route}".format(route=test_route), transport=linphone.SipTransports( 0, 5070, 0, 0))
def test_transport_change(self): cm = CoreManager('multi_account_rc', False) number_of_udp_proxies = reduce( lambda x, y: x + int(y.transport == "udp"), cm.lc.proxy_config_list, 0) total_number_of_proxies = len(cm.lc.proxy_config_list) assert_equals( CoreManager.wait_for( cm, cm, lambda cm1, cm2: cm1.stats. number_of_LinphoneRegistrationOk == total_number_of_proxies), True) register_ok = cm.stats.number_of_LinphoneRegistrationOk # Keep only UDP tr = linphone.SipTransports(0, 0, 0, 0) tr.udp_port = cm.lc.sip_transports.udp_port cm.lc.sip_transports = tr assert_equals( CoreManager.wait_for( cm, cm, lambda cm1, cm2: cm1.stats.number_of_LinphoneRegistrationOk == (register_ok + number_of_udp_proxies)), True) assert_equals( CoreManager.wait_for( cm, cm, lambda cm1, cm2: cm1.stats. number_of_LinphoneRegistrationFailed == (total_number_of_proxies - number_of_udp_proxies)), True)
def register_with_refresh( self, refresh, domain, route, late_auth_info=False, transport=linphone.SipTransports(5070, 5070, 5071, 0), expected_final_state=linphone.RegistrationState.Ok): self.register_with_refresh_base( refresh, domain, route, late_auth_info, expected_final_state=expected_final_state)
def register_with_refresh_base( self, refresh, domain, route, late_auth_info=False, transport=linphone.SipTransports(5070, 5070, 5071, 0), expected_final_state=linphone.RegistrationState.Ok): assert self.lc is not None self.stats.reset() self.lc.sip_transports = transport proxy_cfg = self.lc.create_proxy_config() from_address = create_address(domain) proxy_cfg.identity = from_address.as_string() server_addr = from_address.domain proxy_cfg.register_enabled = True proxy_cfg.expires = 1 if route is None: proxy_cfg.server_addr = server_addr else: proxy_cfg.route = route proxy_cfg.server_addr = route self.lc.add_proxy_config(proxy_cfg) self.lc.default_proxy_config = proxy_cfg retry = 0 expected_count = 1 if refresh: expected_count += 1 max_retry = 110 if expected_final_state == linphone.RegistrationState.Progress: max_retry += 200 while self.stats.number_of_LinphoneRegistrationOk < expected_count and retry < max_retry: retry += 1 self.lc.iterate() if self.stats.number_of_auth_info_requested > 0 and proxy_cfg.state == linphone.RegistrationState.Failed and late_auth_info: if len(self.lc.auth_info_list) == 0: assert_equals(proxy_cfg.error, linphone.Reason.Unauthorized) info = linphone.AuthInfo.new( test_username, None, test_password, None, None, None) # Create authentication structure from identity self.lc.add_auth_info(info) if proxy_cfg.error == linphone.Reason.Forbidden or \ (self.stats.number_of_auth_info_requested > 2 and proxy_cfg.error == linphone.Reason.Unauthorized): break time.sleep(0.1) assert_equals(proxy_cfg.state, expected_final_state) assert_equals(self.stats.number_of_LinphoneRegistrationNone, 0) assert self.stats.number_of_LinphoneRegistrationProgress >= 1 if expected_final_state == linphone.RegistrationState.Ok: assert_equals(self.stats.number_of_LinphoneRegistrationOk, expected_count) expected_failed = 0 if late_auth_info: expected_failed = 1 assert_equals(self.stats.number_of_LinphoneRegistrationFailed, expected_failed) else: assert_equals(self.stats.number_of_LinphoneRegistrationCleared, 0)
def test_authenticated_register_with_late_credentials(self): cm = RegisterCoreManager() cm.register_with_refresh(False, auth_domain, "sip:{route}".format(route=test_route), True, linphone.SipTransports(5070, 5070, 5071, 0)) assert_equals(cm.stats.number_of_auth_info_requested, 1)
def start(self): DoorPi().event_handler('OnSipPhoneCreate', __name__) self.core.max_calls = conf.get_int(SIPPHONE_SECTION, 'ua.max_calls', 2) self.core.echo_cancellation_enabled = conf.get_bool( SIPPHONE_SECTION, 'echo_cancellation_enabled', False) # set local listen ports, default: random self.core.sip_transports = lin.SipTransports( conf.get_int(SIPPHONE_SECTION, 'local_port', 5060), conf.get_int(SIPPHONE_SECTION, 'local_port', 5060), -1, -1) self.core.video_display_enabled = conf.get_bool( SIPPHONE_SECTION, 'video_display_enabled', False) self.core.stun_server = conf.get(SIPPHONE_SECTION, 'stun_server', '') firewall_policy = conf.get(SIPPHONE_SECTION, 'FirewallPolicy', 'PolicyNoFirewall') if firewall_policy == "PolicyNoFirewall": self.core.firewall_policy = lin.FirewallPolicy.PolicyNoFirewall elif firewall_policy == "PolicyUseNatAddress": self.core.firewall_policy = lin.FirewallPolicy.PolicyUseNatAddress elif firewall_policy == "PolicyUseStun": self.core.firewall_policy = lin.FirewallPolicy.PolicyUseStun elif firewall_policy == "PolicyUseIce": self.core.firewall_policy = lin.FirewallPolicy.PolicyUseIce elif firewall_policy == "PolicyUseUpnp": self.core.firewall_policy = lin.FirewallPolicy.PolicyUseUpnp else: self.core.firewall_policy = lin.FirewallPolicy.PolicyNoFirewall #http://pythonhosted.org/linphone/api_reference.html#linphone.Core.in_call_timeout #After this timeout period, the call is automatically hangup. self.core.in_call_timeout = conf.get_int(SIPPHONE_SECTION, 'max_call_time', 120) #http://pythonhosted.org/linphone/api_reference.html#linphone.Core.inc_timeout #If an incoming call isn’t answered for this timeout period, it is automatically declined. self.core.inc_timeout = conf.get_int(SIPPHONE_SECTION, 'call_timeout', 15) self.__player = LinphonePlayer() self.core.ringback = self.player.player_filename self.__recorder = LinphoneRecorder() if len(self.core.sound_devices) == 0: logger.warning('no audio devices available') else: self.core.capture_device = conf.get(SIPPHONE_SECTION, 'capture_device', self.core.capture_device) self.core.playback_device = conf.get(SIPPHONE_SECTION, 'playback_device', self.core.playback_device) self.core.mic_gain_db = conf.get_float(SIPPHONE_SECTION, 'mic_gain_db', 0) logger.info("found %s possible sounddevices:", len(self.core.sound_devices)) logger.debug("|rec|play| name") logger.debug("------------------------------------") for sound_device in self.core.sound_devices: logger.debug( "| %s | %s | %s", 'X' if self.core.sound_device_can_capture(sound_device) else 'O', 'X' if self.core.sound_device_can_playback(sound_device) else 'O', sound_device) logger.debug("------------------------------------") logger.debug("using capture_device: %s", self.core.capture_device) logger.debug("using playback_device: %s", self.core.playback_device) logger.debug("mic_gain_db: %s", self.core.mic_gain_db) # Only enable PCMU and PCMA audio codecs by default config_audio_codecs = conf.get_list(SIPPHONE_SECTION, 'audio_codecs', 'PCMA,PCMU') for codec in self.core.audio_codecs: if codec.mime_type in config_audio_codecs: logger.debug('enable audio codec %s', codec.mime_type) self.core.enable_payload_type(codec, True) else: logger.debug('disable audio codec %s', codec.mime_type) self.core.enable_payload_type(codec, False) if len(self.core.video_devices) == 0: self.core.video_capture_enabled = False logger.warning('no video devices available') else: logger.info("found %s possible videodevices:", len(self.core.video_devices)) logger.debug("| name") logger.debug("------------------------------------") for video_device in self.core.video_devices: logger.debug("| %s ", video_device) logger.debug("------------------------------------") config_camera = conf.get(SIPPHONE_SECTION, 'video_device', self.core.video_devices[0]) if config_camera not in self.core.video_devices: logger.warning( 'camera "%s" from config does not exist in possible video devices.', config_camera) logger.debug('switching to first possible video device "%s"', self.core.video_devices[0]) config_camera = self.core.video_devices[0] self.core.video_capture_enabled = True self.core.video_device = config_camera self.core.preferred_video_size_by_name = conf.get( SIPPHONE_SECTION, 'video_size', 'vga') logger.debug("using video_device: %s", self.core.video_device) # Only enable VP8 video codec config_video_codecs = conf.get_list(SIPPHONE_SECTION, 'video_codecs', 'VP8') for codec in self.core.video_codecs: if codec.mime_type in config_video_codecs and self.core.video_capture_enabled: logger.debug('enable video codec %s', codec.mime_type) self.core.enable_payload_type(codec, True) else: logger.debug('disable video codec %s', codec.mime_type) self.core.enable_payload_type(codec, False) # Configure the SIP account server = conf.get(SIPPHONE_SECTION, "sipserver_server") username = conf.get(SIPPHONE_SECTION, "sipserver_username") password = conf.get(SIPPHONE_SECTION, "sipserver_password", username) realm = conf.get(SIPPHONE_SECTION, "sipserver_realm", server) if server and username and password: logger.info('using DoorPi with SIP-Server') proxy_cfg = self.core.create_proxy_config() proxy_cfg.identity_address = lin.Address.new( "%s <sip:%s@%s>" % (conf.get(SIPPHONE_SECTION, "identity", 'DoorPi'), username, server)) proxy_cfg.server_addr = "sip:%s" % server proxy_cfg.register_enabled = True self.core.add_proxy_config(proxy_cfg) self.core.default_proxy_config = proxy_cfg auth_info = self.core.create_auth_info(username, None, password, None, None, realm) self.core.add_auth_info(auth_info) else: logger.info('using DoorPi without SIP-Server? Okay...') proxy_cfg = self.core.create_proxy_config() proxy_cfg.register_enabled = False self.core.add_proxy_config(proxy_cfg) self.core.default_proxy_config = proxy_cfg logger.debug('%s', self.core.proxy_config_list) logger.debug("start successfully")
def start(self): DoorPi().event_handler('OnSipPhoneCreate', __name__) self.core.max_calls = conf.get_int(SIPPHONE_SECTION, 'ua.max_calls', 2) self.core.echo_cancellation_enabled = conf.get_bool(SIPPHONE_SECTION, 'echo_cancellation_enabled', False) # set local listen ports, default: random self.core.sip_transports = lin.SipTransports(conf.get_int(SIPPHONE_SECTION, 'local_port', 5060), conf.get_int(SIPPHONE_SECTION, 'local_port', 5060), -1, -1) self.core.video_display_enabled = conf.get_bool(SIPPHONE_SECTION, 'video_display_enabled', False) self.core.stun_server = conf.get(SIPPHONE_SECTION, 'stun_server', '') firewall_policy = conf.get(SIPPHONE_SECTION, 'FirewallPolicy', 'PolicyNoFirewall') if firewall_policy == 'PolicyNoFirewall': self.core.firewall_policy = lin.FirewallPolicy.PolicyNoFirewall elif firewall_policy == 'PolicyUseNatAddress': self.core.firewall_policy = lin.FirewallPolicy.PolicyUseNatAddress elif firewall_policy == 'PolicyUseStun': self.core.firewall_policy = lin.FirewallPolicy.PolicyUseStun elif firewall_policy == 'PolicyUseIce': self.core.firewall_policy = lin.FirewallPolicy.PolicyUseIce elif firewall_policy == 'PolicyUseUpnp': self.core.firewall_policy = lin.FirewallPolicy.PolicyUseUpnp else: self.core.firewall_policy = lin.FirewallPolicy.PolicyNoFirewall # After this timeout period, the call is automatically hangup. self.core.in_call_timeout = conf.get_int(SIPPHONE_SECTION, 'max_call_time', 120) # If an incoming call isn’t answered for this timeout period, it is automatically declined. self.core.inc_timeout = conf.get_int(SIPPHONE_SECTION, 'call_timeout', 15) self.__player = LinphonePlayer() self.core.ringback = self.player.player_filename self.__recorder = LinphoneRecorder() if len(self.core.sound_devices) == 0: logger.warning('no audio devices available') else: self.core.capture_device = conf.get(SIPPHONE_SECTION, 'capture_device', self.core.capture_device) self.core.playback_device = conf.get(SIPPHONE_SECTION, 'playback_device', self.core.playback_device) self.core.mic_gain_db = conf.get_float(SIPPHONE_SECTION, 'mic_gain_db', 0) logger.info('found %s possible sounddevices:', len(self.core.sound_devices)) logger.debug('| rec | play | name') logger.debug('------------------------------------') for sound_device in self.core.sound_devices: logger.debug('| %s | %s | %s', 'X' if self.core.sound_device_can_capture(sound_device) else 'O', 'X' if self.core.sound_device_can_playback(sound_device) else 'O', sound_device) logger.debug('------------------------------------') logger.debug('using capture_device: %s', self.core.capture_device) logger.debug('using playback_device: %s', self.core.playback_device) logger.debug('set mic_gain (in db): %s', self.core.mic_gain_db) # Only enable PCMU and PCMA audio codecs by default config_audio_codecs = conf.get_list(SIPPHONE_SECTION, 'audio_codecs', 'PCMA,PCMU') logger.debug('found %s supported audio codecs', len(self.core.audio_codecs)) logger.debug('------------------------------------') for codec in self.core.audio_codecs: if codec.mime_type in config_audio_codecs: logger.debug('%s enabled', codec.mime_type) self.core.enable_payload_type(codec, True) else: logger.debug('%s disabled', codec.mime_type) self.core.enable_payload_type(codec, False) logger.debug('------------------------------------') logger.info('found %s possible videodevices', len(self.core.video_devices)) # no video device or video not enabled? if (len(self.core.video_devices) == 0 or not conf.get_boolean(SIPPHONE_SECTION, 'video', False)): self.core.video_capture_enabled = False else: logger.debug('| name') logger.debug('------------------------------------') for video_device in self.core.video_devices: logger.debug('| %s', video_device) logger.debug('------------------------------------') # get video device - if not selected use first possible! config_camera = conf.get(SIPPHONE_SECTION, 'video_device', self.core.video_devices[0]) if config_camera not in self.core.video_devices: logger.warning('camera "%s" from config does not exist in possible video devices.', config_camera) logger.debug('switching to first possible video device "%s"', self.core.video_devices[0]) config_camera = self.core.video_devices[0] self.core.video_capture_enabled = True self.core.video_device = config_camera self.core.preferred_video_size_by_name = conf.get(SIPPHONE_SECTION, 'video_size', 'vga') logger.debug('using video_device: %s', self.core.video_device) # only enable VP8 video codec by default config_video_codecs = conf.get_list(SIPPHONE_SECTION, 'video_codecs', 'VP8') logger.debug('found %s supported video codecs', len(self.core.video_codecs)) logger.debug('------------------------------------') for codec in self.core.video_codecs: if codec.mime_type in config_video_codecs and self.core.video_capture_enabled: logger.debug('%s enabled', codec.mime_type) self.core.enable_payload_type(codec, True) else: logger.debug('%s disabled', codec.mime_type) self.core.enable_payload_type(codec, False) logger.debug('------------------------------------') # Configure the SIP account server = conf.get(SIPPHONE_SECTION, 'sipserver_server') username = conf.get(SIPPHONE_SECTION, 'sipserver_username') password = conf.get(SIPPHONE_SECTION, 'sipserver_password', username) realm = conf.get(SIPPHONE_SECTION, 'sipserver_realm', server) if server and username and password: logger.info('using DoorPi with SIP-Server') proxy_cfg = self.core.create_proxy_config() proxy_cfg.identity_address = lin.Address.new(('{0} <sip:{1}@{2}>').format( conf.get(SIPPHONE_SECTION, 'identity', 'DoorPi'), username, server)) proxy_cfg.server_addr = ('sip:{}').format(server) proxy_cfg.register_enabled = True self.core.add_proxy_config(proxy_cfg) self.core.default_proxy_config = proxy_cfg auth_info = self.core.create_auth_info(username, None, password, None, None, realm) self.core.add_auth_info(auth_info) else: logger.info('using DoorPi without SIP-Server? Okay...') proxy_cfg = self.core.create_proxy_config() proxy_cfg.register_enabled = False self.core.add_proxy_config(proxy_cfg) self.core.default_proxy_config = proxy_cfg logger.debug('%s', self.core.proxy_config_list) logger.debug('start successfully')