98 lines
2.6 KiB
C++
98 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
|
|
#include <mongoose.h>
|
|
|
|
#include "StaticFileHandler.H"
|
|
//#include "DynamicObjects.H"
|
|
|
|
class DynamicObjects;
|
|
|
|
int event_route_wrap(struct mg_connection *conn, mg_event ev);
|
|
|
|
class Routerin
|
|
{
|
|
public:
|
|
//Routerin(StaticFileHandler &sfh);
|
|
|
|
~Routerin();
|
|
// const ???
|
|
static Routerin * get_instance()
|
|
{
|
|
static Routerin * me = nullptr;
|
|
if (!me)
|
|
return me = new Routerin();
|
|
return me;
|
|
}
|
|
|
|
//after configuration:
|
|
void start(void);
|
|
|
|
void function_name()
|
|
{
|
|
}
|
|
|
|
/*enum mg_result { MG_FALSE, MG_TRUE, MG_MORE };*/
|
|
//enum mg_event {
|
|
//MG_POLL = 100, // Callback return value is ignored
|
|
//MG_CONNECT, // If callback returns MG_FALSE, connect fails
|
|
//MG_AUTH, // If callback returns MG_FALSE, authentication fails
|
|
//MG_REQUEST, // If callback returns MG_FALSE, Mongoose continues with req
|
|
//MG_REPLY, // If callback returns MG_FALSE, Mongoose closes connection
|
|
//MG_CLOSE, // Connection is closed, callback return value is ignored
|
|
//MG_WS_HANDSHAKE, // New websocket connection, handshake request
|
|
//MG_HTTP_ERROR // If callback returns MG_FALSE, Mongoose continues with err
|
|
//};
|
|
|
|
|
|
int event_route(struct mg_connection *conn, enum mg_event event)
|
|
{
|
|
// Foohash fh;
|
|
switch (event) {
|
|
case MG_REQUEST:
|
|
return event_request_route(conn);
|
|
case MG_AUTH:
|
|
return MG_TRUE;
|
|
default:
|
|
return event_fallback_route(event, conn);
|
|
}
|
|
}
|
|
|
|
std::string const & get_baseurl()const{return baseurl;}
|
|
void set_baseurl(std::string baseurl);
|
|
|
|
std::string const & get_file_path()const{return file_path;}
|
|
void set_file_path(std::string file_path);
|
|
|
|
std::string const & get_json_path()const{return json_path;}
|
|
void set_json_path(std::string json_path);
|
|
|
|
private:
|
|
explicit Routerin();
|
|
std::unique_ptr<StaticFileHandler> sfh;
|
|
DynamicObjects * _dyn_obs;
|
|
std::string baseurl;
|
|
|
|
std::string file_path;
|
|
std::string json_path;
|
|
|
|
// bool hasInstance = false;
|
|
|
|
int event_request_route ( struct mg_connection *conn);
|
|
// int event_newthread_route ( struct mg_event *event);
|
|
int event_fallback_route ( enum mg_event event, struct mg_connection *conn );
|
|
// int event_requend_route ( struct mg_event *event);
|
|
|
|
int rq_static(char const * const restrstr , struct mg_connection *conn);
|
|
int rq_file(char const * const reststr , struct mg_connection *conn);
|
|
int rq_date(char const * const reststr , struct mg_connection *conn);
|
|
int rq_upload(char const * const reststr , struct mg_connection *conn);
|
|
int rq_render_mainpage(struct mg_connection *conn);
|
|
|
|
int handle_upload(struct mg_connection *conn);
|
|
|
|
};
|
|
|
|
|