def service_resolved(self, interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags): stdb = ServiceTypeDatabase() h_type = stdb.get_human_type(type) print "%s %s %s %s %s %i" % (name, h_type, type, domain, self.siocgifname(interface), protocol) print "%s %s %i %s" % (host, address, port, avahi.txt_array_to_string_array(txt)) # # Output to file # f = open(host.split('.')[0] + ".service", "w") f.write('''<?xml version="1.0" standalone='no'?><!--*-nxml-*-->\n''') f.write('''<!DOCTYPE service-group SYSTEM "avahi-service.dtd">\n''') f.write('<service-group>\n') f.write(' <name>%s</name>\n' % name) f.write(' <service>\n') f.write(' <type>%s</type>\n' % type) f.write(' <port>%s</port>\n' % port) f.write(' <host-name>%s</host-name>\n' % host) for each in avahi.txt_array_to_string_array(txt): f.write(' <txt-record>%s</txt-record>\n' % each) f.write(' </service>\n') f.write('</service-group>\n') f.close f = open(host.split('.')[0] + ".hosts", "w") f.write('# Add the following entry to /etc/avani/hosts\n') f.write('%s %s' % (address, host)) f.close
def service_resolved(self, interface, protocol, name, servicetype, domain, host, aprotocol, address, port, txt, flags): del aprotocol del flags stdb = ServiceTypeDatabase() h_type = stdb.get_human_type(servicetype) if self.debug: print "Service data for service '%s' of type '%s' (%s) in domain '%s' on %s.%i:" % (name, h_type, servicetype, domain, self.siocgifname(interface), protocol) print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, avahi.txt_array_to_string_array(txt)) txts = avahi.txt_array_to_string_array(txt) match = False dsn = None uuid = None for txt in txts: key, value = txt.split('=') if key == 'dsn': dsn = value elif key == 'uuid': uuid = value match = self.uuid == value match = match or (self.uuid == '') if match: data = ServiceData() data.name = name data.dsn = dsn data.uuid = uuid data.txts = txts with self.discovered_condition: self.service_names[name] = data self.discovered_condition.notify() if self.debug: print('discovered: %s %s %s' % (name, dsn, uuid)) for func in self.on_discovered: func(data)
def service_resolved(self, interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags): stdb = ServiceTypeDatabase() h_type = stdb.get_human_type(type) print "%s %s %s %s %s %i" % (name, h_type, type, domain, self.siocgifname(interface), protocol) print "%s %s %i %s" % (host, address, port, avahi.txt_array_to_string_array(txt)) # # Output to file # f = open(host.split('.')[0] + ".service","w") f.write('''<?xml version="1.0" standalone='no'?><!--*-nxml-*-->\n''') f.write('''<!DOCTYPE service-group SYSTEM "avahi-service.dtd">\n''') f.write('<service-group>\n') f.write(' <name>%s</name>\n' % name) f.write(' <service>\n') f.write(' <type>%s</type>\n' % type) f.write(' <port>%s</port>\n' % port) f.write(' <host-name>%s</host-name>\n' % host) for each in avahi.txt_array_to_string_array(txt): f.write(' <txt-record>%s</txt-record>\n' % each) f.write(' </service>\n') f.write('</service-group>\n') f.close f = open(host.split('.')[0] + ".hosts","w") f.write('# Add the following entry to /etc/avani/hosts\n') f.write('%s %s' % (address, host)) f.close
def __service_resolved(self, *args): ''' print 'service resolved' print 'name:', args[2] print 'type:', args[3] print 'domain:', args[4] print 'full_domain:', args[5] print 'address:', args[7] print 'port:', args[8] print avahi.txt_array_to_string_array(args[9]) ''' # construct service s = service() s.type = args[3] s.port = int(args[8]) txt_records = avahi.txt_array_to_string_array(args[9]) for record in txt_records: key = record[0:record.find('=')] value = record[record.find('=') + 1:len(record)] if key == 'sysname': s.sysname = value elif key == 'state': s.state = value else: s.txt[key] = value # add service to results self.__results.append(s)
def requestResolve(self, master_info): result = None try: self._lock.acquire(True) if not (master_info is None): interface, protocol, name, stype, domain, five, six, host, port, txt, flags = self.__server.ResolveService( master_info.interface, master_info.protocol, master_info.name, master_info.stype, master_info.domain, avahi.PROTO_UNSPEC, dbus.UInt32(0)) result = MasterInfo(name, stype, domain, host, port, avahi.txt_array_to_string_array(txt), interface, protocol, online=True) except dbus.DBusException: result = None except: import traceback print traceback.format_exc() finally: self._lock.release() return result
def NewServiceCallback(interface, protocol, serviceName, regtype, replyDomain, flags): global server # Get service info and print url in TXT record interface, protocol, serviceName, regtype, replyDomain, \ host, aprotocol, address, port, txtRecord, flags = \ server.ResolveService(int(interface), int(protocol), serviceName, regtype, replyDomain, avahi.PROTO_UNSPEC, dbus.UInt32(0)) parts = avahi.txt_array_to_string_array(txtRecord) for txt in parts: txtparts = txt.split('=') url = '' if txtparts and len(txtparts) > 1 and txtparts[0] == 'url': url = txtparts[1] print "+%s=%s" % (serviceName, url) try: sys.stdout.flush() # avoids blocking in ServiceDiscovery.py except IOError, e: pass
def new_service(interface, protocol, name, stype, domain, fqdn, aprotocol, address, port, txt, flags): txt = avahi.txt_array_to_string_array(txt) if config["verbose"]: print("New service: %s:%s:%s:%d (%s)" %(fqdn, address, stype, port, txt)) trayIcon.starttimer() # host already known? if not fqdn in root[(interface, domain)]["hosts"]: host = Host(domain, fqdn) root[(interface, domain)]["hosts"][fqdn] = host; host.on_new(); else: host = root[(interface, domain)]["hosts"][fqdn]; service = Service(host, protocol, name, stype, port, txt) # register service to host if not (name,stype) in host.services: host.services[(name,stype)] = service; service.on_new() # register service in the service directory if not name in root[(interface, domain)]["services"][stype]["items"]: root[(interface, domain)]["services"][stype]["items"][name] = service
def new_service(interface, protocol, name, stype, domain, fqdn, aprotocol, address, port, txt, flags): txt = avahi.txt_array_to_string_array(txt) if verbose: print "New service: %s:%s:%s:%d (%s)" %(fqdn, address, stype, port, txt) # host already known? if not fqdn in root[(interface, domain)]["hosts"]: host = Host(domain, fqdn) host.submenu = add_menu(trayIcon.hostmenu, fqdn); root[(interface, domain)]["hosts"][fqdn] = host; host.on_new(); else: host = root[(interface, domain)]["hosts"][fqdn]; service = Service(host, protocol, name, stype, port, txt) # is service already in hostmenu? if not (name,stype,port) in host.services: host.services[(name,stype,port)] = service; service.on_new() title = "%s (%s)" % (name, re.sub(r'_(.*)\._(.*)', r'\1,\2', stype)); service.menuentry = (add_action(host.submenu, title, service, service.onClick)); # is service already in servicemenu? if not name in root[(interface, domain)]["services"][stype]["items"]: root[(interface, domain)]["services"][stype]["items"][name] = service ssubmenu = root[(interface, domain)]["services"][stype]["obj"].submenu title = "%s (%s)" % (name, fqdn); service.smenuentry = (add_action(ssubmenu, title, service, service.onClick));
def remove_service(interface, protocol, name, stype, domain, fqdn, aprotocol, address, port, txt, flags): txt = avahi.txt_array_to_string_array(txt) if verbose: print "Remove service '%s' type '%s' domain '%s' " % (name, stype, domain) # is host known? if not fqdn in root[(interface, domain)]["hosts"]: if verbose: print "unknown host" return # delete service from host menu if (name,stype,port) in root[(interface, domain)]["hosts"][fqdn].services: root[(interface, domain)]["hosts"][fqdn].services[(name,stype,port)].on_rem() remove_action(root[(interface, domain)]["hosts"][fqdn].submenu, root[(interface, domain)]["hosts"][fqdn].services[(name,stype,port)].menuentry) del root[(interface, domain)]["hosts"][fqdn].services[(name,stype,port)] # delete service from service menu if name in root[(interface, domain)]["services"][stype]["items"]: remove_action(root[(interface, domain)]["services"][stype]["obj"].submenu, root[(interface, domain)]["services"][stype]["items"][name].smenuentry) del root[(interface, domain)]["services"][stype]["items"][name] # last service of this host? if yes delete host menu if len(root[(interface, domain)]["hosts"][fqdn].services.keys()) < 1: root[(interface, domain)]["hosts"][fqdn].on_rem(); # TODO how to remove QMenu? root[(interface, domain)]["hosts"][fqdn].submenu.clear() #root[(interface, domain)]["hosts"][fqdn].submenu.setVisible(False) root[(interface, domain)]["hosts"][fqdn].submenu.deleteLater() del root[(interface, domain)]["hosts"][fqdn].submenu del root[(interface, domain)]["hosts"][fqdn]
def __resolve_handler__(self, riface, rproto, rname, rtype, rdomain, rhost, raproto, raddr, rport, rtxt, rflags): string_txt = avahi.txt_array_to_string_array(rtxt) kw = {} rhost_prefix = re_mdns.split(rhost)[0] for i in string_txt: key, value = i.split('=', 1) kw[key] = value try: family, socktype, proto, canonname, (dns_raddr, unknown) = \ socket.getaddrinfo( rhost_prefix, None, socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP, socket.AI_CANONNAME)[0] rhost = rhost_prefix raddr = dns_raddr except socket.gaierror: if logger.isEnabledFor(logging.INFO): logger.info( "Cannot Resolve <%s> with dns using mdns instead ..." % rhost_prefix) if logger.isEnabledFor(logging.DEBUG): fname = kw["name"].strip("/c") if "name" in kw else "UNKNOWN" logger.debug("%s relolved[%s] : %s on %s - %s (%s)" % (fname, self.domain, rname, raddr, rhost, rport)) self.addedEvent(rname, rhost, raddr, rport, kw, rhost)
def requestResolve(self, master_info): result = None try: self._lock.acquire(True) if not (master_info is None): interface, protocol, name, stype, domain, five, six, host, port, txt, flags = self.__server.ResolveService( master_info.interface, master_info.protocol, master_info.name, master_info.stype, master_info.domain, avahi.PROTO_UNSPEC, dbus.UInt32(0), ) result = MasterInfo( name, stype, domain, host, port, avahi.txt_array_to_string_array(txt), interface, protocol, online=True, ) except dbus.DBusException: result = None except: import traceback print traceback.format_exc() finally: self._lock.release() return result
def service_resolved(*args): log("Service resolved") amount=0 try: conn.commit() cursor.execute("SELECT * FROM game_hostnode where hostname = %s",(args[2]+"."+args[4],)) try: amount = len(cursor.fetchall()) except Exception as e: log(str(e)) amount=cursor.rowcount log(str(cursor._executed)) except Exception as e: log("WTf, DB is gone or?" + str(e)) return log("found :"+str(amount)+" entries") if amount == 0: txt = dict(item.split('=') for item in avahi.txt_array_to_string_array(args[9])) serviceentry = (args[2]+"."+args[4],args[8],txt["path"]) log("New entry to DB:"+args[2]+"."+args[4]) cursor.execute('INSERT INTO game_hostnode(hostname,port,path) VALUES(%s,%s,%s)', serviceentry) conn.commit() try: logentry=urllib2.urlopen("http://localhost/refresh/%s" %(args[2]+".local")).read() log(logentry) except urllib2.HTTPError as e: log("Error on refresh: %s"% (e.read()))
def __get_service(self, txt): l = avahi.txt_array_to_string_array(txt) for k in l: if k[:8] == "service=": return k[8:] return None
def service_resolved(self, interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags): stdb = ServiceTypeDatabase() h_type = stdb.get_human_type(type) print "Service data for service '%s' of type '%s' (%s) in domain '%s' on %s.%i:" % ( name, h_type, type, domain, self.siocgifname(interface), protocol) print "\tHost %s (%s), port %i, TXT data: %s" % ( host, address, port, avahi.txt_array_to_string_array(txt))
def service_resolved(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags): print("Service data for service '%s' of type '%s' in domain '%s' on %i.%i:" % (name, stype, domain, interface, protocol)) print("\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, str(avahi.txt_array_to_string_array(txt)))) self.update_label(interface, protocol, name, stype, domain, host, aprotocol, address, port, avahi.txt_array_to_string_array(txt))
def _service_resolved(self, interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags): txt = avahi.txt_array_to_string_array(txt) meta = {"path": "/"} for t in txt: key, value = t.split("=") meta[key] = value self._done() self.results.append("https://%s:%s%s" % (host, port, meta["path"]))
def __get_path(self, txt): l = avahi.txt_array_to_string_array(txt) for k in l: if k[:5] == "path=": if k[5:].startswith("/"): return k[5:] else: return "/" + k[5:] return "/"
def __init__(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags): self.interface = interface self.protocol = protocol self.name = name self.stype = stype self.domain = domain self.host = host self.aprotocol = aprotocol self.address = address self.port = port self.txt = txt self.flags = flags self.command = None if (self.stype == "_http._tcp"): path = "" for data in avahi.txt_array_to_string_array(self.txt): if (data.startswith("path=")): path = data[len("path="):] self.command = "xdg-open http://%s:%i%s &" % (self.host, self.port, path) if (self.stype == "_https._tcp"): path = "" for data in avahi.txt_array_to_string_array(self.txt): if (data.startswith("path=")): path = data[len("path="):] self.command = "xdg-open https://%s:%i%s &" % (self.host, self.port, path) if (self.stype == "_ssh._tcp"): self.command = "gnome-terminal -x ssh %s %i &" % (self.host, self.port) # TODO: Ask for username and password if (self.stype == "_sftp-ssh._tcp"): self.command = "nautilus ssh://%s:%i &" % (self.host, self.port) if (self.stype == "_smb._tcp"): self.command = "nautilus smb://%s:%i &" % (self.host, self.port)
def found(interface, protcol, name, type, domain, host, aprotocol, address, port, txt, flags): ## Construct a server url from address and port number. ## Uses '[' ']' incase of IPv6 addresses. servers[name] = "".join([ "http://", "[" , address, "]", ":", str(port)]) ## Look for a "url" txt field to override the one constructed above. txt_arr = avahi.txt_array_to_string_array(txt) for rec in txt_arr: (key, value) = rec.split("=") if key == "url": servers[name] = value print "Found server: " + servers[name]
def resolve_service_reply(*service): address, port = service[-4:-2] name = unicode(service[2]) data=avahi.txt_array_to_string_array(service[9]) datdict={} for i in data: bit=i.split('=') if len(bit)==2: datdict[bit[0]]=bit[1] for cb in self._callbacks['new-service']: self._plugged[name] = (address,port) cb(self,name, address, port,datdict)
def find_path(self, txt): l = avahi.txt_array_to_string_array(txt) for k in l: if k[:5] == "path=": if k[5:].startswith("/"): return k[5:] else: return "/" + k[5:] return "/"
def service_resolved(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags): """\ Called when all the information about a service is avaliable. """ assert threading.currentThread() == self.dbusthread if len(txt) != 0: details = self.pair_to_dict(avahi.txt_array_to_string_array(txt)) else: details = [] self.ServiceFound(name, stype.split('.')[0][1:], (host, address, port), details, details)
def resolved(self, interface, protocol, name, service, domain, host, aprotocol, address, port, txt, flags): # check everything needed is there tr = self.pair_to_dict(avahi.txt_array_to_string_array(txt)) if not 'uuid' in tr: return if not 'dsn' in tr: return if not 'service' in tr: return if tr['uuid'] == self.uuid: self.resolvecb(tr)
def serviceResolvedCallback(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags): if not self.connected: return if stype == "_workstation._tcp": hostadded = re.sub(r'\.%s$' % domain, '', host) self.discoveredHosts.add(hostadded) elif stype == "_sinerji._tcp": self.serviceHost = re.sub(r'\.%s$' % domain, '', host) self.clientlist[self.serviceHost + "=" + address] = avahi.txt_array_to_string_array(txt) else: pass
def __init__(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags): self.interface = interface self.protocol = protocol self.name = name self.type = stype self.domain = domain self.host = host self.aprotocol = aprotocol self.address = address self.port = port self.txt = avahi.txt_array_to_string_array(txt) self.flags = flags
def __avahi_callback_service_resolved(self, *args): ''' This callback will be called, if a new service was registered or a resolve request was called. The _master list will be updated. ''' self.on_resolve_reply( MasterInfo(args[2], args[3], args[4], args[7], args[8], avahi.txt_array_to_string_array(args[9]), args[0], args[1], online=False))
def service_resolved(self, interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags, **kwargs): r = Arg() r.interface = self.siocgifname(interface) r.protocol = protocol r.name = name r.type = type r.domain = domain r.host = host r.aprotocol = aprotocol r.address = address r.port = port r.txt = avahi.txt_array_to_string_array(txt) r.flags = flags r.kwargs = kwargs self.emit('service-resolved', r)
def service_resolved(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags): print "Service data for service '%s' of type '%s' in domain '%s' on %i.%i:" % ( name, stype, domain, interface, protocol) print "\tHost %s (%s), port %i, TXT data: %s" % ( host, address, port, str(avahi.txt_array_to_string_array(txt))) self.services.append( Service(interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags)) secs_since_launch = (time.clock() - self.start_time) / 60 print("\t" + str(secs_since_launch) + " secs since launch") # Services that are added after 2 seconds after launch trigger a notification if (secs_since_launch > 2.0): Notify.init("Avahi") Hello = Notify.Notification.new(name, stype, "dialog-information") Hello.show() self.rebuild_menu()
def _handle_service_resolved(self, *args): # Obtenemos el campo txt del recurso: diccionario codificado con json avahi_txt_list = avahi.txt_array_to_string_array(args[9]) elem = ''.join(avahi_txt_list)[::-1] try: info_dict = json.loads(elem) except: info_dict = {} # Resto de datos del servicio.. s_name = args[2] s_type = args[3] s_domain = args[4] s_address = args[7] s_port = args[8] self.found_handler(s_name, s_domain, s_address, s_port, info_dict)
def newRemote(self,interface,protocol,name,stype,domain,flags): print "ADDED"+str(interface)+" "+str(protocol)+" "+str(name)+" "+str(stype)+" "+str(domain)+" "+str(flags) dbusinfos = self.server.ResolveService(int(interface),int(protocol),str(name),str(stype),str(domain),0,0) self.source = gobject.new (RemoteSource, shell=self.shell, entry_type=self.entry_type, plugin=self.rbplugin, icon=self.icon, source_group=self.group) self.source.address = str(dbusinfos[7]) self.source.port = str(dbusinfos[8]) self.source.pairkey = ((str(avahi.txt_array_to_string_array(dbusinfos[9])[4])).split("="))[1] self.source.remotename = name self.source.storage = self.rbplugin.storage self.source.httpserver = self.rbplugin.httpserver self.shell.register_entry_type_for_source(self.source, self.entry_type) self.shell.append_source(self.source, None) # Add the source to the list
def __avahi_callback_service_resolved(self, *args): """.......................................................................... This callback will be called, if a new service was registered or a resolve request was called. The _master list will be updated. ..........................................................................""" self.on_resolve_reply( MasterInfo( args[2], args[3], args[4], args[7], args[8], avahi.txt_array_to_string_array(args[9]), args[0], args[1], online=False, ) )
def _service_resolved(self, interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags): """ Callback from dbus when a new service is available and resolved. """ txtdict = {} for record in avahi.txt_array_to_string_array(txt): if record.find('=') > 0: k, v = record.split('=', 2) txtdict[k] = v local = False try: if flags & avahi.LOOKUP_RESULT_LOCAL: local = True except dbus.DBusException: pass self._services[type]._add(int(interface), int(protocol), str(name), str(domain), str(host), str(address), int(port), local, txtdict)
def ItemNew_handler(self, interface, protocol, name, stype, domain, flags): self.still_receiving_events = 1 if self.verbose: print "Found service '%s' type '%s' domain '%s' " % (name, stype, domain) r_interface, r_protocol, r_name, r_stype, r_domain, r_host, r_aprotocol, r_address, r_port, r_txt, r_flags = \ self.server.ResolveService( interface, protocol, name, stype, domain, self.search_protocol, dbus.UInt32(0) ) if self.verbose: print "RESOLVED: ", r_host, "-", r_name, "-", r_address, "-", r_port, "-", r_domain self.printers.append( dict( host = str(r_host), name = str(r_name), address = str(r_address), port = int(r_port), domain = str(r_domain), txt = self.txtarray_to_dict(avahi.txt_array_to_string_array(r_txt)) ) )
def service_resolved(self, *args): service_name=str(args[2]) if self.default_service_name and not service_name.startswith(self.default_service_name): return name = args[5].split('.')[0] ip = args[7] port = args[8] txt = args[9] #print "NEW hostname=%s ip=%s port=%s TXT=%s"%(name, ip, port, avahi.txt_array_to_string_array(txt)) self.services[str(args[2])]={'port':int(port), 'ip': str(ip), 'hostname':str(name), 'txt':avahi.txt_array_to_string_array(txt), 'service_type':str(args[3]), 'service_name':str(args[2])} print "------------------------------------------------------------" pprint(self.services) print "------------------------------------------------------------" self.callback()
def NewServiceCallback(interface, protocol, serviceName, regtype, replyDomain, flags): global server # Get service info and print url in TXT record interface, protocol, serviceName, regtype, replyDomain, host, aprotocol, address, port, txtRecord, flags = server.ResolveService( int(interface), int(protocol), serviceName, regtype, replyDomain, avahi.PROTO_UNSPEC, dbus.UInt32(0) ) parts = avahi.txt_array_to_string_array(txtRecord) for txt in parts: txtparts = txt.split("=") url = "" if txtparts and len(txtparts) > 1 and txtparts[0] == "url": url = txtparts[1] print "+%s=%s" % (serviceName, url) try: sys.stdout.flush() # avoids blocking in ServiceDiscovery.py except IOError, e: pass
def _service_resolved(self, interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags): """ Callback from dbus when a new service is available and resolved. """ txtdict = {} for record in avahi.txt_array_to_string_array(txt): if record.find('=') > 0: k, v = record.split('=', 2) txtdict[k] = v local = False try: if flags & avahi.LOOKUP_RESULT_LOCAL: local = True except dbus.DBusException: pass self._services[type]._add( int(interface), int(protocol), str(name), str(domain), str(host), str(address), int(port), local, txtdict )
def __serviceResolved(self, *args): new_service = { 'name': unicode(args[2]), 'address': unicode(args[7]), 'port': int(args[8]) } for entry in avahi.txt_array_to_string_array(args[9]): equals_pos = entry.find('=') key = entry[:equals_pos] data = entry[equals_pos+1:] # ignore duplicate keys if not new_service.has_key(key): new_service[key] = data else: print "duplicate entry in text array: ", entry # prevent duplicates (until we figure out how to avoid this) if self.__services.count(new_service): print "duplicate service found:", new_service else: self.__services.append(new_service)
def service_resolved(self, *args): str_ = ''.join( avahi.txt_array_to_string_array(args[9])) domain = str(args[4]) '''print 'name:', unicode(args[2]) print 'address:', args[7] print 'port:', args[8] print str_, '\n', args print 'service resolved.' ''' __str_state = ''; __str_encode = '' chunks = str_.split(';') for _str in chunks : if _str.startswith('Encoding=') : __str_encode = self.extractValue(_str) #break #else : __str_encode = _str if _str.startswith('State=') : __str_state = self.extractValue(_str) #print [unicode(args[2]), str(args[7]), str(args[8]), __str_encode, __str_state, domain, True] self.obj.addNewContact(unicode(args[2]), str(args[7]), str(args[8]), __str_encode, __str_state, domain, True)
def __serviceResolved(self, *args): new_service = { 'name': unicode(args[2]), 'address': unicode(args[7]), 'port': int(args[8]) } for entry in avahi.txt_array_to_string_array(args[9]): equals_pos = entry.find('=') key = entry[:equals_pos] data = entry[equals_pos + 1:] # ignore duplicate keys if not new_service.has_key(key): new_service[key] = data else: print "duplicate entry in text array: ", entry # prevent duplicates (until we figure out how to avoid this) if self.__services.count(new_service): print "duplicate service found:", new_service else: self.__services.append(new_service)
def _resolve_service(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags): """ Dbus callback """ extra_info = avahi.txt_array_to_string_array(txt) print "RESOLVED SERVICE %s on %s - %s:%s\nExtra Info: %s" % (name, host, address, port, extra_info)
def _inner(interface, protocol, name, stype, domain, host, arprotocol, address, port, txt, flags): txtd = dict( x.split('=') for x in avahi.txt_array_to_string_array(txt) ) callback({"action": "add", "name": name, "type": stype, "address": address, "port": port, "txt": txtd, "interface": interface})
def test_txt_array_to_string_array(self): self.assertEqual( avahi.txt_array_to_string_array([[1, 2], [ord('a'), ord('b')]]), ['..', 'ab'])
def service_resolved(self, interface, protocol, name, type, domain, host, aprotocol, address, port, txt, flags): stdb = ServiceTypeDatabase() h_type = stdb.get_human_type(type) print "Service data for service '%s' of type '%s' (%s) in domain '%s' on %s.%i:" % (name, h_type, type, domain, self.siocgifname(interface), protocol) print "\tHost %s (%s), port %i, TXT data: %s" % (host, address, port, avahi.txt_array_to_string_array(txt))