summaryrefslogtreecommitdiff
path: root/poco-httpd
diff options
context:
space:
mode:
Diffstat (limited to 'poco-httpd')
-rw-r--r--poco-httpd/Makefile221
-rw-r--r--poco-httpd/poco-httpd.cpp169
2 files changed, 0 insertions, 390 deletions
diff --git a/poco-httpd/Makefile b/poco-httpd/Makefile
deleted file mode 100644
index 9098836..0000000
--- a/poco-httpd/Makefile
+++ /dev/null
@@ -1,221 +0,0 @@
-# The pre-processor and compiler options.
-MY_CFLAGS =
-
-# The linker options.
-MY_LIBS = -lPocoNet -lPocoXML -lPocoUtil -lPocoFoundation
-
-# The pre-processor options used by the cpp (man cpp for more).
-CPPFLAGS = -Wall
-
-# The options used in linking as well as in any direct use of ld.
-LDFLAGS =
-
-# The directories in which source files reside.
-# If not specified, only the current directory will be serached.
-SRCDIRS =
-
-# The executable file name.
-# If not specified, current directory name or `a.out' will be used.
-PROGRAM =
-
-## Implicit Section: change the following only when necessary.
-##==========================================================================
-
-# The source file types (headers excluded).
-# .c indicates C source files, and others C++ ones.
-SRCEXTS = .c .C .cc .cpp .CPP .c++ .cxx .cp
-
-# The header file types.
-HDREXTS = .h .H .hh .hpp .HPP .h++ .hxx .hp
-
-# The pre-processor and compiler options.
-# Users can override those variables from the command line.
-CFLAGS = -g -O2
-CXXFLAGS= -g -O2
-
-# The C program compiler.
-#CC = gcc
-
-# The C++ program compiler.
-#CXX = g++
-
-# Un-comment the following line to compile C programs as C++ ones.
-#CC = $(CXX)
-
-# The command used to delete file.
-#RM = rm -f
-
-ETAGS = etags
-ETAGSFLAGS =
-
-CTAGS = ctags
-CTAGSFLAGS =
-
-## Stable Section: usually no need to be changed. But you can add more.
-##==========================================================================
-SHELL = /bin/sh
-EMPTY =
-SPACE = $(EMPTY) $(EMPTY)
-ifeq ($(PROGRAM),)
- CUR_PATH_NAMES = $(subst /,$(SPACE),$(subst $(SPACE),_,$(CURDIR)))
- PROGRAM = $(word $(words $(CUR_PATH_NAMES)),$(CUR_PATH_NAMES))
- ifeq ($(PROGRAM),)
- PROGRAM = a.out
- endif
-endif
-ifeq ($(SRCDIRS),)
- SRCDIRS = .
-endif
-SOURCES = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
-HEADERS = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(HDREXTS))))
-SRC_CXX = $(filter-out %.c,$(SOURCES))
-OBJS = $(addsuffix .o, $(basename $(SOURCES)))
-DEPS = $(OBJS:.o=.d)
-
-## Define some useful variables.
-DEP_OPT = $(shell if `$(CC) --version | grep "GCC" >/dev/null`; then \
- echo "-MM -MP"; else echo "-M"; fi )
-DEPEND = $(CC) $(DEP_OPT) $(MY_CFLAGS) $(CFLAGS) $(CPPFLAGS)
-DEPEND.d = $(subst -g ,,$(DEPEND))
-COMPILE.c = $(CC) $(MY_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c
-COMPILE.cxx = $(CXX) $(MY_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c
-LINK.c = $(CC) $(MY_CFLAGS) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
-LINK.cxx = $(CXX) $(MY_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)
-
-.PHONY: all objs tags ctags clean distclean help show
-
-# Delete the default suffixes
-.SUFFIXES:
-
-all: $(PROGRAM)
-
-# Rules for creating dependency files (.d).
-#------------------------------------------
-
-%.d:%.c
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.C
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.cc
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.cpp
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.CPP
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.c++
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.cp
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-%.d:%.cxx
- @echo -n $(dir $<) > $@
- @$(DEPEND.d) $< >> $@
-
-# Rules for generating object files (.o).
-#----------------------------------------
-objs:$(OBJS)
-
-%.o:%.c
- $(COMPILE.c) $< -o $@
-
-%.o:%.C
- $(COMPILE.cxx) $< -o $@
-
-%.o:%.cc
- $(COMPILE.cxx) $< -o $@
-
-%.o:%.cpp
- $(COMPILE.cxx) $< -o $@
-
-%.o:%.CPP
- $(COMPILE.cxx) $< -o $@
-
-%.o:%.c++
- $(COMPILE.cxx) $< -o $@
-
-%.o:%.cp
- $(COMPILE.cxx) $< -o $@
-
-%.o:%.cxx
- $(COMPILE.cxx) $< -o $@
-
-# Rules for generating the tags.
-#-------------------------------------
-tags: $(HEADERS) $(SOURCES)
- $(ETAGS) $(ETAGSFLAGS) $(HEADERS) $(SOURCES)
-
-ctags: $(HEADERS) $(SOURCES)
- $(CTAGS) $(CTAGSFLAGS) $(HEADERS) $(SOURCES)
-
-# Rules for generating the executable.
-#-------------------------------------
-$(PROGRAM):$(OBJS)
-ifeq ($(SRC_CXX),) # C program
- $(LINK.c) $(OBJS) $(MY_LIBS) -o $@
- @echo Type ./$@ to execute the program.
-else # C++ program
- $(LINK.cxx) $(OBJS) $(MY_LIBS) -o $@
- @echo Type ./$@ to execute the program.
-endif
-
-ifndef NODEP
-ifneq ($(DEPS),)
- sinclude $(DEPS)
-endif
-endif
-
-clean:
- $(RM) $(OBJS) $(PROGRAM) $(PROGRAM).exe
-
-distclean: clean
- $(RM) $(DEPS) TAGS
-
-# Show help.
-help:
- @echo 'Generic Makefile for C/C++ Programs (gcmakefile) version 0.5'
- @echo 'Copyright (C) 2007, 2008 whyglinux <whyglinux@hotmail.com>'
- @echo
- @echo 'Usage: make [TARGET]'
- @echo 'TARGETS:'
- @echo ' all (=make) compile and link.'
- @echo ' NODEP=yes make without generating dependencies.'
- @echo ' objs compile only (no linking).'
- @echo ' tags create tags for Emacs editor.'
- @echo ' ctags create ctags for VI editor.'
- @echo ' clean clean objects and the executable file.'
- @echo ' distclean clean objects, the executable and dependencies.'
- @echo ' show show variables (for debug use only).'
- @echo ' help print this message.'
- @echo
- @echo 'Report bugs to <whyglinux AT gmail DOT com>.'
-
-# Show variables (for debug use only.)
-show:
- @echo 'PROGRAM :' $(PROGRAM)
- @echo 'SRCDIRS :' $(SRCDIRS)
- @echo 'HEADERS :' $(HEADERS)
- @echo 'SOURCES :' $(SOURCES)
- @echo 'SRC_CXX :' $(SRC_CXX)
- @echo 'OBJS :' $(OBJS)
- @echo 'DEPS :' $(DEPS)
- @echo 'DEPEND :' $(DEPEND)
- @echo 'COMPILE.c :' $(COMPILE.c)
- @echo 'COMPILE.cxx :' $(COMPILE.cxx)
- @echo 'link.c :' $(LINK.c)
- @echo 'link.cxx :' $(LINK.cxx)
-
-## End of the Makefile ## Suggestions are welcome ## All rights reserved ##
-#############################################################################
diff --git a/poco-httpd/poco-httpd.cpp b/poco-httpd/poco-httpd.cpp
deleted file mode 100644
index 5ca33b6..0000000
--- a/poco-httpd/poco-httpd.cpp
+++ /dev/null
@@ -1,169 +0,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/Timestamp.h"
-#include "Poco/DateTimeFormatter.h"
-#include "Poco/DateTimeFormat.h"
-#include "Poco/Exception.h"
-#include "Poco/ThreadPool.h"
-#include "Poco/Util/ServerApplication.h"
-#include "Poco/Util/Option.h"
-#include "Poco/Util/OptionSet.h"
-#include "Poco/Util/HelpFormatter.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::Timestamp;
-using Poco::DateTimeFormatter;
-using Poco::DateTimeFormat;
-using Poco::ThreadPool;
-using Poco::Util::ServerApplication;
-using Poco::Util::Application;
-using Poco::Util::Option;
-using Poco::Util::OptionSet;
-using Poco::Util::OptionCallback;
-using Poco::Util::HelpFormatter;
-
-class TimeRequestHandler: public HTTPRequestHandler
-{
-public:
- TimeRequestHandler(const std::string& format): _format(format)
- {
- }
-
- void handleRequest(HTTPServerRequest& request,
- HTTPServerResponse& response)
- {
- Application& app = Application::instance();
- app.logger().information("Request from "
- + request.clientAddress().toString());
-
- Timestamp now;
- std::string dt(DateTimeFormatter::format(now, _format));
-
- response.setChunkedTransferEncoding(true);
- response.setContentType("text/html");
-
- std::ostream& ostr = response.send();
- ostr << "<html><head><title>HTTPTimeServer powered by "
- "POCO C++ Libraries</title>";
- ostr << "<meta http-equiv=\"refresh\" content=\"1\"></head>";
- ostr << "<body><p style=\"text-align: center; "
- "font-size: 48px;\">";
- ostr << dt;
- ostr << "</p></body></html>";
- }
-
-private:
- std::string _format;
-};
-
-class TimeRequestHandlerFactory: public HTTPRequestHandlerFactory
-{
-public:
- TimeRequestHandlerFactory(const std::string& format):
- _format(format)
- {
- }
-
- HTTPRequestHandler* createRequestHandler(
- const HTTPServerRequest& request)
- {
- if (request.getURI() == "/")
- return new TimeRequestHandler(_format);
- else
- return 0;
- }
-
-private:
- std::string _format;
-};
-
-class HTTPTimeServer: public Poco::Util::ServerApplication
-{
-public:
- HTTPTimeServer(): _helpRequested(false)
- {
- }
-
- ~HTTPTimeServer()
- {
- }
-
-protected:
- void initialize(Application& self)
- {
- loadConfiguration();
- ServerApplication::initialize(self);
- }
-
- void uninitialize()
- {
- ServerApplication::uninitialize();
- }
-
- void defineOptions(OptionSet& options)
- {
- ServerApplication::defineOptions(options);
-
- options.addOption(
- Option("help", "h", "display argument help information")
- .required(false)
- .repeatable(false)
- .callback(OptionCallback<HTTPTimeServer>(
- this, &HTTPTimeServer::handleHelp)));
- }
-
- void handleHelp(const std::string& name,
- const std::string& value)
- {
- 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);
- stopOptionsProcessing();
- _helpRequested = true;
- }
-
- int main(const std::vector<std::string>& args)
- {
- if (!_helpRequested)
- {
- unsigned short port = (unsigned short)
- config().getInt("HTTPTimeServer.port", 9980);
- std::string format(
- config().getString("HTTPTimeServer.format",
- DateTimeFormat::SORTABLE_FORMAT));
-
- ServerSocket svs(port);
- HTTPServer srv(new TimeRequestHandlerFactory(format),
- svs, new HTTPServerParams);
- srv.start();
- waitForTerminationRequest();
- srv.stop();
- }
- return Application::EXIT_OK;
- }
-
-private:
- bool _helpRequested;
-};
-
-int main(int argc, char** argv)
-{
- HTTPTimeServer app;
- return app.run(argc, argv);
-} \ No newline at end of file