4 // Libmicrohttpd: https://www.gnu.org/software/libmicrohttpd/
6 #include <sys/select.h>
7 #include <sys/socket.h>
8 #include <microhttpd.h>
13 // Log docs: https://github.com/gabime/spdlog
14 #include <spdlog/spdlog.h>
15 namespace spd = spdlog;
17 #include "vdrclient.h"
22 static bool StartServer(std::string docRoot, int port, const char* configDir);
23 static void StopServer();
25 // static callbacks from libmicrohttpd
26 static int uri_key_value(void *cls, enum MHD_ValueKind kind, const char* key, const char* value);
27 static int iterate_post(void *clientIdentifier, enum MHD_ValueKind kind, const char *key,
28 const char *filename, const char* content_type,
29 const char *transfer_encoding, const char *data, uint64_t off, size_t size);
30 static void request_completed(void *cls, struct MHD_Connection *mhd_connection,
31 void **unused, enum MHD_RequestTerminationCode toe);
32 static void connection_notify(void *cls, struct MHD_Connection* mhd_connection,
33 void **socket_context, enum MHD_ConnectionNotificationCode toe);
34 static int handle_connection(void *cls, struct MHD_Connection *connection,
35 const char *url, const char *method,
36 const char *version, const char *upload_data,
37 size_t *upload_data_size, void **con_cls);
40 static std::shared_ptr<spd::logger> logger;
41 static struct MHD_Daemon* httpdserver;
42 static std::string docRoot;
43 static std::string configDir;
45 HTTPDClient(struct MHD_Connection*, const std::string& configDir);
48 int handleConnection(const char *url, const char *method,
49 const char *version, const char *upload_data,
50 size_t *upload_data_size, void **con_cls);
54 std::map<std::string, std::string> getVars;
55 std::map<std::string, std::string> postFields;
56 struct MHD_PostProcessor* postprocessor;
58 struct MHD_Connection* mhd_connection;
62 void addGetVar(const char* key, const char* value);
63 void addPostField(const char* key, const char* value, int valueLength);
64 void requestComplete();
65 int sendStockResponse(int code);