blob: 76fd37e12bec4bce3c32d90959a2a4e911928bd3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
## Set your variables here.
namespace eval http {
# The directory which files are searched for.
variable srv {/home/aleksei/www/files/}
namespace eval cache {
variable precache {
{/fonts/}
}
}
namespace eval module {
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
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;
|