This file is indexed.

/usr/share/pyshared/blueman/Sdp.py is in blueman 1.23-0ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
SDP_SERVER_SVCLASS_ID		= 0x1000
BROWSE_GRP_DESC_SVCLASS_ID	= 0x1001
PUBLIC_BROWSE_GROUP		= 0x1002
SERIAL_PORT_SVCLASS_ID		= 0x1101
LAN_ACCESS_SVCLASS_ID		= 0x1102
DIALUP_NET_SVCLASS_ID		= 0x1103
IRMC_SYNC_SVCLASS_ID		= 0x1104
OBEX_OBJPUSH_SVCLASS_ID		= 0x1105
OBEX_FILETRANS_SVCLASS_ID	= 0x1106
IRMC_SYNC_CMD_SVCLASS_ID	= 0x1107
HEADSET_SVCLASS_ID		= 0x1108
CORDLESS_TELEPHONY_SVCLASS_ID	= 0x1109
AUDIO_SOURCE_SVCLASS_ID		= 0x110a
AUDIO_SINK_SVCLASS_ID		= 0x110b
AV_REMOTE_TARGET_SVCLASS_ID	= 0x110c
ADVANCED_AUDIO_SVCLASS_ID	= 0x110d
AV_REMOTE_SVCLASS_ID		= 0x110e
VIDEO_CONF_SVCLASS_ID		= 0x110f
INTERCOM_SVCLASS_ID		= 0x1110
FAX_SVCLASS_ID			= 0x1111
HEADSET_AGW_SVCLASS_ID		= 0x1112
WAP_SVCLASS_ID			= 0x1113
WAP_CLIENT_SVCLASS_ID		= 0x1114
PANU_SVCLASS_ID			= 0x1115
NAP_SVCLASS_ID			= 0x1116
GN_SVCLASS_ID			= 0x1117
DIRECT_PRINTING_SVCLASS_ID	= 0x1118
REFERENCE_PRINTING_SVCLASS_ID	= 0x1119
IMAGING_SVCLASS_ID		= 0x111a
IMAGING_RESPONDER_SVCLASS_ID	= 0x111b
IMAGING_ARCHIVE_SVCLASS_ID	= 0x111c
IMAGING_REFOBJS_SVCLASS_ID	= 0x111d
HANDSFREE_SVCLASS_ID		= 0x111e
HANDSFREE_AGW_SVCLASS_ID	= 0x111f
DIRECT_PRT_REFOBJS_SVCLASS_ID	= 0x1120
REFLECTED_UI_SVCLASS_ID		= 0x1121
BASIC_PRINTING_SVCLASS_ID	= 0x1122
PRINTING_STATUS_SVCLASS_ID	= 0x1123
HID_SVCLASS_ID			= 0x1124
HCR_SVCLASS_ID			= 0x1125
HCR_PRINT_SVCLASS_ID		= 0x1126
HCR_SCAN_SVCLASS_ID		= 0x1127
CIP_SVCLASS_ID			= 0x1128
VIDEO_CONF_GW_SVCLASS_ID	= 0x1129
UDI_MT_SVCLASS_ID		= 0x112a
UDI_TA_SVCLASS_ID		= 0x112b
AV_SVCLASS_ID			= 0x112c
SAP_SVCLASS_ID			= 0x112d
PBAP_PCE_SVCLASS_ID		= 0x112e
PBAP_PSE_SVCLASS_ID		= 0x112f
PBAP_SVCLASS_ID			= 0x1130
PNP_INFO_SVCLASS_ID		= 0x1200
GENERIC_NETWORKING_SVCLASS_ID	= 0x1201
GENERIC_FILETRANS_SVCLASS_ID	= 0x1202
GENERIC_AUDIO_SVCLASS_ID	= 0x1203
GENERIC_TELEPHONY_SVCLASS_ID	= 0x1204
UPNP_SVCLASS_ID			= 0x1205
UPNP_IP_SVCLASS_ID		= 0x1206
UPNP_PAN_SVCLASS_ID		= 0x1300
UPNP_LAP_SVCLASS_ID		= 0x1301
UPNP_L2CAP_SVCLASS_ID		= 0x1302
VIDEO_SOURCE_SVCLASS_ID		= 0x1303
VIDEO_SINK_SVCLASS_ID		= 0x1304
VIDEO_DISTRIBUTION_SVCLASS_ID	= 0x1305
MDP_SVCLASS_ID			= 0x1400
MDP_SOURCE_SVCLASS_ID		= 0x1401
MDP_SINK_SVCLASS_ID		= 0x1402
APPLE_AGENT_SVCLASS_ID		= 0x2112

