libutil++  1.9.3
 All Classes Functions Variables
callbacks.cpp
1 /*
2 ** libutil++
3 ** $Id: callbacks.cpp 1653 2016-02-28 19:54:59Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 static const char rcsid[] __attribute__((used)) = "$Id: callbacks.cpp 1653 2016-02-28 19:54:59Z sella $";
10 
11 #include "callbacks.h"
12 #include "Code.h"
13 #include "../util/CommonMacro.h"
14 #include "../util/Log.h"
15 
16 using namespace sella::server;
17 
18 bool http::acl_callback(HTTPConnection::shared connection) throw (ServerException) {
19  return true;
20 }
21 
22 bool http::authentication_callback(HTTPConnection::shared connection) throw (ServerException) {
23  return true;
24 }
25 
26 bool http::request_callback(HTTPConnection::shared connection) throw (ServerException) {
27  const HTTPRequest &request = connection->getRequest();
28 
29  if (IS_TRACE(PACKAGE "-detail")) {
30  request.print();
31  }
32 
33  switch (request.getMethod()) {
34  case HTTPRequest::Head:
35  connection->methodHead();
36  break;
37 
38  case HTTPRequest::Get:
39  connection->methodGet();
40  break;
41 
42  case HTTPRequest::Post:
43  connection->methodPost();
44  break;
45 
46  case HTTPRequest::Put:
47  connection->methodPut();
48  break;
49 
50  case HTTPRequest::Delete:
51  connection->methodDelete();
52  break;
53 
54  case HTTPRequest::Patch:
55  connection->methodPatch();
56  break;
57 
58  case HTTPRequest::Options:
59  connection->methodOptions();
60  break;
61 
62  case HTTPRequest::Trace:
63  connection->methodTrace();
64  break;
65 
66  case HTTPRequest::Connect:
67  connection->methodConnect();
68  break;
69 
70  default:
71  THROW_CODE(ServerException, Code::NotImplemented, "Requested method has not been implemented.");
72  }
73 
74  return true;
75 }
76 
77 bool http::error_callback(HTTPConnection::shared connection, int code, const std::string &detail) throw (ServerException) {
78  TRACE(PACKAGE "-detail", "HTTP Error[%d]: %s", code, detail.c_str());
79 
80  if (connection->isUsable()) {
81  connection->error(code, detail);
82 
83  return true;
84  }
85 
86  return false;
87 }
88 
89 /*
90 ** vim: noet ts=3 sw=3
91 */