diff --git a/src/common/zeroconf/connection_zeroconf.py b/src/common/zeroconf/connection_zeroconf.py index 072c9b674..1ff695585 100644 --- a/src/common/zeroconf/connection_zeroconf.py +++ b/src/common/zeroconf/connection_zeroconf.py @@ -232,7 +232,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf): def change_status(self, show, msg, sync = False, auto = False): if not show in STATUS_LIST: return -1 - + check = True #to check for errors from zeroconf # 'connect' @@ -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)) diff --git a/src/common/zeroconf/zeroconf.py b/src/common/zeroconf/zeroconf.py index a1ac54d5f..b3f534b23 100755 --- a/src/common/zeroconf/zeroconf.py +++ b/src/common/zeroconf/zeroconf.py @@ -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,8 +253,9 @@ class Zeroconf: return True def disconnect(self): - self.connected = False - self.remove_announce() + if self.connected: + self.connected = False + self.remove_announce() # refresh txt data of all contacts manually (no callback available) def resolve_all(self): @@ -292,26 +296,30 @@ 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 = '' - - print 'receive:' + recvd - - self.send("", sock) - self.send("" + msg + "" + msg +"", sock) + # 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] ) ) + + sock.connect ( ( self.contacts[jid][4], int((self.txt_array_to_dict(self.contacts[jid][7]))['port.p2pj']) ) ) + #TODO: better use an xml-class for this... + self.send("", sock) + try: recvd = sock.recv(16384) except: recvd = '' print 'receive:' + recvd + + #adium requires the html parts + self.send("" + msg + "" + msg +"", sock) + +# self.send("" + msg + "", sock) self.send('', sock) sock.close()