[chatter] r11808 - trunk/libraries/network/koala/sources/koala
cgay at mccarthy.opendylan.org
cgay at mccarthy.opendylan.org
Mon May 12 09:57:14 CEST 2008
Author: cgay
Date: Mon May 12 09:57:11 2008
New Revision: 11808
Modified:
trunk/libraries/network/koala/sources/koala/config.dylan
trunk/libraries/network/koala/sources/koala/modules.dylan
trunk/libraries/network/koala/sources/koala/server.dylan
trunk/libraries/network/koala/sources/koala/variables.dylan
trunk/libraries/network/koala/sources/koala/vhost.dylan
Log:
job: koala
Moved *server-root* to server-root(<server>).
Modified: trunk/libraries/network/koala/sources/koala/config.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/config.dylan (original)
+++ trunk/libraries/network/koala/sources/koala/config.dylan Mon May 12 09:57:11 2008
@@ -53,7 +53,7 @@
let defaults
= merge-locators(merge-locators(as(<file-locator>, $koala-config-filename),
as(<directory-locator>, $koala-config-dir)),
- *server-root*);
+ server-root(*server*));
let config-loc
= as(<string>, merge-locators(as(<file-locator>, config-file | defaults),
defaults));
@@ -195,7 +195,7 @@
(node :: xml$<element>, name == #"virtual-host")
let name = get-attr(node, #"name");
if (name)
- let vhost = make(<virtual-host>, name: trim(name));
+ let vhost = make-virtual-host(*server*, name: trim(name));
add-virtual-host(name, vhost);
dynamic-bind (%vhost = vhost,
%dir = root-directory-spec(vhost))
@@ -254,12 +254,13 @@
define method process-config-element
(node :: xml$<element>, name == #"server-root")
// Note use of %vhost directly rather than active-vhost() here.
- // Don't want to blow out while setting *server-root* just because
+ // Don't want to blow out while setting server-root just because
// the config doesn't allow fallback to the default vhost.
if (%vhost == default-virtual-host(*server*))
let loc = get-attr(node, #"location");
if (loc)
- *server-root* := merge-locators(as(<directory-locator>, loc), *server-root*);
+ server-root(*server*)
+ := merge-locators(as(<directory-locator>, loc), server-root(*server*));
log-info("Server root set to %s", loc);
else
warn("Invalid <SERVER-ROOT> spec. "
@@ -279,7 +280,7 @@
if (loc)
let vhost = active-vhost();
document-root(vhost)
- := merge-locators(as(<directory-locator>, loc), *server-root*);
+ := merge-locators(as(<directory-locator>, loc), server-root(*server*));
log-info("VHost '%s': document root = %s.",
vhost-name(vhost), document-root(vhost));
else
@@ -295,7 +296,7 @@
if (loc)
let vhost = active-vhost();
vhost.dsp-root := merge-locators(as(<directory-locator>, loc),
- *server-root*);
+ server-root(*server*));
log-info("VHost '%s': DSP root = %s.",
vhost-name(vhost), dsp-root(vhost));
else
@@ -328,7 +329,7 @@
let log = iff(location,
make(<rolling-file-log-target>,
file: merge-locators(as(<file-locator>, location),
- *server-root*),
+ server-root(*server*)),
max-size: max-size | default-size),
make(<stream-log-target>,
stream: iff(string-equal?(type, "error"),
@@ -423,7 +424,7 @@
= as(<string>,
merge-locators(merge-locators(as(<file-locator>, filename),
as(<directory-locator>, $koala-config-dir)),
- *server-root*));
+ server-root(*server*)));
log-info("Loading mime-type map from %s", mime-type-loc);
let mime-text = file-contents(mime-type-loc);
Modified: trunk/libraries/network/koala/sources/koala/modules.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/modules.dylan (original)
+++ trunk/libraries/network/koala/sources/koala/modules.dylan Mon May 12 09:57:11 2008
@@ -12,7 +12,7 @@
=> (path :: <string>)
let module = as(<file-locator>,
format-to-string("%s/%s", $module-directory, module-name));
- as(<string>, merge-locators(module, *server-root*))
+ as(<string>, merge-locators(module, server-root(*server*)))
end function module-pathname;
define function load-module
Modified: trunk/libraries/network/koala/sources/koala/server.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/server.dylan (original)
+++ trunk/libraries/network/koala/sources/koala/server.dylan Mon May 12 09:57:11 2008
@@ -72,8 +72,15 @@
// Note that the document root may be changed when the config file is
// processed, so don't use it except during request processing.
//
- constant slot default-virtual-host :: <virtual-host>,
- required-init-keyword: default-virtual-host:;
+ slot default-virtual-host :: <virtual-host>,
+ init-keyword: default-virtual-host:;
+
+ // The top of the directory tree under which the server's configuration, error,
+ // and log files are kept. Other pathnames are merged against this one, so if
+ // they're relative they will be relative to this. The server-root pathname is
+ // relative to the koala executable, unless changed in the config file.
+ slot server-root :: <directory-locator>
+ = parent-directory(locator-directory(as(<file-locator>, application-filename())));
end class <server>;
@@ -92,32 +99,33 @@
let lock = make(<recursive-lock>);
let listeners-notification = make(<notification>, lock: lock);
let clients-notification = make(<notification>, lock: lock);
- let stdout-log = make(<stream-log-target>, stream: *standard-output*);
- let vhost = make(<virtual-host>,
- name: "default",
- activity-log: stdout-log,
- debug-log: stdout-log,
- error-log: make(<stream-log-target>, stream: *standard-error*));
apply(next-method, class,
lock: lock,
listeners: listeners,
listeners-notification: listeners-notification,
clients-notification: clients-notification,
- default-virtual-host: vhost,
keys)
end method make;
-// API
+// API (in the sense that its args are passed directly by the user)
define method initialize
(server :: <http-server>,
#rest keys,
#key document-root: doc-root)
apply(next-method, server, remove-keys(keys, #"document-root"));
- let vhost :: <virtual-host> = default-virtual-host(server);
+ let stdout-log = make(<stream-log-target>, stream: *standard-output*);
+ let stderr-log = make(<stream-log-target>, stream: *standard-error*);
+ default-virtual-host(server)
+ := make-virtual-host(server,
+ name: "default",
+ activity-log: stdout-log,
+ debug-log: stdout-log,
+ error-log: stderr-log);
if (doc-root)
- document-root(vhost) := as(<directory-locator>, doc-root);
+ document-root(default-virtual-host(server))
+ := as(<directory-locator>, doc-root);
end;
-end;
+end method initialize;
// Keep some stats on user-agents
define method note-user-agent
@@ -271,7 +279,7 @@
configure-server(config-file);
end;
ensure-sockets-started(); // TODO: Can this be moved into start-server?
- log-info("Server root directory is %s", *server-root*);
+ log-info("Server root directory is %s", server-root(server));
run-init-functions();
end init-server;
@@ -604,6 +612,25 @@
define thread variable *request* :: false-or(<request>) = #f;
+// Making a virtual hosts requires an instantiated server to do some
+// initialization, so use this instead of calling make(<virtual-host>).
+//
+define method make-virtual-host
+ (server :: <server>,
+ #rest args, #key name, document-root, dsp-root, #all-keys)
+ => (vhost :: <virtual-host>)
+ let vhost :: <virtual-host>
+ = apply(make, <virtual-host>,
+ document-root:
+ document-root | subdirectory-locator(server.server-root, name),
+ dsp-root:
+ dsp-root | subdirectory-locator(server.server-root, name),
+ args);
+ // Add a spec that matches all urls.
+ add-directory-spec(vhost, root-directory-spec(vhost));
+ vhost
+end;
+
define method virtual-host
(request :: <request>) => (vhost :: false-or(<virtual-host>))
let host-spec = request-host(request);
Modified: trunk/libraries/network/koala/sources/koala/variables.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/variables.dylan (original)
+++ trunk/libraries/network/koala/sources/koala/variables.dylan Mon May 12 09:57:11 2008
@@ -7,15 +7,6 @@
Warranty: Distributed WITHOUT WARRANTY OF ANY KIND
-// The top of the directory tree under which the server's configuration, error,
-// and log files are kept. Other pathnames are merged against this one, so if
-// they're relative they will be relative to this. The server-root pathname is
-// relative to the koala executable, unless changed in the config file.
-// (Moving this into the <server> class causes initialization ordering problems
-// with <virtual-host>...deal with it later.)
-define variable *server-root* :: <directory-locator>
- = parent-directory(locator-directory(as(<file-locator>, application-filename())));
-
// TODO: The follow 3 should probably be per vhost.
define variable *mime-type-map* :: <table> = make(<table>);
Modified: trunk/libraries/network/koala/sources/koala/vhost.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/vhost.dylan (original)
+++ trunk/libraries/network/koala/sources/koala/vhost.dylan Mon May 12 09:57:11 2008
@@ -157,16 +157,6 @@
generate-server-header?-setter;
end;
-define method initialize
- (vhost :: <virtual-host>, #key name, #all-keys)
- next-method();
- // This may be overridden by a <document-root> spec in the config file.
- vhost.document-root := subdirectory-locator(*server-root*, name);
- vhost.dsp-root := subdirectory-locator(*server-root*, name);
- // Add a spec that matches all urls.
- add-directory-spec(vhost, root-directory-spec(vhost));
-end;
-
define method activity-log-target
(vhost :: <virtual-host>) => (target :: <log-target>)
vhost.%activity-log-target
More information about the chatter
mailing list