Posted to tcl by patthoyts at Thu Apr 13 10:20:44 GMT 2006view raw

  1. proc tkjabber::ProxyConnect {proxyserver proxyport jabberserver jabberport} {
  2. global Options
  3. variable have_tls
  4.  
  5. set sock [socket $proxyserver $proxyport]
  6. fconfigure $sock -blocking 0 -buffering line -translation crlf
  7.  
  8. set proxyauth [join [::tkchat::buildProxyHeaders] {: }]
  9. puts $sock "CONNECT $jabberserver:$jabberport HTTP/1.1"
  10. puts $sock "Host: $jabberserver"
  11. puts $sock "User-Agent: [http::config -useragent]"
  12. puts $sock "Proxy-Connection: keep-alive"
  13. puts $sock "Connection: keep-alive"
  14. if {[string length $proxyauth] > 0} {
  15. puts $sock "$proxyauth"
  16. }
  17. puts $sock ""
  18.  
  19. fileevent $sock readable {set proxy_readable ""}
  20. global proxy_readable
  21. vwait proxy_readable
  22. fileevent $sock readable {}
  23.  
  24. set block [read $sock]
  25. set result [lindex [split $block \n] 0]
  26. set code [lindex [split $result { }] 1]
  27. fconfigure $sock -blocking 1 -translation binary -buffering none
  28.  
  29. if {$code >= 200 && $code < 300} {
  30. if {$have_tls && $Options(UseJabberSSL) eq "ssl"} {
  31. tls::import $sock
  32. }
  33. } else {
  34. error "proxy connect failed: $block"
  35. }
  36. return $sock
  37. }
  38.