From: Pat Thoyts Date: Sat, 17 Oct 2020 10:00:09 +0000 (+0100) Subject: s2s: whitespace cleanup X-Git-Url: https://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=310851ddbf23208dc79b1806b2b8dd218b11e7b8;p=tclxmppd.git s2s: whitespace cleanup --- diff --git a/s2s.tcl b/s2s.tcl index da7e84e..cdd6edc 100644 --- a/s2s.tcl +++ b/s2s.tcl @@ -1,7 +1,7 @@ # s2s.tcl - Copyright (C) 2004 Pat Thoyts # # A Tcl implementation of the Jabber server-to-server protocol. -# See http://www.jabber.org/ +# See http://www.jabber.org/ # # RFC 3920 [http://www.ietf.org/rfc/rfc3921.txt] # RFC 3921 [http://www.ietf.org/rfc/rfc3921.txt] @@ -11,7 +11,7 @@ # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ------------------------------------------------------------------------- -package require xmppd::core; # tclxmppd +package require xmppd::core; # tclxmppd package require uuid; # tcllib package require sha1; # tcllib package require logger; # tcllib @@ -21,7 +21,6 @@ namespace eval ::xmppd {} namespace eval ::xmppd::s2s { variable version 1.0.0 - variable rcsid {$Id: s2s.tcl,v 1.15 2006/04/17 10:14:47 pat Exp $} namespace export start stop route @@ -77,7 +76,8 @@ proc ::xmppd::s2s::stop {} { catch { set info [fconfigure $srv -sockname] close $srv - Log notice "XMPP s2s stopped listening on [lindex $info 0]:[lindex $info 2]" + Log notice "XMPP s2s stopped listening on\ + [lindex $info 0]:[lindex $info 2]" } msg puts stderr $msg } @@ -139,7 +139,7 @@ proc ::xmppd::s2s::route {args} { -from { set jid [jid domain [Pop args 1]] if {[string length $jid] > 0} { - puts "$option jid: '$jid'" + #puts "$option jid: '$jid'" set opts($option) $jid } } @@ -148,7 +148,7 @@ proc ::xmppd::s2s::route {args} { } Pop args } - + foreach opt {-from -to} { if {[string length $opts($opt)] < 1} { return -code error "invalid argument \"$opt\":\ @@ -285,7 +285,7 @@ proc ::xmppd::s2s::FindSession {op args} { foreach {from to} $args break foreach Session [info vars [namespace current]::session*] { upvar #0 $Session session - if {[info exists session(from)] && $session(from) eq $from + if {[info exists session(from)] && $session(from) eq $from && [info exists session(to)] && $session(to) eq $to} { lappend r $Session Log debug " Found session $r: $from -> $to" @@ -297,7 +297,7 @@ proc ::xmppd::s2s::FindSession {op args} { set Channel [lindex $args 0] foreach Session [info vars [namespace current]::session*] { upvar #0 $Session session - if {[info exists session(channel)] + if {[info exists session(channel)] && $session(channel) eq $Channel} { lappend r $Session } @@ -360,11 +360,12 @@ proc ::xmppd::s2s::Open {from to} { # First, resolve the hostname. If possible we can re-use a connection that # already exists. - + if {[llength [set addr [resolve $to]]] < 1} { - return -code error "hostname invalid: \"$to\" failed to resolve ip address" + return -code error "hostname invalid: \"$to\" \ + failed to resolve ip address" } - + set Channel [FindChannel out [lindex $addr 0]] if {[llength $Channel] < 1} { set Channel [CreateChannel] @@ -379,8 +380,7 @@ proc ::xmppd::s2s::Open {from to} { [list [namespace current]::OnOpenStream $Channel] \ [list [namespace current]::OnCloseStream $Channel] \ [list [namespace current]::OnInput $Channel] \ - [list [namespace current]::OnError $Channel] \ - -namespace 0] + [list [namespace current]::OnError $Channel]] set sock [socket -async $channel(address) $channel(port)] set channel(sock) $sock @@ -409,8 +409,7 @@ proc ::xmppd::s2s::Accept {chan clientaddr clientport} { [list [namespace current]::OnOpenStream $Channel] \ [list [namespace current]::OnCloseStream $Channel] \ [list [namespace current]::OnInput $Channel] \ - [list [namespace current]::OnError $Channel] \ - -namespace 0] + [list [namespace current]::OnError $Channel]] fconfigure $chan -translation binary -encoding utf-8 \ -buffering none -blocking 0 @@ -478,7 +477,7 @@ proc ::xmppd::s2s::Close {Channel} { # # proc ::xmppd::s2s::Log {level msg} { - ::xmppd::Log s2s $level $msg + ::xmppd::Log s2s $level $msg } # ------------------------------------------------------------------------- @@ -488,14 +487,14 @@ proc ::xmppd::s2s::OnOpenStream {Channel args} { array set attr {version 0.0} array set attr $args - Log debug "OPENSTREAM $channel(sock) [array get attr]" if {[info exists attr(id)]} { + Log info "OPENSTREAM out $channel(sock) [array get attr]" # RFC3920 8.3(3): Remote server sends up a unique session id. # The from and to elements are optional here. # We must reject invalid namespace. - #if {![info exists attr(xmlns)] + #if {![info exists attr(xmlns)] # || $attr(xmlns) ne "http://etherx.jabber.org/streams"} { # return [Raise $Channel invalid-namespace] #} @@ -509,11 +508,10 @@ proc ::xmppd::s2s::OnOpenStream {Channel args} { set session(queue) [list $channel(queue)] } set channel(from) {}; # clean up temporary channel items - set channel(to) {}; # + set channel(to) {}; # set channel(queue) {} - - # RFC3920 8.3(4): The Originating Server (us) sends a dialback key + # RFC3920 8.3(4): The Originating Server (us) sends a dialback key # to the Receiving Server (them) # # JID-0185: Dialback key generation and validation @@ -522,12 +520,15 @@ proc ::xmppd::s2s::OnOpenStream {Channel args} { set session(key) [sha1::sha1 $key] set xml "$session(key)" + to='$session(to)'\ + from='$session(from)'>$session(key)" set session(state) dialback WriteTo $Channel $xml } else { + Log debug "OPENSTREAM in $channel(sock) [array get attr]" + # RFC3920 8.3(6): The Receiving Server (them) sends the Authoritative # Server (us) a stream header. From and to are # optional. We MUST reject invalid namespaces. @@ -536,7 +537,7 @@ proc ::xmppd::s2s::OnOpenStream {Channel args} { # return [Raise $Channel invalid-namespace] #} - # RFC3920 8.3(7): The Authoritative Server (us) sends the Receiving + # RFC3920 8.3(7): The Authoritative Server (us) sends the Receiving # Server (them) a stream header - with a session id # We don't have enough info to create a session, so we store the # id on the channel @@ -597,13 +598,13 @@ proc ::xmppd::s2s::OnInput {Channel xmllist} { Raise $Channel improper-addressing } - if {$a(xmlns:db) eq [xmlns dialback]} { - + if {$a(xmlns) eq [xmlns dialback]} { + if {[info exists a(type)]} { - # RFC3920 8.3(10): The Receiving Server (them) informs the + # RFC3920 8.3(10): The Receiving Server (them) informs the # Originating Server (us)of the result. set Session [FindSession name $a(from) $a(to)] - if {$Session eq {}} { + if {$Session eq {}} { return [Raise $Channel invalid-from] } upvar #0 $Session session @@ -611,7 +612,7 @@ proc ::xmppd::s2s::OnInput {Channel xmllist} { return } - # RFC3290 8.3(4): The Originating Server (them) sends a + # RFC3290 8.3(4): The Originating Server (them) sends a # dialback key to the Receiving Server (us) # if {![info exists channel(id)]} { @@ -620,14 +621,14 @@ proc ::xmppd::s2s::OnInput {Channel xmllist} { } set Session [CreateSession] upvar #0 $Session session - set session(id) $channel(id) + set session(id) $channel(id) set session(state) dialback set session(channel) $Channel set session(from) $a(from) set session(to) $a(to) set session(key) $value - # We need to send this key on the out channel with the + # We need to send this key on the out channel with the # out session id, from and to. set Out [FindSession name $a(to) $a(from)] if {$Out ne {}} { @@ -637,24 +638,24 @@ proc ::xmppd::s2s::OnInput {Channel xmllist} { id='$session(id)'>$session(key)" WriteTo $out(channel) $xml } else { - Log debug "- Creating new out channel to $a(from)" + Log info "- Creating new out channel to $a(from)" Open $a(to) $a(from) } } else { - Log error "unespected 'result' namespace'" + Log error "unexpected 'result' namespace'" } } verify { - Log debug "- verify $xmllist" - + Log debug "- verify $xmllist" + # RFC3920 8.3: All stanzas MUST include both to and from if {$a(from) eq "" || $a(to) eq ""} { Raise $Channel improper-addressing } - + set Session [FindSession id $a(id)] - if {$Session eq {}} { + if {$Session eq {}} { # Raise invalid-id ?? Log error "Failed to find session for '$a(id)'" return @@ -666,9 +667,9 @@ proc ::xmppd::s2s::OnInput {Channel xmllist} { } if {![info exists a(type)]} { - - # RFC3920 8.3(8): The Receiving Server (them) sends the - # Authoritative Server (us) a request for + + # RFC3920 8.3(8): The Receiving Server (them) sends the + # Authoritative Server (us) a request for # verification of a key. This is the id we # recieved in step 3 and its key. So we are # validating the out channel using data @@ -689,7 +690,7 @@ proc ::xmppd::s2s::OnInput {Channel xmllist} { WriteTo $Channel $xml } else { - + # RFC3920 8.3(9): The Authoritative Server (them) verifies the # valididy of the key and posts a message to # the Recieving Server (us). @@ -715,13 +716,13 @@ proc ::xmppd::s2s::OnInput {Channel xmllist} { # IMPOSSIBLE?? Log error "ARGH: 8.3(10) this isnt supposed to happen" } - + } else { Close $Channel } } } - + iq - message - presence {