more methods in roster_zeroconf, on_new_service when service is resolved
This commit is contained in:
parent
cf5ad66259
commit
40fc5202a5
|
@ -190,12 +190,12 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
|
|
||||||
def _on_new_service(self,jid):
|
def _on_new_service(self,jid):
|
||||||
self.roster.setItem(jid)
|
self.roster.setItem(jid)
|
||||||
self.dispatch('ROSTER', self.roster)
|
#self.dispatch('ROSTER', self.roster)
|
||||||
|
self.dispatch('NOTIFY', (jid, self.roster.getStatus(jid), '', 'Gajim', 0, None, 0))
|
||||||
|
|
||||||
def _on_remove_service(self,jid):
|
def _on_remove_service(self,jid):
|
||||||
# roster.delItem(jid)
|
self.roster.delItem(jid)
|
||||||
# self.dispatch('ROSTER', roster)
|
#self.dispatch('NOTIFY', self, )
|
||||||
pass
|
|
||||||
|
|
||||||
def connect(self, data = None, show = 'online'):
|
def connect(self, data = None, show = 'online'):
|
||||||
if self.connection:
|
if self.connection:
|
||||||
|
@ -204,6 +204,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
self.zeroconf.connect()
|
self.zeroconf.connect()
|
||||||
self.connection = client_zeroconf.ClientZeroconf(self.zeroconf)
|
self.connection = client_zeroconf.ClientZeroconf(self.zeroconf)
|
||||||
self.roster = self.connection.getRoster()
|
self.roster = self.connection.getRoster()
|
||||||
|
self.dispatch('ROSTER', self.roster)
|
||||||
self.connected = STATUS_LIST.index(show)
|
self.connected = STATUS_LIST.index(show)
|
||||||
|
|
||||||
def connect_and_init(self, show, msg, signed):
|
def connect_and_init(self, show, msg, signed):
|
||||||
|
@ -254,25 +255,9 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
self.zeroconf.update_txt(txt)
|
self.zeroconf.update_txt(txt)
|
||||||
self.dispatch('STATUS', show)
|
self.dispatch('STATUS', show)
|
||||||
|
|
||||||
'''
|
|
||||||
def _on_disconnected(self):
|
|
||||||
self.dispatch('STATUS', 'offline')
|
|
||||||
self.disconnect()
|
|
||||||
'''
|
|
||||||
|
|
||||||
def get_status(self):
|
def get_status(self):
|
||||||
return STATUS_LIST[self.connected]
|
return STATUS_LIST[self.connected]
|
||||||
|
|
||||||
def send_motd(self, jid, subject = '', msg = ''):
|
|
||||||
'''
|
|
||||||
if not self.connection:
|
|
||||||
return
|
|
||||||
msg_iq = common.xmpp.Message(to = jid, body = msg, subject = subject)
|
|
||||||
self.connection.send(msg_iq)
|
|
||||||
'''
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
def send_message(self, jid, msg, keyID, type = 'chat', subject='',
|
def send_message(self, jid, msg, keyID, type = 'chat', subject='',
|
||||||
chatstate = None, msg_id = None, composing_jep = None, resource = None):
|
chatstate = None, msg_id = None, composing_jep = None, resource = None):
|
||||||
'''
|
'''
|
||||||
|
@ -455,13 +440,10 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
self.connection.getRoster().delItem(agent)
|
self.connection.getRoster().delItem(agent)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def update_contact(self, jid, name, groups):
|
def update_contact(self, jid, name, groups):
|
||||||
'''
|
|
||||||
# update roster item on jabber server
|
|
||||||
if self.connection:
|
if self.connection:
|
||||||
self.connection.getRoster().setItem(jid = jid, name = name,
|
self.connection.getRoster().setItem(jid = jid, name = name,
|
||||||
groups = groups)
|
groups = groups)
|
||||||
'''
|
|
||||||
|
|
||||||
def new_account(self, name, config, sync = False):
|
def new_account(self, name, config, sync = False):
|
||||||
'''
|
'''
|
||||||
|
@ -567,9 +549,8 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
'''
|
'''
|
||||||
pass
|
pass
|
||||||
|
|
||||||
'''
|
|
||||||
def get_metacontacts(self):
|
def get_metacontacts(self):
|
||||||
|
'''
|
||||||
# Get metacontacts list from storage as described in JEP 0049
|
# Get metacontacts list from storage as described in JEP 0049
|
||||||
if not self.connection:
|
if not self.connection:
|
||||||
return
|
return
|
||||||
|
@ -577,7 +558,9 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
iq2 = iq.addChild(name='query', namespace='jabber:iq:private')
|
iq2 = iq.addChild(name='query', namespace='jabber:iq:private')
|
||||||
iq2.addChild(name='storage', namespace='storage:metacontacts')
|
iq2.addChild(name='storage', namespace='storage:metacontacts')
|
||||||
self.connection.send(iq)
|
self.connection.send(iq)
|
||||||
'''
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
'''
|
'''
|
||||||
def store_metacontacts(self, tags_list):
|
def store_metacontacts(self, tags_list):
|
||||||
# Send meta contacts to the storage namespace
|
# Send meta contacts to the storage namespace
|
||||||
|
|
|
@ -15,27 +15,91 @@ class Roster:
|
||||||
if self._data.has_key(jid):
|
if self._data.has_key(jid):
|
||||||
return self._data[jid]
|
return self._data[jid]
|
||||||
|
|
||||||
def setItem(self, item):
|
def setItem(self, jid, name = '', groups = ''):
|
||||||
print 'setItem in Roster: jid: %s' % item
|
print 'setItem %s in Roster' % jid
|
||||||
# data is maybe not already resolved
|
(service_jid, domain, interface, protocol, host, address, port, txt) \
|
||||||
# what data is expected here?
|
= self.zeroconf.get_contact(jid)
|
||||||
self._data[item] = self.zeroconf.get_contact(item)
|
|
||||||
|
self._data[jid]={}
|
||||||
|
self._data[jid]['name']=jid[:jid.find('@')]
|
||||||
|
self._data[jid]['ask'] = 'no' #?
|
||||||
|
self._data[jid]['subscription'] = 'both'
|
||||||
|
self._data[jid]['groups'] = []
|
||||||
|
self._data[jid]['resources'] = {}
|
||||||
|
self._data[jid]['address'] = address
|
||||||
|
self._data[jid]['host'] = host
|
||||||
|
self._data[jid]['port'] = port
|
||||||
|
self._data[jid]['txt'] = txt
|
||||||
|
txt_dict = self.zeroconf.txt_array_to_dict(txt)
|
||||||
|
if txt_dict.has_key('status'):
|
||||||
|
status = txt_dict['status']
|
||||||
|
else:
|
||||||
|
status = ''
|
||||||
|
if status == 'avail': status = 'online'
|
||||||
|
self._data[jid]['status'] = status
|
||||||
|
self._data[jid]['show'] = status
|
||||||
|
print self._data[jid]
|
||||||
|
|
||||||
|
def delItem(self, jid):
|
||||||
|
print 'delItem %s in Roster' % jid
|
||||||
|
if self._data.has_key(jid):
|
||||||
|
del self._data[jid]
|
||||||
|
|
||||||
def __getitem__(self,item):
|
def __getitem__(self,jid):
|
||||||
print '__getitem__ in Roster'
|
print '__getitem__ in Roster'
|
||||||
return self._data[item]
|
return self._data[jid]
|
||||||
|
|
||||||
|
def getItems(self):
|
||||||
|
print 'getItems in Roster'
|
||||||
|
# Return list of all [bare] JIDs that the roster is currently tracks.
|
||||||
|
return self._data.keys()
|
||||||
|
|
||||||
|
def keys(self):
|
||||||
|
print 'keys in Roster'
|
||||||
|
return self._data.keys()
|
||||||
|
|
||||||
def getRaw(self):
|
def getRaw(self):
|
||||||
print 'getRaw in Roster'
|
print 'getRaw in Roster'
|
||||||
return self._data
|
return self._data
|
||||||
|
|
||||||
def getResources(self, jid):
|
def getResources(self, jid):
|
||||||
print 'getResources(%s) in Roster' % jid
|
print 'getResources(%s) in Roster' % jid
|
||||||
# return self
|
return {}
|
||||||
|
|
||||||
|
def getStatus(self, jid):
|
||||||
|
print 'getStatus %s in Roster' % jid
|
||||||
|
txt = self._data[jid]['txt']
|
||||||
|
txt_dict = self.zeroconf.txt_array_to_dict(txt)
|
||||||
|
if txt_dict.has_key('status'):
|
||||||
|
status = txt_dict['status']
|
||||||
|
else:
|
||||||
|
status = ''
|
||||||
|
|
||||||
'''
|
if status == 'avail' or status == '':
|
||||||
delItem(jid)
|
return 'online'
|
||||||
getStatus(jid)
|
else:
|
||||||
getPriority(jid)
|
return status
|
||||||
getShow(jid)
|
|
||||||
'''
|
def getShow(self, jid):
|
||||||
|
print 'getShow in Roster'
|
||||||
|
return getStatus(jid)
|
||||||
|
|
||||||
|
|
||||||
|
def getPriority(jid):
|
||||||
|
return 5
|
||||||
|
|
||||||
|
def getSubscription(self,jid):
|
||||||
|
print 'getSubscription in Roster'
|
||||||
|
return 'both'
|
||||||
|
|
||||||
|
def Subscribe(self,jid):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def Unsubscribe(self,jid):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def Authorize(self,jid):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def Unauthorize(self,jid):
|
||||||
|
pass
|
||||||
|
|
|
@ -41,7 +41,6 @@ class Zeroconf:
|
||||||
self.server.ResolveService( int(interface), int(protocol), name, stype, \
|
self.server.ResolveService( int(interface), int(protocol), name, stype, \
|
||||||
domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), \
|
domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), \
|
||||||
reply_handler=self.service_resolved_callback, error_handler=self.print_error_callback)
|
reply_handler=self.service_resolved_callback, error_handler=self.print_error_callback)
|
||||||
self.new_serviceCB(name)
|
|
||||||
|
|
||||||
def remove_service_callback(self, interface, protocol, name, stype, domain, flags):
|
def remove_service_callback(self, interface, protocol, name, stype, domain, flags):
|
||||||
print "Service '%s' in domain '%s' on %i.%i disappeared." % (name, domain, interface, protocol)
|
print "Service '%s' in domain '%s' on %i.%i disappeared." % (name, domain, interface, protocol)
|
||||||
|
@ -76,21 +75,16 @@ class Zeroconf:
|
||||||
l[str[:poseq]] = str[poseq+1:]
|
l[str[:poseq]] = str[poseq+1:]
|
||||||
return l
|
return l
|
||||||
|
|
||||||
def service_resolved_callback(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
|
def service_resolved_callback(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
|
||||||
print "Service data for service '%s' in domain '%s' on %i.%i:" % (name, domain, interface, protocol)
|
self.contacts[name] = (name, domain, interface, protocol, host, address, port, txt)
|
||||||
print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(avahi.txt_array_to_string_array(txt)))
|
self.new_serviceCB(name)
|
||||||
|
|
||||||
'''
|
|
||||||
# add domain to stay unique
|
|
||||||
if domain != 'local':
|
|
||||||
add_domain = '.'+domain
|
|
||||||
else:
|
|
||||||
add_domain = ''
|
|
||||||
|
|
||||||
self.contacts[name'@'+host+add_domain] = (name, stype, domain, interface, protocol, host, address, port, txt)
|
|
||||||
'''
|
|
||||||
|
|
||||||
self.contacts[name] = (name, stype, domain, interface, protocol, host, address, port, txt)
|
# different handler when resolving all contacts
|
||||||
|
def service_resolved_all_callback(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
|
||||||
|
print "Service data for service '%s' in domain '%s' on %i.%i:" % (name, domain, interface, protocol)
|
||||||
|
print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(avahi.txt_array_to_string_array(txt)))
|
||||||
|
|
||||||
|
self.contacts[name] = (name, domain, interface, protocol, host, address, port, txt)
|
||||||
|
|
||||||
def service_added_callback(self):
|
def service_added_callback(self):
|
||||||
print 'Service successfully added'
|
print 'Service successfully added'
|
||||||
|
@ -150,6 +144,9 @@ class Zeroconf:
|
||||||
self.entrygroup.Commit(reply_handler=self.service_committed_callback, error_handler=self.print_error_callback)
|
self.entrygroup.Commit(reply_handler=self.service_committed_callback, error_handler=self.print_error_callback)
|
||||||
|
|
||||||
def announce(self):
|
def announce(self):
|
||||||
|
#for testing
|
||||||
|
#self.contacts['stefan@munin'] = ('stefan@munin', 'local', '8', '0', 'munin', '192.168.1.29', '5121',avahi.string_array_to_txt_array(['status','avail']))
|
||||||
|
#self.new_serviceCB('stefan@munin')
|
||||||
state = self.server.GetState()
|
state = self.server.GetState()
|
||||||
|
|
||||||
if state == avahi.SERVER_RUNNING:
|
if state == avahi.SERVER_RUNNING:
|
||||||
|
@ -193,10 +190,10 @@ class Zeroconf:
|
||||||
# refresh data manually - really ok or too much traffic?
|
# refresh data manually - really ok or too much traffic?
|
||||||
def resolve_all(self):
|
def resolve_all(self):
|
||||||
for val in self.contacts.values():
|
for val in self.contacts.values():
|
||||||
#val:(name, stype, domain, interface, protocol, host, address, port, txt)
|
#val:(name, domain, interface, protocol, host, address, port, txt)
|
||||||
self.server.ResolveService( int(val[3]), int(val[4]), val[0], \
|
self.server.ResolveService( int(val[2]), int(val[3]), val[0], \
|
||||||
self.stype, val[2], avahi.PROTO_UNSPEC, dbus.UInt32(0),\
|
self.stype, val[1], avahi.PROTO_UNSPEC, dbus.UInt32(0),\
|
||||||
reply_handler=self.service_resolved_callback, error_handler=self.print_error_callback)
|
reply_handler=self.service_resolved_all_callback, error_handler=self.print_error_callback)
|
||||||
|
|
||||||
def get_contacts(self):
|
def get_contacts(self):
|
||||||
self.resolve_all()
|
self.resolve_all()
|
||||||
|
|
Loading…
Reference in New Issue