Permalink
Browse files

Merge branch 'http_overhaul'

  • Loading branch information...
sconemad committed Jun 3, 2017
2 parents 1b3da64 + a340e41 commit c6e8abb15b8d4a25abe77579dba03102f194a2f7
Showing with 2,170 additions and 1,631 deletions.
  1. +1 −2 config.h.in
  2. +12 −25 configure.in
  3. +1 −1 http/Client.cpp
  4. +1 −1 http/ConnectionStream.cpp
  5. +27 −22 http/{DirIndexStream.cpp → DirIndex.cpp}
  6. +28 −11 http/{DirIndexStream.h → DirIndex.h}
  7. +0 −544 http/DocRoot.cpp
  8. +0 −165 http/DocRoot.h
  9. +0 −224 http/ErrorPageStream.cpp
  10. +0 −56 http/ErrorPageStream.h
  11. +118 −0 http/GetFile.cpp
  12. +12 −18 http/{GetFileStream.h → GetFile.h}
  13. +0 −122 http/GetFileStream.cpp
  14. +26 −17 http/HTTPModule.cpp
  15. +7 −0 http/HTTPModule.h
  16. +109 −0 http/Handler.cpp
  17. +88 −0 http/Handler.h
  18. +389 −98 http/Host.cpp
  19. +61 −12 http/Host.h
  20. +12 −18 http/HostMapper.cpp
  21. +4 −3 http/HostMapper.h
  22. +10 −10 http/Makefile.am
  23. +59 −49 http/MessageStream.cpp
  24. +5 −2 http/MessageStream.h
  25. +0 −1 http/PartialResponseStream.h
  26. +8 −22 http/Request.cpp
  27. +2 −15 http/Request.h
  28. +6 −0 http/Status.cpp
  29. +3 −0 http/Status.h
  30. +438 −0 http/WebSocket.cpp
  31. +96 −0 http/WebSocket.h
  32. +2 −1 image/Makefile.am
  33. +1 −1 sconeserver.conf
  34. +2 −4 sconesite/Article.cpp
  35. +10 −20 sconesite/Profile.cpp
  36. +0 −1 sconesite/Profile.h
  37. +5 −5 sconesite/RenderMarkup.cpp
  38. +3 −3 sconesite/RenderMarkup.h
  39. +4 −15 sconesite/SconesiteModule.cpp
  40. +4 −3 sconesite/SconesiteModule.h
  41. +109 −54 sconesite/SconesiteStream.cpp
  42. +21 −3 sconesite/SconesiteStream.h
  43. +3 −2 sconesite/XMLDoc.cpp
  44. +39 −39 sconesite/test-site/art/article.xml
  45. +113 −0 sconesite/test-site/art/markdown/article.md
  46. +24 −8 sconesite/test-site/art/style/common.css
  47. +65 −0 sconesite/test-site/art/websocket/article.xml
  48. BIN sconesite/test-site/test.db
  49. +3 −2 sconesite/test-site/tpl/common.xml
  50. +4 −4 sconesite/tpl/account.xml
  51. +5 −3 sconesite/tpl/botdetect.xml
  52. +63 −16 sconesite/tpl/normal.xml
  53. +1 −0 sconesite/tpl/start.xml
  54. +66 −0 sconesite/tpl/wiki.xml
  55. +93 −0 sconesite/tpl/wiki_edit.xml
  56. +3 −2 sconex/ScriptEngine.cpp
  57. +0 −5 sconex/ScriptTypes_ut.cpp
  58. +2 −0 sconex/StreamTransfer.cpp
  59. +2 −2 server/ServerModule.h
@@ -257,8 +257,7 @@
slash. */
#undef LSTAT_FOLLOWS_SLASHED_SYMLINK

/* Define to the sub-directory in which libtool stores uninstalled libraries.
*/
/* Define to the sub-directory where libtool stores uninstalled libraries. */
#undef LT_OBJDIR

/* Name of package */
@@ -201,36 +201,23 @@ if test "x$SCONESITE" = "xyes"; then
fi
fi

