added callback that put a jid in _data of Roster
(though something is wrong with it)
This commit is contained in:
parent
e88186d669
commit
cf5ad66259
|
@ -228,7 +228,7 @@ class ConnectionHandlersZeroconf(ConnectionVcard):
|
||||||
idle.init()
|
idle.init()
|
||||||
except:
|
except:
|
||||||
HAS_IDLE = False
|
HAS_IDLE = False
|
||||||
|
'''
|
||||||
def build_http_auth_answer(self, iq_obj, answer):
|
def build_http_auth_answer(self, iq_obj, answer):
|
||||||
if answer == 'yes':
|
if answer == 'yes':
|
||||||
iq = iq_obj.buildReply('result')
|
iq = iq_obj.buildReply('result')
|
||||||
|
@ -236,6 +236,7 @@ class ConnectionHandlersZeroconf(ConnectionVcard):
|
||||||
iq = iq_obj.buildReply('error')
|
iq = iq_obj.buildReply('error')
|
||||||
iq.setError('not-authorized', 401)
|
iq.setError('not-authorized', 401)
|
||||||
self.connection.send(iq)
|
self.connection.send(iq)
|
||||||
|
'''
|
||||||
|
|
||||||
def parse_data_form(self, node):
|
def parse_data_form(self, node):
|
||||||
dic = {}
|
dic = {}
|
||||||
|
@ -295,28 +296,3 @@ class ConnectionHandlersZeroconf(ConnectionVcard):
|
||||||
i += 1
|
i += 1
|
||||||
return dic
|
return dic
|
||||||
|
|
||||||
|
|
||||||
def _on_roster_set(self, roster):
|
|
||||||
raw_roster = roster.getRaw()
|
|
||||||
roster = {}
|
|
||||||
our_jid = helpers.parse_jid(gajim.get_jid_from_account(self.name))
|
|
||||||
for jid in raw_roster:
|
|
||||||
try:
|
|
||||||
j = helpers.parse_jid(jid)
|
|
||||||
except:
|
|
||||||
print >> sys.stderr, _('JID %s is not RFC compliant. It will not be added to your roster. Use roster management tools such as http://jru.jabberstudio.org/ to remove it') % jid
|
|
||||||
else:
|
|
||||||
infos = raw_roster[jid]
|
|
||||||
|
|
||||||
if jid != our_jid and (not infos['subscription'] or infos['subscription'] == \
|
|
||||||
'none') and (not infos['ask'] or infos['ask'] == 'none') and not infos['name'] \
|
|
||||||
and not infos['groups']:
|
|
||||||
# remove this useless item, it won't be shown in roster anyway
|
|
||||||
#self.connection.getRoster().delItem(jid)
|
|
||||||
pass
|
|
||||||
elif jid != our_jid: # don't add our jid
|
|
||||||
roster[j] = raw_roster[jid]
|
|
||||||
|
|
||||||
|
|
||||||
self.dispatch('ROSTER', roster)
|
|
||||||
# self.dispatch('SIGNED_IN', ())
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
ConnectionHandlersZeroconf.__init__(self)
|
ConnectionHandlersZeroconf.__init__(self)
|
||||||
self.name = name
|
self.name = name
|
||||||
self.zeroconf = zeroconf.Zeroconf()
|
self.zeroconf = zeroconf.Zeroconf(self._on_new_service, self._on_remove_service)
|
||||||
self.connected = 0 # offline
|
self.connected = 0 # offline
|
||||||
self.connection = None # dummy connection variable
|
self.connection = None # dummy connection variable
|
||||||
# this property is used to prevent double connections
|
# this property is used to prevent double connections
|
||||||
|
@ -188,12 +188,22 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
|
||||||
self.dispatch('BAD_PASSPHRASE', ())
|
self.dispatch('BAD_PASSPHRASE', ())
|
||||||
return signed
|
return signed
|
||||||
|
|
||||||
|
def _on_new_service(self,jid):
|
||||||
|
self.roster.setItem(jid)
|
||||||
|
self.dispatch('ROSTER', self.roster)
|
||||||
|
|
||||||
|
def _on_remove_service(self,jid):
|
||||||
|
# roster.delItem(jid)
|
||||||
|
# self.dispatch('ROSTER', roster)
|
||||||
|
pass
|
||||||
|
|
||||||
def connect(self, data = None, show = 'online'):
|
def connect(self, data = None, show = 'online'):
|
||||||
if self.connection:
|
if self.connection:
|
||||||
return self.connection, ''
|
return self.connection, ''
|
||||||
|
|
||||||
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.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):
|
||||||
|
|
|
@ -15,6 +15,12 @@ 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):
|
||||||
|
print 'setItem in Roster: jid: %s' % item
|
||||||
|
# data is maybe not already resolved
|
||||||
|
# what data is expected here?
|
||||||
|
self._data[item] = self.zeroconf.get_contact(item)
|
||||||
|
|
||||||
def __getitem__(self,item):
|
def __getitem__(self,item):
|
||||||
print '__getitem__ in Roster'
|
print '__getitem__ in Roster'
|
||||||
return self._data[item]
|
return self._data[item]
|
||||||
|
|
|
@ -14,18 +14,19 @@ except ImportError, e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Zeroconf:
|
class Zeroconf:
|
||||||
def __init__(self):
|
def __init__(self, new_serviceCB, remove_serviceCB):
|
||||||
self.domain = None # specific domain to browse
|
self.domain = None # specific domain to browse
|
||||||
self.stype = '_presence._tcp'
|
self.stype = '_presence._tcp'
|
||||||
self.port = 5298 # listening port that gets announced
|
self.port = 5298 # listening port that gets announced
|
||||||
|
self.name = getpass.getuser()+'@'+socket.gethostname() # service name
|
||||||
self.name = getpass.getuser()+'@'+socket.gethostname() # service name / username
|
|
||||||
|
|
||||||
self.txt = {} # service data
|
self.txt = {} # service data
|
||||||
|
|
||||||
|
self.new_serviceCB = new_serviceCB
|
||||||
|
self.remove_serviceCB = remove_serviceCB
|
||||||
|
|
||||||
self.service_browsers = {}
|
self.service_browsers = {}
|
||||||
self.contacts = {} # all current local contacts with data
|
self.contacts = {} # all current local contacts with data
|
||||||
self.entrygroup = ''
|
self.entrygroup = None
|
||||||
|
|
||||||
## handlers for dbus callbacks
|
## handlers for dbus callbacks
|
||||||
|
|
||||||
|
@ -40,10 +41,12 @@ 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)
|
||||||
del self.contacts[name]
|
del self.contacts[name]
|
||||||
|
self.remove_serviceCB(name)
|
||||||
|
|
||||||
def new_service_type(self, interface, protocol, stype, domain, flags):
|
def new_service_type(self, interface, protocol, stype, domain, flags):
|
||||||
# Are we already browsing this domain for this type?
|
# Are we already browsing this domain for this type?
|
||||||
|
@ -129,7 +132,7 @@ class Zeroconf:
|
||||||
return show
|
return show
|
||||||
|
|
||||||
def create_service(self):
|
def create_service(self):
|
||||||
if self.entrygroup == '':
|
if not self.entrygroup:
|
||||||
# create an EntryGroup for publishing
|
# create an EntryGroup for publishing
|
||||||
self.entrygroup = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.EntryGroupNew()), avahi.DBUS_INTERFACE_ENTRY_GROUP)
|
self.entrygroup = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME, self.server.EntryGroupNew()), avahi.DBUS_INTERFACE_ENTRY_GROUP)
|
||||||
self.entrygroup.connect_to_signal('StateChanged', self.entrygroup_state_changed_callback)
|
self.entrygroup.connect_to_signal('StateChanged', self.entrygroup_state_changed_callback)
|
||||||
|
@ -155,7 +158,7 @@ class Zeroconf:
|
||||||
def remove_announce(self):
|
def remove_announce(self):
|
||||||
self.entrygroup.Reset()
|
self.entrygroup.Reset()
|
||||||
self.entrygroup.Free()
|
self.entrygroup.Free()
|
||||||
self.entrygroup = ''
|
self.entrygroup = None
|
||||||
|
|
||||||
def browse_domain(self, interface, protocol, domain):
|
def browse_domain(self, interface, protocol, domain):
|
||||||
self.new_service_type(interface, protocol, self.stype, domain, '')
|
self.new_service_type(interface, protocol, self.stype, domain, '')
|
||||||
|
@ -199,6 +202,9 @@ class Zeroconf:
|
||||||
self.resolve_all()
|
self.resolve_all()
|
||||||
return self.contacts
|
return self.contacts
|
||||||
|
|
||||||
|
def get_contact(self, jid):
|
||||||
|
return self.contacts[jid]
|
||||||
|
|
||||||
def update_txt(self, txt):
|
def update_txt(self, txt):
|
||||||
# update only given keys
|
# update only given keys
|
||||||
for key in txt.keys():
|
for key in txt.keys():
|
||||||
|
|
Loading…
Reference in New Issue