Add support for using TOML as configuration file format

Add basic support for trojan-grpc nodes.
Refactor codes.
This commit is contained in:
Tindy X committed 2021-09-20 17:02:13 +08:00
1 parent bc0a8dc925
commit 9797197c85
35 files changed
+2345 -531

No files matched your search

+40 -6
View File
@@ -3,8 +3,13 @@
#include <string>
#include <map>
#include <atomic>
#include <event2/http.h>
#include <curl/curlver.h>
#include "../utils/map_extra.h"
#include "../utils/string.h"
#include "../version.h"
struct Request
{
@@ -36,11 +41,40 @@ struct listener_args
uint32_t looper_interval = 200;
};
void append_response(const std::string &method, const std::string &uri, const std::string &content_type, response_callback response);
void append_redirect(const std::string &uri, const std::string &target);
void reset_redirect();
int start_web_server(void *argv);
int start_web_server_multi(void *argv);
void stop_web_server();
struct responseRoute
{
std::string method;
std::string path;
std::string content_type;
response_callback rc;
};
class WebServer
{
public:
std::string user_agent_str = "subconverter/" VERSION " cURL/" LIBCURL_VERSION;
std::atomic_bool SERVER_EXIT_FLAG{false};
// file server
bool serve_file = false;
std::string serve_file_root;
// basic authentication
bool require_auth = false;
std::string auth_user, auth_password, auth_realm = "Please enter username and password:";
void append_response(const std::string &method, const std::string &uri, const std::string &content_type, response_callback response);
void append_redirect(const std::string &uri, const std::string &target);
void reset_redirect();
int start_web_server(void *argv);
int start_web_server_multi(void *argv);
void stop_web_server();
private:
int serveFile(const std::string &filename, std::string &content_type, std::string &return_data);
inline int process_request(Request &request, Response &response, std::string &return_data);
void on_request(evhttp_request *req, void *args);
std::vector<responseRoute> responses;
string_map redirect_map;
};
#endif // WEBSERVER_H_INCLUDED