Example #1
0
 def dataReceived(self, data):
     try:
         self.timeout_checker.cancel()
     except:
         pass
     self.info("response received from the Service Events HTTP server ")
     # self.debug(data)
     cmd, headers = utils.parse_http_response(data)
     self.debug("%r %r", cmd, headers)
     if int(cmd[1]) != 200:
         self.warning("response with error code %r received upon our %r request", cmd[1], self.action)
     else:
         try:
             self.service.set_sid(headers["sid"])
             timeout = headers["timeout"]
             self.debug("%r %r", headers["sid"], headers["timeout"])
             if timeout == "infinite":
                 self.service.set_timeout(time.time() + 4294967296)  # FIXME: that's lame
             elif timeout.startswith("Second-"):
                 timeout = int(timeout[len("Second-") :])
                 self.service.set_timeout(timeout)
         except:
             # print headers
             pass
     self.teardown()
Example #2
0
 def dataReceived(self, data):
     try:
         self.timeout_checker.cancel()
     except Exception:
         pass
     self.info('response received from the Service Events HTTP server ')
     # self.debug(data)
     cmd, headers = parse_http_response(data)
     self.debug(f'{cmd} {headers}')
     if int(cmd[1]) != 200:
         self.warning(f'response with error code {cmd[1]!r} '
                      f'received upon our {self.action!r} request')
         # XXX get around devices that return an
         # error on our event subscribe request
         self.service.process_event({})
     else:
         try:
             self.service.set_sid(headers['sid'])
             timeout = headers['timeout']
             self.debug(f'{headers["sid"]} {headers["timeout"]}')
             if timeout == 'infinite':
                 self.service.set_timeout(time.time() +
                                          4294967296)  # FIXME: that's lame
             elif timeout.startswith('Second-'):
                 timeout = int(timeout[len('Second-'):])
                 self.service.set_timeout(timeout)
         except Exception as e:
             self.warning(f'EventProtocol.dataReceived: {e}')
     self.teardown()
Example #3
0
 def dataReceived(self, data):
     try:
         self.timeout_checker.cancel()
     except:
         pass
     self.info("response received from the Service Events HTTP server ")
     #self.debug(data)
     cmd, headers = utils.parse_http_response(data)
     self.debug("%r %r", cmd, headers)
     if int(cmd[1]) != 200:
         self.warning(
             "response with error code %r received upon our %r request",
             cmd[1], self.action)
         # XXX get around devices that return an error on our event subscribe request
         self.service.process_event({})
     else:
         try:
             self.service.set_sid(headers['sid'])
             timeout = headers['timeout']
             self.debug("%r %r", headers['sid'], headers['timeout'])
             if timeout == 'infinite':
                 self.service.set_timeout(time.time() +
                                          4294967296)  # FIXME: that's lame
             elif timeout.startswith('Second-'):
                 timeout = int(timeout[len('Second-'):])
                 self.service.set_timeout(timeout)
         except:
             #print headers
             pass
     self.teardown()
Example #4
0
File: event.py Project: pezam/Cohen
 def dataReceived(self, data):
     try:
         self.timeout_checker.cancel()
     except:
         pass
     self.info("response received from the Service Events HTTP server ")
     #self.debug(data)
     cmd, headers = utils.parse_http_response(data)
     self.debug("%r %r", cmd, headers)
     if int(cmd[1]) != 200:
         self.warning("response with error code %r received upon our %r request", cmd[1], self.action)
         # XXX get around devices that return an error on our event subscribe request
         self.service.process_event({})
     else:
         try:
             self.service.set_sid(headers['sid'])
             timeout = headers['timeout']
             self.debug("%r %r", headers['sid'], headers['timeout'])
             if timeout == 'infinite':
                 self.service.set_timeout(time.time() + 4294967296)  # FIXME: that's lame
             elif timeout.startswith('Second-'):
                 timeout = int(timeout[len('Second-'):])
                 self.service.set_timeout(timeout)
         except:
             #print headers
             pass
     self.teardown()
Example #5
0
    def datagramReceived(self, data, xxx_todo_changeme):
        (host, port) = xxx_todo_changeme
        if isinstance(data, bytes):
            data = data.decode('utf-8')

        cmd, headers = utils.parse_http_response(data)
        self.info(
            f'datagramReceived from {host}:{port:d}, '
            f'protocol {cmd[0]} code {cmd[1]}'
        )
        if cmd[0].startswith('HTTP/1.') and cmd[1] == '200':
            self.msg(f'for {headers["usn"]}')
            if not self.ssdp_server.isKnown(headers['usn']):
                self.info(
                    f'register as remote {headers["usn"]}, '
                    f'{headers["st"]}, {headers["location"]}'
                )
                self.ssdp_server.register(
                    'remote',
                    headers['usn'],
                    headers['st'],
                    headers['location'],
                    headers['server'],
                    headers['cache-control'],
                    host=host,
                )
            else:
                self.ssdp_server.known[headers['usn']][
                    'last-seen'
                ] = time.time()
                self.debug(f'updating last-seen for {headers["usn"]}')

        # make raw data available
        # send out the signal after we had a chance to register the device
        self.dispatch_event('datagram_received', data, host, port)
