mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2026-08-05 23:37:12 +02:00
Major plugin refactor and cleanup.
Switched to POCO library for unified platform/library interface. Deprecated the external module API. It was creating more problems than solving. Removed most built-in libraries in favor of system libraries for easier maintenance. Cleaned and secured code with help from static analyzers.
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
//
|
||||
// HTTPTimeServerApp.cpp
|
||||
//
|
||||
// This sample demonstrates the HTTPServer and related classes.
|
||||
//
|
||||
// Copyright (c) 2010, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Net/HTTPServer.h"
|
||||
#include "Poco/Net/HTTPRequestHandler.h"
|
||||
#include "Poco/Net/HTTPRequestHandlerFactory.h"
|
||||
#include "Poco/Net/HTTPServerParams.h"
|
||||
#include "Poco/Net/HTTPServerRequest.h"
|
||||
#include "Poco/Net/HTTPServerResponse.h"
|
||||
#include "Poco/Net/HTTPServerParams.h"
|
||||
#include "Poco/Net/ServerSocket.h"
|
||||
#include "Poco/Util/ServerApplication.h"
|
||||
#include "Poco/Util/Option.h"
|
||||
#include "Poco/Util/OptionSet.h"
|
||||
#include "Poco/Util/HelpFormatter.h"
|
||||
#include "TimeHandler.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using Poco::Net::ServerSocket;
|
||||
using Poco::Net::HTTPRequestHandler;
|
||||
using Poco::Net::HTTPRequestHandlerFactory;
|
||||
using Poco::Net::HTTPServer;
|
||||
using Poco::Net::HTTPServerRequest;
|
||||
using Poco::Net::HTTPServerResponse;
|
||||
using Poco::Net::HTTPServerParams;
|
||||
using Poco::Util::ServerApplication;
|
||||
using Poco::Util::Application;
|
||||
using Poco::Util::Option;
|
||||
using Poco::Util::OptionSet;
|
||||
using Poco::Util::HelpFormatter;
|
||||
|
||||
|
||||
class TimeRequestHandlerFactory: public HTTPRequestHandlerFactory
|
||||
{
|
||||
public:
|
||||
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
|
||||
{
|
||||
if (request.getURI() == "/")
|
||||
return new TimeHandler;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class HTTPTimeServerApp: public Poco::Util::ServerApplication
|
||||
/// The main application class.
|
||||
///
|
||||
/// This class handles command-line arguments and
|
||||
/// configuration files.
|
||||
/// Start the HTTPTimeServer executable with the help
|
||||
/// option (/help on Windows, --help on Unix) for
|
||||
/// the available command line options.
|
||||
///
|
||||
/// To use the sample configuration file (HTTPTimeServer.properties),
|
||||
/// copy the file to the directory where the HTTPTimeServer executable
|
||||
/// resides. If you start the debug version of the HTTPTimeServer
|
||||
/// (HTTPTimeServerd[.exe]), you must also create a copy of the configuration
|
||||
/// file named HTTPTimeServerd.properties. In the configuration file, you
|
||||
/// can specify the port on which the server is listening (default
|
||||
/// 9980) and the format of the date/time string sent back to the client.
|
||||
///
|
||||
/// To test the TimeServer you can use any web browser (http://localhost:9980/).
|
||||
{
|
||||
public:
|
||||
HTTPTimeServerApp(): _helpRequested(false)
|
||||
{
|
||||
}
|
||||
|
||||
~HTTPTimeServerApp()
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
void initialize(Application& self)
|
||||
{
|
||||
loadConfiguration(); // load default configuration files, if present
|
||||
ServerApplication::initialize(self);
|
||||
}
|
||||
|
||||
void uninitialize()
|
||||
{
|
||||
ServerApplication::uninitialize();
|
||||
}
|
||||
|
||||
void defineOptions(OptionSet& options)
|
||||
{
|
||||
ServerApplication::defineOptions(options);
|
||||
|
||||
options.addOption(
|
||||
Option("help", "h", "display help information on command line arguments")
|
||||
.required(false)
|
||||
.repeatable(false));
|
||||
}
|
||||
|
||||
void handleOption(const std::string& name, const std::string& value)
|
||||
{
|
||||
ServerApplication::handleOption(name, value);
|
||||
|
||||
if (name == "help")
|
||||
_helpRequested = true;
|
||||
}
|
||||
|
||||
void displayHelp()
|
||||
{
|
||||
HelpFormatter helpFormatter(options());
|
||||
helpFormatter.setCommand(commandName());
|
||||
helpFormatter.setUsage("OPTIONS");
|
||||
helpFormatter.setHeader("A web server that serves the current date and time.");
|
||||
helpFormatter.format(std::cout);
|
||||
}
|
||||
|
||||
int main(const std::vector<std::string>& args)
|
||||
{
|
||||
if (_helpRequested)
|
||||
{
|
||||
displayHelp();
|
||||
}
|
||||
else
|
||||
{
|
||||
// get parameters from configuration file
|
||||
unsigned short port = (unsigned short) config().getInt("HTTPTimeServer.port", 9980);
|
||||
|
||||
// set-up a server socket
|
||||
ServerSocket svs(port);
|
||||
// set-up a HTTPServer instance
|
||||
HTTPServer srv(new TimeRequestHandlerFactory, svs, new HTTPServerParams);
|
||||
// start the HTTPServer
|
||||
srv.start();
|
||||
// wait for CTRL-C or kill
|
||||
waitForTerminationRequest();
|
||||
// Stop the HTTPServer
|
||||
srv.stop();
|
||||
}
|
||||
return Application::EXIT_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
bool _helpRequested;
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
HTTPTimeServerApp app;
|
||||
return app.run(argc, argv);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// TimeHandler.cpp
|
||||
//
|
||||
// This file has been generated from TimeHandler.cpsp on 2016-05-08 21:03:48.
|
||||
//
|
||||
|
||||
|
||||
#include "TimeHandler.h"
|
||||
#include "Poco/Net/HTTPServerRequest.h"
|
||||
#include "Poco/Net/HTTPServerResponse.h"
|
||||
#include "Poco/Net/HTMLForm.h"
|
||||
|
||||
|
||||
#include "Poco/DateTime.h"
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
|
||||
|
||||
void TimeHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
|
||||
{
|
||||
response.setChunkedTransferEncoding(true);
|
||||
response.setContentType("text/html");
|
||||
|
||||
Poco::Net::HTMLForm form(request, request.stream());
|
||||
std::ostream& responseStream = response.send();
|
||||
responseStream << "";
|
||||
responseStream << "\n";
|
||||
responseStream << "";
|
||||
responseStream << "\n";
|
||||
responseStream << "\n";
|
||||
responseStream << "";
|
||||
#line 6 "Z:\\git\\poco-1.7.3\\PageCompiler\\samples\\HTTPTimeServer\\src\\TimeHandler.cpsp"
|
||||
|
||||
Poco::DateTime now;
|
||||
std::string dt(Poco::DateTimeFormatter::format(now, "%W, %e %b %y %H:%M:%S %Z"));
|
||||
responseStream << "\n";
|
||||
responseStream << "<html>\n";
|
||||
responseStream << "<head>\n";
|
||||
responseStream << "<title>HTTPTimeServer powered by POCO C++ Libraries and PageCompiler</title>\n";
|
||||
responseStream << "<meta http-equiv=\"refresh\" content=\"1\">\n";
|
||||
responseStream << "</head>\n";
|
||||
responseStream << "<body>\n";
|
||||
responseStream << "<p style=\"text-align: center; font-size: 48px;\">";
|
||||
#line 16 "Z:\\git\\poco-1.7.3\\PageCompiler\\samples\\HTTPTimeServer\\src\\TimeHandler.cpsp"
|
||||
responseStream << ( dt );
|
||||
responseStream << "</p>\n";
|
||||
responseStream << "</body>\n";
|
||||
responseStream << "</html>\n";
|
||||
responseStream << "";
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<%@ page class="TimeHandler" %>
|
||||
<%@ impl include="Poco/DateTime.h"
|
||||
include="Poco/DateTimeFormatter.h"
|
||||
%>
|
||||
|
||||
<%
|
||||
Poco::DateTime now;
|
||||
std::string dt(Poco::DateTimeFormatter::format(now, "%W, %e %b %y %H:%M:%S %Z"));
|
||||
%>
|
||||
<html>
|
||||
<head>
|
||||
<title>HTTPTimeServer powered by POCO C++ Libraries and PageCompiler</title>
|
||||
<meta http-equiv="refresh" content="1">
|
||||
</head>
|
||||
<body>
|
||||
<p style="text-align: center; font-size: 48px;"><%= dt %></p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// TimeHandler.h
|
||||
//
|
||||
// This file has been generated from TimeHandler.cpsp on 2016-05-08 21:03:48.
|
||||
//
|
||||
|
||||
|
||||
#ifndef TimeHandler_INCLUDED
|
||||
#define TimeHandler_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/HTTPRequestHandler.h"
|
||||
|
||||
|
||||
class TimeHandler: public Poco::Net::HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response);
|
||||
};
|
||||
|
||||
|
||||
#endif // TimeHandler_INCLUDED
|
||||
Reference in New Issue
Block a user