示例#1
0
 def _resolve_cb(self, file, flags, interface_index, error_code, fullname,
                 host_target, port, txtrecord):
     notification_center = NotificationCenter()
     settings = SIPSimpleSettings()
     file = BonjourResolutionFile.find_by_file(file)
     if error_code == bonjour.kDNSServiceErr_NoError:
         txt = bonjour.TXTRecord.parse(txtrecord)
         name = txt['name'].decode('utf-8') if 'name' in txt else None
         host = re.match(r'^(.*?)(\.local)?\.?$', host_target).group(1)
         contact = txt.get('contact', file.service_description.name).split(
             None, 1)[0].strip('<>')
         try:
             uri = FrozenSIPURI.parse(contact)
         except SIPCoreError:
             pass
         else:
             account = BonjourAccount()
             service_description = file.service_description
             transport = uri.transport
             supported_transport = transport in settings.sip.transport_list and (
                 transport != 'tls' or account.tls.certificate is not None)
             if not supported_transport and service_description in self._servers:
                 del self._servers[service_description]
                 notification_center.post_notification(
                     'BonjourConferenceServicesDidRemoveServer',
                     sender=self,
                     data=TimestampedNotificationData(
                         server=service_description))
             elif supported_transport:
                 try:
                     contact_uri = account.contact[transport]
                 except KeyError:
                     return
                 if uri != contact_uri:
                     notification_name = 'BonjourConferenceServicesDidUpdateServer' if service_description in self._servers else 'BonjourConferenceServicesDidAddServer'
                     notification_data = TimestampedNotificationData(
                         server=service_description,
                         name=name,
                         host=host,
                         uri=uri)
                     server_description = BonjourConferenceServerDescription(
                         uri, host, name)
                     self._servers[service_description] = server_description
                     notification_center.post_notification(
                         notification_name,
                         sender=self,
                         data=notification_data)
     else:
         self._files.remove(file)
         self._select_proc.kill(RestartSelect)
         file.close()
         error = bonjour.BonjourError(error_code)
         notification_center.post_notification(
             'BonjourConferenceServicesDiscoveryFailure',
             sender=self,
             data=TimestampedNotificationData(error=str(error),
                                              transport=file.transport))
示例#2
0
 def __init__(self, service_description, host, txtrecord):
     self.id = txtrecord.get('instance_id', None)
     self.name = txtrecord.get('name', '').decode('utf-8') or None
     self.host = re.match(r'^(?P<host>.*?)(\.local)?\.?$',
                          host).group('host')
     self.uri = FrozenSIPURI.parse(
         txtrecord.get('contact', service_description.name))
     self.presence = BonjourNeighbourPresence(
         txtrecord.get('state', txtrecord.get('status', None)),
         txtrecord.get('note', '').decode('utf-8')
         or None)  # status is read for legacy (remove later) -Dan
示例#3
0
 def _resolve_cb(self, file, flags, interface_index, error_code, fullname, host_target, port, txtrecord):
     notification_center = NotificationCenter()
     settings = SIPSimpleSettings()
     file = BonjourResolutionFile.find_by_file(file)
     if error_code == _bonjour.kDNSServiceErr_NoError:
         txt = _bonjour.TXTRecord.parse(txtrecord)
         name = txt['name'].decode('utf-8') if 'name' in txt else None
         host = re.match(r'^(.*?)(\.local)?\.?$', host_target).group(1)
         contact = txt.get('contact', file.service_description.name).split(None, 1)[0].strip('<>')
         try:
             uri = FrozenSIPURI.parse(contact)
         except SIPCoreError:
             pass
         else:
             account = BonjourAccount()
             service_description = file.service_description
             transport = uri.transport
             supported_transport = transport in settings.sip.transport_list and (transport!='tls' or account.tls.certificate is not None)
             if not supported_transport and service_description in self._servers:
                 del self._servers[service_description]
                 notification_center.post_notification('BonjourConferenceServicesDidRemoveServer', sender=self, data=NotificationData(server=service_description))
             elif supported_transport:
                 try:
                     contact_uri = account.contact[transport]
                 except KeyError:
                     return
                 if uri != contact_uri:
                     notification_name = 'BonjourConferenceServicesDidUpdateServer' if service_description in self._servers else 'BonjourConferenceServicesDidAddServer'
                     notification_data = NotificationData(server=service_description, name=name, host=host, uri=uri)
                     server_description = BonjourConferenceServerDescription(uri, host, name)
                     self._servers[service_description] = server_description
                     notification_center.post_notification(notification_name, sender=self, data=notification_data)
     else:
         self._files.remove(file)
         self._select_proc.kill(RestartSelect)
         file.close()
         error = _bonjour.BonjourError(error_code)
         notification_center.post_notification('BonjourConferenceServicesDiscoveryFailure', sender=self, data=NotificationData(error=str(error), transport=file.transport))
示例#4
0
 def __init__(self, service_description, host, txtrecord):
     self.id = txtrecord.get('instance_id', None)
     self.name = txtrecord.get('name', '').decode('utf-8') or None
     self.host = re.match(r'^(?P<host>.*?)(\.local)?\.?$', host).group('host')
     self.uri = FrozenSIPURI.parse(txtrecord.get('contact', service_description.name))
     self.presence = BonjourNeighbourPresence(txtrecord.get('state', txtrecord.get('status', None)), txtrecord.get('note', '').decode('utf-8') or None) # status is read for legacy (remove later) -Dan