Ejemplo n.º 1
0
    def offline_state(self):
        if self.account is BonjourAccount():
            return None

        blink_settings = BlinkSettings()

        account_id = hashlib.md5(self.account.id.encode()).hexdigest()
        timestamp = ISOTimestamp.now()

        doc = pidf.PIDF(str(self.account.uri))

        person = pidf.Person('PID-%s' % account_id)
        person.timestamp = timestamp
        person.activities = rpid.Activities()
        person.activities.add('offline')
        doc.add(person)

        service = pidf.Service('SID-%s' % account_id)
        service.status = 'closed'
        service.status.extended = 'offline'
        service.contact = str(self.account.uri)
        service.timestamp = timestamp
        service.capabilities = caps.ServiceCapabilities()
        service.display_name = self.account.display_name or None
        service.icon = "%s#blink-icon%s" % (
            self.account.xcap.icon.url, self.account.xcap.icon.etag
        ) if self.account.xcap.icon is not None else None
        if blink_settings.presence.offline_note:
            service.notes.add(blink_settings.presence.offline_note)
        doc.add(service)

        return doc
Ejemplo n.º 2
0
 def _build_pidf(self):
     if not self._stanza_cache:
         self._pidf = None
         return None
     pidf_doc = pidf.PIDF(str(self.xmpp_identity))
     uri = next(self._stanza_cache.iterkeys())
     person = pidf.Person(
         "PID-%s" % hashlib.md5("%s@%s" % (uri.user, uri.host)).hexdigest())
     person.activities = rpid.Activities()
     pidf_doc.add(person)
     for stanza in self._stanza_cache.itervalues():
         if not stanza.available:
             status = pidf.Status('closed')
             status.extended = 'offline'
         else:
             status = pidf.Status('open')
             if stanza.show == 'away':
                 status.extended = 'away'
                 if 'away' not in person.activities:
                     person.activities.add('away')
             elif stanza.show == 'xa':
                 status.extended = 'away'
                 if 'away' not in person.activities:
                     person.activities.add('away')
             elif stanza.show == 'dnd':
                 status.extended = 'busy'
                 if 'busy' not in person.activities:
                     person.activities.add('busy')
             else:
                 status.extended = 'available'
         if stanza.sender.uri.resource:
             resource = encode_resource(stanza.sender.uri.resource)
         else:
             # Workaround for clients not sending the resource under certain (unknown) circumstances
             resource = hashlib.md5("%s@%s" %
                                    (uri.user, uri.host)).hexdigest()
         service_id = "SID-%s" % resource
         sip_uri = stanza.sender.uri.as_sip_uri()
         sip_uri.parameters['gr'] = resource
         sip_uri.parameters['xmpp'] = None
         contact = pidf.Contact(str(sip_uri))
         service = pidf.Service(service_id, status=status, contact=contact)
         service.add(pidf.DeviceID(resource))
         service.device_info = pidf.DeviceInfo(
             resource, description=stanza.sender.uri.resource)
         service.timestamp = pidf.ServiceTimestamp(stanza.timestamp)
         service.capabilities = caps.ServiceCapabilities(text=True,
                                                         message=True)
         for lang, note in stanza.statuses.iteritems():
             service.notes.add(pidf.PIDFNote(note, lang=lang))
         pidf_doc.add(service)
     if not person.activities:
         person.activities = None
     self._pidf = pidf_doc.toxml()
     return self._pidf
 def build_offline_pidf(self, account):
     settings = SIPSimpleSettings()
     note = settings.presence_state.offline_note
     if not note:
         return None
     pidf_doc = pidf.PIDF(account.id)
     account_hash = hashlib.md5(account.id.encode()).hexdigest()
     person = pidf.Person("PID-%s" % account_hash)
     person.activities = rpid.Activities()
     person.activities.add('offline')
     person.notes.add(str(note))
     pidf_doc.add(person)
     service = pidf.Service("SID-%s" % account_hash)
     service.status = pidf.Status(basic='closed')
     service.status.extended = 'offline'
     service.contact = pidf.Contact(str(account.uri))
     service.capabilities = caps.ServiceCapabilities()
     service.notes.add(str(note))
     pidf_doc.add(service)
     return pidf_doc
