Exemplo n.º 1
0
    def __init__(self, device, interfaces=None, bind=None):
        """SSDP Client/Listener

        :type device: Device
        """
        self.device = device

        if self.device.uuid is None:
            raise ValueError()

        self.targets = [
            'ssdp:all', 'upnp:rootdevice', 'uuid:' + self.device.uuid,
            self.device.deviceType
        ]
        for service in self.device.services:
            self.targets.append(service.serviceType)

        if not interfaces:
            self.interfaces = ['', get_default_v4_address()]
        else:
            self.interfaces = interfaces

        # Which interface the upnpn server is bind to
        self.bind = bind

        _clients = []
        for interface in self.interfaces:
            _clients.append(SSDP_Client(self, interface, bind))
        self.clients = SSDP_ClientsInterface(_clients)

        self.listener = SSDP_Listener(self, self.interfaces, bind)
Exemplo n.º 2
0
    def send_NOTIFY(self, nt, uuid=None, nts='ssdp:alive'):
        if self.ssdp.device.bootID is None:
            self.ssdp.device.bootID = int(time.time())

        location = self.ssdp.device.getLocation(get_default_v4_address())

        if uuid is None:
            uuid = self.ssdp.device.uuid

        usn, nt = build_notification_type(uuid, nt)

        Logr.debug("send_NOTIFY %s:%s", nts, usn)

        headers = {
            # max-age is notifySequenceInterval + 10 minutes
            'CACHE-CONTROL': 'max-age = %d' % (self.notifySequenceInterval + (10 * 60)),
            'LOCATION': location,
            'SERVER': self.ssdp.device.server,
            'NT': nt,
            'NTS': nts,
            'USN': usn,
            'BOOTID.UPNP.ORG': self.ssdp.device.bootID,
            'CONFIGID.UPNP.ORG': self.ssdp.device.configID
        }

        self.send('NOTIFY', headers, (SSDP_ADDR_V4, SSDP_PORT))
Exemplo n.º 3
0
    def __init__(self, device):
        """SSDP Client/Listener

        :type device: Device
        """
        self.device = device

        if self.device.uuid is None:
            raise ValueError()

        self.targets = [
            'ssdp:all',
            'upnp:rootdevice',
            'uuid:' + self.device.uuid,
            self.device.deviceType
        ]
        for service in self.device.services:
            self.targets.append(service.serviceType)

        self.interfaces = [
            '',
            get_default_v4_address()
        ]

        _clients = []
        for interface in self.interfaces:
            _clients.append(SSDP_Client(self, interface))
        self.clients = SSDP_ClientsInterface(_clients)

        self.listener = SSDP_Listener(self, self.interfaces)
Exemplo n.º 4
0
            self.transport.write(msg, (address, port))
        except socket.error, e:
            Logr.warning("socket.error: %s", e)

    def respond_MSEARCH(self, st, (address, port)):
        Logr.debug("respond_MSEARCH")

        if self.ssdp.device.bootID is None:
            self.ssdp.device.bootID = int(time.time())

        if address == '127.0.0.1':
            location = self.ssdp.device.getLocation('127.0.0.1')
        else:
            if not self.bind:
                location = self.ssdp.device.getLocation(
                    get_default_v4_address())
            else:
                location = self.ssdp.device.getLocation(self.bind)

        usn, st = build_notification_type(self.ssdp.device.uuid, st)

        headers = {
            'CACHE-CONTROL': 'max-age = %d' % self.responseExpire,
            'EXT': '',
            'LOCATION': location,
            'SERVER': self.ssdp.device.server,
            'ST': st,
            'USN': usn,
            'OPT': '"http://schemas.upnp.org/upnp/1/0/"; ns=01',
            '01-NLS': self.ssdp.device.bootID,
            'BOOTID.UPNP.ORG': self.ssdp.device.bootID,
Exemplo n.º 5
0
        try:
            self.transport.write(msg, (address, port))
        except socket.error, e:
            Logr.warning("socket.error: %s", e)

    def respond_MSEARCH(self, st, (address, port)):
        Logr.debug("respond_MSEARCH")

        if self.ssdp.device.bootID is None:
            self.ssdp.device.bootID = int(time.time())

        if address == '127.0.0.1':
            location = self.ssdp.device.getLocation('127.0.0.1')
        else:
            location = self.ssdp.device.getLocation(get_default_v4_address())

        usn, st = build_notification_type(self.ssdp.device.uuid, st)

        headers = {
            'CACHE-CONTROL': 'max-age = %d' % self.responseExpire,
            'EXT': '',
            'LOCATION': location,
            'SERVER': self.ssdp.device.server,
            'ST': st,
            'USN': usn,
            'OPT': '"http://schemas.upnp.org/upnp/1/0/"; ns=01',
            '01-NLS': self.ssdp.device.bootID,
            'BOOTID.UPNP.ORG': self.ssdp.device.bootID,
            'CONFIGID.UPNP.ORG': self.ssdp.device.configID,
        }