allow a request to be processed in a job

Now we allow a request to be passed into a job queue,
and after the job finishes the request is passed into
a controller again. In order to achieve this we have
a requests queue in System, when we put a request
to the job this Request structure is preserved in the
queue and for a new request a new Request is added to
the queue.

while here:
- remove App::Lock()/Unlock(), use scoped locking
- fix: Plugin now has a Call method which takes ModelConnector
  and a logger (used in multithreaded environment)
- BaseThread has a main_model_connector pointer
  to the main (from the main thread) model connector
- the FastCGI structure fcgi_request moved from App to Request
- some methods for handling requests moved from App to Request
- small refactoring in main.cpp
- add Http class (a http client)
This commit is contained in:
2022-07-25 14:21:21 +02:00
parent b2d92b85a0
commit 979ef907fe
65 changed files with 7018 additions and 4437 deletions

View File

@@ -74,18 +74,20 @@ public:
bool DropPrivileges();
void InitLoggers();
Log & GetMainLog();
void LoadPlugins();
bool InitializePlugins();
bool Init();
bool InitializeRequestForFastCGI();
void SetRequestDependency();
void InitializeNewRequest();
void PrepareRequest();
void PutRequestToJob();
void Start();
void Close();
void LogUserGroups();
void LogRequestTime();
bool Demonize();
void SetStopSignal();
bool WasStopSignal();
bool Lock();
void Unlock();
Synchro * GetSynchro();
void StartThreads();
void WaitForThreads();
@@ -95,10 +97,6 @@ public:
// pointers to the current request and a session
Cur cur;
// temporary one request object
// current request
Request req;
// users sessions
SessionManager session_manager;
@@ -106,7 +104,8 @@ public:
Db db;
DbConn db_conn;
// an unique id for each request
size_t request_id;
// ...
System system;
@@ -136,24 +135,12 @@ private:
AcceptBaseParser accept_base_parser;
AcceptEncodingParser accept_encoding_parser;
Compress compress;
FCGX_Request fcgi_request;
int fcgi_socket;
Synchro synchro;
pthread_t signal_thread;
std::string socket_to_send_on_exit;
std::string send_data_buf;
pt::WTextStream json_out_stream;
std::string aheader_name, aheader_value;
//std::wstring html_filtered;
//std::string output_8bit;
pt::TextStream serialized_model;
pt::WTextStream post_log_tmp_buffer;
pt::WTextStream output_tmp_filtered_stream;
BinaryPage output_8bit;
BinaryPage compressed_output;
std::wstring cookie_id_string;
std::wstring http_header_name;
std::wstring http_header_value;
std::string http_header_8bit;
@@ -199,48 +186,15 @@ private:
void CheckIfNeedSSLredirect();
void SetLocale();
void CheckPostRedirect();
void UseEzcGenerator();
void AddDefaultModels();
void SaveSessionsIfNeeded(); // !! IMPROVE ME wywalic do menagera sesji??
void LogAccess();
void SendData(const BinaryPage & page, FCGX_Stream * out);
void ReadRequest();
void SendAnswer();
void PrepareRawAnswer();
void PrepareJsonAnswer();
void PrepareXmlAnswer();
void PrepareCsvAnswer();
void PrepareContenerizedAnswer();
void PutSeparatorIfNeeded(bool put_separator);
void SerializeFieldJson(const wchar_t * field_name);
void SerializeStream(const pt::WTextStream & input_stream, const wchar_t * field_name);
void SerializeStreamJson(const pt::WTextStream & input_stream, const wchar_t * field_name);
void SerializeStreamXml(const pt::WTextStream & input_stream, const wchar_t * field_name);
void SerializeStreamCsv(const pt::WTextStream & input_stream, const wchar_t * field_name);
void SerializeAllFrames();
void SerializeSpecificFrames();
void SerializeModels();
void Send8bitOutput(BinaryPage & output);
void SerializeModel(morm::Wrapper & wrapper, const wchar_t * field_name);
void SerializeModelJson(morm::Wrapper & wrapper, const wchar_t * field_name);
void SerializeModelXml(morm::Wrapper & wrapper, const wchar_t * field_name);
void SerializeModelCsv(morm::Wrapper & wrapper, const wchar_t * field_name);
void FilterHtmlIfNeeded(const pt::WTextStream & input_stream, BinaryPage & output, bool clear_stream = true);
void LogEnvironmentVariables();
void LogEnvironmentHTTPVariables();
void ParseAcceptHeader(const wchar_t * header_name, const std::wstring & env, std::vector<HeaderValue> & container, size_t max_len);
void ParseAcceptHeader();
void ParseAcceptLanguageHeader();
void SetEnv(const char * name, std::wstring & env);
void ReadEnvVariables();
void ReadEnvHTTPVariables();
@@ -250,37 +204,17 @@ private:
void ParsePostJson();
void ReadPostJson();
void ReadPostVars();
void CheckIE();
void CheckKonqueror();
void CheckRequestMethod();
void CheckSSL();
void CheckHtmx();
void SetSubdomain();
bool IsRequestedFrame();
void ModifyStatusCodeIfNeeded();
void PrepareSessionCookie();
void SendHeaders();
void SendCookies();
bool AddHeader(const wchar_t * name, const wchar_t * value);
bool AddHeader(const std::wstring & name, const std::wstring & value);
bool AddHeader(const wchar_t * name, const pt::WTextStream & value);
bool AddHeader(const std::wstring & name, const pt::WTextStream & value);
bool CreateStaticResourcePath(pt::WTextStream & out_path);
void PrepareSendFileHeaderForStaticMountpoint();
void PrepareHeaderContentType();
void ModifyStatusForRedirect();
void PrepareSendFileHeader();
void PrepareContentEncodingHeader(int compress_encoding);
void PrepareContentLengthHeader(size_t output_size);
void PrepareHeaderStatus(int http_status);
void PrepareHeaders(bool compressing, int compress_encoding, size_t output_size);
int SelectDeflateVersion();
void SelectCompression(size_t source_len, bool & compression_allowed, int & compression_encoding);
bool CanSendContent();
void ClearAfterRequest();
void IncrementRequestId();
void LogUser(const char * msg, uid_t id);
void LogGroup(const char * msg, gid_t id, bool put_logend = true);
@@ -295,6 +229,7 @@ private:
bool DoDatabaseMigration();
bool TryToMakeDatabaseMigration();
void WaitForRequestsToFinish();
// !! IMPROVE ME