ESSENTIAL WWW SERVER
Essential WWW Server is an I/O completion port web server with support for dynamic content generation and HTTP basic authentication written in 2001 by Vito Plantamura.
INTRODUCTION
With years, I became progressively more obsessed with HTML interfaces and with the DOM object model in general in my programs. The code that I have packaged here in this Essential Web Server has been included in more than one project I have developed in the past. In those cases its primary purpose was to show and render the application user interface to the user, with the implicit and important advantage of location transparency over traditional user interfaces. Why not using IIS and ISAPI extensions in those cases? Simply because in my programs I was rendering HTML content on the screen for presenting to the user what was essentially a desktop interface in the context of a desktop application. I could NOT rely on the presence on the end-user computers of the Internet Information Services installed and on complex installation procedures for my software. In those cases I simply link the core code of the Web Server against the executable of my application and then fill the wwwroot of the server with the DLL extensions that generate dinamically the content. Those DLL Extensions may eventually talk with the application itself through a set of ordinary communication systems.
The source codes of the server are available only upon explicit request and only in special cases. I have omitted to provide the source codes of my Web Server here on my site for obvious security reasons: despite its slimness and size and despite the fact that I have tested it thoroughly, I would avoid to make public eventual flaws or bugs in its implementation (posing a risk of attack to all the applications that actually use it).
INSTALLATION
Unpack the zip archive that can be downloaded at the bottom of this page in a folder, locate the executable file with name "EssentialWs" and lauch it with the option "/register". This will register the service with the SCM on your computer. Then run from the console the command "services.msc": this will open the Services Snap-In of Windows; locate in the list the "Essential WWW Server" service and then start it.
Before starting the service you can specify the username and password pair enforced through HTTP Basic Authentication for accessing the root of the server. Simply edit the "basic.inf" file and write in it a single line with this format "username:password". Note that the Basic Authentication scheme is only enforced for requests that come from the local network (all the requests from the local computer, i.e. from the address 127.0.0.1, are granted access by default).
In the same manner, you can set the listening port of the server editing the "port.inf" file.
FEATURES
Here is a summary list of its capabilities:
|
Slim and optimized C++ implementation (the executable file of the service is only 76Kb in size) |
|
|
Thoroughly tested multi-threaded implementation. |
|
|
Support for static and dynamic content through the writing and publishing of Server Extensions. |
|
|
Support in the Server Extensions for all HTTP methods: GET, POST etc. |
|
|
Smart caching mechanism for both dynamic and static content. |
|
|
I/O completion port based winsock server listening by default at the TCP port 49274. |
|
|
Customizable listening port: in the release available from this page the port is set to 48001 through the "port.inf" file. |
|
|
"MZ signature check" on all the returned content: no user can get by mistake a Server Extension (that actually is a Windows PE Module) suitable for reverse engineering attacks. |
WRITING SERVER EXTENSIONS
WWW Server Extensions are similar in concept to the IIS Extensions in the Microsoft Server.
What you have to do for writing an Extension is simply summarized in this step-by-step list:
|
Create a DLL module with Visual Studio. |
|
|
Include the file "WebServerCommon.h", whose source is included below in this same page. |
|
|
Define an exported function with this prototype and name:
extern "C" __declspec(dllexport) size_t _cdecl ProcessHttpRequest(
UINT uiProtocolVersion,
SServerFunctions& ssf,
BYTE* pbRequest,
size_t sRequestLen,
BYTE* pbResponse,
size_t sResponseBufferLen,
unsignedlong ulLocalAddr,
unsignedlong ulRemoteAddr
);
|
|
|
Examine the request data available through the variables pbRequest/sRequestLen and write the HTTP response in the pbResponseBuffer, that is sResponseBufferLen bytes in size. Return the number of bytes written in the buffer as the return value of the export function itself. |
|
|
Compile, build and rename the dll with a ".dyn" extension. |
|
|
Copy the ".dyn" file in the wwwroot directory or in one of its subfolders in order to publish it through the WWW Server. |
That's all. For a very clarifying demonstration of the WWW Server potentialities in an end-user desktop application, download the WWW Server Extension "MsdnTreeXmlGen" example.
This is the source code of the "WebServerCommon.h" include file:
//
// WebServerCommon.h
//
#pragma once
//
// definitions
//
#define HTTPREQ_METHOD_MAXLEN 16
#define HTTPREQ_URI_MAXLEN 1024
#define HTTPREQ_PROTVERSION_MAXLEN 16
#define HTTPPROTOCOL_VERSION_UNK (-1)
#define HTTPPROTOCOL_VERSION_1_0 0
#define HTTPPROTOCOL_VERSION_1_1 1
//
// common structures and types used by the server and by the extensions
//
struct SResponseCharacteristics
{
UINT uiProtocolVersion;
UINT uiStatusCode;
BOOL bDate;
char* pszServer;
char* pszWwwAuthenticate;
char* pszContentType;
char* pszLastModified;
UINT uiContentLength;
BYTE* pbData;
};
typedef size_t (_cdecl *fnReturn_Response)(
SResponseCharacteristics& srchrs,
BYTE* pbResponse,
size_t sResponseBufferLen
);
typedef void (_cdecl *fnInitializeResponseCharacteristics)(
UINT uiProtocolVersion,
SResponseCharacteristics& srchrs
);
typedef size_t (_cdecl *fnReturn_Error)(
UINT uiProtocolVersion,
|