From d5cc926ec6c3020d2d51cacc7d14e59c558c4167 Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Sun, 30 Jun 2024 14:48:13 +1000 Subject: beginning draftwork on modules --- configure.tcl | 18 +++++++++++++++--- html.tcl | 16 ++++++++++++++++ http.tcl | 8 ++++---- main.tcl | 8 -------- modules/template.tcl | 14 ++++++++++++++ tcl-httpd | 11 +++++++++++ 6 files changed, 60 insertions(+), 15 deletions(-) create mode 100755 html.tcl delete mode 100755 main.tcl create mode 100644 modules/template.tcl create mode 100755 tcl-httpd diff --git a/configure.tcl b/configure.tcl index 5691763..3c3a426 100755 --- a/configure.tcl +++ b/configure.tcl @@ -2,7 +2,7 @@ namespace eval http { # The directory which files are searched for. - variable root {/home/aleksei/www/files/} + 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. @@ -14,12 +14,24 @@ namespace eval http { {/fonts/} } } -} + namespace eval module { + #variable directory {} + source modules/template.tcl + } +} -## Import HTML Generating Modules ## 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 +} diff --git a/html.tcl b/html.tcl new file mode 100755 index 0000000..9a6a946 --- /dev/null +++ b/html.tcl @@ -0,0 +1,16 @@ + +namespace eval html { + + proc start {title} { + return "$title"; + } + + proc end {} { + return "" + } + + proc link {name link} { + return "$name" + } + +} diff --git a/http.tcl b/http.tcl index 307aebf..3995c80 100755 --- a/http.tcl +++ b/http.tcl @@ -1,5 +1,5 @@ # From configuration -# root Directory which files reside in. +# srv Directory which files reside in. namespace eval http { @@ -41,7 +41,7 @@ namespace eval http { proc server {channel address port} { variable hook_namespace; - variable root; + variable srv; ## (1) Handle first line puts "(1)" @@ -80,7 +80,7 @@ namespace eval http { ## (3) Find if the file exists, or there is a hooked application. # If file exists, then 200 OK! - set filename [string cat $root [request_target::file $request_target]] + set filename [string cat $srv [request_target::file $request_target]] if [expr [file exists $filename] && [file isfile $filename]] { respond $channel 200 $filename } elseif [expr [file exists [string cat $filename "index.html"]] && [file isfile [string cat $filename "index.html"]]] { @@ -121,7 +121,7 @@ namespace eval http { proc respond {channel status {optional {}}} { ## Import Variables - variable root; + variable srv; variable status_codes; variable hook_namespace; ## New Variables diff --git a/main.tcl b/main.tcl deleted file mode 100755 index bd24e69..0000000 --- a/main.tcl +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/tclsh - -source configure.tcl -source http.tcl - -socket -server http::server 8000 - -vwait forever diff --git a/modules/template.tcl b/modules/template.tcl new file mode 100644 index 0000000..b76c201 --- /dev/null +++ b/modules/template.tcl @@ -0,0 +1,14 @@ +namespace eval template { + + variable targets { + target1 target2 + } + + proc run {request_target} { + return [string cat \ + [http::start "Title"] \ + "This is a template
" \ + "request_target: $request_target" \ + [http::end]] + } +} diff --git a/tcl-httpd b/tcl-httpd new file mode 100755 index 0000000..ade8359 --- /dev/null +++ b/tcl-httpd @@ -0,0 +1,11 @@ +#!/bin/tclsh + +source configure.tcl + +source http.tcl + +source html.tcl + +socket -server http::server 8000 + +vwait forever -- cgit v1.2.3