make sending compatible with ichat and adium

This commit is contained in:
Stefan Bethge 2006-08-02 00:04:47 +00:00
parent da06dfb6ca
commit 9ac7e753f1
2 changed files with 26 additions and 19 deletions

View File

@ -307,7 +307,6 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
msg_iq = common.xmpp.Message(to = fjid, body = msgtxt,
typ = 'normal')
if msgenc:
msg_iq.setTag(common.xmpp.NS_ENCRYPTED + ' x').setData(msgenc)
@ -342,7 +341,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
kind = 'single_msg_sent'
gajim.logger.write(kind, jid, log_msg)
self.zeroconf.send_message(jid, msgtxt)
self.zeroconf.send_message(jid, msgtxt, type)
self.dispatch('MSGSENT', (jid, msg, keyID))

View File

@ -43,6 +43,7 @@ class Zeroconf:
self.contacts = {} # all current local contacts with data
self.entrygroup = None
self.connected = False
self.announced = False
## handlers for dbus callbacks
@ -158,12 +159,10 @@ class Zeroconf:
# make zeroconf-valid names
def replace_show(self, show):
if show == 'chat' or show == '':
show = 'online'
if show == 'chat' or show == 'online' or show == '':
show = 'avail'
elif show == 'xa':
show = 'away'
elif show == 'online':
show = 'avail'
return show
def create_service(self):
@ -197,16 +196,20 @@ class Zeroconf:
if state == avahi.SERVER_RUNNING:
self.create_service()
self.announced = True
return True
else:
return False
def remove_announce(self):
if self.announced == False:
return False
try:
if self.entrygroup.GetState() != avahi.ENTRY_GROUP_FAILURE:
self.entrygroup.Reset()
self.entrygroup.Free()
self.entrygroup = None
self.announced = False
return True
else:
return False
@ -250,6 +253,7 @@ class Zeroconf:
return True
def disconnect(self):
if self.connected:
self.connected = False
self.remove_announce()
@ -292,27 +296,31 @@ class Zeroconf:
raise RuntimeError, "socket connection broken"
totalsent = totalsent + sent
def send_message(self, jid, msg):
def send_message(self, jid, msg, type = 'chat'):
print 'zeroconf.py: send_message:'+ msg
jid = self.recreate_bad_jid(jid)
sock = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
#sock.setblocking(False)
sock.connect ( ( self.contacts[jid][4], self.contacts[jid][6] ) )
try : recvd = sock.recv(16384)
except: recvd = ''
# jep-0174 wants clients to use the port from the srv record
# but at least adium uses the txt record (port.p2pj)
#sock.connect ( ( self.contacts[jid][4], self.contacts[jid][6] ) )
print 'receive:' + recvd
sock.connect ( ( self.contacts[jid][4], int((self.txt_array_to_dict(self.contacts[jid][7]))['port.p2pj']) ) )
self.send("<?xml version='1.0' encoding='UTF-8'?><stream:stream to="+ self.contacts[jid][5] +" xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>", sock)
self.send("<message to=" + jid + " type='chat'><body>" + msg + "</body><html xmlns='html://www.w3.org/1999/xhtml'><body ichatballoncolor='#111111' ichattextcolor='#000000'><font face='Courier' ABSZ='3'>" + msg +"</font></body></html><x xmlns='jabber:x:event'><delivered /></x></message>", sock)
#TODO: better use an xml-class for this...
self.send("<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>", sock)
try: recvd = sock.recv(16384)
except: recvd = ''
print 'receive:' + recvd
#adium requires the html parts
self.send("<message to='" + jid + "' from='" + self.name + "' type='" + type + "'><body>" + msg + "</body><html xmlns='html://www.w3.org/1999/xhtml'><body ichatballoncolor='#5598d7' ichattextcolor='#000000'><font face='Courier' ABSZ='3'>" + msg +"</font></body></html><x xmlns='jabber:x:event'><composing /></x></message>", sock)
# self.send("<message to='" + jid + "' from='" + self.name +"' type='" + type + "'><body>" + msg + "</body></message>", sock)
self.send('</stream>', sock)
sock.close()