Webdar 1.0.0
Web user interface to libdar
parser.hpp
1/*********************************************************************/
2// webdar - a web server and interface program to libdar
3// Copyright (C) 2013-2025 Denis Corbin
4//
5// This file is part of Webdar
6//
7// Webdar is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Webdar is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with Webdar. If not, see <http://www.gnu.org/licenses/>
19//
20//----
21// to contact the author: dar.linux@free.fr
22/*********************************************************************/
23
24#ifndef PARSER_HPP
25#define PARSER_HPP
26
27#include "my_config.h"
28
29 // C++ system header files
30#include <memory>
31
32 // webdar headers
33#include "exceptions.hpp"
34#include "proto_connexion.hpp"
35#include "central_report.hpp"
36#include "request.hpp"
37#include "answer.hpp"
38
40
41class parser
42{
43public:
52 parser(std::unique_ptr<proto_connexion> & input,
53 const std::shared_ptr<central_report> & log);
54
55 parser(const parser & ref) = delete;
56 parser(parser && ref) noexcept = delete;
57 parser & operator = (const parser & ref) = delete;
58 parser & operator = (parser && ref) noexcept = delete;
59
61 ~parser() { close(); };
62
64 proto_connexion::status get_status() const { if(!source) return proto_connexion::not_connected; return source->get_status(); };
65
70 bool get_next_request_uri(uri & val);
71
73 const request & get_request();
74
76 void send_answer(answer & ans);
77
79 void close();
80
81private:
82 bool answered; //< whether last request was answered or not
83 std::unique_ptr<proto_connexion> source; //< the proto_connexion to the client
84 request req; //< value of the last request
85
86 void valid_source() const { if(!source || source->get_status() != proto_connexion::connected) throw exception_range("socket disconnected"); };
87 void checks_main(const request & req, answer & ans);
88 void checks_webdar(const request & req, answer & ans);
89 void checks_rfc1945(const request & req, answer & ans);
90};
91
92
93#endif
class answer provides easy means to set an HTTP answer and means to sent it back to a proto_connexion...
Definition: answer.hpp:49
exception used to report out or range value or argument
Definition: exceptions.hpp:109
parser class is given a connection object and format the incoming byte flow in structured request obj...
Definition: parser.hpp:42
bool get_next_request_uri(uri &val)
Definition: parser.cpp:54
void send_answer(answer &ans)
modify the answer to conform to RFC 1945 before sending it
Definition: parser.cpp:107
const request & get_request()
provides the next request
Definition: parser.cpp:69
proto_connexion::status get_status() const
provides visibility on the connection status
Definition: parser.hpp:64
~parser()
destructor
Definition: parser.hpp:61
void close()
closes the current connection
Definition: parser.cpp:48
parser(std::unique_ptr< proto_connexion > &input, const std::shared_ptr< central_report > &log)
Definition: parser.cpp:32
class holding fields of an HTTP request (method, URI, header, cookies, and so on)
Definition: request.hpp:45
uri type holds the splitted list of the scheme / hostname / path # anchor
Definition: uri.hpp:44