Exemple #1
0
 def __init__(self, endpoint, server=None, port=None, use_srv=True, wait=80,
         hold=4, requests=5, headers=None, PIPELINE=True, GZIP=True):
     PlugIn.__init__(self)
     self.DBG_LINE = 'bosh'
     self._exported_methods = [
         self.send, self.receive, self.disconnect,
     ]
     url = urlparse(endpoint)
     self._http_host = url.hostname
     self._http_path = url.path
     if url.port:
         self._http_port = url.port
     elif url.scheme == 'https':
         self._http_port = 443
     else:
         self._http_port = 80
     self._http_proto = url.scheme
     self._server = server
     self._port = port
     self.use_srv = use_srv
     self.Sid = None
     self._rid = 0
     self.wait = wait
     self.hold = hold
     self.requests = requests
     self._pipeline = None
     self.PIPELINE = PIPELINE
     if self.PIPELINE:
         self._respobjs = []
     else:
         self._respobjs = {}
     self.headers = headers or self.default_headers
     self.GZIP = GZIP
Exemple #2
0
 def __init__(self, browser):
     """Initialises class and sets up local variables"""
     PlugIn.__init__(self)
     DBG_LINE='commands'
     self._exported_methods=[]
     self._handlers={'':{}}
     self._browser = browser
 def __init__(self):
     PlugIn.__init__(self)
     DBG_LINE = "dispatcher"
     self.handlers = {}
     self._expected = {}
     self._defaultHandler = None
     self._pendingExceptions = []
     self._eventHandler = None
     self._cycleHandlers = []
     self._exported_methods = [
         self.Process,
         self.RegisterHandler,
         self.RegisterDefaultHandler,
         self.RegisterEventHandler,
         self.UnregisterCycleHandler,
         self.RegisterCycleHandler,
         self.RegisterHandlerOnce,
         self.UnregisterHandler,
         self.RegisterProtocol,
         self.WaitForResponse,
         self.SendAndWaitForResponse,
         self.send,
         self.disconnect,
         self.SendAndCallForResponse,
     ]
 def __init__(self):
     """ Init internal variables. """
     PlugIn.__init__(self)
     self.DBG_LINE = 'roster'
     self._data = {}
     self.set = None
     self._exported_methods = [self.getRoster]
Exemple #5
0
 def __init__(self, browser):
     """Initialises class and sets up local variables"""
     PlugIn.__init__(self)
     DBG_LINE = 'commands'
     self._exported_methods = []
     self._handlers = {'': {}}
     self._browser = browser
Exemple #6
0
 def __init__(self,user,password,resource):
     """ Caches username, password and resource for auth. """
     PlugIn.__init__(self)
     self.DBG_LINE='gen_auth'
     self.user=user
     self.password=password
     self.resource=resource
Exemple #7
0
 def __init__(self):
     """ Init internal variables. """
     PlugIn.__init__(self)
     self.DBG_LINE='roster'
     self._data = {}
     self.set=None
     self._exported_methods=[self.getRoster]
Exemple #8
0
	def __init__(self, user, password, resource, on_auth):
		''' Caches username, password and resource for auth. '''
		PlugIn.__init__(self)
		self.DBG_LINE ='gen_auth'
		self.user = user
		self.password= password
		self.resource = resource
		self.on_auth = on_auth
Exemple #9
0
    def __init__(self, server=None, use_srv=True):
        """ Cache connection point 'server'. 'server' is the tuple of (host, port)
            absolutely the same as standard tcp socket uses. """
        PlugIn.__init__(self)
        self.DBG_LINE = 'socket'
        self._exported_methods = [self.send, self.disconnect]

        self._server = server
Exemple #10
0
    def __init__(self, server=None, use_srv=True):
        """ Cache connection point 'server'. 'server' is the tuple of (host, port)
            absolutely the same as standard tcp socket uses. """
        PlugIn.__init__(self)
        self.DBG_LINE='socket'
        self._exported_methods=[self.send,self.disconnect]

        self._server = server
 def __init__(self,jid=''):
     """Set up the class"""
     PlugIn.__init__(self)
     DBG_LINE='command'
     self.sessioncount = 0
     self.sessions = {}
     # Disco information for command list pre-formatted as a tuple
     self.discoinfo = {'ids':[{'category':'automation','type':'command-node','name':self.description}],'features': self.discofeatures}
     self._jid = jid
