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

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2019, Tomasz Sowa
* Copyright (c) 2008-2022, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -40,6 +40,7 @@
#include "session.h"
#include "sessionparser.h"
#include "functions/functionbase.h"
#include "system.h"
@@ -558,7 +559,7 @@ SessionContainer::Iterator SessionManager::SessionEnd()
// called from the main thread (from App::Close)
void SessionManager::DeleteSessions()
{
SessionContainer::Iterator i;
@@ -567,7 +568,7 @@ void SessionManager::DeleteSessions()
{
if( i->puser && !i->remember_me )
{
plugin->Call(&(*i), WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
plugin->Call(main_model_connector, &main_log, &(*i), nullptr, nullptr, WINIX_PREPARE_USER_TO_LOGOUT, i->puser, nullptr, 0, 0);
last_container->UserLogout(i->puser->id, i->id);
}
}
@@ -599,7 +600,7 @@ SessionContainer::Iterator i = session_tab.FindById(old_id);
}
if( changed )
plugin->Call(&(*i), WINIX_SESSION_CHANGED_ID, old_id, new_id);
plugin->Call(main_model_connector, &main_log, &(*i), nullptr, nullptr, WINIX_SESSION_CHANGED_ID, nullptr, nullptr, old_id, new_id);
else
main_log << log1 << "SM: I cannot create a new session id (still uses old one)" << logend;
}
@@ -612,19 +613,20 @@ return changed;
}
// called from the main thread (from App::Init)
void SessionManager::InitTmpSession()
{
Session * old_session = cur->session;
main_log << log4 << "SM: initializing temporary session" << logend;
cur->session = &temporary_session;
plugin->Call(WINIX_SESSION_CREATED);
plugin->Call(main_model_connector, &main_log, nullptr, WINIX_SESSION_CREATED);
cur->session = old_session;
}
// called from the main thread at the and (from App::Close)
void SessionManager::UninitTmpSession()
{
Session * old_session = cur->session;
@@ -635,18 +637,16 @@ void SessionManager::UninitTmpSession()
if( cur->session->plugin_data.HasAllocatedData() )
{
plugin->Call(cur->session, WINIX_PLUGIN_SESSION_DATA_REMOVE);
plugin->Call(main_model_connector, &main_log, cur->session, nullptr, nullptr, WINIX_PLUGIN_SESSION_DATA_REMOVE);
}
//cur->session->plugin_data.DeleteAll(); // this will call plugin.Call(WINIX_PLUGIN_SESSION_DATA_REMOVE);
cur->session->plugin_data.Resize(0);
cur->session = old_session;
}
// called from the main thread (from App::Init)
void SessionManager::LoadSessions()
{
SessionParser sp;
@@ -665,7 +665,7 @@ SessionContainer::Iterator i;
for(i=session_tab.Begin() ; i != session_tab.End() ; ++i)
{
i->plugin_data.Resize(plugin->Size());
plugin->Call(&(*i), WINIX_SESSION_CREATED);
plugin->Call(main_model_connector, &main_log, &(*i), nullptr, nullptr, WINIX_SESSION_CREATED);
/*
!! IMPROVE ME
@@ -673,7 +673,7 @@ SessionContainer::Iterator i;
*/
if( i->puser )
plugin->Call(&(*i), WINIX_USER_LOGGED);
plugin->Call(main_model_connector, &main_log, &(*i), nullptr, nullptr, WINIX_USER_LOGGED);
}
}
else
@@ -758,7 +758,7 @@ size_t SessionManager::MarkAllSessionsToRemove(long user_id)
{
if( i->puser && i->puser->id == user_id )
{
plugin->Call(&(*i), WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
plugin->Call(main_model_connector, &main_log, &(*i), nullptr, nullptr, WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
last_container->UserLogout(i->puser->id, i->id);
i->remove_me = true;
i->puser = 0;
@@ -871,7 +871,7 @@ const int deleted_max_at_once = 10;
}
else
{
if( i->remove_me || IsSessionOutdated(*i) )
if( i->allow_to_delete && (i->remove_me || IsSessionOutdated(*i)) )
{
Session * ses = &(*i);
++i;
@@ -917,16 +917,16 @@ void SessionManager::DeleteSession(Session * del_session)
{
if( del_session->puser )
{
plugin->Call(del_session, WINIX_PREPARE_USER_TO_LOGOUT, del_session->puser);
plugin->Call(model_connector, &log, del_session, nullptr, nullptr, WINIX_PREPARE_USER_TO_LOGOUT, del_session->puser, nullptr, 0, 0);
last_container->UserLogout(del_session->puser->id, del_session->id);
del_session->puser = 0;
}
long id = del_session->id;
plugin->Call(del_session, WINIX_PREPARE_SESSION_TO_REMOVE);
plugin->Call(model_connector, &log, del_session, nullptr, nullptr, WINIX_PREPARE_SESSION_TO_REMOVE, del_session->puser, nullptr, 0, 0);
session_tab.EraseById(del_session->id);
plugin->Call((Session*)0, WINIX_SESSION_REMOVED, id);
plugin->Call(model_connector, &log, nullptr, WINIX_SESSION_REMOVED, nullptr, nullptr, id, 0);
}