Tubio/Tubio/HttpServer.h

44 lines
1.1 KiB
C
Raw Normal View History

2020-09-24 01:16:44 +02:00
#pragma once
#include <vector>
#include <iostream>
#include <sstream>
#include "external_dependencies/casenta/mongoose/mongoose.h"
2020-09-24 01:16:44 +02:00
#include "Logger.h"
2020-09-24 14:31:30 +02:00
#include "RestResponseTemplates.h"
#include "RestQueryHandler.h"
#include "XGConfig.h"
2020-09-24 01:16:44 +02:00
2020-09-24 14:31:30 +02:00
namespace Rest
2020-09-24 01:16:44 +02:00
{
class HttpServer
2020-09-24 14:31:30 +02:00
{
public:
HttpServer();
~HttpServer();
2020-09-24 01:16:44 +02:00
2020-09-24 14:31:30 +02:00
void PostInit();
void Update();
void OnExit();
2020-09-24 01:16:44 +02:00
2020-09-24 14:31:30 +02:00
private:
bool InitWebServer();
static void ProcessAPIRequest(struct mg_connection* pNc, int ev, void* p, std::string peerAddress);
static void ServeDownloadeableResource(struct mg_connection* pNc, int ev, void* p, std::string uri);
2020-09-24 01:16:44 +02:00
2020-09-24 14:31:30 +02:00
static void EventHandler(struct mg_connection* pNc, int ev, void* p);
static void ServeStringToConnection(struct mg_connection* c, std::string str, int httpStatusCode = 200);
static std::string FixUnterminatedString(const char* cstr, const std::size_t len);
2020-09-24 01:16:44 +02:00
static bool IsConnectionAllowed(std::string peer_address);
2020-09-24 01:16:44 +02:00
2020-09-24 14:31:30 +02:00
struct mg_mgr* pMgr;
struct mg_connection* pNc;
2020-09-24 15:35:07 +02:00
static mg_serve_http_opts frontend_serve_opts;
2020-09-24 01:16:44 +02:00
2020-09-24 14:31:30 +02:00
Logging::Logger* log;
2020-09-24 01:16:44 +02:00
2020-09-24 15:15:18 +02:00
bool isBootedSuccessfully = false;
2020-09-24 14:31:30 +02:00
};
}