/usr/share/amsn/msnp2p/p2p.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 | namespace eval ::p2p {
snit::type MSNObjectStore {
option -client ""
variable outgoing_sessions -array {}
variable incoming_sessions -array {}
variable published_objects {}
variable incoming_DPs_by_user -array {}
constructor {args} {
$self configurelist $args
#::Event::registerEvent p2pIncomingCompleted all [list $self Incoming_session_transfer_completed]
}
destructor {
set handles [list p2pOnSessionAnswered On_session_answered p2pOnSessionRejected On_session_rejected p2pOutgoingSessionTransferCompleted Outgoing_session_transfer_completed]
foreach {event callb} $handles {
catch {::Event::unregisterEvent $event all [list $self $callb]}
}
}
method Can_handle_message { message} {
status_log "Can I handle $message with body [$message body]?"
set euf_guid [[$message body] cget -euf_guid]
if { $euf_guid == $::p2p::EufGuid::MSN_OBJECT } {
return 1
} else {
return 0
}
}
method Handle_message { peer guid message} {
#status_log "Received message of type [$message info type]!!!"
set session [MSNObjectSession %AUTO% -session_manager [$self cget -client] -peer $peer -guid $guid -application_id [$message cget -application_id] -message $message -context [[$message body] cget -context]]
$session conf2
set incoming_sessions($session) {p2pIncomingCompleted Incoming_session_transfer_completed}
set msnobj [MSNObject parse [$session cget -context]]
foreach obj $published_objects {
if {[$obj cget -shad] == [$msnobj cget -shad]} {
$session accept [$obj cget -data]
status_log "Returning session $session!!!!!!"
$msnobj destroy
return $session
}
}
$msnobj destroy
$session reject
status_log "No such object, rejecting"
return $session
}
method request { msnobj callback {errback ""} {peer ""}} {
if { [$msnobj cget -data] != "" } {
status_log "p2p.tcl method request going to eval [lindex $callback 0] $msnobj [lindex $callback 1]"
eval [lindex $callback 0] $msnobj [lindex $callback 1]
}
if { $peer == "" } {
set peer [$msnobj cget -creator]
}
if { [$msnobj cget -type] == $::p2p::MSNObjectType::CUSTOM_EMOTICON } {
set application_id $::p2p::ApplicationID::CUSTOM_EMOTICON_TRANSFER
} elseif { [$msnobj cget -type] == $::p2p::MSNObjectType::DISPLAY_PICTURE } {
set application_id $::p2p::ApplicationID::DISPLAY_PICTURE_TRANSFER
} elseif { [$msnobj cget -type] == $::p2p::MSNObjectType::WINK } {
set application_id $::p2p::ApplicationID::WINK_TRANSFER
} elseif { [$msnobj cget -type] == $::p2p::MSNObjectType::VOICE_CLIP } {
set application_id $::p2p::ApplicationID::VOICE_CLIP_TRANSFER
} else {
return ""
}
# TODO: p2pv2: send a request to all end points of the peer and cancel the other sessions when one of them answers
set context [$msnobj toString]
status_log "Context: $context"
status_log "Peer: $peer"
set session [MSNObjectSession %AUTO% -session_manager [$self cget -client] -peer $peer -guid "" -application_id $application_id -context $context]
$session conf2
status_log "Session $session created with peer [$session cget -peer]"
set handles [list p2pOnSessionAnswered On_session_answered p2pOnSessionRejected On_session_rejected p2pOutgoingSessionTransferCompleted Outgoing_session_transfer_completed]
foreach {event callb} $handles {
::Event::registerEvent $event all [list $self $callb]
}
set outgoing_sessions([$session p2p_session]) [list $handles $callback $errback $msnobj]
$session invite $context
}
method publish { msnobj } {
if { [$msnobj cget -data] != "" } {
foreach obj $published_objects {
if {[$obj cget -shad] == [$msnobj cget -shad]} {
$msnobj destroy
return
}
}
set published_objects [lappend published_objects $msnobj]
}
}
method Outgoing_session_transfer_completed { event session data} {
if {![info exists outgoing_sessions($session)] } {
status_log "$self Outgoing_session_transfer_completed : Couldn't find outgoing session" red
return
}
status_log "Outgoing session transfer completed!!!!!!!"
set lst $outgoing_sessions($session)
set handles [lindex $lst 0]
set callback [lindex $lst 1]
set errback [lindex $lst 2]
set msnobj [lindex $lst 3]
status_log "Callback is $callback"
foreach {event callb} $handles {
::Event::unregisterEvent $event all [list $self $callb]
}
$msnobj configure -data $data
set method_name [lindex $callback 0]
set args [lreplace $callback 0 0]
status_log "p2p.tcl method Outgoing_session_transfer_completed going to eval $method_name $msnobj $args"
eval $method_name $msnobj $args
array unset outgoing_sessions $session
set type [$msnobj cget -type]
if { $type == $::p2p::MSNObjectType::CUSTOM_EMOTICON || $type == $::p2p::MSNObjectType::WINK || $type == $::p2p::MSNObjectType::VOICE_CLIP } {
catch {$msnobj destroy}
} elseif { $type == $::p2p::MSNObjectType::DISPLAY_PICTURE } {
catch {$incoming_DPs_by_user([$msnobj cget -creator]) destroy}
set incoming_DPs_by_user([$msnobj cget -creator]) $msnobj
}
}
method Incoming_session_transfer_completed { event session data } {
if {![info exists incoming_sessions($session)] } {
status_log "Incoming_session_transfer_completed : unknown session" red
return
}
set {event callback} $incoming_sessions($session)
::Event::unregisterEvent $event all [list $self $callback]
array unset incoming_sessions $session
}
method On_session_answered { answered_session } {
foreach session [array names outgoing_sessions] {
if { $session == $answered_session } { continue }
if { [$session cget -peer] != [$answered_session cget -peer] } { continue }
if { [$session cget -context] != [$answered_session cget -context] } { continue }
set lst $outgoing_sessions($session)
set handles [lindex $lst 0]
set callback [lindex $lst 1]
set errback [lindex $lst 2]
set msnobj [lindex $lst 3]
foreach {event callback} $handles {
::Event::unregisterEvent $event all [list $self $callback]
}
$session cancel
array unset outgoing_sessions $session
}
}
method On_session_rejected { session } {
if {![info exists outgoing_sessions($session)] } {
status_log "$self On_session_rejected : Couldn't find outgoing session" red
return
}
$self On_session_answered $session
set lst $outgoing_sessions($session)
set handles [lindex $lst 0]
set callback [lindex $lst 1]
set errback [lindex $lst 2]
set msnobj [lindex $lst 3]
foreach {event callback} $handles {
::Event::unregisterEvent $event all [list $self $callback]
}
if { [info exists [lindex $errback 0]] } {
status_log "p2p.tcl rejected going to eval [lindex $errback 0] $msnobj [lindex $errback 1]"
eval [lindex $errback 0] $msnobj [lindex $errback 1]
}
array unset outgoing_sessions $session
}
method get_all_objects { } {
return $published_objects
}
}
snit::type WebcamHandler {
option -client ""
variable sessions {}
constructor {args} {
$self configurelist $args
}
method Can_handle_message { message } {
status_log "Can webcam handle [[$message body] cget -euf_guid]?"
set euf_guid [[$message body] cget -euf_guid]
if { $euf_guid == $::p2p::EufGuid::MEDIA_SESSION || $euf_guid == $::p2p::EufGuid::MEDIA_RECEIVE_ONLY } {
return 1
}
return 0
}
method Handle_message { peer guid message } {
set euf_guid [[$message body] cget -euf_guid]
if { $euf_guid == $::p2p::EufGuid::MEDIA_SESSION } {
set producer 0
} elseif { $euf_guid == $::p2p::EufGuid::MEDIA_RECEIVE_ONLY } {
set producer 1
}
set session [WebcamSession %AUTO% -producer $producer -session_manager $options(-client) -peer $peer -euf_guid [[$message body] cget -euf_guid] -message $message]
set sessions [lappend sessions $session]
::Event::fireEvent p2pSessionCreated p2pWebcamHandler $session $producer
$session On_invite_received $message
return $session
}
method Invite { peer producer } {
status_log "Creating new webcam session"
if { $producer == 1 } {
set euf_guid $::p2p::EufGuid::MEDIA_SESSION
} else {
set euf_guid $::p2p::EufGuid::MEDIA_RECEIVE_ONLY
}
set session [WebcamSession %AUTO% -producer $producer -session_manager $options(-client) -peer $peer -euf_guid $euf_guid]
set sessions [lappend sessions $session]
$session invite
return $session
}
}
}
|