Author: tomk
Date: 2008-08-18 16:34:09 +0200 (Mon, 18 Aug 2008)
New Revision: 10257
Modified:
branches/bosh_support/src/common/zeroconf/client_zeroconf.py
branches/bosh_support/src/common/zeroconf/connection_handlers_zeroconf.py
branches/bosh_support/src/common/zeroconf/connection_zeroconf.py
Log:
fixed zeroconf to work with refactored dispatcher
Modified: branches/bosh_support/src/common/zeroconf/client_zeroconf.py
===================================================================
--- branches/bosh_support/src/common/zeroconf/client_zeroconf.py 2008-08-18 14:20:03 UTC (rev 10256)
+++ branches/bosh_support/src/common/zeroconf/client_zeroconf.py 2008-08-18 14:34:09 UTC (rev 10257)
@@ -23,6 +23,7 @@
from common.xmpp import dispatcher_nb, simplexml
from common.xmpp.client import *
from common.xmpp.simplexml import ustr
+from common.xmpp.transports_nb import DATA_RECEIVED, DATA_SENT
from common.zeroconf import zeroconf
from common.xmpp.protocol import *
@@ -36,8 +37,6 @@
from common.zeroconf import roster_zeroconf
MAX_BUFF_LEN = 65536
-DATA_RECEIVED = 'DATA RECEIVED'
-DATA_SENT = 'DATA SENT'
TYPE_SERVER, TYPE_CLIENT = range(2)
# wait XX sec to establish a connection
@@ -120,6 +119,7 @@
on_ok=None, on_not_ok=None):
self._owner = self
self.Namespace = 'jabber:client'
+ self.protocol_type = 'XMPP'
self.defaultNamespace = self.Namespace
self._component = 0
self._registered_name = None
@@ -130,16 +130,7 @@
self.Server = host
self.on_ok = on_ok
self.on_not_ok = on_not_ok
- self.DBG = 'client'
self.Connection = None
- if gajim.verbose:
- debug = ['always', 'nodebuilder']
- else:
- debug = []
- self._DEBUG = Debug.Debug(debug)
- self.DEBUG = self._DEBUG.Show
- self.debug_flags = self._DEBUG.debug_flags
- self.debug_flags.append(self.DBG)
self.sock_hash = None
if _sock:
self.sock_type = TYPE_SERVER
@@ -202,8 +193,6 @@
self.Dispatcher.Stream._dispatch_depth = 2
self.Dispatcher.Stream.dispatch = self.Dispatcher.dispatch
self.Dispatcher.Stream.stream_header_received = self._check_stream_start
- self.debug_flags.append(simplexml.DBG_NODEBUILDER)
- self.Dispatcher.Stream.DEBUG = self.DEBUG
self.Dispatcher.Stream.features = None
if self.sock_type == TYPE_CLIENT:
self.send_stream_header()
@@ -221,8 +210,7 @@
def _check_stream_start(self, ns, tag, attrs):
if ns<>NS_STREAMS or tag<>'stream':
- self.Connection.DEBUG('Incorrect stream start: (%s,%s).Terminating! ' \
- % (tag, ns), 'error')
+ log.error('Incorrect stream start: (%s,%s).Terminating!' % (tag, ns), 'error')
self.Connection.disconnect()
if self.on_not_ok:
self.on_not_ok('Connection to host could not be established: Incorrect answer from server.')
@@ -472,13 +460,13 @@
if self._owner.sock_type == TYPE_CLIENT:
self.set_timeout(ACTIVITY_TIMEOUT_SECONDS)
if received.strip():
- self.DEBUG(received, 'got')
+ log.debug('received: %s', received)
if hasattr(self._owner, 'Dispatcher'):
self._owner.Dispatcher.Event('', DATA_RECEIVED, received)
self.on_receive(received)
else:
# This should never happed, so we need the debug
- self.DEBUG('Unhandled data received: %s' % received,'error')
+ log.error('Unhandled data received: %s' % received)
self.disconnect()
return True
@@ -553,7 +541,7 @@
def _on_send(self):
if self.sent_data and self.sent_data.strip():
- self.DEBUG(self.sent_data,'sent')
+ log.debug('sent: %s' % self.sent_data)
if hasattr(self._owner, 'Dispatcher'):
self._owner.Dispatcher.Event('', DATA_SENT, self.sent_data)
self.sent_data = None
@@ -562,7 +550,7 @@
self.buff_is_message = False
def _on_send_failure(self):
- self.DEBUG("Socket error while sending data",'error')
+ log.error('Socket error while sending data')
self._owner.disconnected()
self.sent_data = None
@@ -698,19 +686,23 @@
# look for hashed connections
if to in self.recipient_to_hash:
conn = self.connections[self.recipient_to_hash[to]]
+ id = conn.Dispatcher.getAnID()
+ stanza.setID(id)
if conn.add_stanza(stanza, is_message):
if on_ok:
on_ok()
- return 0
+ return id
if item['address'] in self.ip_to_hash:
hash = self.ip_to_hash[item['address']]
if self.hash_to_port[hash] == item['port']:
conn = self.connections[hash]
+ id = conn.Dispatcher.getAnID()
+ stanza.setID(id)
if conn.add_stanza(stanza, is_message):
if on_ok:
on_ok()
- return 0
+ return id
# otherwise open new connection
P2PClient(None, item['address'], item['port'], self,
Modified: branches/bosh_support/src/common/zeroconf/connection_handlers_zeroconf.py
===================================================================
--- branches/bosh_support/src/common/zeroconf/connection_handlers_zeroconf.py 2008-08-18 14:20:03 UTC (rev 10256)
+++ branches/bosh_support/src/common/zeroconf/connection_handlers_zeroconf.py 2008-08-18 14:34:09 UTC (rev 10257)
@@ -460,7 +460,7 @@
else:
# XXX this shouldn't be hardcoded
if isinstance(session, ChatControlSession):
- session.received(frm, msgtxt, tim, encrypted, subject, msg)
+ session.received(frm, msgtxt, tim, encrypted, msg)
else:
session.received(msg)
# END messageCB
Modified: branches/bosh_support/src/common/zeroconf/connection_zeroconf.py
===================================================================
--- branches/bosh_support/src/common/zeroconf/connection_zeroconf.py 2008-08-18 14:20:03 UTC (rev 10256)
+++ branches/bosh_support/src/common/zeroconf/connection_zeroconf.py 2008-08-18 14:34:09 UTC (rev 10257)
@@ -138,6 +138,7 @@
if gajim.handlers.has_key(event):
gajim.handlers[event](self.name, data)
+
def _reconnect(self):
# Do not try to reco while we are already trying
self.time_to_reconnect = None
@@ -449,19 +450,20 @@
else:
kind = 'single_msg_sent'
gajim.logger.write(kind, jid, log_msg)
-
+
self.dispatch('MSGSENT', (jid, msg, keyID))
def on_send_not_ok(reason):
reason += ' ' + _('Your message could not be sent.')
self.dispatch('MSGERROR', [jid, '-1', reason, None, None, session])
-
ret = self.connection.send(msg_iq, msg != None, on_ok=on_send_ok,
on_not_ok=on_send_not_ok)
if ret == -1:
# Contact Offline
self.dispatch('MSGERROR', [jid, '-1', _('Contact is offline. Your message could not be sent.'), None, None, session])
+ return ret
+
def send_stanza(self, stanza):
# send a stanza untouched
if not self.connection:
@@ -547,9 +549,9 @@
def _event_dispatcher(self, realm, event, data):
if realm == '':
- if event == common.xmpp.transports.DATA_RECEIVED:
+ if event == common.xmpp.transports_nb.DATA_RECEIVED:
self.dispatch('STANZA_ARRIVED', unicode(data, errors = 'ignore'))
- elif event == common.xmpp.transports.DATA_SENT:
+ elif event == common.xmpp.transports_nb.DATA_SENT:
self.dispatch('STANZA_SENT', unicode(data))
# END ConnectionZeroconf