From 3c487c5cd69c53d6fea948643c0a76df03516605 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 1 Apr 2022 21:23:39 +0200 Subject: Moved Stars45 to StarsEx --- Stars45/NetFileServlet.cpp | 117 --------------------------------------------- 1 file changed, 117 deletions(-) delete mode 100644 Stars45/NetFileServlet.cpp (limited to 'Stars45/NetFileServlet.cpp') diff --git a/Stars45/NetFileServlet.cpp b/Stars45/NetFileServlet.cpp deleted file mode 100644 index 6b23d9d..0000000 --- a/Stars45/NetFileServlet.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* Starshatter: The Open Source Project - Copyright (c) 2021-2022, Starshatter: The Open Source Project Contributors - Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors - Copyright (c) 1997-2006, Destroyer Studios LLC. - - AUTHOR: John DiCamillo - - - OVERVIEW - ======== - HTTP Servlet for File Transfer -*/ - - -#include "NetFileServlet.h" -#include "NetAdminServer.h" -#include "NetLayer.h" - -#include "DataLoader.h" - -// +-------------------------------------------------------------------+ - -bool -NetFileServlet::DoGet(HttpRequest& request, HttpResponse& response) -{ - if (!CheckUser(request, response)) - return true; - - Text content; - Text path = request.GetParam("path"); - Text name = request.GetParam("name"); - - if (name.length()) { - BYTE* buffer = 0; - DataLoader* loader = DataLoader::GetLoader(); - - if (loader) { - loader->SetDataPath(path); - int len = loader->LoadBuffer(name, buffer); - - if (len) { - content = Text((const char*) buffer, len); - } - - loader->ReleaseBuffer(buffer); - loader->SetDataPath(0); - } - } - - response.SetStatus(HttpResponse::SC_OK); - response.AddHeader("MIME-Version", "1.0"); - response.AddHeader("Cache-Control", "no-cache"); - response.AddHeader("Expires", "-1"); - response.AddHeader("Content-Type", "text/plain"); - response.SetContent(content); - - return true; -} - -// +-------------------------------------------------------------------+ - -bool -NetWebServlet::DoGet(HttpRequest& request, HttpResponse& response) -{ - Text content; - Text name = request.URI(); - bool found = false; - - if (name.length() > 4) { - char filename[256]; - strcpy_s(filename, name.data() + 1); // skip leading '/' - - FILE* f; - ::fopen_s(&f, filename, "rb"); - - if (f) { - ::fseek(f, 0, SEEK_END); - int len = ftell(f); - ::fseek(f, 0, SEEK_SET); - - BYTE* buf = new BYTE[len]; - - ::fread(buf, len, 1, f); - ::fclose(f); - - content = Text((const char*) buf, len); - delete [] buf; - - found = true; - ::Print("weblog: 200 OK %s %d bytes\n", name.data(), len); - } - else { - ::Print("weblog: 404 Not Found %s\n", name.data()); - } - } - - if (found) { - Text content_type = "text/plain"; - - if (name.contains(".gif")) - content_type = "image/gif"; - else if (name.contains(".jpg")) - content_type = "image/jpeg"; - else if (name.contains(".htm")) - content_type = "text/html"; - - response.SetStatus(HttpResponse::SC_OK); - response.AddHeader("MIME-Version", "1.0"); - response.AddHeader("Content-Type", content_type); - response.SetContent(content); - } - else { - response.SetStatus(HttpResponse::SC_NOT_FOUND); - } - - return true; -} -- cgit v1.1