This file is indexed.

/usr/share/amsn/msnp2p/webcam.tcl is in amsn-data 0.98.9-1.

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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
namespace eval ::p2p {

	################################################################################
	#
	# setObjOption vars: needed here?
	#
	# YES: canceled, producer, state, my_rid, rid, chatid, inviter, xml, session
	# NO: grabber, window, socket, fd, connected_ips, server, listening, ips,
	#     listening_socket, listening_port, reflector
	# 1: send_syn, webcam
	# 0: conference, authenticated
	#
	################################################################################

	snit::type WebcamSessionMessage {

		option -id ""
		option -producer ""
		option -session ""
		option -body ""
		option -partof ""

		option -localip ""
		option -localport ""
		option -remoteip ""
		option -remoteport ""
		option -rid ""
		option -my_rid ""


		constructor { args } {

			$self configurelist $args
			if { $options(-body) != "" } {
				$self Parse $options(-body)
			} else {
				set rid [myRand 100 199]
				set options(-my_rid) $rid
				$options(-partof) configure -my_rid $rid
			}

		}

		method Parse { body } {

			set body [string map { "\r\n" "" } $body]
			set options(-body) $body
			set list [xml2list $body]
			if { $options(-producer) == 1 } {
				set type "viewer"
			} else {
				set type "producer"
			}
			set session [GetXmlEntry $list "$type:session"]
			set rid [GetXmlEntry $list "$type:rid"]
			set options(-session) $session
			set options(-rid) $rid
			$options(-partof) configure -session $session -rid $rid -producer $options(-producer)
			status_log "Configured parent $options(-partof) to have session $session"
			::MSNCAM::ConnectSockets $options(-partof)

		}

		method toString { } {

			set session $options(-session)
			if { $session == "" } {
				set session [myRand 9000 9999]
				status_log "Random session $session for $options(-partof)"
			}
			set options(-session) $session
			set sid $options(-id)

			if { $options(-rid) != "" } {
				set rid $options(-rid)
			} else {
				set rid $options(-my_rid)
			}

			set udprid [expr {$rid + 1}]
			set conntype [abook::getDemographicField conntype]
			set listening [abook::getDemographicField listening]
			set producer $options(-producer)

			set port [::MSNCAM::OpenCamPort [config::getKey initialftport] $options(-partof)]
			if { [info exists ::cam_mask_ip] } {
				set clientip $::cam_mask_ip
				set localip $::cam_mask_ip
			} else {
				set clientip [::abook::getDemographicField clientip]
				set localip [::abook::getDemographicField localip]
			}

			if { $producer } {
				set begin_type "<producer>"
				set end_type "</producer>"
			} else {
				set begin_type "<viewer>"
				set end_type "</viewer>"
			}

			set header "<version>2.0</version><rid>$rid</rid><session>$session</session><ctypes>0</ctypes><cpu>730</cpu>"
			set tcp "<tcp><tcpport>$port</tcpport><tcplocalport>$port</tcplocalport><tcpexternalport>$port</tcpexternalport><tcpipaddress1>$clientip</tcpipaddress1>"
			if { $clientip != $localip} {
				set tcp "${tcp}<tcpipaddress2>$localip</tcpipaddress2></tcp>"
			} else {
				set tcp "${tcp}</tcp>"
			}

			set udp "<udp><udplocalport>$port</udplocalport><udpexternalport>$port</udpexternalport><udpexternalip>$clientip</udpexternalip><a1_port>$port</a1_port><b1_port>$port</b1_port><b2_port>$port</b2_port><b3_port>$port</b3_port><symmetricallocation>0</symmetricallocation><symmetricallocationincrement>0</symmetricallocationincrement><udpinternalipaddress1>$localip</udpinternalipaddress1></udp>"
			set footer "<codec></codec><channelmode>1</channelmode>"

			set xml "${begin_type}${header}${tcp}${footer}${end_type}\r\n\r\n"

			return $xml

		}

	}

