better xmmpppy plugin integration.
fixed xml error with iChats
This commit is contained in:
parent
44e2bd0247
commit
e9a855007b
|
@ -400,7 +400,7 @@ class Dispatcher(PlugIn):
|
||||||
''' Serialise stanza and put it on the wire. Assign an unique ID to it before send.
|
''' Serialise stanza and put it on the wire. Assign an unique ID to it before send.
|
||||||
Returns assigned ID.'''
|
Returns assigned ID.'''
|
||||||
if type(stanza) in [type(''), type(u'')]:
|
if type(stanza) in [type(''), type(u'')]:
|
||||||
return self._owner.send_stanza(stanza)
|
return self._owner.Connection.send(stanza)
|
||||||
if not isinstance(stanza, Protocol):
|
if not isinstance(stanza, Protocol):
|
||||||
_ID=None
|
_ID=None
|
||||||
elif not stanza.getID():
|
elif not stanza.getID():
|
||||||
|
@ -423,7 +423,7 @@ class Dispatcher(PlugIn):
|
||||||
stanza=route
|
stanza=route
|
||||||
stanza.setNamespace(self._owner.Namespace)
|
stanza.setNamespace(self._owner.Namespace)
|
||||||
stanza.setParent(self._metastream)
|
stanza.setParent(self._metastream)
|
||||||
self._owner.send_stanza(stanza)
|
self._owner.Connection.send(stanza)
|
||||||
return _ID
|
return _ID
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
|
|
|
@ -362,7 +362,7 @@ class NodeBuilder:
|
||||||
if self.last_is_data:
|
if self.last_is_data:
|
||||||
if self.data_buffer:
|
if self.data_buffer:
|
||||||
self.data_buffer.append(data)
|
self.data_buffer.append(data)
|
||||||
else:
|
elif self._ptr:
|
||||||
self.data_buffer = [data]
|
self.data_buffer = [data]
|
||||||
self.last_is_data = 1
|
self.last_is_data = 1
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
## common/zeroconf/client_zeroconf.py
|
## common/zeroconf/client_zeroconf.py
|
||||||
##
|
##
|
||||||
## Copyright (C) 2006 Stefan Bethge <stefan@lanpartei.de>
|
## Copyright (C) 2006 Stefan Bethge <stefan@lanpartei.de>
|
||||||
## 2006 Dimitur Kirov <dkirov@gmail.com>
|
## 2006 Dimitur Kirov <dkirov@gmail.com>
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
##
|
##
|
||||||
from common import gajim
|
from common import gajim
|
||||||
from common.xmpp.idlequeue import IdleObject
|
from common.xmpp.idlequeue import IdleObject
|
||||||
from common.xmpp import dispatcher_nb, debug
|
from common.xmpp import dispatcher_nb
|
||||||
from common.xmpp.client import *
|
from common.xmpp.client import *
|
||||||
from common.xmpp.simplexml import ustr
|
from common.xmpp.simplexml import ustr
|
||||||
from dialogs import BindPortError
|
from dialogs import BindPortError
|
||||||
|
@ -58,12 +58,12 @@ class ZeroconfListener(IdleObject):
|
||||||
|
|
||||||
def pollend(self):
|
def pollend(self):
|
||||||
''' called when we stop listening on (host, port) '''
|
''' called when we stop listening on (host, port) '''
|
||||||
self.disconnect2()
|
self.disconnect()
|
||||||
|
|
||||||
def pollin(self):
|
def pollin(self):
|
||||||
''' accept a new incomming connection and notify queue'''
|
''' accept a new incomming connection and notify queue'''
|
||||||
sock = self.accept_conn()
|
sock = self.accept_conn()
|
||||||
P2PConnection('', sock[0], sock[1][0], sock[1][1], self.caller)
|
P2PClient(sock[0], sock[1][0], sock[1][1], self.caller)
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
''' free all resources, we are not listening anymore '''
|
''' free all resources, we are not listening anymore '''
|
||||||
|
@ -83,59 +83,32 @@ class ZeroconfListener(IdleObject):
|
||||||
return _sock
|
return _sock
|
||||||
|
|
||||||
|
|
||||||
class P2PConnection(IdleObject, PlugIn):
|
|
||||||
''' class for sending file to socket over socks5 '''
|
class P2PClient(IdleObject):
|
||||||
def __init__(self, sock_hash, _sock, host = None, port = None, caller = None):
|
def __init__(self, _sock, host, port, caller):
|
||||||
PlugIn.__init__(self)
|
self._owner = self
|
||||||
self.sendqueue = []
|
|
||||||
self.sendbuff = None
|
|
||||||
self._sock = _sock
|
|
||||||
self._sock.setblocking(False)
|
|
||||||
self.fd = _sock.fileno()
|
|
||||||
self._recv = _sock.recv
|
|
||||||
self._send = _sock.send
|
|
||||||
self.connected = True
|
|
||||||
self.state = 1
|
|
||||||
self.writable = False
|
|
||||||
self.readable = False
|
|
||||||
# waiting for first bytes
|
|
||||||
# start waiting for data
|
|
||||||
self.Namespace = 'jabber:client'
|
self.Namespace = 'jabber:client'
|
||||||
self.defaultNamespace = self.Namespace
|
self.defaultNamespace = self.Namespace
|
||||||
self._component=0
|
self._component=0
|
||||||
self._caller = caller
|
self._caller = caller
|
||||||
self.Server = host
|
self.Server = host
|
||||||
self.Connection = self
|
|
||||||
self._registered_name = None
|
|
||||||
self.DBG = 'client'
|
self.DBG = 'client'
|
||||||
debug = ['always', 'nodebuilder']
|
debug = ['always', 'nodebuilder']
|
||||||
self._DEBUG = Debug.Debug(debug)
|
self._DEBUG = Debug.Debug(debug)
|
||||||
self.DEBUG = self._DEBUG.Show
|
self.DEBUG = self._DEBUG.Show
|
||||||
self.debug_flags = self._DEBUG.debug_flags
|
self.debug_flags = self._DEBUG.debug_flags
|
||||||
self.debug_flags.append(self.DBG)
|
self.debug_flags.append(self.DBG)
|
||||||
self._owner = self
|
self.Connection = P2PConnection('', _sock, host, port, caller)
|
||||||
self._exported_methods=[self.send_stanza, self.disconnect2, self.pollend]
|
self.Connection.PlugIn(self)
|
||||||
self.on_receive = None
|
|
||||||
gajim.idlequeue.plug_idle(self, False, True)
|
|
||||||
self.onreceive(self._on_receive_document_attrs)
|
|
||||||
dispatcher_nb.Dispatcher().PlugIn(self)
|
dispatcher_nb.Dispatcher().PlugIn(self)
|
||||||
|
|
||||||
self.RegisterHandler('message', self._messageCB)
|
self.RegisterHandler('message', self._messageCB)
|
||||||
|
|
||||||
|
def disconnected(self):
|
||||||
def _messageCB(self, conn, data):
|
if self.__dict__.has_key('Dispatcher'):
|
||||||
self._caller._messageCB(self.Server, conn, data)
|
self.Dispatcher.PlugOut()
|
||||||
|
if self.__dict__.has_key('P2PConnection'):
|
||||||
def onreceive(self, recv_handler):
|
self.P2PConnection.PlugOut()
|
||||||
if not recv_handler:
|
|
||||||
if hasattr(self._owner, 'Dispatcher'):
|
|
||||||
self.on_receive = self._owner.Dispatcher.ProcessNonBlocking
|
|
||||||
else:
|
|
||||||
self.on_receive = None
|
|
||||||
return
|
|
||||||
_tmp = self.on_receive
|
|
||||||
# make sure this cb is not overriden by recursive calls
|
|
||||||
if not recv_handler(None) and _tmp == self.on_receive:
|
|
||||||
self.on_receive = recv_handler
|
|
||||||
|
|
||||||
def _on_receive_document_attrs(self, data):
|
def _on_receive_document_attrs(self, data):
|
||||||
if data:
|
if data:
|
||||||
|
@ -152,7 +125,67 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
self.onreceive(None)
|
self.onreceive(None)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def send_stanza(self, stanza):
|
|
||||||
|
def _messageCB(self, conn, data):
|
||||||
|
self._caller._messageCB(self.Server, conn, data)
|
||||||
|
|
||||||
|
|
||||||
|
class P2PConnection(IdleObject, PlugIn):
|
||||||
|
''' class for sending file to socket over socks5 '''
|
||||||
|
def __init__(self, sock_hash, _sock, host = None, port = None, caller = None):
|
||||||
|
IdleObject.__init__(self)
|
||||||
|
PlugIn.__init__(self)
|
||||||
|
self.DBG_LINE='socket'
|
||||||
|
self.sendqueue = []
|
||||||
|
self.sendbuff = None
|
||||||
|
self._sock = _sock
|
||||||
|
self._sock.setblocking(False)
|
||||||
|
self.fd = _sock.fileno()
|
||||||
|
self._recv = _sock.recv
|
||||||
|
self._send = _sock.send
|
||||||
|
self.connected = True
|
||||||
|
self.state = 1
|
||||||
|
self.writable = False
|
||||||
|
self.readable = False
|
||||||
|
# waiting for first bytes
|
||||||
|
# start waiting for data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#~ self.Connection = self
|
||||||
|
self._registered_name = None
|
||||||
|
|
||||||
|
self._exported_methods=[self.send, self.disconnect, self.onreceive]
|
||||||
|
self.on_receive = None
|
||||||
|
|
||||||
|
|
||||||
|
def plugin(self, owner):
|
||||||
|
self.onreceive(owner._on_receive_document_attrs)
|
||||||
|
gajim.idlequeue.plug_idle(self, False, True)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def plugout(self):
|
||||||
|
''' Disconnect from the remote server and unregister self.disconnected method from
|
||||||
|
the owner's dispatcher. '''
|
||||||
|
self.disconnect()
|
||||||
|
self._owner.Connection = None
|
||||||
|
self._owner = None
|
||||||
|
|
||||||
|
def onreceive(self, recv_handler):
|
||||||
|
if not recv_handler:
|
||||||
|
if hasattr(self._owner, 'Dispatcher'):
|
||||||
|
self.on_receive = self._owner.Dispatcher.ProcessNonBlocking
|
||||||
|
else:
|
||||||
|
self.on_receive = None
|
||||||
|
return
|
||||||
|
_tmp = self.on_receive
|
||||||
|
# make sure this cb is not overriden by recursive calls
|
||||||
|
if not recv_handler(None) and _tmp == self.on_receive:
|
||||||
|
self.on_receive = recv_handler
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def send(self, stanza):
|
||||||
'''Append stanza to the queue of messages to be send.
|
'''Append stanza to the queue of messages to be send.
|
||||||
If supplied data is unicode string, encode it to utf-8.
|
If supplied data is unicode string, encode it to utf-8.
|
||||||
'''
|
'''
|
||||||
|
@ -161,8 +194,8 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
r = stanza
|
r = stanza
|
||||||
if isinstance(r, unicode):
|
if isinstance(r, unicode):
|
||||||
r = r.encode('utf-8')
|
r = r.encode('utf-8')
|
||||||
elif not isinstance(r, str):
|
#~ elif not isinstance(r, str):
|
||||||
r = ustr(r).encode('utf-8')
|
#~ r = ustr(r).encode('utf-8')
|
||||||
self.sendqueue.append(r)
|
self.sendqueue.append(r)
|
||||||
self._plug_idle()
|
self._plug_idle()
|
||||||
|
|
||||||
|
@ -177,11 +210,10 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
return
|
return
|
||||||
gajim.idlequeue.remove_timeout(self.fd)
|
gajim.idlequeue.remove_timeout(self.fd)
|
||||||
self._do_send()
|
self._do_send()
|
||||||
# self.idlequeue.plug_idle(self, False, True)
|
|
||||||
|
|
||||||
def pollend(self):
|
def pollend(self):
|
||||||
self.state = -1
|
self.state = -1
|
||||||
self.disconnect2()
|
self.disconnect()
|
||||||
|
|
||||||
def pollin(self):
|
def pollin(self):
|
||||||
''' Reads all pending incoming data. Calls owner's disconnected() method if appropriate.'''
|
''' Reads all pending incoming data. Calls owner's disconnected() method if appropriate.'''
|
||||||
|
@ -206,7 +238,7 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
# 8 EOF occurred in violation of protocol
|
# 8 EOF occurred in violation of protocol
|
||||||
self.pollend()
|
self.pollend()
|
||||||
if self.state >= 0:
|
if self.state >= 0:
|
||||||
self.disconnect2()
|
self.disconnect()
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.state < 0:
|
if self.state < 0:
|
||||||
|
@ -218,7 +250,7 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
else:
|
else:
|
||||||
# This should never happed, so we need the debug
|
# This should never happed, so we need the debug
|
||||||
self.DEBUG('Unhandled data received: %s' % received,'got')
|
self.DEBUG('Unhandled data received: %s' % received,'got')
|
||||||
self.disconnect2()
|
self.disconnect()
|
||||||
if self.on_connect_failure:
|
if self.on_connect_failure:
|
||||||
self.on_connect_failure()
|
self.on_connect_failure()
|
||||||
return True
|
return True
|
||||||
|
@ -235,7 +267,7 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
if not recv_handler(None) and _tmp == self.on_receive:
|
if not recv_handler(None) and _tmp == self.on_receive:
|
||||||
self.on_receive = recv_handler
|
self.on_receive = recv_handler
|
||||||
|
|
||||||
def disconnect2(self):
|
def disconnect(self):
|
||||||
''' Closes the socket. '''
|
''' Closes the socket. '''
|
||||||
gajim.idlequeue.remove_timeout(self.fd)
|
gajim.idlequeue.remove_timeout(self.fd)
|
||||||
gajim.idlequeue.unplug_idle(self.fd)
|
gajim.idlequeue.unplug_idle(self.fd)
|
||||||
|
@ -248,6 +280,7 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.fd = -1
|
self.fd = -1
|
||||||
self.state = -1
|
self.state = -1
|
||||||
|
self._owner.disconnected()
|
||||||
|
|
||||||
def _do_send(self):
|
def _do_send(self):
|
||||||
if not self.sendbuff:
|
if not self.sendbuff:
|
||||||
|
@ -263,7 +296,7 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
if self.state < 0:
|
if self.state < 0:
|
||||||
gajim.idlequeue.unplug_idle(self.fd)
|
gajim.idlequeue.unplug_idle(self.fd)
|
||||||
self._on_send()
|
self._on_send()
|
||||||
self.disconnect2()
|
self.disconnect()
|
||||||
return
|
return
|
||||||
# we are not waiting for write
|
# we are not waiting for write
|
||||||
self._plug_idle()
|
self._plug_idle()
|
||||||
|
@ -273,9 +306,8 @@ class P2PConnection(IdleObject, PlugIn):
|
||||||
if e[0] == socket.SSL_ERROR_WANT_WRITE:
|
if e[0] == socket.SSL_ERROR_WANT_WRITE:
|
||||||
return True
|
return True
|
||||||
if self.state < 0:
|
if self.state < 0:
|
||||||
self.disconnect2()
|
self.disconnect()
|
||||||
return
|
return
|
||||||
if self._on_send_failure:
|
|
||||||
self._on_send_failure()
|
self._on_send_failure()
|
||||||
return
|
return
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue