Beispiel #1
0
    def registerApp(self, app_name, app_mode, app_factory, feedbackService):
        """
        Initialises a new app's connection with the APNS server so when
        time comes for requests it can be used.
        """
        logger.debug('registerApp: %s (%s)' % (app_name, app_mode))
        real_app_name = APNSDaemon._getRealAppName(app_mode, app_name)

        if real_app_name in self.conn_factories:
            raise errors.AppRegistrationError(
                real_app_name, "Application already registered for APNS")

        logger.debug("Registering Application for APNS: %s..." % real_app_name)
        self.conn_factories[real_app_name] = app_factory

        if feedbackService:
            if real_app_name in self.feedback_services:
                raise errors.AppRegistrationError(
                    real_app_name,
                    "Application already registered for feedback service")

            logger.debug(
                "Registering Application for feedback service: %s..." %
                (real_app_name))
            self.feedback_services[real_app_name] = feedbackService
Beispiel #2
0
    def getFeedback(self, app_name, app_mode, deferred):
        """
        Retrieves feedback
        """
        real_app_name = APNSDaemon._getRealAppName(app_mode, app_name)
        if real_app_name not in self.feedback_services:
            raise errors.AppRegistrationError(
                app_name, "Application not registered for feedback")

        self.feedback_services[real_app_name].getFeedback(deferred)
Beispiel #3
0
    def sendMessage(self, orig_app, target_device, payload):
        """ 
        Sends a message/payload from a given app to a target device.
        """
        if orig_app not in self.connections:
            raise errors.AppRegistrationError(orig_name,
                                              "Application not registered")

        if len(payload) > constants.MAX_PAYLOAD_LENGTH:
            raise errors.PayloadLengthError()

        connection = self.connections[orig_app]
        factory = connection['client_factory']
        if connection['num_connections'] == 0:
            print "Connecting to APNS Server, App: ", orig_app
            context_factory = connection['client_context_factory']
            self.reactor.connectSSL(connection['apns_host'],
                                    connection['apns_port'], factory,
                                    context_factory)
            connection['num_connections'] = connection['num_connections'] + 1

        factory.sendMessage(target_device, payload)
Beispiel #4
0
    def sendMessage(self,
                    app_name,
                    app_mode,
                    device_token,
                    payload,
                    identifier=None,
                    expiry=None):
        """
        Sends a message/payload from a given app to a target device.
        """
        logger.info('sendMessage: %s %s %s' % (app_name, app_mode, payload))
        real_app_name = APNSDaemon._getRealAppName(app_mode, app_name)
        if real_app_name not in self.conn_factories:
            raise errors.AppRegistrationError(
                app_name, "Application not registered for APNS",
                self.conn_factories.keys())

        if len(payload) > constants.MAX_PAYLOAD_LENGTH:
            raise errors.PayloadLengthError()

        self.conn_factories[real_app_name].sendMessage(device_token, payload,
                                                       identifier, expiry)
Beispiel #5
0
    def registerApp(self,
                    app_name,
                    certificate_file,
                    privatekey_file,
                    apns_host=constants.DEFAULT_APNS_DEV_HOST,
                    apns_port=constants.DEFAULT_APNS_DEV_PORT,
                    feedback_host=constants.DEFAULT_FEEDBACK_DEV_HOST,
                    feedback_port=constants.DEFAULT_FEEDBACK_DEV_PORT):
        """
        Initialises a new app's connection with the APNS server so when
        time comes for requests it can be used.
        """

        if app_name in self.connections:
            raise errors.AppRegistrationError(
                app_name, "Application already registered")

        print "Registering Application: %s, Bundle ID: %s" % (app_name)
        from twisted.internet.ssl import DefaultOpenSSLContextFactory as SSLContextFactory
        self.connections[app_name] = {
            'num_connections':
            0,
            'apns_host':
            apns_host,
            'apns_port':
            apns_port,
            'feedback_host':
            feedback_host,
            'feedback_port':
            feedback_port,
            'certificate_file':
            certificate_file,
            'privatekey_file':
            privatekey_file,
            'client_factory':
            APNSFactory(),
            'client_context_factory':
            SSLContextFactory(privatekey_file, certificate_file)
        }