Exemplo n.º 1
0
    def send_file_rejection(self, file_props, code='403', typ=None):
        """
        Inform sender that we refuse to download the file

        typ is used when code = '400', in this case typ can be 'strean' for
        invalid stream or 'profile' for invalid profile
        """
        # user response to ConfirmationDialog may come after we've disconneted
        if not self.connection or self.connected < 2:
            return
        if file_props.session_type == 'jingle':
            if file_props.sid in self._sessions:
                jingle = self._sessions[file_props.sid]
                jingle.cancel_session()
            return
        iq = nbxmpp.Iq(to=file_props.sender, typ='error')
        iq.setAttr('id', file_props.request_id)
        if code == '400' and typ in ('stream', 'profile'):
            name = 'bad-request'
            text = ''
        else:
            name = 'forbidden'
            text = 'Offer Declined'
        err = nbxmpp.ErrorNode(code=code, typ='cancel', name=name, text=text)
        if code == '400' and typ in ('stream', 'profile'):
            if typ == 'stream':
                err.setTag('no-valid-streams', namespace=nbxmpp.NS_SI)
            else:
                err.setTag('bad-profile', namespace=nbxmpp.NS_SI)
        iq.addChild(node=err)
        self.connection.send(iq)
Exemplo n.º 2
0
 def _answer_bob_request(self, _con, stanza, _properties):
     self._log.info('Request from %s for BoB data', stanza.getFrom())
     iq = stanza.buildReply('error')
     err = nbxmpp.ErrorNode(nbxmpp.ERR_ITEM_NOT_FOUND)
     iq.addChild(node=err)
     self._log.info('Sending item-not-found')
     self._con.connection.send(iq)
     raise nbxmpp.NodeProcessed
Exemplo n.º 3
0
 def _answer_request(self, con, stanza):
     log.info('%s asked for the software version', stanza.getFrom())
     if app.config.get_per('accounts', self._account, 'send_os_info'):
         os_info = get_os_info()
         iq = stanza.buildReply('result')
         query = iq.getQuery()
         query.setTagData('name', 'Gajim')
         query.setTagData('version', app.version)
         query.setTagData('os', os_info)
         log.info('Answer: Gajim %s %s', app.version, os_info)
     else:
         iq = stanza.buildReply('error')
         err = nbxmpp.ErrorNode(nbxmpp.ERR_SERVICE_UNAVAILABLE)
         iq.addChild(node=err)
         log.info('Send service-unavailable')
     self._con.connection.send(iq)
     raise nbxmpp.NodeProcessed
Exemplo n.º 4
0
 def _answer_request(self, _con, stanza, _properties):
     self._log.info('%s asked for the time', stanza.getFrom())
     if app.settings.get_account_setting(self._account, 'send_time_info'):
         iq = stanza.buildReply('result')
         time_ = iq.setTag('time', namespace=Namespace.TIME_REVISED)
         formated_time = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
         time_.setTagData('utc', formated_time)
         isdst = time.localtime().tm_isdst
         zone = -(time.timezone, time.altzone)[isdst] / 60.0
         tzo = (zone / 60, abs(zone % 60))
         time_.setTagData('tzo', '%+03d:%02d' % (tzo))
         self._log.info('Answer: %s %s', formated_time, '%+03d:%02d' % (tzo))
     else:
         iq = stanza.buildReply('error')
         err = nbxmpp.ErrorNode(nbxmpp.ERR_SERVICE_UNAVAILABLE)
         iq.addChild(node=err)
         self._log.info('Send service-unavailable')
     self._con.connection.send(iq)
     raise nbxmpp.NodeProcessed
Exemplo n.º 5
0
    def _answer_request(self, con, stanza):
        log.info('Request from %s', stanza.getFrom())
        if not app.account_is_connected(self._account):
            return

        allow_send = app.config.get_per('accounts', self._account,
                                        'send_idle_time')
        if app.is_installed('IDLE') and allow_send:
            iq = stanza.buildReply('result')
            query = iq.setQuery()
            query.attrs['seconds'] = idle.Monitor.get_idle_sec()
        else:
            iq = stanza.buildReply('error')
            err = nbxmpp.ErrorNode(nbxmpp.ERR_SERVICE_UNAVAILABLE)
            iq.addChild(node=err)

        self._con.connection.send(iq)

        raise nbxmpp.NodeProcessed
Exemplo n.º 6
0
    def _answer_request(self, _con, stanza, properties):
        self._log.info('Request from %s', properties.jid)

        allow_send = app.config.get_per('accounts', self._account,
                                        'send_idle_time')
        if app.is_installed('IDLE') and allow_send:
            iq = stanza.buildReply('result')
            query = iq.setQuery()
            seconds = idle.Monitor.get_idle_sec()
            query.attrs['seconds'] = seconds
            self._log.info('Respond with seconds: %s', seconds)
        else:
            iq = stanza.buildReply('error')
            err = nbxmpp.ErrorNode(nbxmpp.ERR_SERVICE_UNAVAILABLE)
            iq.addChild(node=err)

        self._con.connection.send(iq)

        raise nbxmpp.NodeProcessed