Exemple #12
0
 def __init__(self,jid=''):
     """Set up the class"""
     PlugIn.__init__(self)
     DBG_LINE='command'
     self.sessioncount = 0
     self.sessions = {}
     # Disco information for command list pre-formatted as a tuple
     self.discoinfo = {'ids':[{'category':'automation','type':'command-node','name':self.description}],'features': self.discofeatures}
     self._jid = jid
 def __init__(self, server=None, use_srv=True):
     """ Cache connection point 'server'. 'server' is the tuple of (host, port)
         absolutely the same as standard tcp socket uses. However library will lookup for 
         ('_xmpp-client._tcp.' + host) SRV record in DNS and connect to the found (if it is)
         server instead
     """
     PlugIn.__init__(self)
     self.DBG_LINE = 'socket'
     self._exported_methods = [self.send, self.disconnect]
     self._server, self.use_srv = server, use_srv
Exemple #14
0
 def __init__(self, server=None, use_srv=True):
     """ Cache connection point 'server'. 'server' is the tuple of (host, port)
         absolutely the same as standard tcp socket uses. However library will lookup for
         ('_xmpp-client._tcp.' + host) SRV record in DNS and connect to the found (if it is)
         server instead
     """
     PlugIn.__init__(self)
     self.DBG_LINE='socket'
     self._exported_methods=[self.send,self.disconnect]
     self._server, self.use_srv = server, use_srv
Exemple #15
0
 def __init__(self, jid=""):
     """Set up the class"""
     PlugIn.__init__(self)
     DBG_LINE = "command"
     self.sessioncount = 0
     self.sessions = {}
     # Disco information for command list pre-formatted as a tuple
     self.discoinfo = {
         "ids": [{"category": "automation", "type": "command-node", "name": self.description}],
         "features": self.discofeatures,
     }
     self._jid = jid
Exemple #16
0
 def __init__(self):
     PlugIn.__init__(self)
     DBG_LINE='dispatcher'
     self.handlers={}
     self._expected={}
     self._defaultHandler=None
     self._eventHandler=None
     self._cycleHandlers=[]
     self._exported_methods=[self.Process,self.RegisterHandler,self.RegisterDefaultHandler,\
     self.RegisterEventHandler,self.UnregisterCycleHandler,self.RegisterCycleHandler,\
     self.RegisterHandlerOnce,self.UnregisterHandler,self.RegisterProtocol,\
     self.WaitForResponse,self.SendAndWaitForResponse,self.send,self.disconnect]
Exemple #17
0
 def __init__(self,
              endpoint,
              server=None,
              port=None,
              use_srv=True,
              wait=80,
              hold=4,
              requests=5,
              headers=None,
              PIPELINE=True,
              GZIP=True):
     PlugIn.__init__(self)
     self.DBG_LINE = 'bosh'
     self._exported_methods = [
         self.send,
         self.receive,
         self.disconnect,
     ]
     url = urlparse(endpoint)
     self._http_host = url.hostname
     self._http_path = url.path
     if url.port:
         self._http_port = url.port
     elif url.scheme == 'https':
         self._http_port = 443
     else:
         self._http_port = 80
     self._http_proto = url.scheme
     self._server = server
     self._port = port
     self.use_srv = use_srv
     self.Sid = None
     self._rid = 0
     self.wait = 80
     self.hold = hold
     self.requests = requests
     self._pipeline = None
     self.PIPELINE = PIPELINE
     if self.PIPELINE:
         self._respobjs = []
     else:
         self._respobjs = {}
     self.headers = headers or self.default_headers
     self.GZIP = GZIP
