]> git.ipfire.org Git - thirdparty/pdns.git/blame - pdns/webserver.hh
add OpenSSL exception to PowerDNS, Netherlabs, van Dijk and Hubert copyrights
[thirdparty/pdns.git] / pdns / webserver.hh
CommitLineData
12c86877
BH
1/*
2 PowerDNS Versatile Database Driven Nameserver
a2ce158c 3 Copyright (C) 2002-2012 PowerDNS.COM BV
12c86877
BH
4
5 This program is free software; you can redistribute it and/or modify
22dc646a
BH
6 it under the terms of the GNU General Public License version 2
7 as published by the Free Software Foundation
f782fe38
MH
8
9 Additionally, the license of this program contains a special
10 exception which allows to distribute the program in binary form when
11 it is linked against OpenSSL.
12c86877
BH
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
06bd9ccf 20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
12c86877
BH
21*/
22#ifndef WEBSERVER_HH
23#define WEBSERVER_HH
24#include <map>
25#include <string>
26
27
10f4eea8 28#include "namespaces.hh"
96d299db 29class Server;
12c86877 30
33196945
CH
31class HttpException
32{
33public:
34 HttpException(int status_code, const std::string& reason_phrase) :
35 d_status_code(status_code), d_reason_phrase(reason_phrase)
36 {
37 };
38
39 virtual std::string statusLine() const {
40 return "HTTP/1.0 " + lexical_cast<string>(d_status_code) + " " + d_reason_phrase + "\n";
41 }
42
43 virtual std::string headers() const {
44 return "";
45 }
46
47 virtual std::string what() const {
48 return d_reason_phrase;
49 }
50
51private:
52 int d_status_code;
53 std::string d_reason_phrase;
54};
55
56class HttpBadRequestException : public HttpException {
57public:
58 HttpBadRequestException() : HttpException(400, "Bad Request") { };
59};
60
61class HttpUnauthorizedException : public HttpException {
62public:
63 HttpUnauthorizedException() : HttpException(401, "Unauthorized") { };
64
65 std::string headers() const {
66 return "WWW-Authenticate: Basic realm=\"PowerDNS\"\n";
67 }
68};
69
70class HttpNotFoundException : public HttpException {
71public:
72 HttpNotFoundException() : HttpException(404, "Not Found") { };
73};
74
75class HttpMethodNotAllowedException : public HttpException {
76public:
77 HttpMethodNotAllowedException() : HttpException(405, "Method Not Allowed") { };
78};
79
12c86877
BH
80class WebServer
81{
82public:
83 WebServer(const string &listenaddress, int port, const string &password="");
84 void go();
85 static void* serveConnection(void *);
86 void setCaller(void *that);
a2ce158c 87 typedef string HandlerFunction(const string& method, const string& post, const map<string,string>&varmap, void *that, bool *custom);
12c86877
BH
88 void registerHandler(const string &, HandlerFunction *ptr);
89private:
90 static char B64Decode1(char cInChar);
91 static int B64Decode(const std::string& strInput, std::string& strOutput);
92 string d_listenaddress;
93 int d_port;
94 static map<string,HandlerFunction *>d_functions;
95 static void *d_that;
96 static string d_password;
96d299db 97 Server* d_server;
12c86877
BH
98};
99#endif /* WEBSERVER_HH */