Version 1 of Wikit write patch

Updated 2003-10-28 22:09:07

My Michael Heca simple patch for enable writing in Wikit embeded httpd server:

 diff -Naur wikit.vfs.original/lib/app-wikit/start.tcl wikit.vfs/lib/app-wikit/start.tcl
 --- wikit.vfs.original/lib/app-wikit/start.tcl        2003-06-06 00:43:50.000000000 +0200
 +++ wikit.vfs/lib/app-wikit/start.tcl        2003-10-28 22:41:31.000000000 +0100
 @@ -162,7 +162,7 @@
        package require Web
        package require wikithttpd
        #warning, POST not supported! read-only!
 -      set roflag 1
 +      #set roflag 1

        #set ::httpd::debug 1
        eval [mk::get wdb.pages!9 page]
 diff -Naur wikit.vfs.original/lib/httpd/wikithttpd.tcl wikit.vfs/lib/httpd/wikithttpd.tcl
 --- wikit.vfs.original/lib/httpd/wikithttpd.tcl        2003-06-06 00:43:50.000000000 +0200
 +++ wikit.vfs/lib/httpd/wikithttpd.tcl        2003-10-28 22:43:18.000000000 +0100
 @@ -67,16 +67,19 @@
              }
              data {
                  append server($channel.data) [read $channel]
 -                if { $server($channel.contentLenght) > -1 } {
 +                if { $server($channel.contentLength) > -1 } {
                      if {[string length $server($channel.data)] >= \
 -                            $server($channel.contentLenght) } {
 +                            $server($channel.contentLength) } {
                          processRequestData $channel
                      }
                  } else {
 +                    httpReturn $channel 501 text/plain "501 Unknown content length"
 +                    close $channel
 +                    cleanupChannel $channel
                      #seeing as we don't know how many bytes to expect 
                      #we must, alas, process every time...
                      #note that this code is untested...
 -                    processRequestData $channel
 +                    #processRequestData $channel
                  }
              }
          }
 @@ -107,7 +110,7 @@

          if { [info exists server($channel.ch.Content-Length)] && \
                   [string is integer $server($channel.ch.Content-Length)]} {
 -            set server(contentLength) $server($channel.ch.Content-Length)
 +            set server($channel.contentLength) $server($channel.ch.Content-Length)
          }

          log  "\[[lindex [fconfigure $channel -peername] 0]\]" "$method $uri"
 @@ -117,6 +120,9 @@
              "GET" {
                  runWikit $channel
              }
 +            "POST" {
 +                set server($channel.position) data
 +            }
              default {
                  httpReturn $channel 501 text/plain "501 Method not supported\nSorry wikit-httpd only supports GET"
                  close $channel
 @@ -214,6 +220,9 @@
          set ::env(SERVER_SOFTWARE) $serverSoftware
          set ::env(PATH_INFO) $server($channel.uri)
          set ::env(PATH_TRANSLATED) [file join $documentRoot $server($channel.uri)]
 +        if { $server($channel.contentLength) != -1 } {
 +            set ::env(CONTENT_LENGTH) $server($channel.contentLength)
 +        }

          rename ::puts ::real_puts
          rename ::httpd::capture_puts ::puts
 @@ -239,11 +248,6 @@

      }

 -    proc processRequestData { channel } {
 -        variable server
 -
 -    }
 -
      proc httpReturn { channel code type data } {
          variable serverSoftware

 @@ -323,9 +327,9 @@

      proc log { type text } {
          variable debug
 -        variable server                    
 -        $server(puts) "[httpTime]: $type $text"
 -    }
 +        variable server
 +            $server(puts) "[httpTime]: $type $text"
 +        }



 @@ -337,8 +341,8 @@
          #arguments, reading stdin: [read stdin length]
          #or some other fd: [read fd]

 -        if { [llength $args] == 3 } {
 -            return $server(cgidata)
 +        if { [llength $args] == 2 && [lindex $args 0] == "stdin" } {
 +            return $::httpd::server(cgidata)
          } else {
              eval real_read $args
          }
 diff -Naur wikit.vfs.original/lib/wikit/web.tcl wikit.vfs/lib/wikit/web.tcl
 --- wikit.vfs.original/lib/wikit/web.tcl        2003-10-15 02:35:41.000000000 +0200
 +++ wikit.vfs/lib/wikit/web.tcl        2003-10-28 19:53:02.000000000 +0100
 @@ -102,6 +102,13 @@

    set ::script_name $::env(SCRIPT_NAME)

 +  # fix embedded wikithttpd server script name
 +  if { [string first "WikitHttpd" $env(SERVER_SOFTWARE)] > -1 } {
 +      if { $::script_name == "/" } {
 +          set ::script_name ""
 +      }
 +  }
 +
    # this code added 1-5-2001 to handle ErrorDocument redirection/caching
    if {[info exists ::env(REDIRECT_URL)]} {