Ejemplo n.º 4
0
    def online_state(self):
        blink_settings = BlinkSettings()

        state = blink_settings.presence.current_state.state
        note = blink_settings.presence.current_state.note

        state = 'offline' if state == 'Invisible' else state.lower()

        if self.account is BonjourAccount():
            return BonjourPresenceState(state, note)

        try:
            hostname = socket.gethostname()
        except Exception:
            hostname = 'localhost'
        account_id = hashlib.md5(self.account.id.encode()).hexdigest()
        timestamp = ISOTimestamp.now()

        doc = pidf.PIDF(str(self.account.uri))

        person = pidf.Person('PID-%s' % account_id)
        person.timestamp = timestamp
        person.activities = rpid.Activities()
        person.activities.add(state)
        doc.add(person)

        if state == 'offline':
            service = pidf.Service('SID-%s' % account_id)
            service.status = 'closed'
            service.status.extended = state
            service.contact = str(self.account.uri)
            service.timestamp = timestamp
            service.capabilities = caps.ServiceCapabilities()
            service.display_name = self.account.display_name or None
            service.icon = "%s#blink-icon%s" % (
                self.account.xcap.icon.url, self.account.xcap.icon.etag
            ) if self.account.xcap.icon is not None else None
            doc.add(service)
        else:
            settings = SIPSimpleSettings()
            instance_id = str(uuid.UUID(settings.instance_id))
            service = pidf.Service('SID-%s' % instance_id)
            service.status = 'open'
            service.status.extended = state
            service.contact = str(self.account.contact.public_gruu
                                  or self.account.uri)
            service.timestamp = timestamp
            service.capabilities = caps.ServiceCapabilities()
            service.capabilities.audio = True
            service.capabilities.text = False
            service.capabilities.message = True
            service.capabilities.file_transfer = True
            service.capabilities.screen_sharing_server = True
            service.capabilities.screen_sharing_client = True
            service.display_name = self.account.display_name or None
            service.icon = "%s#blink-icon%s" % (
                self.account.xcap.icon.url, self.account.xcap.icon.etag
            ) if self.account.xcap.icon is not None else None
            service.device_info = pidf.DeviceInfo(
                instance_id,
                description=hostname,
                user_agent=settings.user_agent)
            service.device_info.time_offset = pidf.TimeOffset()
            # TODO: Add real user input data -Saul
            service.user_input = rpid.UserInput()
            service.user_input.idle_threshold = 600
            service.add(pidf.DeviceID(instance_id))
            if note:
                service.notes.add(note)
            doc.add(service)

            device = pidf.Device('DID-%s' % instance_id,
                                 device_id=pidf.DeviceID(instance_id))
            device.timestamp = timestamp
            device.notes.add('%s at %s' % (settings.user_agent, hostname))
            doc.add(device)

        return doc
    def build_pidf(self, account):
        if account is None or not account.enabled or not account.presence.enabled:
            return None

        selected_item = self.owner.presenceActivityPopUp.selectedItem()

        if selected_item is None:
            return None

        activity_object = selected_item.representedObject()
        if activity_object is None:
            return None

        offline = activity_object['basic_status'] == 'closed' and activity_object['extended_status'] == 'offline'

        settings = SIPSimpleSettings()
        instance_id = str(uuid.UUID(settings.instance_id))

        pidf_doc = pidf.PIDF(str(account.uri))
        person = pidf.Person("PID-%s" % hashlib.md5(account.id.encode()).hexdigest())
        person.timestamp = pidf.PersonTimestamp(settings.presence_state.timestamp)
        if not account.presence.disable_timezone and not offline:
            person.time_offset = rpid.TimeOffset()
        pidf_doc.add(person)

        status = pidf.Status(activity_object['basic_status'])
        status.extended = activity_object['extended_status']

        person.activities = rpid.Activities()
        person.activities.add(str(status.extended))
        service = pidf.Service("SID-%s" % instance_id, status=status)
        service.timestamp = pidf.ServiceTimestamp(settings.presence_state.timestamp)

        if offline:
            note = settings.presence_state.offline_note
            if note:
                service.notes.add(str(note))
            pidf_doc.add(service)
            return pidf_doc

        service.contact = pidf.Contact(str(account.contact.public_gruu or account.uri))

        if account.display_name:
            service.display_name = cipid.DisplayName(account.display_name)

        # TODO: location should be part of PresenceStateSettings
        if self.location and not account.presence.disable_location:
            if self.location['city']:
                location = '%s/%s' % (self.location['country'], self.location['city'])
                service.map = cipid.Map(location)
            elif self.location['country']:
                service.map = cipid.Map(self.location['country'])

        service.icon = "%s#blink-icon%s" % (account.xcap.icon.path, account.xcap.icon.etag) if account.xcap.icon is not None else None

        if account.presence.homepage is not None:
            service.homepage = cipid.Homepage(account.presence.homepage)

        service.notes.add(str(settings.presence_state.note))
        service.device_info = pidf.DeviceInfo(instance_id, description=str(self.hostname), user_agent=settings.user_agent)
        if not account.presence.disable_timezone:
            service.device_info.time_offset = pidf.TimeOffset()
        service.capabilities = caps.ServiceCapabilities(audio=True, text=True)
        service.capabilities.message = not settings.chat.disabled
        if NSApp.delegate().contactsWindowController.sessionControllersManager.isMediaTypeSupported('video'):
            service.capabilities.video = (settings.video.device != "None")
        else:
            service.capabilities.video = False
        service.capabilities.file_transfer = not settings.file_transfer.disabled
        service.capabilities.screen_sharing_server = not settings.screen_sharing_server.disabled
        service.capabilities.screen_sharing_client = True
        service.user_input = rpid.UserInput()
        service.user_input.value = self.user_input['state']
        service.user_input.last_input = self.user_input['last_input']
        service.user_input.idle_threshold = settings.gui.idle_threshold
        service.add(pidf.DeviceID(instance_id))
        pidf_doc.add(service)

        device = pidf.Device("DID-%s" % instance_id, device_id=pidf.DeviceID(instance_id))
        device.timestamp = pidf.DeviceTimestamp(settings.presence_state.timestamp)
        device.notes.add('%s at %s' % (settings.user_agent, self.hostname))
        pidf_doc.add(device)
        self.last_service_timestamp[account.id] = service.timestamp
        return pidf_doc