Posted to tcl by patthoyts at Thu Apr 13 10:20:44 GMT 2006view raw
- proc tkjabber::ProxyConnect {proxyserver proxyport jabberserver jabberport} {
- global Options
- variable have_tls
- set sock [socket $proxyserver $proxyport]
- fconfigure $sock -blocking 0 -buffering line -translation crlf
- set proxyauth [join [::tkchat::buildProxyHeaders] {: }]
- puts $sock "CONNECT $jabberserver:$jabberport HTTP/1.1"
- puts $sock "Host: $jabberserver"
- puts $sock "User-Agent: [http::config -useragent]"
- puts $sock "Proxy-Connection: keep-alive"
- puts $sock "Connection: keep-alive"
- if {[string length $proxyauth] > 0} {
- puts $sock "$proxyauth"
- }
- puts $sock ""
- fileevent $sock readable {set proxy_readable ""}
- global proxy_readable
- vwait proxy_readable
- fileevent $sock readable {}
- set block [read $sock]
- set result [lindex [split $block \n] 0]
- set code [lindex [split $result { }] 1]
- fconfigure $sock -blocking 1 -translation binary -buffering none
- if {$code >= 200 && $code < 300} {
- if {$have_tls && $Options(UseJabberSSL) eq "ssl"} {
- tls::import $sock
- }
- } else {
- error "proxy connect failed: $block"
- }
- return $sock
- }