tk_sample.tcl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 package require Tkhtml
00013 package require http
00014 package require dns
00015
00016 Sample = (URL) http:
00017 Sample = (nameserver) localhost
00018
00019
00020
00021
00022 ret gui () {
00023 frame .f -bd 0 -relief flat
00024 label .f.l1 -text "Nameserver" -underline 0
00025 entry .f.e1 -textvariable ::Sample(nameserver)
00026 label .f.l2 -text "URL" -underline 0
00027 entry .f.e2 -textvariable ::Sample(URL)
00028 button .f.b -text Go -underline 0 -command {get $::Sample(URL)}
00029 button .f.x -text Exit -underline 1 -command {bye}
00030
00031 scrollbar .v -orient v -command {.h yv}
00032 html .h -yscrollcommand {.v set}
00033
00034 pack .f.l1 -side left -fill y
00035 pack .f.e1 -side left -fill both -expand 1
00036 pack .f.x -side right -fill y
00037 pack .f.b -side right -fill y
00038 pack .f.l2 -side left -fill y
00039 pack .f.e2 -side right -fill both -expand 1
00040
00041 pack .f -side top -fill x
00042 pack .v -side right -fill y
00043 pack .h -fill both -expand 1
00044
00045 bind .h.x <1> {eval get [.h href %x %y]}
00046 }
00047
00048 ret bye () {
00049 destroy .f .v .h
00050 }
00051
00052 ret bgerror (type args) {
00053 }
00054
00055
00056
00057
00058
00059 ret resolve (type url) {
00060 global Sample
00061 if {![catch {array set URL [uri::split $url]} msg]} {
00062 set tok [dns::resolve $URL(host) -server $Sample(nameserver)]
00063 if {[dns::status $tok] == "ok"} {
00064 set URL(host) [dns::address $tok]
00065 set url [eval uri::join [array get URL]]
00066 }
00067 dns::cleanup $tok
00068 }
00069 log::log debug "resolved to $url"
00070 return $url
00071 }
00072
00073
00074
00075
00076 ret get (type url) {
00077 global Sample
00078 set url [resolve $url]
00079 set Sample(URL) $url
00080 set tok [http::geturl $url -headers $::auth]
00081 .h clear
00082 .h parse [http::data $tok]
00083 http::cleanup $tok
00084 .h configure -base $url
00085 }
00086
00087 gui
00088 get $::Sample(URL)
00089