~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/indiva/imgr/imgr-httpd.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 import Httpd
  2 import IMgrHTML
  3 Class IMgrHttpd -superclass Httpd
  4 
  5 IMgrHttpd instproc init { mgr root port } {
  6     $self set imgroot_ "[$self get_option webroot]/images"
  7     $self set show_edges_ 0
  8     $self next $root $port ""
  9     $self set mgr_ $mgr
 10     $self set h_ [new IMgrHTML]
 11     $self set mimetype_() "text/html"
 12 }
 13 
 14 
 15 IMgrHttpd instproc respond { sock } {
 16     $self instvar config_ urlcache_
 17     upvar #0 Httpd$sock data
 18     #puts [array get data]
 19 
 20     regsub {(^http://[^/]+)?} $data(url) {} url
 21     if {[info exists urlcache_($url)]} {
 22         set mypath $urlcache_($url)
 23     } else {
 24         set mypath [$self url2file $config_(root) $url]
 25         # There is no default file in Indiva.
 26         #if {[file isdirectory $mypath]} {
 27         #    append mypath / $config_(default)
 28         #}
 29         set urlcache_($url) $mypath
 30     }
 31     if {[string length $mypath] == 0} {
 32         $self error $sock 400
 33     } elseif {![file readable $mypath]} {
 34         $self exec $sock $mypath
 35     } else {
 36         $self instvar mgr_
 37         if {![$mgr_ exists $mypath]} {
 38             $self exec $sock $mypath
 39         } else {
 40             $self output $sock [$self mob2html $sock $mypath]
 41         }
 42     }
 43 }
 44 
 45 IMgrHttpd instproc exec { sock command } {
 46     upvar #0 Httpd$sock data
 47     set command [lindex [split $command /] end]
 48     if [catch {eval $self $command $sock}] {
 49         global errorInfo
 50         puts $errorInfo
 51         $self error $sock 400
 52         return
 53     }
 54 }
 55 
 56 IMgrHttpd instproc services {sock} {
 57     upvar #0 Httpd$sock data
 58     
 59     $self instvar mgr_ h_
 60     set drivers [$mgr_ array names services_]
 61 
 62     set result "<h2>Services in Indiva</h2>"
 63 
 64     append result "<p><table class=flow cellspacing=0 cellpadding=2 width=100%>"
 65     foreach d $drivers {
 66         set list [split $d ,]
 67         append result "<tr>"
 68         append result "<td class=flowkey valign=top align=right>[short_name [lindex $list 0]]</td>"
 69         append result "<td class=flowkey valign=top align=right>[short_name [lindex $list 1]]</td>"
 70         append result "<td class=flowkey valign=top align=right>[short_name [lindex $list 2]]</td>"
 71         append result "<td>[[$mgr_ set ascp_($d)] service_location]</td></tr>"
 72     }
 73     append result "</table></p>"
 74 
 75     set result [$h_ html [$h_ head  [$h_ body $result] ] ]
 76 
 77     $self output $sock $result
 78 }
 79 
 80 
 81 IMgrHttpd instproc servents {sock} {
 82     upvar #0 Httpd$sock data
 83     
 84     $self instvar mgr_ h_
 85     set drivers [$mgr_ array names servents_]
 86 
 87     set result "<h2>Servents</h2>"
 88 
 89     append result "<p><table class=flow cellspacing=0 cellpadding=2 width=100%>"
 90     foreach d $drivers {
 91         append result "<tr>"
 92         append result "<td class=flowkey>$d</td>"
 93         append result "<td>[$mgr_ set servents_($d)]</td></tr>"
 94     }
 95     append result "</table></p>"
 96 
 97     set result [$h_ html [$h_ head  [$h_ body $result] ] ]
 98 
 99     $self output $sock $result
100 }
101 
102 IMgrHttpd instproc flow {sock} {
103     upvar #0 Httpd$sock data
104     
105 #   foreach {key value} [split $data(query) =&] {
106 #       puts "$key is $value"
107 #   }
108 
109     $self instvar mgr_
110     set flows [$mgr_ flow ls]
111 
112     set result "<h2>Flows</h2>"
113 
114     foreach flow $flows {
115         append result "<p><table class=flow cellspacing=0 cellpadding=2 width=100%>"
116         foreach {key value} $flow {
117             if {$key != "Flow Segments"} {
118                 append result "<tr><td class=flowkey valign=top align=right><b>$key</b></td>"
119                 append result "<td class=flowvalue>[short_name $value]</td></tr>"
120             } else {
121                 append result "<tr><td class=flowkey valign=top align=right><b>$key</b></td>"
122                 append result "<td><table class=flowvalue cellpadding=3 cellspacing=0 width=100%>"
123                 set from [lindex [lindex $value 0] 0]
124                 set name [short_name $from]
125                 append result "<tr><td class=flowsegment><a href=$name>$name</a></td></tr>\n"
126                 foreach {from to service} $value {
127                     append result "<td class=flowsegment>&nbsp;&nbsp;&nbsp;"
128                     append result "<img src=http://www.bmrc.berkeley.edu/~weitsang/indiva/images/downarrow.gif align=middle>"
129                     append result "&nbsp;<small><i><font color=#666699>$service</font></small></i></td></tr>"
130                     set name [short_name $to]
131                     append result "<td class=flowsegment><a href=$name>$name</a></td></tr>"
132                 }
133                 append result "</table></td>"
134             }
135         }
136         append result "</table></p>"
137     }
138     $self instvar h_
139     set result [$h_ html [$h_ head  [$h_ body $result] ] ]
140 
141     $self output $sock $result
142 }
143 
144 
145 
146 IMgrHttpd instproc output {sock msg} {
147     upvar #0 Httpd$sock data
148 
149     puts $sock "HTTP/1.$data(version) 200 Data follows"
150     puts $sock "Date: [$self date [clock seconds]]"
151     puts $sock "Last-Modified: [$self date [clock seconds]]"
152     puts $sock "Content-Type: text/html"
153     puts $sock "Content-Length: [string length $msg]"
154 
155     set close [expr {$data(left) == 0}]
156 
157     if {$close} {
158         puts $sock "Connection close:"
159     } elseif {$data(version) == 0 && [info exists data(mime,connection)]} {
160         if {$data(mime,connection) == "Keep-Alive"} {
161             set close 0
162             puts $sock "Connection: Keep-Alive"
163         }
164     }
165     puts $sock ""
166     if {$data(proto) != "HEAD"} {
167         fconfigure $sock -translation binary
168         puts $sock $msg
169         flush $sock
170         $self sockdone $sock $close
171     } else {
172         $self sockdone $sock $close
173     }
174 }
175 
176 
177 IMgrHttpd instproc flow2html { sock mob } {
178 }
179 
180 # print information about $mob
181 IMgrHttpd instproc mob2html { sock mob } {
182     upvar #0 Httpd$sock data
183     $self instvar mgr_
184 
185 
186     # print name of $mob, with links to parent directories.
187     set dirs [file split [short_name $mob]]
188     set href "/"
189     set name "<a href=/>/</a>"
190     foreach dir [lrange $dirs 1 end] {
191         if {$href != "/"} {
192             append href /
193             append name /
194         }
195         append href $dir
196         append name "<a href=$href>$dir</a>"
197     }
198 
199     set result "<h2>$name</h2>"
200 
201     # print attributes about $mob.
202     set attributes [$mgr_ info $mob]
203     if {$attributes != ""} {
204         append result "<h3>Attributes</h3>"
205         append result "<p>"
206         append result "<table class=attr cellspacing=0 cellpadding=3>"
207         foreach {key value} $attributes {
208             append result "<tr><td class=attrkey><b>$key</b></td>"
209             if {$value == ""} { set value "&nbsp;"}
210             append result "<td class=attrvalue>$value</td></tr>"
211         }
212         append result "</table>"
213         append result "</p>"
214     }
215 
216     # Show interconnection in graph.
217     $self instvar show_edges_
218     if {$show_edges_} {
219         append result "<h3>Outgoing Edges</h3>"
220         append result "<p>"
221         append result "<table cellpadding=4>"
222         set graph [$mgr_ set mob_graph_]
223         set node [$graph get_node $mob]
224         foreach n [$graph get_out_neighbors $mob] {
225             set name [short_name $n]
226             append result "<tr><td align=right bgcolor=#eeeeff><a href=$name>$name</a></td>"
227             set e [$graph get_edge $mob $n]
228             append result "<td align=left bgcolor=#eeeeee>[$e cost]</td></tr>"
229         }
230         append result "</table>"
231         append result "</p>"
232 
233         append result "<h3>Incoming Edges</h3>"
234         append result "<p>"
235         append result "<table cellpadding=4>"
236         set node [$graph get_node $mob]
237         foreach n [$graph get_in_neighbors $mob] {
238             set name [short_name $n]
239             append result "<tr><td align=right bgcolor=#eeeeff><a href=$name>$name</a></td>"
240             set e [$graph get_edge $n $mob]
241             append result "<td align=left bgcolor=#eeeeee>[$e cost]</td></tr>"
242         }
243         append result "</table>"
244         append result "</p>"
245     }
246 
247     if {[$mgr_ isdir $mob]} {
248         set content [exec ls $mob]
249 
250         # find a list of all keys
251         set keys ""
252         foreach c $content {
253             foreach {key value} [$mgr_ info $mob/$c] {
254                 lappend keys $key
255                 set values($c,$key) $value
256             }
257         }
258         set keys [lsort -unique $keys]
259 
260         # print the content of the directory.
261         if {$content != ""} {
262             append result "<h3>Content</h3>"
263             append result "<p>"
264             append result "<table class=content width=100% cellspacing=0 cellpadding=3>"
265             append result "\n<tr>"
266             append result "<td class=conthead><b>name</b></td>"
267             foreach key $keys {
268                 append result "<td class=conthead><b>$key</b></td>"
269             }
270             append result "<td class=conthead>&nbsp;</td>"
271             append result "</tr>\n"
272 
273             foreach c $content {
274                 set type [$mgr_ info $mob/$c -class]
275                 if {$type != ""} {
276                     $self instvar imgroot_
277                     set img "<img align=middle src=$imgroot_/$type.gif>&nbsp;&nbsp;"
278                 } else {
279                     set img ""
280                 }
281                 append result "<tr><td class=\"contvalue\" nobr><nobr>$img<a href=\"$c\">$c</a></nobr></td>"
282                 foreach key $keys {
283                     if [info exists values($c,$key)] {
284                         append result "<td class=\"contvalue\" nobr><nobr>$values($c,$key)</nobr></td>"
285                     } else {
286                         append result "<td class=\"contvalue\" nobr><b>&nbsp;</b></td>"
287                     }
288                 }
289                 append result "<td class=contvalue width=100%>&nbsp;</td>"
290                 append result "</tr>"
291             }
292             append result "</table>"
293             append result "</p>"
294         }
295     }
296 
297     append result "
298 
299             </body>
300         </html>"
301 
302     $self instvar h_
303     set result [$h_ html [$h_ head "<base href=http://$data(mime,host)$data(url)/>"] [$h_ body $result]]
304     return $result
305 }
306 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.