Skip to content

Commit

Permalink
Merge branch 'http_overhaul'
Browse files Browse the repository at this point in the history
  • Loading branch information
sconemad committed Jun 3, 2017
2 parents 1b3da64 + a340e41 commit c6e8abb
Show file tree
Hide file tree
Showing 59 changed files with 2,170 additions and 1,631 deletions.
3 changes: 1 addition & 2 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
37 changes: 12 additions & 25 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion http/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion http/ConnectionStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 27 additions & 22 deletions http/DirIndexStream.cpp → http/DirIndex.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}

Expand All @@ -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());
Expand All @@ -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\" "
Expand Down Expand Up @@ -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;

}
Expand Down
39 changes: 28 additions & 11 deletions http/DirIndexStream.h → http/DirIndex.h
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:

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

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

};

Expand Down
Loading

0 comments on commit c6e8abb

Please sign in to comment.