added callback that put a jid in _data of Roster

(though something is wrong with it)
This commit is contained in:
Stefan Bethge 2006-05-30 23:13:36 +00:00
parent e88186d669
commit cf5ad66259
4 changed files with 35 additions and 37 deletions

View File

@ -228,7 +228,7 @@ class ConnectionHandlersZeroconf(ConnectionVcard):
idle.init()
except:
HAS_IDLE = False
'''
def build_http_auth_answer(self, iq_obj, answer):
if answer == 'yes':
iq = iq_obj.buildReply('result')
@ -236,6 +236,7 @@ class ConnectionHandlersZeroconf(ConnectionVcard):
iq = iq_obj.buildReply('error')
iq.setError('not-authorized', 401)
self.connection.send(iq)
'''
def parse_data_form(self, node):
dic = {}
@ -294,29 +295,4 @@ class ConnectionHandlersZeroconf(ConnectionVcard):
dic[i]['values'] = [dic[i]['options'][0]['values'][0]]
i += 1
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', ())

View File

@ -52,7 +52,7 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
def __init__(self, name):
ConnectionHandlersZeroconf.__init__(self)
self.name = name
self.zeroconf = zeroconf.Zeroconf()
self.zeroconf = zeroconf.Zeroconf(self._on_new_service, self._on_remove_service)
self.connected = 0 # offline
self.connection = None # dummy connection variable
# this property is used to prevent double connections
@ -187,13 +187,23 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
if self.connected < 2:
self.dispatch('BAD_PASSPHRASE', ())
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'):
if self.connection:
return self.connection, ''
self.zeroconf.connect()
self.connection = client_zeroconf.ClientZeroconf(self.zeroconf)
self.roster = self.connection.getRoster()
self.connected = STATUS_LIST.index(show)
def connect_and_init(self, show, msg, signed):

View File

@ -15,6 +15,12 @@ class Roster:
if self._data.has_key(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):
print '__getitem__ in Roster'
return self._data[item]

View File

@ -14,18 +14,19 @@ except ImportError, e:
pass
class Zeroconf:
def __init__(self):
def __init__(self, new_serviceCB, remove_serviceCB):
self.domain = None # specific domain to browse
self.stype = '_presence._tcp'
self.port = 5298 # listening port that gets announced
self.name = getpass.getuser()+'@'+socket.gethostname() # service name / username
self.port = 5298 # listening port that gets announced
self.name = getpass.getuser()+'@'+socket.gethostname() # service name
self.txt = {} # service data
self.new_serviceCB = new_serviceCB
self.remove_serviceCB = remove_serviceCB
self.service_browsers = {}
self.contacts = {} # all current local contacts with data
self.entrygroup = ''
self.entrygroup = None
## handlers for dbus callbacks
@ -40,10 +41,12 @@ class Zeroconf:
self.server.ResolveService( int(interface), int(protocol), name, stype, \
domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), \
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):
print "Service '%s' in domain '%s' on %i.%i disappeared." % (name, domain, interface, protocol)
del self.contacts[name]
self.remove_serviceCB(name)
def new_service_type(self, interface, protocol, stype, domain, flags):
# Are we already browsing this domain for this type?
@ -129,7 +132,7 @@ class Zeroconf:
return show
def create_service(self):
if self.entrygroup == '':
if not self.entrygroup:
# 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.connect_to_signal('StateChanged', self.entrygroup_state_changed_callback)
@ -155,7 +158,7 @@ class Zeroconf:
def remove_announce(self):
self.entrygroup.Reset()
self.entrygroup.Free()
self.entrygroup = ''
self.entrygroup = None
def browse_domain(self, interface, protocol, domain):
self.new_service_type(interface, protocol, self.stype, domain, '')
@ -199,6 +202,9 @@ class Zeroconf:
self.resolve_all()
return self.contacts
def get_contact(self, jid):
return self.contacts[jid]
def update_txt(self, txt):
# update only given keys
for key in txt.keys():