# Check for ImageMagick
AC_ARG_WITH([Magick++-config],
[AC_HELP_STRING([--with-Magick++-config=PATH],[Set path to Magick++-config])],
[MAGICK_CONFIG="$withval"],
[MAGICK_CONFIG="Magick++-config"]
)
AC_CHECK_PROG([MAGICK], ["$MAGICK_CONFIG"], [yes], [no])
if test "x$MAGICK" = "xyes"; then
MAGICK_CFLAGS=`$MAGICK_CONFIG --cppflags`
MAGICK_LDFLAGS=`$MAGICK_CONFIG --ldflags`
MAGICK_LIBS=`$MAGICK_CONFIG --libs`
fi

# Image module
# Use if ImageMagick++ found
AC_ARG_WITH([image],
[AC_HELP_STRING([--with-image],[Enable image module])],
[IMAGE="$withval"],
[IMAGE="$MAGICK"]
[IMAGE="check"]
)

# Need ImageMagick for image
if test "x$IMAGE" = "xyes"; then
if test "x$MAGICK" != "xyes"; then
AC_MSG_ERROR([library 'Magick++' is required for image])
fi
CXXFLAGS="$CXXFLAGS $MAGICK_CFLAGS"
IMAGE_LDFLAGS=$MAGICK_LDFLAGS
AC_SUBST(IMAGE_LDFLAGS)
IMAGE_LDFLAGS=$MAGICK_LIBS
AC_SUBST(IMAGE_LIBS)
if test "x$IMAGE" = "xyes" -o "x$IMAGE" = "xcheck"; then
PKG_CHECK_MODULES(
[IMAGE], [ImageMagick++],
[IMAGE=yes],
[if test "x$IMAGE" = "xyes"; then
AC_MSG_FAILURE([$IMAGE_PKG_ERRORS])
else
AC_MSG_WARN([$IMAGE_PKG_ERRORS])
fi
IMAGE="no"])
fi

