diff -rup fatrat-1.2.0_beta2/CMakeLists.txt fatrat-1.2.0_beta2.new/CMakeLists.txt
--- fatrat-1.2.0_beta2/CMakeLists.txt 2012-07-14 12:44:27.000000000 +0100
+++ fatrat-1.2.0_beta2.new/CMakeLists.txt 2013-04-29 19:17:48.697623940 +0100
@@ -148,19 +148,13 @@ if(WITH_DOCUMENTATION)
set(QT_USE_QTHELP TRUE)
endif(WITH_DOCUMENTATION)
if(WITH_WEBINTERFACE)
- pkg_check_modules(pion-net REQUIRED "pion-net >= 3.0.0")
+ pkg_check_modules(pion REQUIRED "pion >= 5.0.0")
- if(pion-net_FOUND)
- include_directories(${pion-net_INCLUDE_DIRS})
- #message(STATUS "Pion libdir: ${pion-net_LIBDIR}")
-
- #FILE(GLOB pion_FileService "${pion-net_LIBDIR}/pion/plugins/FileService.*")
- #if(pion_FileService MATCHES "^$")
- # message(FATAL_ERROR "Pion-net FileService plugin not found (libpion-net-plugins?) - ${pion_FileService}")
- #endif(pion_FileService MATCHES "^$")
- else(pion-net_FOUND)
- message(FATAL_ERROR "No pion-net library found")
- endif(pion-net_FOUND)
+ if(pion_FOUND)
+ include_directories(${pion_INCLUDE_DIRS})
+ else(pion_FOUND)
+ message(FATAL_ERROR "No pion library found")
+ endif(pion_FOUND)
endif(WITH_WEBINTERFACE)
#set(CMAKE_REQUIRED_INCLUDES "sys/types.h")
@@ -570,9 +564,7 @@ ${fatrat_QRC_H} ${lrelease_outputs})
add_executable(fatrat-conf src/fatrat-conf.cpp)
# This used to be a workaround until it started causing the exact opposite... oh dear!
-#STRING(REPLACE "-mt" "" pion-net_LIBRARIES "${pion-net_LIBRARIES}")
-#message(STATUS ${pion-net_LIBRARIES})
-target_link_libraries(fatrat -ldl -lpthread ${QT_LIBRARIES} ${libtorrent_LDFLAGS} ${gloox_LDFLAGS} ${curl_LDFLAGS} ${Boost_LIBRARIES} ${pion-net_LIBRARIES} ${QT_ADDITIONAL_LIBS} ${XATTR_LIBRARIES} -export-dynamic)
+target_link_libraries(fatrat -ldl -lpthread ${QT_LIBRARIES} ${libtorrent_LDFLAGS} ${gloox_LDFLAGS} ${curl_LDFLAGS} ${Boost_LIBRARIES} ${pion_LIBRARIES} ${QT_ADDITIONAL_LIBS} ${XATTR_LIBRARIES} -export-dynamic)
target_link_libraries(fatrat-conf ${QT_LIBRARIES})
set(fatrat_DEV_HEADERS
Only in fatrat-1.2.0_beta2.new/: CMakeLists.txt.orig
diff -rup fatrat-1.2.0_beta2/config.h.in fatrat-1.2.0_beta2.new/config.h.in
--- fatrat-1.2.0_beta2/config.h.in 2012-07-14 12:44:27.000000000 +0100
+++ fatrat-1.2.0_beta2.new/config.h.in 2013-04-29 19:18:03.241412755 +0100
@@ -13,7 +13,7 @@
#cmakedefine WITH_CXX0X
#ifdef WITH_WEBINTERFACE
-# define PION_NET_PLUGINS "${pion-net_LIBDIR}/pion/plugins"
+# define PION_NET_PLUGINS "${pion_LIBDIR}/pion/plugins"
#endif
#cmakedefine ENABLE_FAKEDOWNLOAD
diff -rup fatrat-1.2.0_beta2/src/remote/HttpService.cpp fatrat-1.2.0_beta2.new/src/remote/HttpService.cpp
--- fatrat-1.2.0_beta2/src/remote/HttpService.cpp 2012-07-14 12:44:27.000000000 +0100
+++ fatrat-1.2.0_beta2.new/src/remote/HttpService.cpp 2013-04-29 19:17:17.076634049 +0100
@@ -51,9 +51,8 @@ respects for all of the code used other
#include
#include
#include
-#include
-#include
-#include
+#include
+#include
#include
#include "pion/FileService.hpp"
#include
@@ -63,7 +62,7 @@ respects for all of the code used other
#include
#include
-using namespace pion::net;
+using namespace pion::http;
extern QList g_queues;
extern QReadWriteLock g_queuesLock;
@@ -172,16 +171,16 @@ void HttpService::applySettings()
void HttpService::setupAuth()
{
- pion::net::PionUserManagerPtr userManager(new pion::net::PionUserManager);
+ pion::user_manager_ptr userManager(new pion::user_manager);
QString password = getSettingsValue("remote/password").toString();
- m_auth_ptr = pion::net::HTTPAuthPtr( new pion::net::HTTPBasicAuth(userManager, "FatRat Web Interface") );
- m_server->setAuthentication(m_auth_ptr);
- m_auth_ptr->addRestrict("/");
-
- m_auth_ptr->addUser("fatrat", password.toStdString());
- m_auth_ptr->addUser("admin", password.toStdString());
- m_auth_ptr->addUser("user", password.toStdString());
+ m_auth_ptr = pion::http::auth_ptr( new pion::http::basic_auth(userManager, "FatRat Web Interface") );
+ m_server->set_authentication(m_auth_ptr);
+ m_auth_ptr->add_restrict("/");
+
+ m_auth_ptr->add_user("fatrat", password.toStdString());
+ m_auth_ptr->add_user("admin", password.toStdString());
+ m_auth_ptr->add_user("user", password.toStdString());
}
void HttpService::setup()
@@ -190,28 +189,30 @@ void HttpService::setup()
try
{
- m_server = new pion::net::WebServer(m_port);
+ m_server = new pion::http::plugin_server(m_port);
setupAuth();
setupSSL();
- m_server->addService("/xmlrpc", new XmlRpcService);
- m_server->addService("/subclass", new SubclassService);
- m_server->addService("/log", new LogService);
- m_server->addService("/browse", new TransferTreeBrowserService);
- m_server->addService("/", new pion::plugins::FileService);
- m_server->setServiceOption("/", "directory", DATA_LOCATION "/data/remote");
- m_server->setServiceOption("/", "file", DATA_LOCATION "/data/remote/index.html");
- m_server->addService("/copyrights", new pion::plugins::FileService);
- m_server->setServiceOption("/copyrights", "file", DATA_LOCATION "/README");
- m_server->addService("/download", new TransferDownloadService);
- m_server->addService("/captcha", new CaptchaService);
+ m_server->add_service("/xmlrpc", new XmlRpcService);
+ m_server->add_service("/subclass", new SubclassService);
+ m_server->add_service("/log", new LogService);
+ m_server->add_service("/browse", new TransferTreeBrowserService);
+ m_server->add_service("/", new pion::plugins::FileService);
+ m_server->set_service_option("/", "directory", DATA_LOCATION "/data/remote");
+ m_server->set_service_option("/", "file", DATA_LOCATION "/data/remote/index.html");
+ m_server->add_service("/copyrights", new pion::plugins::FileService);
+ m_server->set_service_option("/copyrights", "file", DATA_LOCATION "/README");
+ m_server->add_service("/download", new TransferDownloadService);
+ m_server->add_service("/captcha", new CaptchaService);
m_server->start();
Logger::global()->enterLogMessage("HttpService", tr("Listening on port %1").arg(m_port));
+ std::cout << "Listening on port " << m_port << std::endl;
}
catch(const std::exception& e)
{
+ std::cerr << e.what() << std::endl;
Logger::global()->enterLogMessage("HttpService", tr("Failed to start: %1").arg(e.what()));
}
}
@@ -225,29 +226,29 @@ void HttpService::setupSSL()
if (file.isEmpty() || !QFile::exists(file))
{
Logger::global()->enterLogMessage("HttpService", tr("SSL key file not found, disabling HTTPS"));
- m_server->setSSLFlag(false);
+ m_server->set_ssl_flag(false);
m_strSSLPem.clear();
}
else
{
Logger::global()->enterLogMessage("HttpService", tr("Loading a SSL key from %1").arg(file));
m_strSSLPem = file;
- m_server->setSSLKeyFile(file.toStdString());
- m_server->setSSLFlag(true);
+ m_server->set_ssl_key_file(file.toStdString());
+ m_server->set_ssl_flag(true);
}
}
else
{
Logger::global()->enterLogMessage("HttpService", tr("Running in plain HTTP mode"));
- m_server->setSSLFlag(false);
+ m_server->set_ssl_flag(false);
m_strSSLPem.clear();
}
}
-void HttpService::LogService::operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn)
+void HttpService::LogService::operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn)
{
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn)));
- QString uuidTransfer = QString::fromStdString(getRelativeResource(request->getResource()));
+ pion::http::response_writer_ptr writer(pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn)));
+ QString uuidTransfer = QString::fromStdString(get_relative_resource(request->get_resource()));
QString data;
if (uuidTransfer.isEmpty())
@@ -260,8 +261,8 @@ void HttpService::LogService::operator()
if (!q || !t)
{
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_NOT_FOUND);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_NOT_FOUND);
writer->send();
return;
}
@@ -272,16 +273,16 @@ void HttpService::LogService::operator()
g_queuesLock.unlock();
}
- writer->getResponse().addHeader("Content-Type", "text/plain");
+ writer->get_response().add_header("Content-Type", "text/plain");
writer->write(data.toStdString());
writer->send();
}
-void HttpService::TransferTreeBrowserService::operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn)
+void HttpService::TransferTreeBrowserService::operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn)
{
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn)));
- QString uuidTransfer = QString::fromStdString(getRelativeResource(request->getResource()));
- QString path = QString::fromStdString(request->getQuery("path"));
+ pion::http::response_writer_ptr writer(pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn)));
+ QString uuidTransfer = QString::fromStdString(get_relative_resource(request->get_resource()));
+ QString path = QString::fromStdString(request->get_query("path"));
path = path.replace("+", " ");
path = QUrl::fromPercentEncoding(path.toUtf8());
@@ -294,8 +295,8 @@ void HttpService::TransferTreeBrowserSer
if (path.contains("/..") || path.contains("../"))
{
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_FORBIDDEN);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_FORBIDDEN);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_FORBIDDEN);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_FORBIDDEN);
writer->send();
return;
}
@@ -304,8 +305,8 @@ void HttpService::TransferTreeBrowserSer
if (!q || !t)
{
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_NOT_FOUND);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_NOT_FOUND);
writer->send();
return;
}
@@ -320,8 +321,8 @@ void HttpService::TransferTreeBrowserSer
if (!dir.cd(path))
{
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_NOT_FOUND);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_NOT_FOUND);
writer->send();
return;
}
@@ -371,11 +372,11 @@ void HttpService::TransferTreeBrowserSer
writer->send();
}
-void HttpService::TransferDownloadService::operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn)
+void HttpService::TransferDownloadService::operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn)
{
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn)));
- QString transfer = QString::fromStdString(request->getQuery("transfer"));
- QString path = QString::fromStdString(request->getQuery("path"));
+ pion::http::response_writer_ptr writer(pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn)));
+ QString transfer = QString::fromStdString(request->get_query("transfer"));
+ QString path = QString::fromStdString(request->get_query("path"));
path = path.replace("+", " ");
path = QUrl::fromPercentEncoding(path.toUtf8());
@@ -387,8 +388,8 @@ void HttpService::TransferDownloadServic
if (path.contains("/..") || path.contains("../"))
{
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_FORBIDDEN);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_FORBIDDEN);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_FORBIDDEN);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_FORBIDDEN);
writer->send();
return;
}
@@ -397,8 +398,8 @@ void HttpService::TransferDownloadServic
if (!q || !t)
{
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_NOT_FOUND);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_NOT_FOUND);
writer->send();
return;
}
@@ -428,24 +429,24 @@ void HttpService::TransferDownloadServic
response_file.update();
pion::plugins::DiskFileSenderPtr sender_ptr(pion::plugins::DiskFileSender::create(response_file, request, tcp_conn, 8192));
- sender_ptr->getWriter()->getResponse().addHeader("Content-Disposition", disposition.toStdString());
+ sender_ptr->getWriter()->get_response().add_header("Content-Disposition", disposition.toStdString());
if (unsigned long long fileSize = response_file.getFileSize())
{
std::stringstream fileSizeStream;
fileSizeStream << fileSize;
- sender_ptr->getWriter()->getResponse().addHeader("Content-Length", fileSizeStream.str());
+ sender_ptr->getWriter()->get_response().add_header("Content-Length", fileSizeStream.str());
}
sender_ptr->send();
}
-void HttpService::SubclassService::operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn)
+void HttpService::SubclassService::operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn)
{
- pion::net::HTTPResponseWriterPtr writer = HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn));
+ pion::http::response_writer_ptr writer = pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn));
HttpService::WriteBackImpl wb = HttpService::WriteBackImpl(writer);
- QString transfer = QString::fromStdString(request->getQuery("transfer"));
- QString method = QString::fromStdString(getRelativeResource(request->getResource()));
+ QString transfer = QString::fromStdString(request->get_query("transfer"));
+ QString method = QString::fromStdString(get_relative_resource(request->get_resource()));
Queue* q = 0;
Transfer* t = 0;
@@ -460,15 +461,15 @@ void HttpService::SubclassService::opera
g_queuesLock.unlock();
}
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
+ writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_NOT_FOUND);
+ writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_NOT_FOUND);
writer->send();
return;
}
QMultiMap map;
- pion::net::HTTPTypes::QueryParams params = request->getQueryParams();
- for (pion::net::HTTPTypes::QueryParams::iterator it = params.begin(); it != params.end(); it++)
+ pion::ihash_multimap params = request->get_queries();
+ for (pion::ihash_multimap::iterator it = params.begin(); it != params.end(); it++)
{
map.insert(QString::fromStdString(it->first), QString::fromStdString(it->second));
}
@@ -481,7 +482,7 @@ void HttpService::SubclassService::opera
g_queuesLock.unlock();
}
-HttpService::WriteBackImpl::WriteBackImpl(pion::net::HTTPResponseWriterPtr& writer)
+HttpService::WriteBackImpl::WriteBackImpl(pion::http::response_writer_ptr& writer)
: m_writer(writer)
{
@@ -489,7 +490,7 @@ HttpService::WriteBackImpl::WriteBackImp
void HttpService::WriteBackImpl::writeNoCopy(void* data, size_t bytes)
{
- m_writer->writeNoCopy(data, bytes);
+ m_writer->write_no_copy(data, bytes);
}
void HttpService::WriteBackImpl::send()
@@ -504,13 +505,13 @@ void HttpService::WriteBackImpl::write(c
void HttpService::WriteBackImpl::setContentType(const char* type)
{
- m_writer->getResponse().addHeader("Content-Type", type);
+ m_writer->get_response().add_header("Content-Type", type);
}
void HttpService::WriteBackImpl::writeFail(QString error)
{
- m_writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_FOUND);
- m_writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND);
+ m_writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_NOT_FOUND);
+ m_writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_NOT_FOUND);
}
int HttpService::findTransfer(QString transferUUID, Queue** q, Transfer** t, bool lockForWrite)
@@ -601,9 +602,9 @@ QVariant HttpService::generateCertificat
/*
-void HttpService::CaptchaService::operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn)
+void HttpService::CaptchaService::operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn)
{
- m_cap.writer = HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn));
+ m_cap.writer = pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn));
std::string upgrade, connection;
upgrade = request->getHeader("Upgrade");
@@ -616,8 +617,8 @@ void HttpService::CaptchaService::operat
if (connection != "upgrade" || upgrade != "websocket" || m_cap.key1.empty() || m_cap.key2.empty())
{
- m_cap.writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_BAD_REQUEST);
- m_cap.writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_BAD_REQUEST);
+ m_cap.writer->get_response().set_status_code(pion::http::types::RESPONSE_CODE_BAD_REQUEST);
+ m_cap.writer->get_response().set_status_message(pion::http::types::RESPONSE_MESSAGE_BAD_REQUEST);
m_cap.writer->send();
}
@@ -668,30 +669,30 @@ void HttpService::CaptchaService::CapSer
*/
-void HttpService::CaptchaHttpResponseWriter::handleWrite(const boost::system::error_code &write_error, std::size_t bytes_written)
+void HttpService::CaptchaHttpResponseWriter::handle_write(const boost::system::error_code &write_error, std::size_t bytes_written)
{
if (!bytes_written)
{
// TODO: handle errors
HttpService::instance()->removeCaptchaClient(client);
- sendFinalChunk();
+ send_final_chunk();
delete client;
}
- pion::net::HTTPResponseWriter::handleWrite(write_error, bytes_written);
+ pion::http::response_writer::handle_write(write_error, bytes_written);
}
-void HttpService::CaptchaService::operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn)
+void HttpService::CaptchaService::operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn)
{
- if (request->hasQuery("id"))
+ if (request->has_query("id"))
{
- QString id = QString::fromStdString(request->getQuery("id"));
- QString solution = QString::fromStdString(request->getQuery("solution"));
+ QString id = QString::fromStdString(request->get_query("id"));
+ QString solution = QString::fromStdString(request->get_query("solution"));
int iid = id.toInt();
HttpService::instance()->m_captchaHttp.captchaEntered(iid, solution);
- pion::net::HTTPResponseWriterPtr writer = HTTPResponseWriter::create(tcp_conn, *request, boost::bind(&TCPConnection::finish, tcp_conn));
+ pion::http::response_writer_ptr writer = pion::http::response_writer::create(tcp_conn, *request, boost::bind(&pion::tcp::connection::finish, tcp_conn));
writer->send();
}
else
@@ -709,13 +710,13 @@ void HttpService::CaptchaService::operat
RegisteredClient* client = new RegisteredClient;
client->writer = CaptchaHttpResponseWriter::create(client, tcp_conn, *request,
- boost::bind(&TCPConnection::finish, tcp_conn));
+ boost::bind(&pion::tcp::connection::finish, tcp_conn));
HttpService::instance()->addCaptchaClient(client);
- client->writer->getResponse().addHeader("Content-Type", "text/event-stream");
- client->writer->getResponse().addHeader("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
- client->writer->getResponse().addHeader("Expires", "Tue, 03 Jul 2001 06:00:00 GMT");
- client->writer->getResponse().addHeader("Pragma", "no-cache");
+ client->writer->get_response().add_header("Content-Type", "text/event-stream");
+ client->writer->get_response().add_header("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
+ client->writer->get_response().add_header("Expires", "Tue, 03 Jul 2001 06:00:00 GMT");
+ client->writer->get_response().add_header("Pragma", "no-cache");
}
}
@@ -747,7 +748,7 @@ void HttpService::RegisteredClient::push
writer->clear();
writer->write(buf.data(), buf.length());
- writer->sendChunk(boost::bind(&HttpService::RegisteredClient::finished, this));
+ writer->send_chunk(boost::bind(&HttpService::RegisteredClient::finished, this));
}
else
writeInProgressLock.unlock();
@@ -760,7 +761,7 @@ void HttpService::RegisteredClient::keep
writer->clear();
writer->write(": keepalive\r\n\r\n");
- writer->sendChunk(boost::bind(&HttpService::RegisteredClient::finished, this));
+ writer->send_chunk(boost::bind(&HttpService::RegisteredClient::finished, this));
}
void HttpService::addCaptchaEvent(int id, QString url)
@@ -803,5 +804,5 @@ void HttpService::keepalive()
void HttpService::RegisteredClient::terminate()
{
- writer->getTCPConnection()->finish();
+ writer->get_connection()->finish();
}
diff -rup fatrat-1.2.0_beta2/src/remote/HttpService.h fatrat-1.2.0_beta2.new/src/remote/HttpService.h
--- fatrat-1.2.0_beta2/src/remote/HttpService.h 2012-07-14 12:44:27.000000000 +0100
+++ fatrat-1.2.0_beta2.new/src/remote/HttpService.h 2013-04-29 19:17:17.076634049 +0100
@@ -40,7 +40,8 @@ respects for all of the code used other
#include
#include
#include
-#include
+#include
+#include
#include "captcha/CaptchaHttp.h"
#include "remote/TransferHttpService.h"
@@ -48,7 +49,8 @@ respects for all of the code used other
# error This file is not supposed to be included!
#endif
-#include
+#include
+#include
class Queue;
class Transfer;
@@ -83,8 +85,8 @@ private:
void killCaptchaClients();
private:
static HttpService* m_instance;
- pion::net::WebServer* m_server;
- pion::net::HTTPAuthPtr m_auth_ptr;
+ pion::http::plugin_server* m_server;
+ pion::http::auth_ptr m_auth_ptr;
CaptchaHttp m_captchaHttp;
quint16 m_port;
QString m_strSSLPem;
@@ -94,27 +96,27 @@ private:
QList m_registeredCaptchaClients;
QMutex m_registeredCaptchaClientsMutex;
- class LogService : public pion::net::WebService
+ class LogService : public pion::http::plugin_service
{
- void operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn);
+ void operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn);
};
- class TransferTreeBrowserService : public pion::net::WebService
+ class TransferTreeBrowserService : public pion::http::plugin_service
{
- void operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn);
+ void operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn);
};
- class TransferDownloadService : public pion::net::WebService
+ class TransferDownloadService : public pion::http::plugin_service
{
- void operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn);
+ void operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn);
};
- class SubclassService : public pion::net::WebService
+ class SubclassService : public pion::http::plugin_service
{
public:
- void operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn);
+ void operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn);
};
- /*class CaptchaService : public pion::net::WebService
+ /*class CaptchaService : public pion::http::plugin_service
{
public:
- void operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn);
+ void operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn);
private:
class CapServCap
{
@@ -126,15 +128,15 @@ private:
std::string key1, key2;
char sig[8];
int inbuf;
- pion::net::TCPConnectionPtr tcp_conn;
+ pion::tcp::connection_ptr tcp_conn;
} m_cap;
};*/
class CaptchaHttpResponseWriter;
- class CaptchaService : public pion::net::WebService
+ class CaptchaService : public pion::http::plugin_service
{
public:
- void operator()(pion::net::HTTPRequestPtr &request, pion::net::TCPConnectionPtr &tcp_conn);
+ void operator()(pion::http::request_ptr &request, pion::tcp::connection_ptr &tcp_conn);
};
struct RegisteredClient
{
@@ -151,16 +153,16 @@ private:
void terminate();
};
- class CaptchaHttpResponseWriter : public pion::net::HTTPResponseWriter
+ class CaptchaHttpResponseWriter : public pion::http::response_writer
{
public:
- CaptchaHttpResponseWriter(HttpService::RegisteredClient* cl, pion::net::TCPConnectionPtr &tcp_conn, const pion::net::HTTPRequest& request, FinishedHandler handler = FinishedHandler())
- : pion::net::HTTPResponseWriter(tcp_conn, request, handler), client(cl)
+ CaptchaHttpResponseWriter(HttpService::RegisteredClient* cl, pion::tcp::connection_ptr &tcp_conn, const pion::http::request& request, finished_handler_t handler = finished_handler_t())
+ : pion::http::response_writer(tcp_conn, request, handler), client(cl)
{
}
- static inline boost::shared_ptr create(HttpService::RegisteredClient* cl, pion::net::TCPConnectionPtr &tcp_conn, const pion::net::HTTPRequest& request, FinishedHandler handler = FinishedHandler())
+ static inline boost::shared_ptr create(HttpService::RegisteredClient* cl, pion::tcp::connection_ptr &tcp_conn, const pion::http::request& request, finished_handler_t handler = finished_handler_t())
{
return boost::shared_ptr(new CaptchaHttpResponseWriter(cl, tcp_conn, request, handler));
}
@@ -171,7 +173,7 @@ private:
m_http_response->prepareBuffersForSend(write_buffers, getTCPConnection()->getKeepAlive(),
sendingChunkedMessage());
}*/
- virtual void handleWrite(const boost::system::error_code &write_error, std::size_t bytes_written);
+ virtual void handle_write(const boost::system::error_code &write_error, std::size_t bytes_written);
HttpService::RegisteredClient* client;
};
@@ -179,14 +181,14 @@ private:
class WriteBackImpl : public TransferHttpService::WriteBack
{
public:
- WriteBackImpl(pion::net::HTTPResponseWriterPtr& writer);
+ WriteBackImpl(pion::http::response_writer_ptr& writer);
void write(const char* data, size_t bytes);
void writeFail(QString error);
void writeNoCopy(void* data, size_t bytes);
void send();
void setContentType(const char* type);
private:
- pion::net::HTTPResponseWriterPtr m_writer;
+ pion::http::response_writer_ptr m_writer;
};
};
diff -rup fatrat-1.2.0_beta2/src/remote/pion/FileService.cpp fatrat-1.2.0_beta2.new/src/remote/pion/FileService.cpp
--- fatrat-1.2.0_beta2/src/remote/pion/FileService.cpp 2012-07-14 12:44:27.000000000 +0100
+++ fatrat-1.2.0_beta2.new/src/remote/pion/FileService.cpp 2013-04-29 19:17:17.079967487 +0100
@@ -15,13 +15,14 @@
#include
#include "FileService.hpp"
-#include
-#include
+#include
+#include
#include
#include
using namespace pion;
-using namespace pion::net;
+using namespace pion::http;
+using namespace pion::tcp;
namespace pion { // begin namespace pion
namespace plugins { // begin namespace plugins
@@ -49,7 +50,7 @@ FileService::FileService(void)
m_writable(false)
{}
-void FileService::setOption(const std::string& name, const std::string& value)
+void FileService::set_option(const std::string& name, const std::string& value)
{
if (name == "directory") {
m_directory = value;
@@ -104,10 +105,10 @@ void FileService::setOption(const std::s
}
}
-void FileService::operator()(HTTPRequestPtr& request, TCPConnectionPtr& tcp_conn)
+void FileService::operator()(request_ptr& request, connection_ptr& tcp_conn)
{
// get the relative resource path for the request
- const std::string relative_path(getRelativeResource(request->getResource()));
+ const std::string relative_path(get_relative_resource(request->get_resource()));
// determine the path of the file being requested
boost::filesystem::path file_path;
@@ -117,7 +118,7 @@ void FileService::operator()(HTTPRequest
if (m_file.empty()) {
// no file is specified, either in the request or in the options
PION_LOG_WARN(m_logger, "No file option defined ("
- << getResource() << ")");
+ << get_resource() << ")");
sendNotFoundResponse(request, tcp_conn);
return;
} else {
@@ -129,7 +130,7 @@ void FileService::operator()(HTTPRequest
if (m_directory.empty()) {
// no directory is specified for the relative file
PION_LOG_WARN(m_logger, "No directory option defined ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
sendNotFoundResponse(request, tcp_conn);
return;
} else {
@@ -142,7 +143,7 @@ void FileService::operator()(HTTPRequest
std::string string = file_path.string();
if (string.find(m_directory.string()) != 0) {
PION_LOG_WARN(m_logger, "Request for file outside of directory ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
static const std::string FORBIDDEN_HTML_START =
"\n"
"403 Forbidden\n"
@@ -152,14 +153,14 @@ void FileService::operator()(HTTPRequest
static const std::string FORBIDDEN_HTML_FINISH =
" is not in the configured directory.
\n"
"\n";
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request,
- boost::bind(&TCPConnection::finish, tcp_conn)));
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_FORBIDDEN);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_FORBIDDEN);
- if (request->getMethod() != HTTPTypes::REQUEST_METHOD_HEAD) {
- writer->writeNoCopy(FORBIDDEN_HTML_START);
- writer << request->getResource();
- writer->writeNoCopy(FORBIDDEN_HTML_FINISH);
+ response_writer_ptr writer(response_writer::create(tcp_conn, *request,
+ boost::bind(&connection::finish, tcp_conn)));
+ writer->get_response().set_status_code(types::RESPONSE_CODE_FORBIDDEN);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_FORBIDDEN);
+ if (request->get_method() != types::REQUEST_METHOD_HEAD) {
+ writer->write_no_copy(FORBIDDEN_HTML_START);
+ writer << request->get_resource();
+ writer->write_no_copy(FORBIDDEN_HTML_FINISH);
}
writer->send();
return;
@@ -168,7 +169,7 @@ void FileService::operator()(HTTPRequest
// requests specifying directories are not allowed
if (boost::filesystem::is_directory(file_path)) {
PION_LOG_WARN(m_logger, "Request for directory ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
static const std::string FORBIDDEN_HTML_START =
"\n"
"403 Forbidden\n"
@@ -178,21 +179,21 @@ void FileService::operator()(HTTPRequest
static const std::string FORBIDDEN_HTML_FINISH =
" is a directory.\n"
"\n";
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request,
- boost::bind(&TCPConnection::finish, tcp_conn)));
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_FORBIDDEN);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_FORBIDDEN);
- if (request->getMethod() != HTTPTypes::REQUEST_METHOD_HEAD) {
- writer->writeNoCopy(FORBIDDEN_HTML_START);
- writer << request->getResource();
- writer->writeNoCopy(FORBIDDEN_HTML_FINISH);
+ response_writer_ptr writer(response_writer::create(tcp_conn, *request,
+ boost::bind(&connection::finish, tcp_conn)));
+ writer->get_response().set_status_code(types::RESPONSE_CODE_FORBIDDEN);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_FORBIDDEN);
+ if (request->get_method() != types::REQUEST_METHOD_HEAD) {
+ writer->write_no_copy(FORBIDDEN_HTML_START);
+ writer << request->get_resource();
+ writer->write_no_copy(FORBIDDEN_HTML_FINISH);
}
writer->send();
return;
}
- if (request->getMethod() == HTTPTypes::REQUEST_METHOD_GET
- || request->getMethod() == HTTPTypes::REQUEST_METHOD_HEAD)
+ if (request->get_method() == types::REQUEST_METHOD_GET
+ || request->get_method() == types::REQUEST_METHOD_HEAD)
{
// the type of response we will send
enum ResponseType {
@@ -207,7 +208,7 @@ void FileService::operator()(HTTPRequest
DiskFile response_file;
// get the If-Modified-Since request header
- const std::string if_modified_since(request->getHeader(HTTPTypes::HEADER_IF_MODIFIED_SINCE));
+ const std::string if_modified_since(request->get_header(types::HEADER_IF_MODIFIED_SINCE));
// check the cache for a corresponding entry (if enabled)
// note that m_cache_setting may equal 0 if m_scan_setting == 1
@@ -225,18 +226,18 @@ void FileService::operator()(HTTPRequest
// all requests must correspond with existing cache entries
// since no match was found, just return file not found
PION_LOG_WARN(m_logger, "Request for unknown file ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
response_type = RESPONSE_NOT_FOUND;
} else {
PION_LOG_DEBUG(m_logger, "No cache entry for request ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
}
} else {
// found an existing cache entry
PION_LOG_DEBUG(m_logger, "Found cache entry for request ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
if (m_cache_setting == 0) {
// cache is disabled
@@ -253,12 +254,12 @@ void FileService::operator()(HTTPRequest
// no need to read the file; the modified times match!
response_type = RESPONSE_NOT_MODIFIED;
} else {
- if (request->getMethod() == HTTPTypes::REQUEST_METHOD_HEAD) {
+ if (request->get_method() == types::REQUEST_METHOD_HEAD) {
response_type = RESPONSE_HEAD_OK;
} else {
response_type = RESPONSE_OK;
PION_LOG_DEBUG(m_logger, "Cache disabled, reading file ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
}
}
@@ -290,7 +291,7 @@ void FileService::operator()(HTTPRequest
// get the response type
if (cache_itr->second.getLastModifiedString() == if_modified_since) {
response_type = RESPONSE_NOT_MODIFIED;
- } else if (request->getMethod() == HTTPTypes::REQUEST_METHOD_HEAD) {
+ } else if (request->get_method() == types::REQUEST_METHOD_HEAD) {
response_type = RESPONSE_HEAD_OK;
} else {
response_type = RESPONSE_OK;
@@ -301,7 +302,7 @@ void FileService::operator()(HTTPRequest
PION_LOG_DEBUG(m_logger, (cache_was_updated ? "Updated" : "Using")
<< " cache entry for request ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
}
}
}
@@ -310,7 +311,7 @@ void FileService::operator()(HTTPRequest
// make sure that the file exists
if (! boost::filesystem::exists(file_path)) {
PION_LOG_WARN(m_logger, "File not found ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
sendNotFoundResponse(request, tcp_conn);
return;
}
@@ -318,7 +319,7 @@ void FileService::operator()(HTTPRequest
response_file.setFilePath(file_path);
PION_LOG_DEBUG(m_logger, "Found file for request ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
// determine the MIME type
response_file.setMimeType(findMIMEType( response_file.getFilePath().string() ));
@@ -330,7 +331,7 @@ void FileService::operator()(HTTPRequest
if (response_file.getLastModifiedString() == if_modified_since) {
// no need to read the file; the modified times match!
response_type = RESPONSE_NOT_MODIFIED;
- } else if (request->getMethod() == HTTPTypes::REQUEST_METHOD_HEAD) {
+ } else if (request->get_method() == types::REQUEST_METHOD_HEAD) {
response_type = RESPONSE_HEAD_OK;
} else {
response_type = RESPONSE_OK;
@@ -341,7 +342,7 @@ void FileService::operator()(HTTPRequest
}
// add new entry to the cache
PION_LOG_DEBUG(m_logger, "Adding cache entry for request ("
- << getResource() << "): " << relative_path);
+ << get_resource() << "): " << relative_path);
boost::mutex::scoped_lock cache_lock(m_cache_mutex);
m_cache_map.insert( std::make_pair(relative_path, response_file) );
}
@@ -360,43 +361,43 @@ void FileService::operator()(HTTPRequest
// sending headers only -> use our own response object
// prepare a response and set the Content-Type
- HTTPResponseWriterPtr writer(HTTPResponseWriter::create(tcp_conn, *request,
- boost::bind(&TCPConnection::finish, tcp_conn)));
- writer->getResponse().setContentType(response_file.getMimeType());
+ response_writer_ptr writer(response_writer::create(tcp_conn, *request,
+ boost::bind(&connection::finish, tcp_conn)));
+ writer->get_response().set_content_type(response_file.getMimeType());
// set Last-Modified header to enable client-side caching
- writer->getResponse().addHeader(HTTPTypes::HEADER_LAST_MODIFIED,
+ writer->get_response().add_header(types::HEADER_LAST_MODIFIED,
response_file.getLastModifiedString());
std::stringstream out;
out << response_file.getFileSize();
- writer->getResponse().addHeader(HTTPTypes::HEADER_CONTENT_LENGTH, out.str());
+ writer->get_response().add_header(types::HEADER_CONTENT_LENGTH, out.str());
switch(response_type) {
case RESPONSE_UNDEFINED:
case RESPONSE_NOT_FOUND:
case RESPONSE_OK:
// this should never happen
- throw UndefinedResponseException(request->getResource());
+ throw UndefinedResponseException(request->get_resource());
break;
case RESPONSE_NOT_MODIFIED:
// set "Not Modified" response
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_NOT_MODIFIED);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_NOT_MODIFIED);
+ writer->get_response().set_status_code(types::RESPONSE_CODE_NOT_MODIFIED);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_NOT_MODIFIED);
break;
case RESPONSE_HEAD_OK:
// set "OK" response (not really necessary since this is the default)
- writer->getResponse().setStatusCode(HTTPTypes::RESPONSE_CODE_OK);
- writer->getResponse().setStatusMessage(HTTPTypes::RESPONSE_MESSAGE_OK);
+ writer->get_response().set_status_code(types::RESPONSE_CODE_OK);
+ writer->get_response().set_status_message(types::RESPONSE_MESSAGE_OK);
break;
}
// send the response
writer->send();
}
- } else if (request->getMethod() == HTTPTypes::REQUEST_METHOD_POST
- || request->getMethod() == HTTPTypes::REQUEST_METHOD_PUT
- || request->getMethod() == HTTPTypes::REQUEST_METHOD_DELETE)
+ } else if (request->get_method() == types::REQUEST_METHOD_POST
+ || request->get_method() == types::REQUEST_METHOD_PUT
+ || request->get_method() == types::REQUEST_METHOD_DELETE)
{
// If not writable, then send 405 (Method Not Allowed) response for POST, PUT or DELETE requests.
if (!m_writable) {
@@ -409,24 +410,24 @@ void FileService::operator()(HTTPRequest
static const std::string NOT_ALLOWED_HTML_FINISH =
" is not allowed on this server.\n"
"