uuid_names = {}
uuid_names[0x0001] = "SDP"
uuid_names[0x0002] = "UDP"
uuid_names[0x0003] = "RFCOMM"
uuid_names[0x0004] = "TCP"
uuid_names[0x0005] = "TCS-BIN"
uuid_names[0x0006] = "TCS-AT"
uuid_names[0x0008] = "OBEX"
uuid_names[0x0009] = "IP"
uuid_names[0x000a] = "FTP"
uuid_names[0x000c] = "HTTP"
uuid_names[0x000e] = "WSP"
uuid_names[0x000f] = "BNEP"
uuid_names[0x0010] = "UPnP/ESDP"
uuid_names[0x0011] = "HIDP"
uuid_names[0x0012] = "Hardcopy Control Channel"
uuid_names[0x0014] = "Hardcopy Data Channel"
uuid_names[0x0016] = "Hardcopy Notification"
uuid_names[0x0017] = "AVCTP"
uuid_names[0x0019] = "AVDTP"
uuid_names[0x001b] = "CMTP"
uuid_names[0x001d] = "UDI_C-Plane"
uuid_names[0x0100] = "L2CAP"
uuid_names[0x1000] = "ServiceDiscoveryServerServiceClassID",
uuid_names[0x1001] = "BrowseGroupDescriptorServiceClassID"
uuid_names[0x1002] = "Public Browse Group"
uuid_names[0x1101] = "Serial Port"
uuid_names[0x1102] = "LAN Access Using PPP"
uuid_names[0x1103] = _("Dialup Networking (DUN)")
uuid_names[0x1104] = "IrMC Sync"
uuid_names[0x1105] = "OBEX Object Push"
uuid_names[0x1106] = "OBEX File Transfer"
uuid_names[0x1107] = "IrMC Sync Command"
uuid_names[0x1108] = "Headset"
uuid_names[0x1109] = "Cordless Telephony"
uuid_names[0x110a] = _("Audio Source")
uuid_names[0x110b] = _("Audio Sink")
uuid_names[0x110c] = "Remote Control Target"
uuid_names[0x110d] = "Advanced Audio"
uuid_names[0x110e] = "Remote Control"
uuid_names[0x110f] = "Video Conferencing"
uuid_names[0x1110] = "Intercom"
uuid_names[0x1111] = "Fax"
uuid_names[0x1112] = "Headset Audio Gateway"
uuid_names[0x1113] = "WAP"
uuid_names[0x1114] = "WAP Client"
uuid_names[0x1115] = "PANU"
uuid_names[0x1116] = _("Network Access Point")
uuid_names[0x1117] = _("Group Network")
uuid_names[0x1118] = "DirectPrinting (BPP)"
uuid_names[0x1119] = "ReferencePrinting (BPP)"
uuid_names[0x111a] = "Imaging (BIP)"
uuid_names[0x111b] = "ImagingResponder (BIP)"
uuid_names[0x111c] = "ImagingAutomaticArchive (BIP)"
uuid_names[0x111d] = "ImagingReferencedObjects (BIP)"
uuid_names[0x111e] = "Handsfree"
uuid_names[0x111f] = "Handsfree Audio Gateway"
uuid_names[0x1120] = "DirectPrintingReferenceObjectsService (BPP)"
uuid_names[0x1121] = "ReflectedUI (BPP)"
uuid_names[0x1122] = "Basic Printing (BPP)"
uuid_names[0x1123] = "Printing Status (BPP)"
uuid_names[0x1124] = "Human Interface Device Service (HID)"
uuid_names[0x1125] = "HardcopyCableReplacement (HCR)"
uuid_names[0x1126] = "HCR_Print (HCR)"
uuid_names[0x1127] = "HCR_Scan (HCR)"
uuid_names[0x1128] = "Common ISDN Access (CIP)"
uuid_names[0x1129] = "VideoConferencingGW (VCP)"
uuid_names[0x112a] = "UDI-MT"
uuid_names[0x112b] = "UDI-TA"
uuid_names[0x112c] = "Audio/Video"
uuid_names[0x112d] = "SIM Access (SAP)"
uuid_names[0x112e] = "Phonebook Access (PBAP) - PCE"
uuid_names[0x112f] = "Phonebook Access (PBAP) - PSE"
uuid_names[0x1130] = "Phonebook Access (PBAP)"
uuid_names[0x1200] = "PnP Information"
uuid_names[0x1201] = "Generic Networking"
uuid_names[0x1202] = "Generic FileTransfer"
uuid_names[0x1203] = "Generic Audio"
uuid_names[0x1204] = "Generi cTelephony"
uuid_names[0x1303] = "Video Source"
uuid_names[0x1304] = "Video Sink"
uuid_names[0x1305] = "Video Distribution"
uuid_names[0x1400] = "MDP"
uuid_names[0x1401] = "MDPSource"
uuid_names[0x1402] = "MDPSink"
uuid_names[0x2112] = "AppleAgent"