	snit::type WebcamSession {

		delegate option * to p2pSession
		delegate method * to p2pSession

		option -producer 0

		variable answered 0

		# Options that both we and msncam.tcl use
		option -sid ""
		option -session ""
		option -xml ""
		option -canceled ""
		option -my_rid ""
		option -rid ""
		option -chatid ""
		option -inviter 0
		option -blob_id ""
		option -send_syn 0

		# Options for msncam.tcl only (lots of them :()
		option -grabber ""
		option -window ""
		option -socket ""
		option -fd ""
		option -connected_ips ""
		option -server ""
		option -listening ""
		option -ips ""
		option -listening_socket ""
		option -listening_port ""
		option -reflector 0
		option -codec ""
		option -image ""
		option -source ""
		option -grabber ""
		option -grab_proc ""
		option -encoder ""
		option -weblog ""

		option -webcam 1
		option -conference 0
		option -authenticated 0

		variable xml_needed 1

		constructor {args} {

			install p2pSession using P2PSession %AUTO% -application_id $::p2p::ApplicationID::WEBCAM
			$self configurelist $args
			$p2pSession conf2
			set options(-chatid) [$p2pSession cget -peer]
			set options(-sid) [$p2pSession cget -id]
			::Event::registerEvent p2pTransreqReceived all [list $self On_transreq_received]
			::Event::registerEvent p2pOutgoingSessionTransferCompleted all [list $self On_data_blob_received] ;#not really completed, just a blob received
			::Event::registerEvent p2pAccepted all [list $self On_session_accepted]
			::Event::registerEvent p2pRejected all [list $self On_session_rejected]
			::Event::registerEvent p2pByeReceived all [list $self On_bye_received]

		}

		destructor {

			#::Event::fireEvent p2pCallEnded p2pWebcamSession {}
                        catch {::Event::unregisterEvent p2pTransreqReceived all [list $self On_transreq_received]}
                        catch {::Event::unregisterEvent p2pOutgoingSessionTransferCompleted all [list $self On_data_blob_received]}
                        catch {::Event::unregisterEvent p2pAccepted all [list $self On_session_accepted]}
                        catch {::Event::unregisterEvent p2pRejected all [list $self On_session_rejected]}
                        catch {::Event::unregisterEvent p2pByeReceived all [list $self On_bye_received]}
			catch {$session_manager Unregister_session $self}
			$p2pSession destroy

		}

		method invite { } {

			set answered 1
			set context "{B8BE70DE-E2CA-4400-AE03-88FF85B9F4E8}"
			set context [encoding convertto unicode $context]
			if { $options(-producer) == 1 } {
				set euf_guid $::p2p::EufGuid::MEDIA_SESSION
				::CAMGUI::InvitationToSendSent $options(-chatid) $self
			} else {
				set euf_guid $::p2p::EufGuid::MEDIA_RECEIVE_ONLY
				::CAMGUI::InvitationToReceiveSent $options(-chatid) $self
			}
			$self configure -inviter 1 -producer $options(-producer)
			$p2pSession configure -euf_guid $euf_guid
			$p2pSession invite $context

		}

		method accept { } {

			set answered 1
			::CAMGUI::InvitationAccepted [$p2pSession cget -peer] [$p2pSession cget -id]
			set temp_appid [$self cget -application_id]
			$self configure -application_id 0
			$p2pSession Respond 200
			$self configure -application_id $temp_appid
			$self send_binary_syn

		}

		method reject { } {

			set answered 1
			::CAMGUI::InvitationRejected [$p2pSession cget -peer] [$p2pSession cget -id]
			$p2pSession Respond 603
			$self configure -canceled 1
			after 60000 [list catch [list $self destroy]]

		}

		method end { } { 

			if { $answered == 0 } {
				$self reject
			} else {
				set context "\x74\x03\x00\x81"
				$self Close $context ""
				::MSNCAM::CamCanceled $options(-chatid) $self 
			}
			$self configure -canceled 1
			after 60000 [list catch [list $self destroy]]

		}

		method on_media_session_prepared { session } {

			if { $xml_needed == 1 } {
				$self Send_xml
			}

		}

		method On_invite_received { message } {

			if { [[$message body] cget -euf_guid] == $::p2p::EufGuid::MEDIA_SESSION } {
				$self configure -producer 0
			} else {
				$self configure -producer 1
			}
			::CAMGUI::AcceptOrRefuse $options(-chatid) $self $options(-producer)

		}

		method On_transreq_received { event msg } {

			if { [$msg cget -call_id] != [$self cget -call_id] } { return }

			#$self Switch_bridge $msg
			$p2pSession Decline_transreq $msg
			$self send_binary_syn

		}

		method On_bye_received { event session } {

			if { $session != $p2pSession } { return }
			$self configure -canceled 1
			::CAMGUI::CamCanceled $options(-chatid) [$self cget -id]
			after 60000 [list catch [list $self destroy]]

		}

		method On_session_accepted { event session } {

			if { $session != $p2pSession } { return }

			set chatid [$p2pSession cget -peer]
                	set producer [$self cget -producer]
	                ::amsn::WinWrite $chatid "\n" green
        	        ::amsn::WinWriteIcon $chatid winwritecam 3 2
                	set nick [::abook::getDisplayNick $chatid]
	                if { $producer == 1 } {
        	                ::amsn::WinWrite $chatid "[timestamp] [trans sendwebcamaccepted $nick]" green
                	} else {
                        	::amsn::WinWrite $chatid "[timestamp] [trans recvwebcamaccepted $nick]" green
	                }
			#::Event::fireEvent p2pCallAccepted p2pWebcamSession {}
	
		}

		method On_session_rejected { event session message } {

			if { $session != $p2pSession } { return }

			::CAMGUI::InvitationDeclined [$p2pSession cget -peer] [$p2pSession cget -id]
			#::Event::fireEvent p2pCallRejected p2pWebcamSession {}
			$self configure -canceled 1
			after 60000 [list catch [list $self destroy]]

		}

		method On_data_blob_received { event session data } {

			if { $session != $p2pSession } { return }

			#set data [$blob cget -data]
			set data [string range $data 10 end]
			set data [encoding convertfrom unicode $data]
			set data [string trim $data "\x00"]
			status_log "Webcam received data $data"

			if { $options(-send_syn) == 0 } {
				#@@@@@@ TODO: really needed?
				$self send_binary_syn
			}
			if { $data == "syn" } {
				$self send_binary_ack
			} elseif { $data == "ack" && $options(-producer) == 1 } {
				$self Send_xml
			} elseif { [string first "<producer>" $data] >= 0 || [string first "<viewer>" $data] >= 0 } {
				$self Handle_xml $data
			} elseif { [string first "ReflData" $data] == 0 } {
				#@@@@@@@@@@@ MSNCAM where?
			} elseif { $data == "receivedViewerData" } {
				#$self configure -blob_id [$blob cget -blob_id]
				::MSNCAM::ConnectSockets $self
			}

		}

		method send_data { data } {

			set h1 "\x80[binary format s [myRand 0 65000]]\x01\x08\x00"
			set h3 [ToUnicode "${data}\x00"]
			set h2 [binary format i [string length $data]]
			set msg "${h1}${h2}${h3}"
			$p2pSession Send_p2p_data $msg

		}

		method send_binary_syn {} {

			$self send_data "syn"
			$self configure -send_syn 1

		}

		method send_binary_ack {} {

			$self send_data "ack"

		}

		method send_binary_viewer_data {} {

			$self send_data "receivedViewerData"

		}

		method Send_xml {} {

			set xml_needed 0
			status_log "Sent XML for session $options(-sid)"
			set message [WebcamSessionMessage %AUTO% -partof $self -id $options(-sid) -producer $options(-producer) -session $options(-session)]
			$self send_data [$message toString]
			catch {$message destroy}

		}

		method Handle_xml { data } {

			$self configure -xml $data
			set message [WebcamSessionMessage %AUTO% -partof $self -body $data -producer $options(-producer) -session $options(-session)]
			status_log "Received XML for session $options(-sid)"
			if { $options(-producer) == 1 } {
				$self send_binary_viewer_data
			} else {
				$self Send_xml
			}
			catch {$message destroy}

		}

	}

}