libyui-rest-api
Loading...
Searching...
No Matches
YHttpServer.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 YHttpServer_h
18#define YHttpServer_h
19
20#include <vector>
21#include <string>
22
23#include "YHttpMount.h"
24#include "YHttpHandler.h"
25#include "YHttpServerSockets.h"
26#include "YHttpWidgetsActionHandler.h"
27
28// environment variables
29#define YUITest_HTTP_REMOTE "YUI_HTTP_REMOTE"
30#define YUITest_HTTP_PORT "YUI_HTTP_PORT"
31#define YUI_AUTH_USER "YUI_AUTH_USER"
32#define YUI_AUTH_PASSWD "YUI_AUTH_PASSWD"
33#define YUI_REUSE_PORT "YUI_REUSE_PORT"
34
35#define YUI_API_VERSION "v1"
36
37struct MHD_Daemon;
38
40{
41
42public:
43
44 static bool enabled()
45 {
46 static bool enabled = port_num() != 0;
47 return enabled;
48 }
49
53 static YHttpServer * yserver() { return _yserver; }
54
55 static int port_num();
56
61 YHttpServer( YHttpWidgetsActionHandler * widgets_action_handler );
62
64
66
70 void start();
71
76 void stop();
77
82 bool process_data();
83
90
91 void mount(std::string path, const std::string &method, YHttpHandler *handler, bool has_api_version = true);
92
93 MHD_RESULT handle(struct MHD_Connection* connection,
94 const char* url, const char* method, const char* upload_data,
95 size_t* upload_data_size);
96
97 // must be public to be accessible from a plain C callback :-/
98 std::string user() const {return auth_user;}
99 std::string passwd() const {return auth_passwd;}
100
101private:
102
103 // dual stack support (for both IPv4 and IPv6)
104 struct MHD_Daemon *server_v4, *server_v6;
105 std::vector<YHttpMount> _mounts;
106 bool redraw;
107 static YHttpServer * _yserver;
108 static YHttpWidgetsActionHandler * _widget_action_handler;
109 // HTTP Basic Auth credentials
110 std::string auth_user;
111 std::string auth_passwd;
112
113 static YHttpWidgetsActionHandler * get_widget_action_handler() { return _widget_action_handler; }
114
115protected:
116};
117
118
119#endif // YHttpServer_h
Definition YHttpHandler.h:40
Definition YHttpServerSockets.h:23
Definition YHttpServer.h:40
bool process_data()
Definition YHttpServer.cc:351
void start()
Definition YHttpServer.cc:261
static YHttpServer * yserver()
Definition YHttpServer.h:53
void stop()
Definition YHttpServer.cc:334
YHttpServerSockets sockets()
Definition YHttpServer.cc:155
Definition YHttpWidgetsActionHandler.h:59