import xml.dom.minidom

SDP_ATTR_RECORD_HANDLE			= 0x0000
SDP_ATTR_SVCLASS_ID_LIST		= 0x0001
SDP_ATTR_RECORD_STATE			= 0x0002
SDP_ATTR_SERVICE_ID			= 0x0003
SDP_ATTR_PROTO_DESC_LIST		= 0x0004
SDP_ATTR_BROWSE_GRP_LIST		= 0x0005
SDP_ATTR_LANG_BASE_ATTR_ID_LIST		= 0x0006
SDP_ATTR_SVCINFO_TTL			= 0x0007
SDP_ATTR_SERVICE_AVAILABILITY		= 0x0008
SDP_ATTR_PFILE_DESC_LIST		= 0x0009
SDP_ATTR_DOC_URL			= 0x000a
SDP_ATTR_CLNT_EXEC_URL			= 0x000b
SDP_ATTR_ICON_URL			= 0x000c
SDP_ATTR_ADD_PROTO_DESC_LIST		= 0x000d

SDP_PRIMARY_LANG_BASE 			= 0x0100

SDP_UUID	= 0x0001
UDP_UUID	= 0x0002
RFCOMM_UUID	= 0x0003
TCP_UUID	= 0x0004
TCS_BIN_UUID	= 0x0005
TCS_AT_UUID	= 0x0006
OBEX_UUID	= 0x0008
IP_UUID		= 0x0009
FTP_UUID	= 0x000a
HTTP_UUID	= 0x000c
WSP_UUID	= 0x000e
BNEP_UUID	= 0x000f
UPNP_UUID	= 0x0010
HIDP_UUID	= 0x0011
HCRP_CTRL_UUID	= 0x0012
HCRP_DATA_UUID	= 0x0014
HCRP_NOTE_UUID	= 0x0016
AVCTP_UUID	= 0x0017
AVDTP_UUID	= 0x0019
CMTP_UUID	= 0x001b
UDI_UUID	= 0x001d
MCAP_CTRL_UUID	= 0x001e
MCAP_DATA_UUID	= 0x001f
L2CAP_UUID	= 0x0100