Example #6
0
class MSearch(DatagramProtocol, log.Loggable):
    logCategory = 'msearch'

    def __init__(self, ssdp_server, test=False):
        self.ssdp_server = ssdp_server
        if test == False:
            self.port = reactor.listenUDP(0, self)

            self.double_discover_loop = task.LoopingCall(self.double_discover)
            self.double_discover_loop.start(120.0)

    def datagramReceived(self, data, (host, port)):
        cmd, headers = utils.parse_http_response(data)
        self.info('datagramReceived from %s:%d, protocol %s code %s' %
                  (host, port, cmd[0], cmd[1]))
        if cmd[0].startswith('HTTP/1.') and cmd[1] == '200':
            self.msg('for %r', headers['usn'])
            if not self.ssdp_server.isKnown(headers['usn']):
                self.info('register as remote %s, %s, %s' %
                          (headers['usn'], headers['st'], headers['location']))
                self.ssdp_server.register('remote',
                                          headers['usn'],
                                          headers['st'],
                                          headers['location'],
                                          headers['server'],
                                          headers['cache-control'],
                                          host=host)
            else:
                self.ssdp_server.known[
                    headers['usn']]['last-seen'] = time.time()
                self.debug('updating last-seen for %r' % headers['usn'])

        # make raw data available
        # send out the signal after we had a chance to register the device
        louie.send('UPnP.SSDP.datagram_received', None, data, host, port)
Example #7
0
 def dataReceived(self, data):
     try:
         self.timeout_checker.cancel()
     except:
         pass
     cmd, headers = utils.parse_http_response(data)
     self.debug("notification response received %r %r", cmd, headers)
     try:
         if int(cmd[1]) != 200:
             self.warning("response with error code %r received upon our notification", cmd[1])
     except:
         self.debug("response without error code received upon our notification")
     self.transport.loseConnection()
Example #8
0
 def dataReceived(self, data):
     try:
         self.timeout_checker.cancel()
     except:
         pass
     cmd, headers = utils.parse_http_response(data)
     self.debug( "notification response received %r %r", cmd, headers)
     try:
         if int(cmd[1]) != 200:
             self.warning("response with error code %r received upon our notification", cmd[1])
     except:
         self.debug("response without error code received upon our notification")
     self.transport.loseConnection()
Example #9
0
 def dataReceived(self, data):
     try:
         self.timeout_checker.cancel()
     except Exception:
         pass
     if isinstance(data, bytes):
         d = str(data)
     else:
         d = data
     cmd, headers = parse_http_response(d)
     self.debug(f'notification response received {cmd} {headers}')
     try:
         if int(cmd[1]) != 200:
             self.warning(f'response with error code {cmd[1]!r}'
                          f' received upon our notification')
     except (IndexError, ValueError):
         self.debug(
             'response without error code received upon our notification')
     self.transport.loseConnection()
Example #10
0
    def datagramReceived(self, data, xxx_todo_changeme):
        (host, port) = xxx_todo_changeme
        cmd, headers = utils.parse_http_response(data)
        self.info('datagramReceived from %s:%d, protocol %s code %s', host, port, cmd[0], cmd[1])
        if cmd[0].startswith('HTTP/1.') and cmd[1] == '200':
            self.msg('for %r', headers['usn'])
            if not self.ssdp_server.isKnown(headers['usn']):
                self.info('register as remote %s, %s, %s', headers['usn'], headers['st'], headers['location'])
                self.ssdp_server.register('remote',
                                            headers['usn'], headers['st'],
                                            headers['location'],
                                            headers['server'],
                                            headers['cache-control'],
                                            host=host)
            else:
                self.ssdp_server.known[headers['usn']]['last-seen'] = time.time()
                self.debug('updating last-seen for %r', headers['usn'])

        # make raw data available
        # send out the signal after we had a chance to register the device
        louie.send('UPnP.SSDP.datagram_received', None, data, host, port)
Example #11
0
 def dataReceived(self, data):
     try:
         self.timeout_checker.cancel()
     except:
         pass
     cmd, headers = utils.parse_http_response(data)
     self.info("response received from the Service Events HTTP server for %s [%s %s]", self.service.get_event_sub_url(), cmd, headers)
     if int(cmd[1]) == 412:
         # retry from scratch?
         # no prerequsite, has the server expired subscription. 
         # Loose sid and then on next attempt try initial subscribe.
         self.service.set_sid(None)
         pass
     elif int(cmd[1]) == 405:
         # Nor allowed/not supported
         self.service.set_sid(None)
         self.service.does_sends_events = False  # no events, do not try subscribe again
     elif int(cmd[1]) != 200:
         self.error("response with error code %s received upon our %s request service %s", cmd[1], self.action, self.service)
     else:
         try:
             # this could be unsubscribe
             if headers.has_key('sid'):
                 self.service.set_sid(headers['sid'])
             if headers.has_key('timeout'):
                 timeout = headers['timeout']
                 self.info("%r %r", headers['sid'], headers['timeout'])
                 if timeout == 'infinite':
                     self.service.set_timeout(time.time() + 4294967296) # FIXME: that's lame
                 elif timeout.startswith('Second-'):
                     timeout = int(timeout[len('Second-'):])
                     self.service.set_timeout(timeout)
         except Exception,ex:
             #print headers
             self.exception(ex)
             pass