Exemple #18
0
 def PlugIn(self, owner, now=0):
     if owner.__dict__.has_key('TLS'): return  # Already enabled.
     PlugIn.PlugIn(self, owner)
     DBG_LINE = 'TLS'
     if now: return self._startSSL()
     if self._owner.Dispatcher.Stream.features:
         self.FeaturesHandler(self._owner.Dispatcher,
                              self._owner.Dispatcher.Stream.features)
     else:
         self._owner.RegisterHandlerOnce('features', self.FeaturesHandler)
     self.starttls = None
Exemple #19
0
	def __init__(self, on_connect = None, on_connect_failure = None, server=None, use_srv = True):
		''' Cache connection point 'server'. 'server' is the tuple of (host, port)
			absolutely the same as standard tcp socket uses. 
			on_connect - called when we connect to the socket
			on_connect_failure  - called if there was error connecting to socket
			'''
		IdleObject.__init__(self)
		PlugIn.__init__(self)
		self.DBG_LINE='socket'
		self._exported_methods=[self.send, self.disconnect, self.onreceive, self.set_send_timeout, 
			self.start_disconnect, self.set_timeout, self.remove_timeout]
		self._server = server
		self.on_connect  = on_connect
		self.on_connect_failure = on_connect_failure
		self.on_receive = None
		self.on_disconnect = None
		self.printed_error = False
		
		#  0 - not connected
		#  1 - connected
		# -1 - about to disconnect (when we wait for final events to complete)
		# -2 - disconnected
		self.state = 0
		
		# queue with messages to be send 
		self.sendqueue = []
		
		# bytes remained from the last send message
		self.sendbuff = ''
		
		# time to wait for SOME stanza to come and then send keepalive
		self.sendtimeout = 0
		
		# in case we want to something different than sending keepalives
		self.on_timeout = None
		
		# writable, readable  -  keep state of the last pluged flags
		# This prevents replug of same object with the same flags
		self.writable = True
		self.readable = False
		self.ais = None
Exemple #20
0
    def __init__(self, server=None, use_srv=True):
        """ Cache connection point 'server'. 'server' is the tuple of (host, port)
            absolutely the same as standard tcp socket uses. """
        PlugIn.__init__(self)
        self.DBG_LINE='socket'
        self._exported_methods=[self.send,self.disconnect]

        # SRV resolver
        if use_srv and (HAVE_DNSPYTHON or HAVE_PYDNS):
            host, port = server
            possible_queries = ['_xmpp-client._tcp.' + host]

            for query in possible_queries:
                try:
                    if HAVE_DNSPYTHON:
                        answers = [x for x in dns.resolver.query(query, 'SRV')]
                        if answers:
                            host = str(answers[0].target)
                            port = int(answers[0].port)
                            break
                    elif HAVE_PYDNS:
                        # ensure we haven't cached an old configuration
                        DNS.ParseResolvConf()
                        response = DNS.Request().req(query, qtype='SRV')
                        answers = response.answers
                        if len(answers) > 0:
                            # ignore the priority and weight for now
                            _, _, port, host = answers[0]['data']
                            del _
                            port = int(port)
                            break
                except:
                    #TODO: use self.DEBUG()
                    print 'An error occurred while looking up %s' % query
            server = (host, port)
        # end of SRV resolver

        self._server = server
Exemple #21
0
    def __init__(self, server=None, use_srv=True):
        """ Cache connection point 'server'. 'server' is the tuple of (host, port)
            absolutely the same as standard tcp socket uses. """
        PlugIn.__init__(self)
        self.DBG_LINE = 'socket'
        self._exported_methods = [self.send, self.disconnect]

        # SRV resolver
        if use_srv and (HAVE_DNSPYTHON or HAVE_PYDNS):
            host, port = server
            possible_queries = ['_xmpp-client._tcp.' + host]

            for query in possible_queries:
                try:
                    if HAVE_DNSPYTHON:
                        answers = [x for x in dns.resolver.query(query, 'SRV')]
                        if answers:
                            host = str(answers[0].target)
                            port = int(answers[0].port)
                            break
                    elif HAVE_PYDNS:
                        # ensure we haven't cached an old configuration
                        DNS.ParseResolvConf()
                        response = DNS.Request().req(query, qtype='SRV')
                        answers = response.answers
                        if len(answers) > 0:
                            # ignore the priority and weight for now
                            _, _, port, host = answers[0]['data']
                            del _
                            port = int(port)
                            break
                except:
                    #TODO: use self.DEBUG()
                    print 'An error occurred while looking up %s' % query
            server = (host, port)
        # end of SRV resolver

        self._server = server
