00001
00002
00003
00004
00005
00006
00007
00008
00009 static const char rcsid[] __attribute__((used)) = "$Id: callbacks.cpp 1197 2014-10-14 22:26:11Z sella $";
00010
00011 #include "callbacks.h"
00012 #include "Code.h"
00013 #include "../util/CommonMacro.h"
00014 #include "../util/Log.h"
00015
00016 using namespace sella::server;
00017
00018 bool http::acl_callback(HTTPConnection::shared connection) throw (ServerException) {
00019 return true;
00020 }
00021
00022 bool http::authentication_callback(HTTPConnection::shared connection) throw (ServerException) {
00023 return true;
00024 }
00025
00026 bool http::request_callback(HTTPConnection::shared connection) throw (ServerException) {
00027 const HTTPRequest &request = connection->getRequest();
00028
00029 if (IS_TRACE(PACKAGE "-detail")) {
00030 request.print();
00031 }
00032
00033 switch (request.getMethod()) {
00034 case HTTPRequest::Head:
00035 connection->methodHead();
00036 break;
00037
00038 case HTTPRequest::Get:
00039 connection->methodGet();
00040 break;
00041
00042 case HTTPRequest::Post:
00043 connection->methodPost();
00044 break;
00045
00046 case HTTPRequest::Put:
00047 connection->methodPut();
00048 break;
00049
00050 case HTTPRequest::Delete:
00051 connection->methodDelete();
00052 break;
00053
00054 case HTTPRequest::Patch:
00055 connection->methodPatch();
00056 break;
00057
00058 case HTTPRequest::Options:
00059 connection->methodOptions();
00060 break;
00061
00062 case HTTPRequest::Trace:
00063 connection->methodTrace();
00064 break;
00065
00066 case HTTPRequest::Connect:
00067 connection->methodConnect();
00068 break;
00069
00070 default:
00071 THROW_CODE(ServerException, Code::NotImplemented, "Requested method has not been implemented.");
00072 }
00073
00074 return true;
00075 }
00076
00077 bool http::error_callback(HTTPConnection::shared connection, int code, const std::string &detail) throw (ServerException) {
00078 TRACE(PACKAGE "-detail", "HTTP Error[%d]: %s", code, detail.c_str());
00079
00080 if (connection->isUsable()) {
00081 connection->error(code, detail);
00082
00083 return true;
00084 }
00085
00086 return false;
00087 }
00088
00089
00090
00091