diff options
Diffstat (limited to 'configure.tcl')
-rwxr-xr-x | configure.tcl | 92 |
1 files changed, 78 insertions, 14 deletions
diff --git a/configure.tcl b/configure.tcl index 3c3a426..76fd37e 100755 --- a/configure.tcl +++ b/configure.tcl @@ -3,35 +3,99 @@ namespace eval http { # The directory which files are searched for. variable srv {/home/aleksei/www/files/} - # hook_namespace refers to a user-created namespace. - # It must have some things such as - # A proc 'main' which is what the server will execute to get information. - # A list $targets which have all the valid targets. - variable hook_namespace {} - namespace eval cache { + namespace eval cache { variable precache { {/fonts/} } } namespace eval module { - #variable directory {} + variable targets {}; source modules/template.tcl } } - +proc temp {} { + # Run through and bring in all targets + foreach i [namespace children ::http::module] { + set ::http::module::targets [concat $::http::module::targets $i::targets] + # If there are duplicate elements, then error. + if [expr [llength [lsort -unique $::http::module::targets]] != [llength $::http::module::targets]] { + error "A duplicate target coming from $i." + } + } +} ## Validate configuration variables. ## Especially file exists content ## Especially validate the existence of necessary components in $content -proc validate {} { - # Two types of rules - # The VARIABLE=value - # For instance, SRV=/ and whatnot - # The @ACTION Etc - # For instance, @MODULE and @PRECACHE + +set config [open /etc/tcl-httpd.conf] + + +## Configure the server, whilst verifying options. + +namespace eval temp { + set error_state 0; + set error_message "Invalid lines:"; + set line_number 1; + + + namespace eval verify { + proc srv {s} { + + } + + proc module_path + } + + namespace eval actions { + proc @MODULE {v} { + if [info exists ::http::configure::module_path] { + set path [string cat $::http::configure::module_path $v ".tcl"] + if { [file exists $path] && [file isFile $path] } { + namespace eval [string cat "::http::module::" $v] { + source $path + } + } else { + error "Fatal Error: While trying to import module '$b', file $path' doesn't exist." + } + } else { + error "Fatal Error: Tried to import module '$b' without a module_path" + } + } + + proc @PRECACHE {a b} { + ::http::cache::add $b + } + } + + while {[gets $config line] != -1} { + if [regexp {^[[:lower:]_]+=[[:alnum:][:punct:]]+$} $line] { + set n [string first "=" $line] + set a [string range start [expr n-1]] + set b [string range [expr n+1] end] + # RUN VERIFICATION + namespace eval ::http::configure "variable $a $b" + } elseif [regexp {^@[[:upper:]]+ [[:alnum:][:punct:]]+$} $line] { + set n [string first " " $line] + set a [string range start [expr n-1]] + set b [string range [expr n+1] end] + # PERFORM ACTION + } else { + append error_message " $line_number" + set error_state 1; + } + incr line_number; + } + + if $error_state { + error "ERROR: There were multiple errors in your configuration.\n$error_message" + } } + +## Delete the namespace afterwards. +namespace delete temp; |