Пример #1
0
    def handle(self):
        self.hostaddr, self.port = self.request.getsockname()
        self.srcaddr, self.srcport = self.client_address
        logger.info('Handling request from %s:%s', self.srcaddr, self.srcport)

        self.data = self.read()

        try:
            message = parse_gntp(self.data, self.server.options.password)
            self.server.message_count += 1
            message.message_id = self.server.message_count

            response = GNTPOK(action=message.info['messagetype'])
            add_origin_info(response)

            if message.info['messagetype'] == 'NOTICE':
                response.add_header('Notification-ID', '')
            elif message.info['messagetype'] == 'SUBSCRIBE':
                response.add_header('Subscription-TTL', '10')

            self.write(response.encode())
        except GNTPError:
            logger.exception('GNTP Error')
            return
        except:
            logger.exception('Unknown Error')
            return

        if self.server.options.debug:
            logger.info('Reloading bridges')
            self.server.notifiers = load_bridges(self.server.config)

        for bridge in self.server.notifiers:
            bridge(self.server.config, message, self.srcaddr, self.srcport)
Пример #2
0
    def handle(self):
        self.hostaddr, self.port = self.request.getsockname()
        logger.info('Handling request from %s:%s', self.hostaddr, self.port)

        self.data = self.read()

        try:
            message = parse_gntp(self.data, self.server.options.password)

            response = GNTPOK(action=message.info['messagetype'])
            add_origin_info(response)

            if message.info['messagetype'] == 'NOTIFY':
                response.add_header('Notification-ID', '')
            elif message.info['messagetype'] == 'SUBSCRIBE':
                response.add_header(
                    'Subscription-TTL',
                    self.getint('timeout', DEFAULTS['timeout']))

            self.write(response.encode())
        except GNTPError:
            logger.exception('GNTP Error')
            return
        except:
            logger.exception('Unknown Error')
            return

        if self.server.options.reload:
            logger.info('Reloading config')
            self.server.config = self.server.config.reload(
                [self.server.options.config])

            logger.info('Reloading bridges')
            self.server.notifiers = load_bridges(self.server.config)

        for bridge in self.server.notifiers:
            try:
                threading.Thread(target=bridge,
                                 args=(self.server.config, message,
                                       self.hostaddr, self.port)).start()
            except:
                logger.exception('Error calling %s', bridge)
Пример #3
0
    def handle(self):
        self.hostaddr, self.port = self.request.getsockname()
        logger.info('Handling request from %s:%s', self.hostaddr, self.port)

        self.data = self.read()

        try:
            message = parse_gntp(self.data, self.server.options.password)

            response = GNTPOK(action=message.info['messagetype'])
            add_origin_info(response)

            if message.info['messagetype'] == 'NOTIFY':
                response.add_header('Notification-ID', '')
            elif message.info['messagetype'] == 'SUBSCRIBE':
                response.add_header(
                    'Subscription-TTL',
                    self.getint('timeout', DEFAULTS['timeout'])
                )

            self.write(response.encode())
        except GNTPError:
            logger.exception('GNTP Error')
            return
        except:
            logger.exception('Unknown Error')
            return

        if self.server.options.reload:
            logger.info('Reloading config')
            self.server.config = self.server.config.reload(
                [self.server.options.config]
            )

            logger.info('Reloading bridges')
            self.server.notifiers = load_bridges(self.server.config)

        for bridge in self.server.notifiers:
            try:
                threading.Thread(
                    target=bridge,
                    args=(self.server.config, message, self.hostaddr, self.port)
                ).start()
            except:
                logger.exception('Error calling %s', bridge)