# rss module
@@ -37,7 +37,7 @@ Client::Client(HTTPModule* module,
const std::string& method,
const scx::Uri& url)
: m_module(module),
m_request(new Request("client","")),
m_request(new Request("")),
m_response(new Response()),
m_error(false)
{
@@ -154,7 +154,7 @@ scx::Condition ConnectionStream::process_input()
delete m_request;
std::ostringstream oss;
oss << m_num_connection << "-" << (m_num_request+1);
m_request = new Request(m_profile,oss.str());
m_request = new Request(oss.str());
if (m_request->parse_request(line,0!=find_stream("ssl"))) {
m_seq = http_Headers;
++m_num_request;
@@ -1,8 +1,8 @@
/* SconeServer (http://www.sconemad.com)
HTTP Directory index stream
HTTP Directory index
Copyright (c) 2000-2013 Andrew Wedgbury <wedge@sconemad.com>
Copyright (c) 2000-2016 Andrew Wedgbury <wedge@sconemad.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,28 +19,33 @@ along with this program (see the file COPYING); if not, write to the
Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */

#include <http/DirIndexStream.h>
#include <http/DirIndex.h>
#include <http/HTTPModule.h>
#include <http/Request.h>
#include <http/MessageStream.h>
#include <http/Status.h>
#include <http/DocRoot.h>

#include <sconex/FileDir.h>
namespace http {

//=========================================================================
scx::Condition DirIndexHandler::handle_message(MessageStream* message)
{
message->add_stream(new DirIndexStream(m_module.object(), message));
return scx::Ok;
}

//=========================================================================
scx::Condition DirIndexStream::send_response()
{
http::MessageStream* msg = GET_HTTP_MESSAGE();
const http::Request& req = msg->get_request();
const http::Request& req = m_message->get_request();
const scx::Uri& uri = req.get_uri();
const http::DocRoot* docroot = req.get_docroot();
const http::Host* host = req.get_host();

if (req.get_method() != "GET" &&
req.get_method() != "HEAD" ) {
// Don't understand the method
msg->get_response().set_status(http::Status::NotImplemented);
m_message->get_response().set_status(http::Status::NotImplemented);
return scx::Close;
}

@@ -49,7 +54,7 @@ scx::Condition DirIndexStream::send_response()

if (stat.is_dir()) {
const scx::ScriptRef* a_default_page =
docroot->get_param("default_page");
host->get_param("default_page");
std::string s_default_page = (BAD_SCRIPTREF(a_default_page) ?
"index.html" :
a_default_page->object()->get_string());
@@ -60,39 +65,39 @@ scx::Condition DirIndexStream::send_response()
if (scx::FileStat(path + s_default_page).exists()) {
// Redirect to default page
if (url[url.size()-1] != '/') url += "/";
msg->log("Redirect '" + url + "' to '" + url + s_default_page + "'");
m_message->log("Redirect '" + url + "' to '" + url + s_default_page + "'");
url += s_default_page;

msg->get_response().set_status(http::Status::Found);
msg->get_response().set_header("Content-Type","text/html");
msg->get_response().set_header("Location",url);
m_message->get_response().set_status(http::Status::Found);
m_message->get_response().set_header("Content-Type","text/html");
m_message->get_response().set_header("Location",url);
return scx::Close;
}

if (!uripath.empty() && uripath[uripath.size()-1] != '/') {
// Redirect to directory URL ending in '/'
scx::Uri new_uri = uri;
new_uri.set_path(uripath + "/");
msg->log("Redirect '" + uri.get_string() +
m_message->log("Redirect '" + uri.get_string() +
"' to '" + new_uri.get_string() + "'");

msg->get_response().set_status(http::Status::Found);
msg->get_response().set_header("Content-Type","text/html");
msg->get_response().set_header("Location",new_uri.get_string());
m_message->get_response().set_status(http::Status::Found);
m_message->get_response().set_header("Content-Type","text/html");
m_message->get_response().set_header("Location",new_uri.get_string());
return scx::Close;
}

const scx::ScriptRef* a_allow_list = docroot->get_param("allow_list");
const scx::ScriptRef* a_allow_list = host->get_param("allow_list");
bool allow_list = (a_allow_list ?
a_allow_list->object()->get_int() :
false);

if (allow_list) {
// Send directory listing if allowed
msg->log("Listing directory '" + url + "'");
m_message->log("Listing directory '" + url + "'");

msg->get_response().set_status(http::Status::Ok);
msg->get_response().set_header("Content-Type","text/html");
m_message->get_response().set_status(http::Status::Ok);
m_message->get_response().set_header("Content-Type","text/html");

if (req.get_method() == "GET") {
write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
@@ -124,7 +129,7 @@ scx::Condition DirIndexStream::send_response()
}

// Otherwise respond unauthorised
msg->get_response().set_status(http::Status::Unauthorized);
m_message->get_response().set_status(http::Status::Unauthorized);
return scx::Close;

}
@@ -1,8 +1,8 @@
/* SconeServer (http://www.sconemad.com)
HTTP Directory index stream
HTTP Directory index
Copyright (c) 2000-2013 Andrew Wedgbury <wedge@sconemad.com>
Copyright (c) 2000-2016 Andrew Wedgbury <wedge@sconemad.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -19,25 +19,41 @@ along with this program (see the file COPYING); if not, write to the
Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */

#ifndef httpDirIndexStream_h
#define httpDirIndexStream_h
#ifndef httpDirIndex_h
#define httpDirIndex_h

#include <http/ResponseStream.h>
#include <http/HTTPModule.h>
#include <sconex/Stream.h>
namespace http {

//=========================================================================
class DirIndexStream : public http::ResponseStream {
class HTTP_API DirIndexHandler : public Handler {
public:

DirIndexStream(
HTTPModule* module
) : http::ResponseStream("dirindex"),
m_module(module)
{ };
DirIndexHandler(HTTPModule* module)
: m_module(module) {}
virtual ~DirIndexHandler() {}

virtual scx::Condition handle_message(MessageStream* message);

private:

HTTPModule::Ref m_module;

};


//=========================================================================
class DirIndexStream : public http::ResponseStream {
public:

~DirIndexStream() { };
DirIndexStream(HTTPModule* module,
MessageStream* message)
: http::ResponseStream("dirindex"),
m_module(module),
m_message(message) {}
virtual ~DirIndexStream() {}

protected:

@@ -46,6 +62,7 @@ class DirIndexStream : public http::ResponseStream {
private:

scx::ScriptRefTo<HTTPModule> m_module;
MessageStream* m_message;

};

Oops, something went wrong.

0 comments on commit c6e8abb

Please sign in to comment.