1# $Id$
2
3# This file is part of avahi.
4#
5# avahi is free software; you can redistribute it and/or modify it
6# under the terms of the GNU Lesser General Public License as
7# published by the Free Software Foundation; either version 2 of the
8# License, or (at your option) any later version.
9#
10# avahi is distributed in the hope that it will be useful, but WITHOUT
11# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
13# License for more details.
14#
15# You should have received a copy of the GNU Lesser General Public
16# License along with avahi; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18# USA.
19
20# Some definitions matching those in avahi-common/defs.h
21
22import dbus
23
24SERVER_INVALID, SERVER_REGISTERING, SERVER_RUNNING, SERVER_COLLISION, SERVER_FAILURE = range(0, 5)
25
26ENTRY_GROUP_UNCOMMITED, ENTRY_GROUP_REGISTERING, ENTRY_GROUP_ESTABLISHED, ENTRY_GROUP_COLLISION, ENTRY_GROUP_FAILURE = range(0, 5)
27
28DOMAIN_BROWSER_BROWSE, DOMAIN_BROWSER_BROWSE_DEFAULT, DOMAIN_BROWSER_REGISTER, DOMAIN_BROWSER_REGISTER_DEFAULT, DOMAIN_BROWSER_BROWSE_LEGACY = range(0, 5)
29
30PROTO_UNSPEC, PROTO_INET, PROTO_INET6  = -1, 0, 1
31
32IF_UNSPEC = -1
33
34PUBLISH_UNIQUE = 1
35PUBLISH_NO_PROBE = 2
36PUBLISH_NO_ANNOUNCE = 4
37PUBLISH_ALLOW_MULTIPLE = 8
38PUBLISH_NO_REVERSE = 16
39PUBLISH_NO_COOKIE = 32
40PUBLISH_UPDATE = 64
41PUBLISH_USE_WIDE_AREA = 128
42PUBLISH_USE_MULTICAST = 256
43
44LOOKUP_USE_WIDE_AREA = 1
45LOOKUP_USE_MULTICAST = 2
46LOOKUP_NO_TXT = 4
47LOOKUP_NO_ADDRESS = 8
48
49LOOKUP_RESULT_CACHED = 1
50LOOKUP_RESULT_WIDE_AREA = 2
51LOOKUP_RESULT_MULTICAST = 4
52LOOKUP_RESULT_LOCAL = 8
53LOOKUP_RESULT_OUR_OWN = 16
54LOOKUP_RESULT_STATIC = 32
55
56SERVICE_COOKIE = "org.freedesktop.Avahi.cookie"
57SERVICE_COOKIE_INVALID = 0
58
59DBUS_NAME = "org.freedesktop.Avahi"
60DBUS_INTERFACE_SERVER = DBUS_NAME + ".Server"
61DBUS_PATH_SERVER = "/"
62DBUS_INTERFACE_ENTRY_GROUP = DBUS_NAME + ".EntryGroup"
63DBUS_INTERFACE_DOMAIN_BROWSER = DBUS_NAME + ".DomainBrowser"
64DBUS_INTERFACE_SERVICE_TYPE_BROWSER = DBUS_NAME + ".ServiceTypeBrowser"
65DBUS_INTERFACE_SERVICE_BROWSER = DBUS_NAME + ".ServiceBrowser"
66DBUS_INTERFACE_ADDRESS_RESOLVER = DBUS_NAME + ".AddressResolver"
67DBUS_INTERFACE_HOST_NAME_RESOLVER = DBUS_NAME + ".HostNameResolver"
68DBUS_INTERFACE_SERVICE_RESOLVER = DBUS_NAME + ".ServiceResolver"
69DBUS_INTERFACE_RECORD_BROWSER = DBUS_NAME + ".RecordBrowser"
70
71def byte_array_to_string(s):
72    r = ""
73
74    for c in s:
75
76        if c >= 32 and c < 127:
77            r += "%c" % c
78        else:
79            r += "."
80
81    return r
82
83def txt_array_to_string_array(t):
84    l = []
85
86    for s in t:
87        l.append(byte_array_to_string(s))
88
89    return l
90
91
92def string_to_byte_array(s):
93    r = []
94
95    for c in s:
96        r.append(dbus.Byte(ord(c)))
97
98    return r
99
100def string_array_to_txt_array(t):
101    l = []
102
103    for s in t:
104        l.append(string_to_byte_array(s))
105
106    return l
107
108def dict_to_txt_array(txt_dict):
109    l = []
110
111    for k,v in txt_dict.items():
112        l.append(string_to_byte_array("%s=%s" % (k,v)))
113
114    return l
115