[Gd-chatter] r11701 - trunk/libraries/network/koala/sources/koala
cgay at gwydiondylan.org
cgay at gwydiondylan.org
Sun Feb 24 07:12:03 CET 2008
Author: cgay
Date: Sun Feb 24 07:12:01 2008
New Revision: 11701
Modified:
trunk/libraries/network/koala/sources/koala/config.dylan
trunk/libraries/network/koala/sources/koala/dsp.dylan
trunk/libraries/network/koala/sources/koala/library-unix.dylan
trunk/libraries/network/koala/sources/koala/library.dylan
trunk/libraries/network/koala/sources/koala/pages.dylan
trunk/libraries/network/koala/sources/koala/responders.dylan
trunk/libraries/network/koala/sources/koala/response.dylan
trunk/libraries/network/koala/sources/koala/server.dylan
trunk/libraries/network/koala/sources/koala/urls.dylan
trunk/libraries/network/koala/sources/koala/utils.dylan
Log:
job: koala
Fix some of the serious warnings in koala. Still three remaining for
calls to register-url that I don't know how to fix yet.
Some coding-style adjustments to match the rest of the library (i.e.,
no tabs and no trailing semi after values list).
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 Sun Feb 24 07:12:01 2008
@@ -285,7 +285,7 @@
log-info("VHost '%s': document root = %s.",
vhost-name(vhost), document-root(vhost));
else
- warn("Invalid <DOCUMENT-ROOT> spec."
+ warn("Invalid <DOCUMENT-ROOT> spec. "
"The 'location' attribute must be specified.");
end if;
end;
@@ -298,11 +298,11 @@
let vhost = active-vhost();
vhost.dsp-root := merge-locators(as(<directory-locator>, loc),
*server-root*);
- log-info("VHost '%s': document root = %s.",
- vhost-name(vhost), document-root(vhost));
+ log-info("VHost '%s': DSP root = %s.",
+ vhost-name(vhost), document-root(vhost));
else
- warn("Invalid <DSP-ROOT> spec."
- "The 'location' attribute must be specified.");
+ warn("Invalid <DSP-ROOT> spec. "
+ "The 'location' attribute must be specified.");
end if;
end;
end;
Modified: trunk/libraries/network/koala/sources/koala/dsp.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/dsp.dylan (original)
+++ trunk/libraries/network/koala/sources/koala/dsp.dylan Sun Feb 24 07:12:01 2008
@@ -722,10 +722,10 @@
end }
=> { define tag-aux #f ?tag ?taglib-spec
(?page, _do-body) (?tag-parameters)
- begin
- let ?=output = curry(format, current-response().output-stream);
+ begin
+ let ?=output = curry(format, current-response().output-stream);
?body; // semicolon is needed even when ?body ends in semicolon.
- end;
+ end;
_do-body(); // process the tag body
end
}
@@ -736,9 +736,9 @@
=> { define tag-aux #t ?tag ?taglib-spec
(?page, ?do-body) (?tag-parameters)
begin
- let ?=output = curry(format, current-response().output-stream);
- ?body;
- end;
+ let ?=output = curry(format, current-response().output-stream);
+ ?body;
+ end;
end
}
@@ -948,7 +948,6 @@
as(<string>, page.source-location));
end;
let source = document-location(url, context: page-directory(page));
- log-debug("source: %s", source);
let contents = source & file-contents(source);
if (contents)
let subtemplate = make(<dsp-template>,
Modified: trunk/libraries/network/koala/sources/koala/library-unix.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/library-unix.dylan (original)
+++ trunk/libraries/network/koala/sources/koala/library-unix.dylan Sun Feb 24 07:12:01 2008
@@ -39,7 +39,7 @@
define module utilities
use dylan;
use common-extensions,
- exclude: { format-to-string, split };
+ exclude: { format-to-string };
use dylan-extensions,
import: { element-no-bounds-check,
element-no-bounds-check-setter,
@@ -48,6 +48,7 @@
// make-symbol,
// case-insensitive-equal,
// case-insensitive-string-hash
+ <format-string-condition>
};
use file-system,
import: { with-open-file, <file-does-not-exist-error> };
@@ -156,6 +157,7 @@
responder-map,
add-responder,
remove-responder,
+ find-responder,
<request>,
*request*, // Holds the active request, per thread.
current-request, // Returns the active request of the thread.
@@ -314,8 +316,7 @@
define module dsp
use dylan;
- use common-extensions,
- exclude: { split };
+ use common-extensions;
use dylan-basics;
use koala,
export: all;
@@ -386,8 +387,7 @@
/*
// Persistence layer maps database records <-> web pages.
export
- note-field-error, // for errors related to processing a specific form field
- with-database-connection,
+ note-field-error, // for errors related to processing a specific form field with-database-connection,
<database-record>,
<modifiable-record>,
initialize-record,
@@ -432,7 +432,6 @@
use dylan;
use threads; // from dylan lib
use common-extensions,
- rename: { split => string-split },
exclude: { format-to-string };
use dylan-basics;
use simple-random;
Modified: trunk/libraries/network/koala/sources/koala/library.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/library.dylan (original)
+++ trunk/libraries/network/koala/sources/koala/library.dylan Sun Feb 24 07:12:01 2008
@@ -27,6 +27,7 @@
use base64;
use memory-manager;
use command-line-parser;
+ use uri;
use regular-expressions;
export koala;
@@ -156,6 +157,7 @@
responder-map,
add-responder,
remove-responder,
+ find-responder,
<request>,
*request*, // Holds the active request, per thread.
current-request, // Returns the active request of the thread.
@@ -312,55 +314,6 @@
create parse-header-value;
end;
-define module httpi // http internals
- use dylan;
- use threads; // from dylan lib
- use common-extensions,
- exclude: { format-to-string };
- use dylan-basics;
- use simple-random;
- use utilities,
- rename: { log-copious => %log-copious,
- log-verbose => %log-verbose,
- log-debug => %log-debug,
- log-info => %log-info,
- log-warning => %log-warning,
- log-error => %log-error };
- use koala;
- use koala-extender;
- use memory-manager;
- use locators,
- rename: { <http-server> => <http-server-url>,
- <ftp-server> => <ftp-server-url>,
- <file-server> => <file-server-url> };
- use dylan-extensions,
- import: { element-no-bounds-check,
- element-no-bounds-check-setter,
- element-range-check,
- element-range-error,
- // make-symbol,
- // case-insensitive-equal,
- // case-insensitive-string-hash
- };
- use format;
- use standard-io;
- use streams;
- use sockets,
- rename: { start-server => start-socket-server };
- use date; // from system lib
- use file-system; // from system lib
- use operating-system; // from system lib
- //use ssl-sockets;
- use xml-parser,
- prefix: "xml$";
- use xml-rpc-common;
- use win32-kernel,
- import: { LoadLibrary, FreeLibrary };
- use base64;
- use command-line-parser;
- use regular-expressions;
-end module httpi;
-
define module dsp
use dylan;
use common-extensions;
@@ -474,3 +427,53 @@
end module dsp;
+define module httpi // http internals
+ use dylan;
+ use threads; // from dylan lib
+ use common-extensions,
+ exclude: { format-to-string };
+ use dylan-basics;
+ use simple-random;
+ use utilities,
+ rename: { log-copious => %log-copious,
+ log-verbose => %log-verbose,
+ log-debug => %log-debug,
+ log-info => %log-info,
+ log-warning => %log-warning,
+ log-error => %log-error };
+ use koala;
+ use koala-extender;
+ use memory-manager;
+ use locators,
+ rename: { <http-server> => <http-server-url>,
+ <ftp-server> => <ftp-server-url>,
+ <file-server> => <file-server-url> };
+ use dylan-extensions,
+ import: { element-no-bounds-check,
+ element-no-bounds-check-setter,
+ element-range-check,
+ element-range-error,
+ // make-symbol,
+ // case-insensitive-equal,
+ // case-insensitive-string-hash
+ };
+ use format;
+ use standard-io;
+ use streams;
+ use sockets,
+ rename: { start-server => start-socket-server };
+ use date; // from system lib
+ use file-system; // from system lib
+ use operating-system; // from system lib
+ //use ssl-sockets;
+ use xml-parser,
+ prefix: "xml$";
+ use xml-rpc-common;
+ use base64;
+ use command-line-parser;
+ use uri;
+ use regular-expressions;
+
+ use dsp;
+end module httpi;
+
Modified: trunk/libraries/network/koala/sources/koala/pages.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/pages.dylan (original)
+++ trunk/libraries/network/koala/sources/koala/pages.dylan Sun Feb 24 07:12:01 2008
@@ -122,7 +122,7 @@
// Update the record with values from the page.
for (slot in slots)
field-name := slot-column-name(slot);
- field-value := get-form-value(field-name, as: slot-type(slot));
+ field-value := get-query-value(field-name, as: slot-type(slot));
if (field-value)
validate-record-field(page, record, slot, field-value);
let f = slot-setter(slot);
Modified: trunk/libraries/network/koala/sources/koala/responders.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/responders.dylan (original)
+++ trunk/libraries/network/koala/sources/koala/responders.dylan Sun Feb 24 07:12:01 2008
@@ -18,13 +18,13 @@
define method add-responder
(url :: <string>, responder :: <responder>, #key replace?)
- => ();
+ => ()
add-responder(parse-url(url), responder, replace?: replace?);
end;
define method add-responder
(url :: <url>, responder :: <responder>, #key replace?)
- => ();
+ => ()
local method responder-registration ()
if (empty?(url.uri-path))
error(make(<koala-api-error>,
@@ -50,14 +50,14 @@
define method find-responder
(url :: <string>)
=> (responder :: false-or(<responder>),
- rest-path :: false-or(<sequence>));
- find-responder(parse-url(url));
+ rest-path :: false-or(<sequence>))
+ find-responder(parse-url(url))
end method find-responder;
define method find-responder
(url :: <url>)
=> (responder :: false-or(<responder>),
- rest-path :: false-or(<sequence>));
+ rest-path :: false-or(<sequence>))
find-object(*server*.url-map, url.uri-path);
end method find-responder;
Modified: trunk/libraries/network/koala/sources/koala/response.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/response.dylan (original)
+++ trunk/libraries/network/koala/sources/koala/response.dylan Sun Feb 24 07:12:01 2008
@@ -190,8 +190,7 @@
// Send the body (or what there is of it so far).
write(stream, contents);
end unless;
- log-debug("Send response.");
-end;
+end method send-response;
// Exported
// Convenience. Seems common to want to add a numeric cookie value.
@@ -218,4 +217,5 @@
domain & format(s, "; Domain=%s", domain);
comment & format(s, "; Comment=\"%s\"", comment);
end);
-end;
+end method add-cookie;
+
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 Sun Feb 24 07:12:01 2008
@@ -627,16 +627,18 @@
// Read first line of the HTTP request. RFC 2068 Section 5.1
+define constant $request-line-regex :: <regex>
+ = compile-regex("^([!#$%&'\\*\\+-\\./0-9A-Z^_`a-z\\|~]+) "
+ "(\\S+) "
+ "(HTTP/\\d+\\.\\d+)");
define function read-request-first-line
(request :: <request>, buffer :: <string>)
=> ()
- let (match, http-method, url, http-version) =
- regex-search-strings("^([!#$%&'\\*\\+-\\./0-9A-Z^_`a-z\\|~]+) "
- "(\\S+) "
- "(HTTP/\\d+\\.\\d+)", buffer);
+ let (entire-match, http-method, url, http-version) =
+ regex-search-strings($request-line-regex, buffer);
log-debug("%= %= %=", http-method, url, http-version);
- if (match)
+ if (entire-match)
request.request-method := as(<symbol>, http-method);
let url = parse-url(url);
// See http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.2
@@ -1061,7 +1063,13 @@
*/
define inline function get-query-value
- (key :: <string>)
+ (key :: <string>, #key as: as-type :: false-or(<type>))
=> (value :: <object>)
- element(*request*.request-query-values, key, default: #f);
-end;
+ let val = element(*request*.request-query-values, key, default: #f);
+ if (as-type & val)
+ as(as-type, val)
+ else
+ val
+ end
+end function get-query-value;
+
Modified: trunk/libraries/network/koala/sources/koala/urls.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/urls.dylan (original)
+++ trunk/libraries/network/koala/sources/koala/urls.dylan Sun Feb 24 07:12:01 2008
@@ -6,7 +6,7 @@
Warranty: Distributed WITHOUT WARRANTY OF ANY KIND
-define inline function current-url () => (url :: <url>);
+define inline function current-url () => (url :: <url>)
*request*.request-url
end;
Modified: trunk/libraries/network/koala/sources/koala/utils.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/koala/utils.dylan (original)
+++ trunk/libraries/network/koala/sources/koala/utils.dylan Sun Feb 24 07:12:01 2008
@@ -31,15 +31,15 @@
define method expired?
(thing :: <expiring-mixin>)
- => (expired? :: <boolean>);
- thing.mod-time == #f | begin
+ => (expired? :: <boolean>)
+ thing.mod-time == #f
+ | begin
let now = current-date();
(now - thing.mod-time) < thing.duration
- end;
+ end
end method expired?;
-
define function file-contents
(filename :: <pathname>, #key error? :: <boolean>)
=> (contents :: false-or(<string>))
@@ -236,7 +236,7 @@
end for;
end;
object;
-end;
+end method remove-object;
// Find the object with the longest path, if any.
More information about the chatter
mailing list