2 files changed, 21 insertions(+), 39 deletions(-)
M app.d
M gopher.d
M app.d => app.d +15 -36
@@ 3,7 3,7 @@ module ardilla.mainapp;
private {
import std.conv : to;
import std.file : exists, isDir;
- import std.string : indexOf, startsWith;
+ import std.string : indexOf, startsWith, strip;
import ardilla.configuration;
import ardilla.gopher : GOPHER_REQUEST_TERMINATOR;
@@ 43,50 43,27 @@ class GopherServer : GenericSimpleServer!(GOPHER_BUFFER_SIZE, GOPHER_NUMBER_OF_C
{
ubyte[] response = GopherResponse.createError("Invalid request");
- /// create response for path
- auto createResponse(string path)
- {
- ubyte[] response;
-
- auto gophermap = path ~ "/" ~ GOPHER_MAP_FILENAME;
-
- if (gophermap.exists)
- {
- response = GopherResponse.fromMap(gophermap);
- }
- else
- {
- response = GopherResponse.fromFs(path, _host, _port.to!string);
- }
-
- return response;
- }
-
- debug
- {
- log("[Client] " ~ textify(request));
- }
-
if (request.length >= 1)
{
if (request == GOPHER_REQUEST_TERMINATOR)
{
debug {
- log("[Client] Menu request");
+ log("[Client] Menu request: " ~ textify(request));
}
- response = createResponse(_path);
+ response = GopherResponse.fromPath(_path, GOPHER_MAP_FILENAME, _host, _port.to!string);
}
else
{
- auto entry = cast(string) request[0..$-2];
+ auto entry = strip(cast(string) request);
auto tab = entry.indexOf("\t");
-
+
if (tab != -1)
{
response = GopherResponse.fromQuery(entry[tab+1..$], _path, GOPHER_DOMAIN, _port.to!string);
debug {
+ log("[Client] Query length: " ~ entry[tab+1..$].length.to!string);
log("[Client] Search for: " ~ entry);
}
}
@@ 100,7 77,7 @@ class GopherServer : GenericSimpleServer!(GOPHER_BUFFER_SIZE, GOPHER_NUMBER_OF_C
log("[Client] Directory request: " ~ entry);
}
- response = createResponse(entry);
+ response = GopherResponse.fromPath(entry, GOPHER_MAP_FILENAME, _host, _port.to!string);
}
else
{
@@ 113,6 90,11 @@ class GopherServer : GenericSimpleServer!(GOPHER_BUFFER_SIZE, GOPHER_NUMBER_OF_C
}
else
{
+ debug {
+ log("[Client] Request: " ~ textify(request));
+ error("[Server]: Wrong request: " ~ entry);
+ }
+
response = GopherResponse.createError("Wrong file or directory");
}
}
@@ 127,15 109,12 @@ class GopherServer : GenericSimpleServer!(GOPHER_BUFFER_SIZE, GOPHER_NUMBER_OF_C
void main()
{
auto gopher = new GopherServer(GOPHER_DOMAIN, GOPHER_FOLDER);
-
- debug {
- info("[Server] IP is " ~ GOPHER_IP);
- info("[Server] PATH is " ~ GOPHER_FOLDER);
- }
-
+
with (gopher)
{
debug {
+ info("[Server] IP is " ~ GOPHER_IP);
+ info("[Server] PATH is " ~ GOPHER_FOLDER);
info("[Server] Server configured.");
}
M gopher.d => gopher.d +6 -3
@@ 78,13 78,13 @@ auto createGopherContentType(string path)
switch (extension)
{
- case ".c", ".d", ".di", ".h", ".txt", ".sh":
+ case ".c", ".cfg", ".d", ".di", ".gmi", ".h", ".md", ".txt", ".sh":
type = GOPHER_CONTENT.TEXT_FILE;
break;
case ".uue":
type = GOPHER_CONTENT.UUE_FILE;
break;
- case ".bmp", ".jpg", ".jpeg", ".pgm", ".png", ".ppm", ".tiff":
+ case ".bmp", ".jpg", ".jpeg", ".qoi", ".pgm", ".png", ".ppm", ".tiff":
type = GOPHER_CONTENT.IMAGE_FILE;
break;
case ".gif":
@@ 93,6 93,9 @@ auto createGopherContentType(string path)
case ".gz", ".rar", ".tar.gz", ".zip":
type = GOPHER_CONTENT.DOS_FILE;
break;
+ case ".doc":
+ type = GOPHER_CONTENT.DOC_FILE;
+ break;
case ".html", ".htm":
type = GOPHER_CONTENT.HTML_FILE;
break;
@@ 102,4 105,4 @@ auto createGopherContentType(string path)
}
return type;
-}
+}<
\ No newline at end of file