changed published service name to name@hostname as in jep-0174

changed contact index to name@hostname
This commit is contained in:
Stefan Bethge 2006-05-29 23:03:20 +00:00
parent 43e44b51dd
commit e88186d669
2 changed files with 30 additions and 26 deletions

View File

@ -29,7 +29,6 @@ class Roster:
''' '''
delItem(jid) delItem(jid)
getItem(jid)
getStatus(jid) getStatus(jid)
getPriority(jid) getPriority(jid)
getShow(jid) getShow(jid)

View File

@ -1,6 +1,7 @@
import os import os
import sys import sys
import getpass import getpass
import socket
try: try:
import avahi, gobject, dbus import avahi, gobject, dbus
@ -17,7 +18,9 @@ class Zeroconf:
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() # service name / username
self.name = getpass.getuser()+'@'+socket.gethostname() # service name / username
self.txt = {} # service data self.txt = {} # service data
self.service_browsers = {} self.service_browsers = {}
@ -40,7 +43,7 @@ class Zeroconf:
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, stype, domain, interface)] del self.contacts[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?
@ -62,26 +65,29 @@ class Zeroconf:
self.browse_domain(interface, protocol, domain) self.browse_domain(interface, protocol, domain)
def txt_array_to_dict(self,t): def txt_array_to_dict(self,t):
l = {} l = {}
for s in t: for s in t:
str = avahi.byte_array_to_string(s) str = avahi.byte_array_to_string(s)
poseq = str.find('=') poseq = str.find('=')
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) 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))) print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(avahi.txt_array_to_string_array(txt)))
'''
# add domain to stay unique # add domain to stay unique
if domain != 'local': if domain != 'local':
add_domain = '%'+domain add_domain = '.'+domain
else: else:
add_domain = '' add_domain = ''
self.contacts[name+add_domain+'@'+host] = (name, stype, domain, interface, protocol, host, address, port, txt) 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)
def service_added_callback(self): def service_added_callback(self):
print 'Service successfully added' print 'Service successfully added'
@ -181,7 +187,6 @@ class Zeroconf:
self.remove_announce() self.remove_announce()
# 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():
@ -194,7 +199,6 @@ class Zeroconf:
self.resolve_all() self.resolve_all()
return self.contacts return self.contacts
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():
@ -215,8 +219,9 @@ class Zeroconf:
zeroconf = Zeroconf() zeroconf = Zeroconf()
zeroconf.connect() zeroconf.connect()
zeroconf.txt[('1st')] = 'foo' zeroconf.txt['1st'] = 'foo'
zeroconf.txt[('last')] = 'bar' zeroconf.txt['last'] = 'bar'
zeroconfptxt['email'] = foo@bar.org
zeroconf.announce() zeroconf.announce()
# updating after announcing # updating after announcing