Exemple #22
0
 def PlugIn(self,owner,now=0):
     """ If the 'now' argument is true then starts using encryption immidiatedly.
         If 'now' in false then starts encryption as soon as TLS feature is
         declared by the server (if it were already declared - it is ok).
     """
     if owner.__dict__.has_key('TLS'): return  # Already enabled.
     PlugIn.PlugIn(self,owner)
     DBG_LINE='TLS'
     if now: return self._startSSL()
     if self._owner.Dispatcher.Stream.features:
         try: self.FeaturesHandler(self._owner.Dispatcher,self._owner.Dispatcher.Stream.features)
         except NodeProcessed: pass
     else: self._owner.RegisterHandlerOnce('features',self.FeaturesHandler,xmlns=NS_STREAMS)
     self.starttls=None
Exemple #23
0
 def __init__(self, server=None):
     PlugIn.__init__(self)
     self.DBG_LINE='socket'
     self._exported_methods=[self.send,self.disconnect]
     self._server = server
Exemple #24
0
 def __init__(self):
     PlugIn.__init__(self)
     self.DBG_LINE = 'roster'
     self._data = {}
     self.set = None
     self._exported_methods = [self.getRoster]
Exemple #25
0
 def __init__(self):
     """Initialises internal variables. Used internally."""
     PlugIn.__init__(self)
     DBG_LINE = 'browser'
     self._exported_methods = []
     self._handlers = {'': {}}
Exemple #26
0
 def __init__(self, username, password):
     PlugIn.__init__(self)
     self.DBG_LINE = 'SASL_auth'
     self.username = username
     self.password = password
     self.startsasl = None
Exemple #27
0
 def __init__(self):
     """Initialises internal variables. Used internally."""
     PlugIn.__init__(self)
     DBG_LINE='browser'
     self._exported_methods=[]
     self._handlers={'':{}}
Exemple #28
0
 def __init__(self):
     PlugIn.__init__(self)
     self.DBG_LINE='roster'
     self._data = {}
     self.set=None
     self._exported_methods=[self.getRoster]
Exemple #29
0
 def __init__(self, server=None):
     PlugIn.__init__(self)
     self.DBG_LINE = 'socket'
     self._exported_methods = [self.send, self.disconnect]
     self._server = server
Exemple #30
0
 def __init__(self,username,password):
     PlugIn.__init__(self)
     self.username=username
     self.password=password
Exemple #31
0
 def __init__(self, username, password):
     PlugIn.__init__(self)
     self.DBG_LINE = "SASL_auth"
     self.username = username
     self.password = password
     self.startsasl = None
Exemple #32
0
 def __init__(self, sasl):
     PlugIn.__init__(self)
     self.DBG_LINE='bind'
     self.bound=None
     self.needsUnregister=None
     self.sasl = sasl
Exemple #33
0
 def __init__(self):
     PlugIn.__init__(self)
     self.DBG_LINE='bind'
     self.bound=None
Exemple #34
0
 def __init__(self, user, password, resource):
     PlugIn.__init__(self)
     self.DBG_LINE = "gen_auth"
     self.user = user
     self.password = password
     self.resource = resource
Exemple #35
0
	def __init__(self,username,password, on_sasl):
		PlugIn.__init__(self)
		self.username=username
		self.password=password
		self.on_sasl = on_sasl
		self.realm = None
Exemple #36
0
 def __init__(self):
     PlugIn.__init__(self)
     DBG_LINE = 'browser'
     self._exported_methods = []
     self._handlers = {'': {}}
Exemple #37
0
 def __init__(self,user,password,resource):
     PlugIn.__init__(self)
     self.DBG_LINE='gen_auth'
     self.user=user
     self.password=password
     self.resource=resource