def parse_sdp_xml(services):
	svc_list = []	
	
	
	def get_value(typename, val):
		if "int" in typename:
			return (typename, int(val, 16))
		else:
			return (typename, val)
	
	def HandleRecord(record):
		svc_list.append(HandleAttribs(record.getElementsByTagName("attribute")))

		
	def HandleSequence(sequence):
		ls = []
		for i in sequence.childNodes:
			if i.nodeName == "sequence":
				r = HandleSequence(i)
				ls.append(r)
			else:
				if i.nodeType != i.TEXT_NODE:
					ls.append(get_value(i.nodeName, i.getAttribute("value")))
					
		return ls
		
		
	def HandleAttribs(attribs):
		attr_list = {}
		for attrib in attribs:
			id = attrib.getAttribute("id")
			id = int(id, 16)
			
			for i in attrib.childNodes:
				if i.nodeName == "sequence":
					attr_list[id] = HandleSequence(i)

				elif i.nodeType != i.TEXT_NODE:
					attr_list[id] = get_value(i.nodeName, i.getAttribute("value"))
					
		return attr_list
		
	for k, v in services.iteritems():
		try:
			dom = xml.dom.minidom.parseString(v)
			HandleRecord(dom.getElementsByTagName("record")[0])
		except Exception, e:
			dprint("Failed to parse xml sdp entry", e)
			dprint(v)
	
	return svc_list

def uuid16_to_name(uuid16):
	try:
		return uuid_names[uuid16]
	except:
		return _("Unknown")

def uuid128_to_uuid16(uuid128):
	try:
		return int('0x'+uuid128[4:8], 16)
	except:
		return 0
		
def bluez_to_friendly_name(svc):
	if svc == "audiosink":
		return uuid_names[0x110b]
	elif svc == "audiosource":
		return uuid_names[0x110a]
	else:
		raise Exception
		
from blueman.main.Config import Config
import pickle
import base64
import zlib

sdp_cache = {}
sdp_conf = Config("sdp")

def on_sdp_changed(c, key, value):
	if value and key in sdp_cache:
		s = pickle.loads(zlib.decompress(base64.b64decode(value)))
		sdp_cache[key] = s
	
sdp_conf.connect("property-changed", on_sdp_changed)

def sdp_get_cached(address):
	if not address in sdp_cache:
		
		d = sdp_conf.get(address)
		if d:
			try:
				s = pickle.loads(zlib.decompress(base64.b64decode(d)))
			except Exception, e:
				dprint(e)
				raise KeyError
				
			sdp_cache[address] = s
			return s
		else:
			raise KeyError("No sdp info for %s found" % address)
	else:
		return sdp_cache[address]
		
def sdp_get_cached_rfcomm(address):
	local_sdp = sdp_get_cached(address)
	ls = []
	for svc in local_sdp:
		channel = 0
		name = None
		uuids = None
	
		for k, v in svc.iteritems():
			if k == SDP_ATTR_PROTO_DESC_LIST:
				#print v
				for i in v:
					try:
						if i[0][0] == "uuid" and int(i[0][1], 16) == RFCOMM_UUID:
							#print "Channel", i[1][1]	
							channel = i[1][1]
					except:
						pass
					
			elif k == SDP_PRIMARY_LANG_BASE:
				name = v[1]
				if name:
					name = name.strip("\n\r ")
			
			elif k == SDP_ATTR_SVCLASS_ID_LIST:
				def m(x):
					try:
						return int(x[1], 16)
					except:
						pass
			
				uuids = map(m, v)
		ls.append((name, channel, uuids))	

	return ls

def sdp_get_serial_type(address, pattern):
	pattern = str(pattern)
	if "-" in pattern:
		return (uuid128_to_uuid16(pattern),)
	else:
		s = sdp_get_cached_rfcomm(address)
		for name, channel, uuids in s:
			if str(channel) == pattern:
				return tuple(uuids)
				
def sdp_get_serial_name(address, pattern):
	pattern = str(pattern)
	if "-" in pattern:
		return uuid16_to_name(uuid128_to_uuid16(pattern))
	else:
		try:
			s = sdp_get_cached_rfcomm(address)
		except:
			return _("Unknown")
			
		for name, channel, uuids in s:
			if str(channel) == pattern:
				if name == None:
					return _("Unknown")
				else:
					return name.strip("\n\r ")
					
def sdp_save(address, records):
	data = base64.b64encode(zlib.compress(pickle.dumps(records, pickle.HIGHEST_PROTOCOL)))
	sdp_conf.set(address, data)