proc clearOutput {} {
global state
if {$state(gui)} {
- .out delete 0.0 end
- catch {.extract.out delete 0.0 end}
+ .out delete 0.0 end
+ catch {.extract.out delete 0.0 end}
}
set state(playback) ""
}
set p $state(playback) ;# Save what gets displayed
clearOutput ;# Erase current screen
foreach {who data time} $p { ;# Replay the input stream
- insertData $who $data $time 1
+ insertData $who $data $time 1
}
set state(autoscroll) $save_as
}
#
proc tfButton {who} {
if {$who == "default"} {
- set ::state(timeFormat) $::state(timeFormatDefault)
+ set ::state(timeFormat) $::state(timeFormatDefault)
} elseif {$who == "ok"} {
- destroy .tf
- redraw
+ destroy .tf
+ redraw
} elseif {$who == "cancel"} {
- set ::state(timeFormat) $::state(oldTimeFormat)
- destroy .tf
+ set ::state(timeFormat) $::state(oldTimeFormat)
+ destroy .tf
}
}
##+##########################################################################
}
proc ERROR {emsg} {
if {$::state(gui)} {
- tk_messageBox -title "SockSpy Error" -message $emsg -icon error
+ tk_messageBox -title "SockSpy Error" -message $emsg -icon error
} else {
- puts $emsg
+ puts $emsg
}
}
##+##########################################################################
global state
set died [catch {set data [read $fromSock]} err]
if {$died || [eof $fromSock]} {
- close $fromSock
- catch { close $toSock }
- if {$died} { INFO $err }
- INFO "----- closed connection $fromSock \[eof\] -----"
- INFO "waiting for new connection..."
- return
+ close $fromSock
+ catch { close $toSock }
+ if {$died} { INFO $err }
+ INFO "----- closed connection $fromSock \[eof\] -----"
+ INFO "waiting for new connection..."
+ return
}
if {$toSock == ""} { ;# Make socks or http proxy connection
if {[catch {ProxyConnect $fromSock $data} err]} {
INFO $err
close $fromSock
INFO "----- closed connection $fromSock -----"
- INFO "waiting for new connection..."
+ INFO "waiting for new connection..."
return 0
}
} else {
- catch { puts -nonewline $toSock $data } ;# Forward if we have a socket
+ catch { puts -nonewline $toSock $data } ;# Forward if we have a socket
}
insertData [list $who $fromSock] $data
update idletasks
set line1 [string trimright $line1 "\r\n"]
INFO "proxy request \"$line1\"" meta2
if {![regexp {^([^ ]+) +([^ ]+)} $line1 -> method uri]} {
- return -code error "failed to parse a uri from '$line1'"
+ return -code error "failed to parse a uri from '$line1'"
}
-
+
set method [string trim [string toupper $method]]
if {$method eq "CONNECT"} {
foreach {host port} [split $uri :] break
if {$URI(port) == ""} { set URI(port) 80 }
set bad [catch {set sockServ [socket $URI(host) $URI(port)]} reason]
if {$bad} {
- return -code error "cannot connect to $URI(host):$URI(port) => $reason"
+ return -code error "cannot connect to $URI(host):$URI(port) => $reason"
}
if {$method eq "CONNECT"} {
- # We must send an HTTP response header to the client
- set s "HTTP/1.0 200 OK\nServer: SockSpy/$::state(version)\n"
- insertData meta $s
- puts $fromSock $s
+ # We must send an HTTP response header to the client
+ set s "HTTP/1.0 200 OK\nServer: SockSpy/$::state(version)\n"
+ insertData meta $s
+ puts $fromSock $s
}
INFO "fowarding $method request to $URI(host):$URI(port)" meta2
if {$skip} {
- fileevent $fromSock readable \
- [list ProxySkip $fromSock $sockServ]
+ fileevent $fromSock readable \
+ [list ProxySkip $fromSock $sockServ]
} else {
- fileevent $fromSock readable \
- [list sockReadable $fromSock $sockServ client]
+ fileevent $fromSock readable \
+ [list sockReadable $fromSock $sockServ client]
}
fconfigure $sockServ -blocking 0 -buffering none -translation binary
fileevent $sockServ readable \
- [list sockReadable $sockServ $fromSock server]
-
+ [list sockReadable $sockServ $fromSock server]
+
puts -nonewline $sockServ $data
return
}
global state
set data [read $fromSock]
if {[string length $data] == 0} {
- close $fromSock
- catch { close $toSock }
- INFO "----- closed connection -----"
- INFO "waiting for new connection..."
- return
+ close $fromSock
+ catch { close $toSock }
+ INFO "----- closed connection -----"
+ INFO "waiting for new connection..."
+ return
}
set pos [string first \r\n\r\n $data]
if { $pos == -1 } {
- # Just drop the data.
- return
+ # Just drop the data.
+ return
}
incr pos 4
set data [string range $data $pos end]
if { [string length $data] > 0 } {
- # Forward the real payload
- catch { puts -nonewline $toSock $data } ;
+ # Forward the real payload
+ catch { puts -nonewline $toSock $data } ;
insertData client $data
}
# And let the normal data handler do the rest:
set state(sockClnt) $sockClnt
set state(meta) ""
-
+
INFO "connect from [fconfigure $sockClnt -sockname] $port" meta2
if {$state(proxy) ne "none"
- || $SP(servHost) == {}
+ || $SP(servHost) == {}
|| $SP(servHost) == "none"} {
- set sockServ ""
+ set sockServ ""
} else {
- set n [catch {set sockServ [socket $SP(servHost) $SP(servPort)]} reason]
- if {$n} {
- INFO "cannot connect: $reason"
- close $sockClnt
- ERROR "cannot connect to $SP(servHost) $SP(servPort): $reason"
- insertData meta "----- closed connection -----"
- insertData meta "waiting for new connection..."
-
- }
- INFO "connecting to $SP(servHost):$SP(servPort)" meta2
+ set n [catch {set sockServ [socket $SP(servHost) $SP(servPort)]} reason]
+ if {$n} {
+ INFO "cannot connect: $reason"
+ close $sockClnt
+ ERROR "cannot connect to $SP(servHost) $SP(servPort): $reason"
+ insertData meta "----- closed connection -----"
+ insertData meta "waiting for new connection..."
+ }
+ INFO "connecting to $SP(servHost):$SP(servPort)" meta2
}
;# Configure connection to the client
fconfigure $sockClnt -blocking 0 -buffering none -translation binary
fileevent $sockClnt readable \
- [list sockReadable $sockClnt $sockServ client]
+ [list sockReadable $sockClnt $sockServ client]
;# Configure connection to the server
if {[string length $sockServ]} {
- fconfigure $sockServ -blocking 0 -buffering none -translation binary
- fileevent $sockServ readable \
- [list sockReadable $sockServ $sockClnt server]
+ fconfigure $sockServ -blocking 0 -buffering none -translation binary
+ fileevent $sockServ readable \
+ [list sockReadable $sockServ $sockClnt server]
}
}
##+##########################################################################
}
switch $::tcl_platform(platform) "macintosh" {
- set stateFile [file join $env(PREF_FOLDER) "SockSpy Preferences"]
+ set stateFile [file join $env(PREF_FOLDER) "SockSpy Preferences"]
} "windows" {
- set stateFile [file join $env(HOME) "sockspy.cfg"]
+ set stateFile [file join $env(HOME) "sockspy.cfg"]
} "unix" {
- if {[info exists env(DOTDIR)]} {
- set stateFile [file join $env(DOTDIR) .sockspy]
- } else {
- set stateFile [file join $env(HOME) .sockspy]
- }
+ if {[info exists env(DOTDIR)]} {
+ set stateFile [file join $env(DOTDIR) .sockspy]
+ } else {
+ set stateFile [file join $env(HOME) .sockspy]
+ }
}
# complain only if it exists and we fail to read it successsfully
if {[file exists $stateFile]} {
- uplevel #0 [list source $stateFile]
+ uplevel #0 [list source $stateFile]
}
set state(stateFile) $stateFile
if {$state(proxy) eq "1"} {set state(proxy) "http"}
foreach v $::saveList {
- trace variable $v w stateSave
+ trace variable $v w stateSave
}
}