libyui-rest-api
 
Loading...
Searching...
No Matches
YHttpHandler.h
1/*
2 Copyright (C) 2017 SUSE LLC
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) version 3.0 of the License. This library
8 is distributed in the hope that it will be useful, but WITHOUT ANY
9 WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11 License for more details. You should have received a copy of the GNU
12 Lesser General Public License along with this library; if not, write
13 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
14 Floor, Boston, MA 02110-1301 USA
15*/
16
17#ifndef YHttpHandler_h
18#define YHttpHandler_h
19
20#include <microhttpd.h>
21
22#if MHD_VERSION >= 0x00097002
26#define MHD_RESULT enum MHD_Result
27#else
31#define MHD_RESULT int
32#endif
33
34#include <string>
35#include <iostream>
36
37struct MHD_Connection;
38
39class YHttpHandler
40{
41
42public:
43
44 YHttpHandler() {}
45 virtual ~YHttpHandler() {}
46
47 virtual MHD_RESULT handle(struct MHD_Connection* connection,
48 const char* url, const char* method, const char* upload_data,
49 size_t* upload_data_size, bool *redraw = nullptr);
50
51
52protected:
53
54 virtual void process_request(struct MHD_Connection* connection,
55 const char* url, const char* method, const char* upload_data,
56 size_t* upload_data_size, std::ostream& body, int& error_code,
57 std::string& content_type, bool *redraw) = 0;
58
59 int handle_error(std::ostream& body, std::string error, int error_code);
60};
61
62#endif // YHttpHandler_h