@@ -41,14 +41,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4141package require tls
4242
4343if {[llength $::argv ] < 2} {
44- puts stdout " Oi, you gotta specify both the port AND the hostname - try: ./ ${argv0} 27070 127.0.0.1"
44+ puts stdout " Oi, you gotta specify both the port AND the hostname - try: ${argv0} 27070 127.0.0.1"
4545 exit
4646}
4747socket -myaddr [lindex $::argv 1] -server acceptconn [lindex $::argv 0]
4848set proxyhost [lindex $::argv 1]
4949
5050proc acceptconn {c a p} {
51- # puts stdout "received connection from 1/$p/$a"
51+ puts stdout " received connection from 1/$p /$a "
5252 chan configure $c -blocking 0 -buffering line -translation {auto crlf}
5353 chan event $c readable [list tgp:read $c $a $p ]
5454}
@@ -62,25 +62,25 @@ proc tgp:fmt-line {type selector path host {port 70} {plus {}}} {
6262
6363proc tgp:read {c a p} {
6464 set gotten [gets $c line]
65- # puts stdout $line
65+ puts stdout $line
6666 if {[string index $line 0] == " /" } {set line [string range $line 1 end]}
6767 set req [split $line " /" ]
6868 if {[llength $req ] < 3} {
6969 puts $c [tgp:fmt-line 3 " Error: insufficient path length" " /" [lindex $::argv 1] [lindex $::argv 0]]
7070 close $c
7171 return
7272 }
73- # puts stdout $req
73+ puts stdout $req
7474 set sendsel [lassign $req stype tp ta]
75- set socketc ::socket
75+ set socketc [ list ::socket]
7676 if {[llength $sendsel ] > 0 || ([lindex $sendsel 0] != {} && [lindex $sendsel 0] != " " )} {set sendsel [join $sendsel " /" ]} {set sendsel " " }
7777 if {[string length $stype ] > 1} {
7878 set stype [string index $stype 0]
79- set socketc [list ::tls::socket -require 0]
79+ set socketc [list ::tls::socket -require 0 -ssl2 0 -ssl3 0 ]
8080 }
8181 if {$tp > 100000} {
8282 set tp [expr {$tp - 100000}]
83- set socketc [list ::tls::socket -require 0]
83+ set socketc [list ::tls::socket -require 0 -ssl2 0 -ssl3 0 ]
8484 }
8585 if {$stype == " 1" || $stype == " 7" } {
8686 set socketrcb tgp:smread
@@ -91,13 +91,16 @@ proc tgp:read {c a p} {
9191 }
9292 if {[set errval [catch [list {*}$socketc $ta $tp ] err]] != 0} {
9393 puts $c [tgp:fmt-line 3 " Error: connection did not synchronise" " /" " 127.0.0.1" [lindex $::argv 0]]
94- # puts stdout [format "%s/%s %s;%s/%s %s %s - failed" $p $a $ta $tp $stype $sendsel $socketc]
94+ puts stdout [format " %s/%s %s;%s/%s %s %s - failed" $p $a $ta $tp $stype $sendsel $socketc ]
9595 close $c
9696 return
9797 } {
98- chan configure $err -blocking 0 -buffering line -buffersize 64
99- puts $err $sendsel
100- # puts stdout [format "%s/%s %s;%s/%s %s %s - fetching" $p $a $ta $tp $stype $sendsel $socketrcb]
98+ chan configure $err -blocking 1 -buffering none -translation binary
99+ if {[lindex $socketc 0] == " ::tls::socket" } {tls::handshake $err }
100+ chan configure $c -blocking 0 -buffering line -translation {auto crlf}
101+ chan configure $err -blocking 0 -buffering line -translation {auto crlf}
102+ puts -nonewline $err [format " %s\r\n " $sendsel ]
103+ puts stdout [format " %s/%s %s;%s/%s %s %s - fetching" $p $a $ta $tp $stype $sendsel $socketrcb ]
101104 # chan event $c readable [list tgp:getitinthere $err $c]
102105 chan event $err readable [list $socketrcb $c $err ]
103106 return
@@ -152,11 +155,13 @@ proc tgp:smread {channel fp} {
152155 if {[catch [list chan tell $fp ] err] != 0} {
153156 close $channel
154157 }
155- fconfigure $channel -translation {auto crlf} -buffering line -buffersize 2048
156- fconfigure $fp -translation {auto crlf} -buffering line -buffersize 2048
157- while {[gets $fp text] > 0} {
158+ fconfigure $channel -translation {auto crlf} -buffering line
159+ fconfigure $fp -translation {crlf crlf} -buffering none
160+ puts stdout [format " %s %s spinning the read" $channel $fp ]
161+ while {[set nn [gets $fp text]] > 0} {
162+ puts stdout $nn
158163 set gopherplus [lassign [tgd:split $text ] st sn ts ta tp]
159- # puts stdout [format "/%s/ -> g+/%s/ st/%s/ sn/%s/ ts/%s/ ta/%s/ tp/%s/" $text $gopherplus $st $sn $ts $ta $tp]
164+ puts stdout [format " /%s/ -> g+/%s/ st/%s/ sn/%s/ ts/%s/ ta/%s/ tp/%s/" $text $gopherplus $st $sn $ts $ta $tp ]
160165 if {$st != " i" && $st != " ." } {
161166 if {$tp > 100000} {
162167 set iss " t"
@@ -173,6 +178,7 @@ proc tgp:smread {channel fp} {
173178 }
174179 puts $channel $otext
175180 }
181+ puts stdout $nn
176182 flush $channel
177183 if {[fblocked $fp ] == 0} {close $fp ; close $channel }
178184}
0 commit comments