rewritten: sessions management
(Session, SessionContainer, SessionManager) now a Session object don't copy all fields in its copy constructor (only id) the rest fields are set after the object is inserted in SessionContainer added: after successfully login a session id is changed added: plugin.Call() methods with a first argument a pointer to a Session object git-svn-id: svn://ttmath.org/publicrep/winix/trunk@823 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
70421b7bd1
commit
e83fd91423
|
@ -158,7 +158,7 @@ bool App::Init()
|
||||||
post_parser.LogValueSize(config.log_post_value_size);
|
post_parser.LogValueSize(config.log_post_value_size);
|
||||||
// post_multi_parser has a pointer to the config
|
// post_multi_parser has a pointer to the config
|
||||||
|
|
||||||
plugin.Call(WINIX_PLUGIN_INIT);
|
plugin.Call((Session*)0, WINIX_PLUGIN_INIT);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -323,12 +323,12 @@ bool moved = false;
|
||||||
item_work.file.has_thumb = true;
|
item_work.file.has_thumb = true;
|
||||||
db->EditHasThumbById(true, item_work.file.id);
|
db->EditHasThumbById(true, item_work.file.id);
|
||||||
log << log3 << "Image: generated a thumbnail: " << dst_path << logend;
|
log << log3 << "Image: generated a thumbnail: " << dst_path << logend;
|
||||||
plugin.Call(WINIX_CREATED_THUMB, &item_work.file);
|
plugin.Call((Session*)0, WINIX_CREATED_THUMB, &item_work.file);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log << log3 << "Image: image resized: " << dst_path << logend;
|
log << log3 << "Image: image resized: " << dst_path << logend;
|
||||||
plugin.Call(WINIX_IMAGE_RESIZED, &item_work.file);
|
plugin.Call((Session*)0, WINIX_IMAGE_RESIZED, &item_work.file);
|
||||||
}
|
}
|
||||||
|
|
||||||
moved = true;
|
moved = true;
|
||||||
|
|
|
@ -107,6 +107,13 @@ LastTab::iterator i = FindNotLoggedOut(user_id, session_id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log << log4 << "LC: there is no such a user to log out" << logend;
|
/*
|
||||||
|
!! IMPROVE ME
|
||||||
|
users read from the session file (at boot time)
|
||||||
|
are not added to LastContainer
|
||||||
|
*/
|
||||||
|
|
||||||
|
log << log4 << "LC: there is no such a user to log out: user_id: "
|
||||||
|
<< user_id << " ses_id: " << session_id << logend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ void Mounts::CreateMounts()
|
||||||
CreateMountFs();
|
CreateMountFs();
|
||||||
CreateMountPar();
|
CreateMountPar();
|
||||||
|
|
||||||
plugin.Call(WINIX_ADD_MOUNTS);
|
plugin.Call((Session*)0, WINIX_ADD_MOUNTS);
|
||||||
|
|
||||||
empty_mount.param.resize(mount_par_tab.size());
|
empty_mount.param.resize(mount_par_tab.size());
|
||||||
empty_mount.ClearParams();
|
empty_mount.ClearParams();
|
||||||
|
@ -191,7 +191,7 @@ void Mounts::ReadMounts(const std::wstring & mounts)
|
||||||
mount_parser.Parse(mounts, mount_tab);
|
mount_parser.Parse(mounts, mount_tab);
|
||||||
|
|
||||||
CalcCurMount();
|
CalcCurMount();
|
||||||
plugin.Call(WINIX_FSTAB_CHANGED);
|
plugin.Call((Session*)0, WINIX_FSTAB_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -251,16 +251,17 @@ bool Plugin::HasMessage(int message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, Slots::iterator & slot, PluginInfo & info)
|
void Plugin::Call(Session * ses, int message, Slots::iterator & slot, PluginInfo & info)
|
||||||
{
|
{
|
||||||
if( !SetPointers(info) )
|
if( !SetPointers(info) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
current_plugin = slot->second.index;
|
current_plugin = slot->second.index;
|
||||||
info.plugin_id = current_plugin;
|
info.plugin_id = current_plugin;
|
||||||
|
info.session = ses;
|
||||||
|
|
||||||
if( current_plugin != -1 )
|
if( current_plugin != -1 && ses )
|
||||||
info.plugin_data_base = cur->session->plugin_data.Get(current_plugin);
|
info.plugin_data_base = ses->plugin_data.Get(current_plugin);
|
||||||
else
|
else
|
||||||
info.plugin_data_base = 0;
|
info.plugin_data_base = 0;
|
||||||
|
|
||||||
|
@ -295,7 +296,7 @@ void Plugin::Call(int message, Slots::iterator & slot, PluginInfo & info)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, void * p1_, void * p2_, long l1_, long l2_)
|
void Plugin::Call(Session * ses, int message, void * p1_, void * p2_, long l1_, long l2_)
|
||||||
{
|
{
|
||||||
// how many plugins return 'false' and 'true'
|
// how many plugins return 'false' and 'true'
|
||||||
// we are using local variables because Call() method can be called
|
// we are using local variables because Call() method can be called
|
||||||
|
@ -315,7 +316,7 @@ PluginInfo info;
|
||||||
info.l1 = l1_;
|
info.l1 = l1_;
|
||||||
info.l2 = l2_;
|
info.l2 = l2_;
|
||||||
|
|
||||||
Call(message, i, info);
|
Call(ses, message, i, info);
|
||||||
|
|
||||||
if( info.res )
|
if( info.res )
|
||||||
++ret_true_loc;
|
++ret_true_loc;
|
||||||
|
@ -331,52 +332,104 @@ PluginInfo info;
|
||||||
|
|
||||||
void Plugin::Call(int message)
|
void Plugin::Call(int message)
|
||||||
{
|
{
|
||||||
Call(message, 0, 0, 0, 0);
|
Call(cur->session, message, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, void * p1_)
|
void Plugin::Call(int message, void * p1_)
|
||||||
{
|
{
|
||||||
Call(message, p1_, 0, 0, 0);
|
Call(cur->session, message, p1_, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, void * p1_, void * p2_)
|
void Plugin::Call(int message, void * p1_, void * p2_)
|
||||||
{
|
{
|
||||||
Call(message, p1_, p2_, 0, 0);
|
Call(cur->session, message, p1_, p2_, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, long l1_)
|
void Plugin::Call(int message, long l1_)
|
||||||
{
|
{
|
||||||
Call(message, 0, 0, l1_, 0);
|
Call(cur->session, message, 0, 0, l1_, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, long l1_, long l2_)
|
void Plugin::Call(int message, long l1_, long l2_)
|
||||||
{
|
{
|
||||||
Call(message, 0, 0, l1_, l2_);
|
Call(cur->session, message, 0, 0, l1_, l2_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, void * p1_, long l1_)
|
void Plugin::Call(int message, void * p1_, long l1_)
|
||||||
{
|
{
|
||||||
Call(message, p1_, 0, l1_, 0);
|
Call(cur->session, message, p1_, 0, l1_, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, void * p1_, long l1_, long l2_)
|
void Plugin::Call(int message, void * p1_, long l1_, long l2_)
|
||||||
{
|
{
|
||||||
Call(message, p1_, 0, l1_, l2_);
|
Call(cur->session, message, p1_, 0, l1_, l2_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Plugin::Call(int message, void * p1_, void * p2_, long l1_)
|
void Plugin::Call(int message, void * p1_, void * p2_, long l1_)
|
||||||
{
|
{
|
||||||
Call(message, p1_, p2_, l1_, 0);
|
Call(cur->session, message, p1_, p2_, l1_, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Plugin::Call(Session * ses, int message)
|
||||||
|
{
|
||||||
|
Call(ses, message, 0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Plugin::Call(Session * ses, int message, void * p1_)
|
||||||
|
{
|
||||||
|
Call(ses, message, p1_, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Plugin::Call(Session * ses, int message, void * p1_, void * p2_)
|
||||||
|
{
|
||||||
|
Call(ses, message, p1_, p2_, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Plugin::Call(Session * ses, int message, long l1_)
|
||||||
|
{
|
||||||
|
Call(ses, message, 0, 0, l1_, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Plugin::Call(Session * ses, int message, long l1_, long l2_)
|
||||||
|
{
|
||||||
|
Call(ses, message, 0, 0, l1_, l2_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Plugin::Call(Session * ses, int message, void * p1_, long l1_)
|
||||||
|
{
|
||||||
|
Call(ses, message, p1_, 0, l1_, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Plugin::Call(Session * ses, int message, void * p1_, long l1_, long l2_)
|
||||||
|
{
|
||||||
|
Call(ses, message, p1_, 0, l1_, l2_);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Plugin::Call(Session * ses, int message, void * p1_, void * p2_, long l1_)
|
||||||
|
{
|
||||||
|
Call(ses, message, p1_, p2_, l1_, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t Plugin::Size()
|
size_t Plugin::Size()
|
||||||
{
|
{
|
||||||
return plugins.size();
|
return plugins.size();
|
||||||
|
|
|
@ -67,8 +67,17 @@ struct PluginInfo
|
||||||
Synchro * synchro;
|
Synchro * synchro;
|
||||||
SessionManager * session_manager;
|
SessionManager * session_manager;
|
||||||
|
|
||||||
// pointer to the plugin session (can be null if not set by the plugin)
|
// a session
|
||||||
// you should use WINIX_SESSION_CREATED and WINIX_SESSION_REMOVE
|
// some messages are sent in a session's context e.g. logging a user
|
||||||
|
// this pointer in not always the same as cur->session, it is preferred
|
||||||
|
// to use this pointer instead of cur->session
|
||||||
|
// (cur->session can point at a temporary object)
|
||||||
|
// this pointer can be null
|
||||||
|
Session * session;
|
||||||
|
|
||||||
|
// pointer to the plugin session (can be null if not set by the plugin or if session is null)
|
||||||
|
// this is taken from session->plugin_data.Get()
|
||||||
|
// you should use WINIX_SESSION_CREATED and WINIX_PLUGIN_SESSION_DATA_REMOVE
|
||||||
// to create your plugin's session data
|
// to create your plugin's session data
|
||||||
PluginDataBase * plugin_data_base; // !! zmienic nazwe na plugin_session_base ? a moze session_base; a moze plugin_session?
|
PluginDataBase * plugin_data_base; // !! zmienic nazwe na plugin_session_base ? a moze session_base; a moze plugin_session?
|
||||||
|
|
||||||
|
@ -86,8 +95,9 @@ struct PluginInfo
|
||||||
l1 = 0;
|
l1 = 0;
|
||||||
l2 = 0;
|
l2 = 0;
|
||||||
|
|
||||||
plugin_id = -1;
|
plugin_id = -1;
|
||||||
plugin_data_base = 0;
|
session = 0;
|
||||||
|
plugin_data_base = 0;
|
||||||
|
|
||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
|
@ -166,8 +176,17 @@ public:
|
||||||
void Call(int message, void * p1_, long l1_);
|
void Call(int message, void * p1_, long l1_);
|
||||||
void Call(int message, void * p1_, long l1_, long l2_);
|
void Call(int message, void * p1_, long l1_, long l2_);
|
||||||
void Call(int message, void * p1_, void * p2_, long l1_);
|
void Call(int message, void * p1_, void * p2_, long l1_);
|
||||||
void Call(int message, void * p1_, void * p2_, long l1_, long l2_);
|
void Call(Session * ses, int message, void * p1_, void * p2_, long l1_, long l2_);
|
||||||
|
|
||||||
|
void Call(Session * ses, int message);
|
||||||
|
void Call(Session * ses, int message, void * p1_);
|
||||||
|
void Call(Session * ses, int message, void * p1_, void * p2_);
|
||||||
|
void Call(Session * ses, int message, long l1_);
|
||||||
|
void Call(Session * ses, int message, long l1_, long l2_);
|
||||||
|
void Call(Session * ses, int message, void * p1_, long l1_);
|
||||||
|
void Call(Session * ses, int message, void * p1_, long l1_, long l2_);
|
||||||
|
void Call(Session * ses, int message, void * p1_, void * p2_, long l1_);
|
||||||
|
|
||||||
// how many plugins there are
|
// how many plugins there are
|
||||||
size_t Size();
|
size_t Size();
|
||||||
|
|
||||||
|
@ -211,7 +230,7 @@ private:
|
||||||
std::string afilename;
|
std::string afilename;
|
||||||
|
|
||||||
void * LoadInitFun(const char * filename, Fun1 & fun_init);
|
void * LoadInitFun(const char * filename, Fun1 & fun_init);
|
||||||
void Call(int message, Slots::iterator & slot, PluginInfo & info);
|
void Call(Session * ses, int message, Slots::iterator & slot, PluginInfo & info);
|
||||||
|
|
||||||
bool SetPointers(PluginInfo & info);
|
bool SetPointers(PluginInfo & info);
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,10 +10,49 @@
|
||||||
#include "plugindata.h"
|
#include "plugindata.h"
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "session.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PluginData::PluginData()
|
||||||
|
{
|
||||||
|
session = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PluginData::PluginData(const PluginData & p)
|
||||||
|
{
|
||||||
|
operator=(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PluginData & PluginData::operator=(const PluginData & p)
|
||||||
|
{
|
||||||
|
// we don't copy all pointers - only resize the table
|
||||||
|
// pointers will be set to zero
|
||||||
|
Resize(p.Size());
|
||||||
|
session = 0;
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
PluginData::~PluginData()
|
||||||
|
{
|
||||||
|
DeleteAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PluginData::SetSession(Session * ses)
|
||||||
|
{
|
||||||
|
session = ses;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void PluginData::Assign(size_t index, PluginDataBase * data)
|
void PluginData::Assign(size_t index, PluginDataBase * data)
|
||||||
{
|
{
|
||||||
|
@ -62,44 +101,37 @@ return Get(plugin.current_plugin);
|
||||||
|
|
||||||
void PluginData::DeleteAll()
|
void PluginData::DeleteAll()
|
||||||
{
|
{
|
||||||
if( table.empty() )
|
bool all_null = true;
|
||||||
return;
|
|
||||||
|
/*
|
||||||
|
when we copy a session's object (and this object then)
|
||||||
|
we resize the table and there are only null pointers there
|
||||||
|
consequently if all pointers are null there is no sens
|
||||||
|
to send WINIX_PLUGIN_SESSION_DATA_REMOVE
|
||||||
|
*/
|
||||||
|
|
||||||
|
for(size_t i=0 ; i<table.size() ; ++i)
|
||||||
|
{
|
||||||
|
if( table[i] != 0 )
|
||||||
|
{
|
||||||
|
all_null = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
in the future this message may be removed
|
||||||
|
and we directly 'delete' the pointers
|
||||||
|
*/
|
||||||
|
|
||||||
|
if( !all_null )
|
||||||
|
plugin.Call(session, WINIX_PLUGIN_SESSION_DATA_REMOVE);
|
||||||
|
|
||||||
plugin.Call(WINIX_SESSION_REMOVE);
|
|
||||||
table.clear();
|
table.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginData::PluginData()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginData::PluginData(const PluginData & p)
|
|
||||||
{
|
|
||||||
operator=(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginData & PluginData::operator=(const PluginData & p)
|
|
||||||
{
|
|
||||||
// we don't copy all pointers - only resize the table
|
|
||||||
// pointers will be set to zero
|
|
||||||
Resize(p.Size());
|
|
||||||
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PluginData::~PluginData()
|
|
||||||
{
|
|
||||||
DeleteAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
size_t PluginData::Size() const
|
size_t PluginData::Size() const
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
class Session;
|
||||||
|
|
||||||
|
|
||||||
struct PluginDataBase
|
struct PluginDataBase
|
||||||
|
@ -21,9 +21,12 @@ struct PluginDataBase
|
||||||
virtual ~PluginDataBase() {}
|
virtual ~PluginDataBase() {}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
!! CHECK ME
|
||||||
|
it is still in use?
|
||||||
|
|
||||||
when deleting sessions we first call Clear() method
|
when deleting sessions we first call Clear() method
|
||||||
consequently the destructor has nothing to do
|
consequently the destructor has nothing to do
|
||||||
(and it doesn not throw an exception)
|
(and it does not throw an exception)
|
||||||
*/
|
*/
|
||||||
virtual void Clear() {}
|
virtual void Clear() {}
|
||||||
};
|
};
|
||||||
|
@ -35,6 +38,13 @@ class PluginData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
PluginData();
|
||||||
|
PluginData(const PluginData & p);
|
||||||
|
PluginData & operator=(const PluginData & p);
|
||||||
|
~PluginData();
|
||||||
|
|
||||||
|
void SetSession(Session * ses);
|
||||||
|
|
||||||
void Assign(size_t index, PluginDataBase * data);
|
void Assign(size_t index, PluginDataBase * data);
|
||||||
void Assign(PluginDataBase * data);
|
void Assign(PluginDataBase * data);
|
||||||
|
|
||||||
|
@ -43,17 +53,13 @@ public:
|
||||||
|
|
||||||
void DeleteAll();
|
void DeleteAll();
|
||||||
|
|
||||||
PluginData();
|
|
||||||
PluginData(const PluginData & p);
|
|
||||||
PluginData & operator=(const PluginData & p);
|
|
||||||
~PluginData();
|
|
||||||
|
|
||||||
size_t Size() const;
|
size_t Size() const;
|
||||||
void Resize(size_t new_size);
|
void Resize(size_t new_size);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Session * session;
|
||||||
std::vector<PluginDataBase*> table;
|
std::vector<PluginDataBase*> table;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,10 @@
|
||||||
#ifndef headerfile_winix_core_pluginmsg
|
#ifndef headerfile_winix_core_pluginmsg
|
||||||
#define headerfile_winix_core_pluginmsg
|
#define headerfile_winix_core_pluginmsg
|
||||||
|
|
||||||
|
|
||||||
// here you can add your own EZC functions ([function])
|
// here you can add your own EZC functions ([function])
|
||||||
// PluginInfo.p1 is a pointer to Ezc::Functions object
|
// PluginInfo.p1 is a pointer to Ezc::Functions object
|
||||||
|
// session pointer is null
|
||||||
#define WINIX_TEMPLATES_CREATEFUNCTIONS 999
|
#define WINIX_TEMPLATES_CREATEFUNCTIONS 999
|
||||||
|
|
||||||
// here you can add your own EZC functions to notify system
|
// here you can add your own EZC functions to notify system
|
||||||
|
@ -24,6 +26,7 @@
|
||||||
// Ezc::Functions<NotifyStream> ezc_functions;
|
// Ezc::Functions<NotifyStream> ezc_functions;
|
||||||
// and Notify Stream is:
|
// and Notify Stream is:
|
||||||
// typedef TextStream<std::wstring> NotifyStream;
|
// typedef TextStream<std::wstring> NotifyStream;
|
||||||
|
// session pointer is null
|
||||||
#define WINIX_NOTIFY_TEMPLATES_CREATEFUNCTIONS 998
|
#define WINIX_NOTIFY_TEMPLATES_CREATEFUNCTIONS 998
|
||||||
|
|
||||||
// winix function and parameters have been parsed
|
// winix function and parameters have been parsed
|
||||||
|
@ -48,13 +51,22 @@
|
||||||
|
|
||||||
// here you should remove your session data
|
// here you should remove your session data
|
||||||
// this message can be sent even if you don't assing your plugin data
|
// this message can be sent even if you don't assing your plugin data
|
||||||
#define WINIX_SESSION_REMOVE 30010
|
#define WINIX_PLUGIN_SESSION_DATA_REMOVE 30010
|
||||||
|
|
||||||
// when a session is changed (you can save a pointer to your data here)
|
// when a session is changed (you can save a pointer to your data here)
|
||||||
|
// 'session changed' means that there is a new request
|
||||||
|
// !! IMPROVE ME it has to be changed to a better name
|
||||||
#define WINIX_SESSION_CHANGED 30020
|
#define WINIX_SESSION_CHANGED 30020
|
||||||
|
|
||||||
|
// a session has changed its id
|
||||||
|
// it is typically when you are logging in
|
||||||
|
// 'login' winix function will change the session id (for security reasons)
|
||||||
|
// in l1 you have the old id, in l2 you have the new id
|
||||||
|
#define WINIX_SESSION_CHANGED_ID 30025
|
||||||
|
|
||||||
// the winix is closing
|
// the winix is closing
|
||||||
// there is not any sessions available (cur->session is null)
|
// there is not any sessions available (cur->session is null)
|
||||||
|
// session pointer is null
|
||||||
#define WINIX_CLOSE 30040
|
#define WINIX_CLOSE 30040
|
||||||
|
|
||||||
// preparing to remove a file (rm function)
|
// preparing to remove a file (rm function)
|
||||||
|
@ -84,14 +96,17 @@
|
||||||
|
|
||||||
// winix is initialized,
|
// winix is initialized,
|
||||||
// now you can initialize your plugin
|
// now you can initialize your plugin
|
||||||
|
// session pointer is null
|
||||||
#define WINIX_PLUGIN_INIT 30080
|
#define WINIX_PLUGIN_INIT 30080
|
||||||
|
|
||||||
// here you can add your own mount point, file systems, mount parameters
|
// here you can add your own mount point, file systems, mount parameters
|
||||||
// for adding a new mount type call: system->mounts.AddMountType("new_mount_name")
|
// for adding a new mount type call: system->mounts.AddMountType("new_mount_name")
|
||||||
|
// session pointer is null
|
||||||
#define WINIX_ADD_MOUNTS 30090
|
#define WINIX_ADD_MOUNTS 30090
|
||||||
|
|
||||||
// add plugin functions (winix functions) here
|
// add plugin functions (winix functions) here
|
||||||
// call info.functions->Add() to add a function
|
// call info.functions->Add() to add a function
|
||||||
|
// session pointer is null
|
||||||
#define WINIX_CREATE_FUNCTIONS 30100
|
#define WINIX_CREATE_FUNCTIONS 30100
|
||||||
|
|
||||||
// choose a default function
|
// choose a default function
|
||||||
|
@ -100,11 +115,13 @@
|
||||||
|
|
||||||
// /etc/fstab has been changed
|
// /etc/fstab has been changed
|
||||||
// now we have new mount points
|
// now we have new mount points
|
||||||
|
// session pointer is null
|
||||||
#define WINIX_FSTAB_CHANGED 30120
|
#define WINIX_FSTAB_CHANGED 30120
|
||||||
|
|
||||||
// here you add your own template to notification system
|
// here you add your own template to notification system
|
||||||
// call system->notify.AddTemplate() method
|
// call system->notify.AddTemplate() method
|
||||||
// with a template file name
|
// with a template file name
|
||||||
|
// session pointer is null
|
||||||
#define WINIX_NOTIFY_ADD_TEMPLATE 30130
|
#define WINIX_NOTIFY_ADD_TEMPLATE 30130
|
||||||
|
|
||||||
// the request is being ended
|
// the request is being ended
|
||||||
|
@ -143,14 +160,16 @@
|
||||||
|
|
||||||
// a thumbnail was created
|
// a thumbnail was created
|
||||||
// this message is called from another thread
|
// this message is called from another thread
|
||||||
// the thread is called Lock() before sending this message
|
// the thread called Lock() before sending this message
|
||||||
// in p1 you have a pointer to the Item struct
|
// in p1 you have a pointer to the Item struct
|
||||||
|
// session pointer is null
|
||||||
#define WINIX_CREATED_THUMB 30500
|
#define WINIX_CREATED_THUMB 30500
|
||||||
|
|
||||||
// an image has been resized
|
// an image has been resized
|
||||||
// this message is called from another thread
|
// this message is called from another thread
|
||||||
// the thread is called Lock() before sending this message
|
// the thread called Lock() before sending this message
|
||||||
// in p1 you have a pointer to the Item struct
|
// in p1 you have a pointer to the Item struct
|
||||||
|
// session pointer is null
|
||||||
#define WINIX_IMAGE_RESIZED 30520
|
#define WINIX_IMAGE_RESIZED 30520
|
||||||
|
|
||||||
// content of a directory was sorted
|
// content of a directory was sorted
|
||||||
|
@ -165,6 +184,8 @@
|
||||||
// a WINIX_USER_LOGGED is sent
|
// a WINIX_USER_LOGGED is sent
|
||||||
// in p1 you have a pointer to User struct
|
// in p1 you have a pointer to User struct
|
||||||
// (if at least one plugin returns false then the user will not be logged)
|
// (if at least one plugin returns false then the user will not be logged)
|
||||||
|
// this message is not sent when winix starts and sessions are read from a sessions file
|
||||||
|
// in such a case only WINIX_USER_LOGGED will be sent
|
||||||
#define WINIX_PREPARE_USER_TO_LOGIN 30550
|
#define WINIX_PREPARE_USER_TO_LOGIN 30550
|
||||||
|
|
||||||
// a user has been logged
|
// a user has been logged
|
||||||
|
@ -175,6 +196,9 @@
|
||||||
|
|
||||||
// a user is going to logout
|
// a user is going to logout
|
||||||
// in p1 you have a pointer to User struct
|
// in p1 you have a pointer to User struct
|
||||||
|
// the message is also sent from the session GC (special thread for deleting sessions)
|
||||||
|
// in such a case is sent with Lock() and Unlock()
|
||||||
|
// so *don't* use Lock() in your procedure
|
||||||
#define WINIX_PREPARE_USER_TO_LOGOUT 30610
|
#define WINIX_PREPARE_USER_TO_LOGOUT 30610
|
||||||
|
|
||||||
// here you add your own html templates
|
// here you add your own html templates
|
||||||
|
@ -185,6 +209,7 @@
|
||||||
// the message will be sent too whenever 'reload/templates' winix function is called
|
// the message will be sent too whenever 'reload/templates' winix function is called
|
||||||
// templates you should add only in this message
|
// templates you should add only in this message
|
||||||
// in other cases after 'reload' function the indexes would be wrong
|
// in other cases after 'reload' function the indexes would be wrong
|
||||||
|
// session pointer is null
|
||||||
#define WINIX_ADD_TEMPLATE 31000
|
#define WINIX_ADD_TEMPLATE 31000
|
||||||
|
|
||||||
// a user will be removed
|
// a user will be removed
|
||||||
|
|
|
@ -17,9 +17,34 @@ Session::Session()
|
||||||
{
|
{
|
||||||
SetTimeToNow();
|
SetTimeToNow();
|
||||||
Clear();
|
Clear();
|
||||||
|
plugin_data.SetSession(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Session::Session(const Session & ses)
|
||||||
|
{
|
||||||
|
operator=(ses);
|
||||||
|
}
|
||||||
|
|
||||||
|
Session & Session::operator=(const Session & ses)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
we can only copy ses.id because it is needen in SessionContainer
|
||||||
|
it have indexes to id
|
||||||
|
*/
|
||||||
|
|
||||||
|
Clear();
|
||||||
|
id = ses.id;
|
||||||
|
plugin_data.SetSession(this);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Session::SetTimeToNow()
|
void Session::SetTimeToNow()
|
||||||
{
|
{
|
||||||
time = std::time(0);
|
time = std::time(0);
|
||||||
|
@ -34,10 +59,9 @@ void Session::SetTimeToNow()
|
||||||
|
|
||||||
|
|
||||||
// this doesn't clear times
|
// this doesn't clear times
|
||||||
void Session::Clear()
|
void Session::Clear(bool clear_plugin_data)
|
||||||
{
|
{
|
||||||
id = 0;
|
id = 0;
|
||||||
time = 0;
|
|
||||||
puser = 0;
|
puser = 0;
|
||||||
rebus_item = 0;
|
rebus_item = 0;
|
||||||
rebus_checked = false;
|
rebus_checked = false;
|
||||||
|
@ -45,7 +69,9 @@ void Session::Clear()
|
||||||
new_session = true;
|
new_session = true;
|
||||||
spam_score = 0;
|
spam_score = 0;
|
||||||
remove_me = false;
|
remove_me = false;
|
||||||
plugin_data.Resize(0);
|
|
||||||
|
if( clear_plugin_data )
|
||||||
|
plugin_data.Resize(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,12 +21,17 @@
|
||||||
#include "textstream.h"
|
#include "textstream.h"
|
||||||
|
|
||||||
|
|
||||||
// when deleting Sessions you should set request.session into the session object as well
|
|
||||||
// this allows to delete plugins session data
|
|
||||||
// because a session object has plugin_data object
|
|
||||||
// and in its destructor the plugin.Call(WINIX_SESSION_REMOVE) is called
|
|
||||||
struct Session
|
struct Session
|
||||||
{
|
{
|
||||||
|
Session();
|
||||||
|
Session(const Session & ses);
|
||||||
|
Session & operator=(const Session & ses);
|
||||||
|
|
||||||
|
void SetTimeToNow();
|
||||||
|
void Clear(bool clear_plugin_data = true);
|
||||||
|
|
||||||
|
|
||||||
// 0 - means that there is a temporary session
|
// 0 - means that there is a temporary session
|
||||||
long id;
|
long id;
|
||||||
|
|
||||||
|
@ -75,9 +80,6 @@ struct Session
|
||||||
// used by some javascript wysiwyg editors (ckeditor, tinymce)
|
// used by some javascript wysiwyg editors (ckeditor, tinymce)
|
||||||
std::vector<std::wstring> last_css;
|
std::vector<std::wstring> last_css;
|
||||||
|
|
||||||
Session();
|
|
||||||
void SetTimeToNow();
|
|
||||||
void Clear();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,43 +44,52 @@ Table::iterator i = table.begin();
|
||||||
|
|
||||||
log << log3 << "SC: deleting all sessions" << logend;
|
log << log3 << "SC: deleting all sessions" << logend;
|
||||||
|
|
||||||
|
cur->session = tmp_session;
|
||||||
|
|
||||||
// don't use table.clear();
|
// don't use table.clear();
|
||||||
// because plugins session data would not be erased
|
// because plugins session data would not be erased
|
||||||
// we must set cur->session for each session and then delete it
|
|
||||||
while( i != table.end() )
|
while( i != table.end() )
|
||||||
{
|
{
|
||||||
cur->session = &(*i);
|
i->plugin_data.DeleteAll(); // it's better to call it here instead in the destructor
|
||||||
cur->session->plugin_data.DeleteAll(); // it's better to call it here instead of the destructor
|
|
||||||
table.erase(i++);
|
table.erase(i++);
|
||||||
}
|
}
|
||||||
|
|
||||||
// erasing indexes
|
// erasing indexes
|
||||||
index_id.clear();
|
index_id.clear();
|
||||||
table_size = 0;
|
table_size = 0;
|
||||||
cur->session = tmp_session;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SessionContainer::EraseById(IdIterator i)
|
void SessionContainer::EraseById(long id)
|
||||||
{
|
{
|
||||||
Session * old_session = tmp_session;
|
IndexId::iterator i = index_id.find(id);
|
||||||
|
|
||||||
if( cur->session != &(*i->second) )
|
if( i != index_id.end() )
|
||||||
old_session = cur->session;
|
{
|
||||||
|
Session * old_session = tmp_session;
|
||||||
|
|
||||||
cur->session = &(*i->second);
|
if( cur->session != &(*i->second) )
|
||||||
|
old_session = cur->session;
|
||||||
|
|
||||||
log << log4 << "SC: deleting session, id: " << i->second->id << logend;
|
cur->session = &(*i->second);
|
||||||
|
|
||||||
// call first DeleteAll() because if not then it would be called from the desctructor
|
log << log4 << "SC: deleting session, id: " << i->second->id << logend;
|
||||||
// and there'll be a problem if it throws an exception there
|
|
||||||
i->second->plugin_data.DeleteAll();
|
|
||||||
table.erase(i->second);
|
|
||||||
index_id.erase(i);
|
|
||||||
table_size -= 1;
|
|
||||||
|
|
||||||
cur->session = old_session;
|
// call first DeleteAll() because if not then it would be called from the destructor
|
||||||
|
// and there'll be a problem if it throws an exception there
|
||||||
|
i->second->plugin_data.DeleteAll();
|
||||||
|
table.erase(i->second);
|
||||||
|
index_id.erase(i);
|
||||||
|
table_size -= 1;
|
||||||
|
|
||||||
|
cur->session = old_session;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log1 << "SC: I cannot delete a session with id: " << id
|
||||||
|
<< " (there is no such a session)" << logend;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,23 +132,24 @@ SessionContainer::IdIterator SessionContainer::IdEnd()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool SessionContainer::PushBack(const Session & session)
|
SessionContainer::Iterator SessionContainer::AddSession(long id)
|
||||||
{
|
{
|
||||||
std::pair<IndexId::iterator, bool> index_id_res = index_id.insert( std::make_pair(session.id, table.end()) );
|
std::pair<IndexId::iterator, bool> index_id_res = index_id.insert( std::make_pair(id, table.end()) );
|
||||||
|
|
||||||
if( !index_id_res.second )
|
if( !index_id_res.second )
|
||||||
{
|
{
|
||||||
// that element already exists (was not inserted now)
|
// that element already exists (was not inserted now)
|
||||||
return false;
|
return End();
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator last = table.insert(table.end(), session);
|
Iterator last = table.insert(table.end(), empty_session);
|
||||||
|
last->id = id;
|
||||||
index_id_res.first->second = last;
|
index_id_res.first->second = last;
|
||||||
table_size += 1;
|
table_size += 1;
|
||||||
|
|
||||||
log << log3 << "SC: added session, id: " << session.id << logend;
|
log << log3 << "SC: added session, id: " << id << logend;
|
||||||
|
|
||||||
return true;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -158,6 +168,41 @@ return i->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SessionContainer::ChangeSessionId(SessionContainer::Iterator ses, long new_id)
|
||||||
|
{
|
||||||
|
std::pair<IndexId::iterator, bool> index_id_res = index_id.insert( std::make_pair(new_id, ses) );
|
||||||
|
|
||||||
|
if( !index_id_res.second )
|
||||||
|
{
|
||||||
|
log << log1 << "SC: session with id: " << new_id << " already exists" << logend;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
long old_id = ses->id;
|
||||||
|
index_id.erase(old_id); // remove the old index
|
||||||
|
ses->id = new_id;
|
||||||
|
log << log3 << "SC: changed session id from: " << old_id << " to " << new_id << logend;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SessionContainer::ChangeSessionId(long old_id, long new_id)
|
||||||
|
{
|
||||||
|
IndexId::iterator i = index_id.find(old_id);
|
||||||
|
|
||||||
|
if( i != index_id.end() )
|
||||||
|
{
|
||||||
|
return ChangeSessionId(i->second, new_id);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log2 << "SC: there is no a session with id: " << old_id << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,6 @@ class SessionContainer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// when deleting Sessions you should set cur->session into the session object
|
|
||||||
// this allows to delete plugins session data
|
|
||||||
// because a session object has plugin_data object
|
|
||||||
// and in its destructor the plugin.Call(WINIX_SESSION_REMOVE) is called
|
|
||||||
typedef std::list<Session> Table;
|
typedef std::list<Session> Table;
|
||||||
typedef Table::iterator Iterator;
|
typedef Table::iterator Iterator;
|
||||||
typedef std::map<long, Iterator> IndexId;
|
typedef std::map<long, Iterator> IndexId;
|
||||||
|
@ -46,13 +42,16 @@ public:
|
||||||
Iterator Begin();
|
Iterator Begin();
|
||||||
Iterator End();
|
Iterator End();
|
||||||
Session & Back();
|
Session & Back();
|
||||||
bool PushBack(const Session & session);
|
Iterator AddSession(long id);
|
||||||
Iterator FindById(long);
|
Iterator FindById(long);
|
||||||
|
|
||||||
IdIterator IdBegin();
|
IdIterator IdBegin();
|
||||||
IdIterator IdEnd();
|
IdIterator IdEnd();
|
||||||
|
|
||||||
void EraseById(IdIterator i);
|
void EraseById(long id);
|
||||||
|
|
||||||
|
bool ChangeSessionId(Iterator ses, long new_id);
|
||||||
|
bool ChangeSessionId(long old_id, long new_id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -63,6 +62,8 @@ private:
|
||||||
Config * config;
|
Config * config;
|
||||||
Session * tmp_session;
|
Session * tmp_session;
|
||||||
|
|
||||||
|
Session empty_session;
|
||||||
|
|
||||||
// in FreeBSD implementation (GCC) list::size() has linear complexity
|
// in FreeBSD implementation (GCC) list::size() has linear complexity
|
||||||
// so we use our own table_size with O(1)
|
// so we use our own table_size with O(1)
|
||||||
size_t table_size;
|
size_t table_size;
|
||||||
|
|
|
@ -108,18 +108,15 @@ return id;
|
||||||
|
|
||||||
void SessionManager::CreateSession()
|
void SessionManager::CreateSession()
|
||||||
{
|
{
|
||||||
int attempts = 100;
|
int attempts = 100;
|
||||||
bool added = false;
|
SessionContainer::Iterator i = session_tab.End();
|
||||||
|
|
||||||
new_session.SetTimeToNow();
|
|
||||||
new_session.Clear();
|
|
||||||
|
|
||||||
if( config->session_max == 0 || session_tab.Size() < config->session_max )
|
if( config->session_max == 0 || session_tab.Size() < config->session_max )
|
||||||
{
|
{
|
||||||
for( ; !added && attempts > 0 ; --attempts )
|
for( ; i == session_tab.End() && attempts > 0 ; --attempts )
|
||||||
{
|
{
|
||||||
new_session.id = CreateSessionId();
|
long id = CreateSessionId();
|
||||||
added = session_tab.PushBack(new_session);
|
i = session_tab.AddSession(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -127,10 +124,12 @@ bool added = false;
|
||||||
log << log2 << "SM: sessions limit exceeded (" << config->session_max << ")" << logend;
|
log << log2 << "SM: sessions limit exceeded (" << config->session_max << ")" << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( added )
|
if( i != session_tab.End() )
|
||||||
{
|
{
|
||||||
session = &session_tab.Back();
|
session = &(*i);
|
||||||
session->new_session = true;
|
session->new_session = true;
|
||||||
|
session->SetTimeToNow();
|
||||||
|
|
||||||
log << log2 << "SM: created a new session: " << session->id << logend;
|
log << log2 << "SM: created a new session: " << session->id << logend;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -138,8 +137,8 @@ bool added = false;
|
||||||
// there is a problem with generating a new session id
|
// there is a problem with generating a new session id
|
||||||
// we do not set a session cookie
|
// we do not set a session cookie
|
||||||
session = &temporary_session;
|
session = &temporary_session;
|
||||||
|
session->Clear(false);
|
||||||
session->SetTimeToNow();
|
session->SetTimeToNow();
|
||||||
session->Clear(); // !! uwaga ten Clear wyczysci plugins data
|
|
||||||
session->new_session = false; // temporary session was initialized at the beginning
|
session->new_session = false; // temporary session was initialized at the beginning
|
||||||
log << log1 << "SM: cannot create a session id (temporary used: with id 0)" << logend;
|
log << log1 << "SM: cannot create a session id (temporary used: with id 0)" << logend;
|
||||||
}
|
}
|
||||||
|
@ -226,8 +225,7 @@ void SessionManager::DeleteSessions()
|
||||||
{
|
{
|
||||||
if( i->puser && !i->remember_me )
|
if( i->puser && !i->remember_me )
|
||||||
{
|
{
|
||||||
cur->session = &(*i); // for correctly setting a session data in plugins
|
plugin.Call(&(*i), WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
|
||||||
plugin.Call(WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
|
|
||||||
last_container->UserLogout(i->puser->id, i->id);
|
last_container->UserLogout(i->puser->id, i->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,6 +235,41 @@ void SessionManager::DeleteSessions()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
don't change a session's id when a user is logged
|
||||||
|
the session id is in last_container and the user would not be
|
||||||
|
correctly removed from the container
|
||||||
|
*/
|
||||||
|
bool SessionManager::ChangeSessionId(long old_id)
|
||||||
|
{
|
||||||
|
int attempts = 100;
|
||||||
|
bool changed = false;
|
||||||
|
long new_id;
|
||||||
|
SessionContainer::Iterator i = session_tab.FindById(old_id);
|
||||||
|
|
||||||
|
if( i != session_tab.End() )
|
||||||
|
{
|
||||||
|
for( ; !changed && attempts > 0 ; --attempts )
|
||||||
|
{
|
||||||
|
new_id = CreateSessionId();
|
||||||
|
changed = session_tab.ChangeSessionId(i, new_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if( changed )
|
||||||
|
plugin.Call(&(*i), WINIX_SESSION_CHANGED_ID, old_id, new_id);
|
||||||
|
else
|
||||||
|
log << log1 << "SM: I cannot create a new session id (still uses old one)" << logend;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log2 << "SM: there is no a session with id: " << old_id << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SessionManager::InitTmpSession()
|
void SessionManager::InitTmpSession()
|
||||||
{
|
{
|
||||||
Session * old_session = cur->session;
|
Session * old_session = cur->session;
|
||||||
|
@ -256,7 +289,7 @@ void SessionManager::UninitTmpSession()
|
||||||
|
|
||||||
log << log4 << "SM: uninitializing temporary session" << logend;
|
log << log4 << "SM: uninitializing temporary session" << logend;
|
||||||
cur->session = &temporary_session;
|
cur->session = &temporary_session;
|
||||||
cur->session->plugin_data.DeleteAll(); // this will call plugin.Call(WINIX_SESSION_REMOVE);
|
cur->session->plugin_data.DeleteAll(); // this will call plugin.Call(WINIX_PLUGIN_SESSION_DATA_REMOVE);
|
||||||
cur->session->plugin_data.Resize(0);
|
cur->session->plugin_data.Resize(0);
|
||||||
|
|
||||||
cur->session = old_session;
|
cur->session = old_session;
|
||||||
|
@ -278,11 +311,15 @@ SessionContainer::Iterator i;
|
||||||
for(i=session_tab.Begin() ; i != session_tab.End() ; ++i)
|
for(i=session_tab.Begin() ; i != session_tab.End() ; ++i)
|
||||||
{
|
{
|
||||||
i->plugin_data.Resize(plugin.Size());
|
i->plugin_data.Resize(plugin.Size());
|
||||||
cur->session = &(*i);
|
plugin.Call(&(*i), WINIX_SESSION_CREATED);
|
||||||
plugin.Call(WINIX_SESSION_CREATED);
|
|
||||||
|
|
||||||
if( cur->session->puser )
|
/*
|
||||||
plugin.Call(WINIX_USER_LOGGED);
|
!! IMPROVE ME
|
||||||
|
we do not add it to the last_container (we don't have IP address stored yet)
|
||||||
|
*/
|
||||||
|
|
||||||
|
if( i->puser )
|
||||||
|
plugin.Call(&(*i), WINIX_USER_LOGGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
cur->session = &temporary_session;
|
cur->session = &temporary_session;
|
||||||
|
@ -347,14 +384,12 @@ size_t SessionManager::MarkAllSessionsToRemove(long user_id)
|
||||||
{
|
{
|
||||||
size_t how_many = 0;
|
size_t how_many = 0;
|
||||||
SessionContainer::Iterator i;
|
SessionContainer::Iterator i;
|
||||||
Session * old_session = cur->session;
|
|
||||||
|
|
||||||
for(i=session_tab.Begin() ; i!=session_tab.End() ; ++i)
|
for(i=session_tab.Begin() ; i!=session_tab.End() ; ++i)
|
||||||
{
|
{
|
||||||
if( i->puser && i->puser->id == user_id )
|
if( i->puser && i->puser->id == user_id )
|
||||||
{
|
{
|
||||||
cur->session = &(*i); // for correctly setting a session data in plugins
|
plugin.Call(&(*i), WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
|
||||||
plugin.Call(WINIX_PREPARE_USER_TO_LOGOUT, i->puser);
|
|
||||||
last_container->UserLogout(i->puser->id, i->id);
|
last_container->UserLogout(i->puser->id, i->id);
|
||||||
i->remove_me = true;
|
i->remove_me = true;
|
||||||
i->puser = 0;
|
i->puser = 0;
|
||||||
|
@ -362,8 +397,6 @@ size_t SessionManager::MarkAllSessionsToRemove(long user_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cur->session = old_session;
|
|
||||||
|
|
||||||
return how_many;
|
return how_many;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,18 +407,20 @@ return how_many;
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* sessions gc (second thread)
|
* sessions gc (second thread)
|
||||||
*
|
* sessions are only removed here
|
||||||
|
* SessionContainer::IndexId can be removed from the other thread
|
||||||
|
* (when ChangeSessionId() method is called)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void SessionManager::Work()
|
void SessionManager::Work()
|
||||||
{
|
{
|
||||||
bool exit = false;
|
bool exit = false;
|
||||||
SessionContainer::IndexId::iterator i;
|
SessionContainer::Iterator i;
|
||||||
|
|
||||||
deleted = 0;
|
deleted = 0;
|
||||||
|
|
||||||
Lock();
|
Lock();
|
||||||
i = session_tab.IdBegin();
|
i = session_tab.Begin();
|
||||||
Unlock();
|
Unlock();
|
||||||
|
|
||||||
while( !exit )
|
while( !exit )
|
||||||
|
@ -401,11 +436,11 @@ SessionContainer::IndexId::iterator i;
|
||||||
|
|
||||||
|
|
||||||
// it's called from the other thread (with Lock and Unlock)
|
// it's called from the other thread (with Lock and Unlock)
|
||||||
void SessionManager::CheckSession(SessionContainer::IndexId::iterator & i)
|
void SessionManager::CheckSession(SessionContainer::Iterator & i)
|
||||||
{
|
{
|
||||||
const int deleted_max_at_once = 10;
|
const int deleted_max_at_once = 10;
|
||||||
|
|
||||||
if( i == session_tab.IdEnd() )
|
if( i == session_tab.End() )
|
||||||
{
|
{
|
||||||
if( deleted > 0 )
|
if( deleted > 0 )
|
||||||
{
|
{
|
||||||
|
@ -413,14 +448,16 @@ const int deleted_max_at_once = 10;
|
||||||
log << logsave;
|
log << logsave;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = session_tab.IdBegin();
|
i = session_tab.Begin();
|
||||||
WaitForSignalSleep(10);
|
WaitForSignalSleep(10);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( i->second->remove_me || IsSessionOutdated(*i->second) )
|
if( i->remove_me || IsSessionOutdated(*i) )
|
||||||
{
|
{
|
||||||
DeleteSession(i++);
|
Session * ses = &(*i);
|
||||||
|
++i;
|
||||||
|
DeleteSession(ses);
|
||||||
++deleted;
|
++deleted;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -444,9 +481,13 @@ bool SessionManager::IsSessionOutdated(const Session & s) const
|
||||||
bool outdated;
|
bool outdated;
|
||||||
|
|
||||||
if( s.remember_me )
|
if( s.remember_me )
|
||||||
|
{
|
||||||
outdated = s.last_time < std::time(0) - config->session_remember_max_idle;
|
outdated = s.last_time < std::time(0) - config->session_remember_max_idle;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
outdated = s.last_time < std::time(0) - config->session_max_idle;
|
outdated = s.last_time < std::time(0) - config->session_max_idle;
|
||||||
|
}
|
||||||
|
|
||||||
return outdated;
|
return outdated;
|
||||||
}
|
}
|
||||||
|
@ -454,14 +495,16 @@ return outdated;
|
||||||
|
|
||||||
|
|
||||||
// it's called from the other thread (with Lock and Unlock)
|
// it's called from the other thread (with Lock and Unlock)
|
||||||
void SessionManager::DeleteSession(SessionContainer::IdIterator i)
|
void SessionManager::DeleteSession(Session * del_session)
|
||||||
{
|
{
|
||||||
Session * del_session = &(*i->second);
|
|
||||||
|
|
||||||
if( del_session->puser )
|
if( del_session->puser )
|
||||||
|
{
|
||||||
|
plugin.Call(del_session, WINIX_PREPARE_USER_TO_LOGOUT, del_session->puser);
|
||||||
last_container->UserLogout(del_session->puser->id, del_session->id);
|
last_container->UserLogout(del_session->puser->id, del_session->id);
|
||||||
|
del_session->puser = 0;
|
||||||
|
}
|
||||||
|
|
||||||
session_tab.EraseById(i);
|
session_tab.EraseById(del_session->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
|
|
||||||
void SetSession();
|
void SetSession();
|
||||||
void DeleteSessions(); // deleting all sessions
|
void DeleteSessions(); // deleting all sessions
|
||||||
|
bool ChangeSessionId(long old_id);
|
||||||
|
|
||||||
void InitTmpSession();
|
void InitTmpSession();
|
||||||
void UninitTmpSession();
|
void UninitTmpSession();
|
||||||
|
@ -68,9 +69,6 @@ private:
|
||||||
// session with id 0
|
// session with id 0
|
||||||
Session temporary_session;
|
Session temporary_session;
|
||||||
|
|
||||||
// for adding a new session to the container
|
|
||||||
Session new_session;
|
|
||||||
|
|
||||||
bool IsSession(long s);
|
bool IsSession(long s);
|
||||||
|
|
||||||
long CreateSessionId();
|
long CreateSessionId();
|
||||||
|
@ -81,9 +79,9 @@ private:
|
||||||
// second thread
|
// second thread
|
||||||
int deleted;
|
int deleted;
|
||||||
virtual void Work();
|
virtual void Work();
|
||||||
void CheckSession(SessionContainer::IndexId::iterator & i);
|
void CheckSession(SessionContainer::Iterator & i);
|
||||||
bool IsSessionOutdated(const Session & s) const;
|
bool IsSessionOutdated(const Session & s) const;
|
||||||
void DeleteSession(SessionContainer::IdIterator i);
|
void DeleteSession(Session * del_session);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -51,33 +51,19 @@ bool SessionParser::Parse(SessionContainer & container)
|
||||||
file format, each rows:
|
file format, each rows:
|
||||||
session_id(long) user_id(long) remember_me(0|1) time(long) last_time(long)
|
session_id(long) user_id(long) remember_me(0|1) time(long) last_time(long)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
long user_id;
|
|
||||||
|
|
||||||
session.Clear();
|
|
||||||
last = file.get();
|
last = file.get();
|
||||||
|
|
||||||
log << log2 << "SP: reading sessions from the session file" << logend;
|
log << log2 << "SP: reading sessions from the session file" << logend;
|
||||||
|
|
||||||
while( true )
|
while( true )
|
||||||
{
|
{
|
||||||
session.id = ReadLong();
|
long id = ReadLong();
|
||||||
|
|
||||||
if( file.eof() )
|
if( file.eof() )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
user_id = ReadLong();
|
long user_id = ReadLong();
|
||||||
session.remember_me = ReadLong();
|
MakeSession(id, user_id, container);
|
||||||
session.time = ReadLong();
|
|
||||||
session.last_time = ReadLong();
|
|
||||||
|
|
||||||
if( MakeSession(user_id) )
|
|
||||||
{
|
|
||||||
users->IncrementLoggedUsers();
|
|
||||||
container.PushBack(session);
|
|
||||||
log << log2 << "SP: read session id: " << session.id << " for user: " << session.puser->name << logend;
|
|
||||||
}
|
|
||||||
|
|
||||||
SkipLine();
|
SkipLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,22 +73,37 @@ return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SessionParser::MakeSession(long user_id)
|
void SessionParser::MakeSession(long id, long user_id, SessionContainer & container)
|
||||||
{
|
{
|
||||||
User * puser = users->GetUser(user_id);
|
User * puser = users->GetUser(user_id);
|
||||||
|
|
||||||
if( !puser )
|
if( !puser )
|
||||||
{
|
{
|
||||||
log << log1 << "SP: there is no a user with id: " << user_id << " (skipped)" << logend;
|
log << log1 << "SP: there is no a user with id: " << user_id << " (skipped)" << logend;
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
session.puser = puser;
|
SessionContainer::Iterator i = container.AddSession(id);
|
||||||
session.new_session = true;
|
|
||||||
session.tm_time = Time(session.time);
|
|
||||||
session.tm_last_time = Time(session.last_time);
|
|
||||||
|
|
||||||
return true;
|
if( i != container.End() )
|
||||||
|
{
|
||||||
|
i->Clear();
|
||||||
|
i->id = id;
|
||||||
|
i->puser = puser;
|
||||||
|
i->new_session = true;
|
||||||
|
i->remember_me = ReadLong();
|
||||||
|
i->time = ReadLong();
|
||||||
|
i->last_time = ReadLong();
|
||||||
|
i->tm_time = Time(i->time);
|
||||||
|
i->tm_last_time = Time(i->last_time);
|
||||||
|
|
||||||
|
users->IncrementLoggedUsers();
|
||||||
|
log << log2 << "SP: read session id: " << id << " for user: " << puser->name << logend;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log1 << "SP: session with id: " << id << " already exists (skipping)" << logend;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ private:
|
||||||
Users * users;
|
Users * users;
|
||||||
|
|
||||||
bool Parse(SessionContainer & container);
|
bool Parse(SessionContainer & container);
|
||||||
bool MakeSession(long user_id);
|
void MakeSession(long id, long user_id, SessionContainer & container);
|
||||||
|
|
||||||
bool IsWhite(int c);
|
bool IsWhite(int c);
|
||||||
bool IsDigit(int c);
|
bool IsDigit(int c);
|
||||||
|
@ -42,7 +42,6 @@ private:
|
||||||
|
|
||||||
std::ifstream file;
|
std::ifstream file;
|
||||||
int last; // last character
|
int last; // last character
|
||||||
Session session;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -231,6 +231,10 @@ bool Users::LoginUser(long user_id, bool remember_me, bool use_ses_log)
|
||||||
cur->session->spam_score = 0;
|
cur->session->spam_score = 0;
|
||||||
cur->session->remember_me = remember_me;
|
cur->session->remember_me = remember_me;
|
||||||
|
|
||||||
|
// change session id before last.UserLogin()
|
||||||
|
if( !cur->session->new_session )
|
||||||
|
session_manager->ChangeSessionId(cur->session->id);
|
||||||
|
|
||||||
last.UserLogin(user_id, cur->session->puser->name, inet_addr(cur->request->env_remote_addr), cur->session->id);
|
last.UserLogin(user_id, cur->session->puser->name, inet_addr(cur->request->env_remote_addr), cur->session->id);
|
||||||
how_many_logged += 1;
|
how_many_logged += 1;
|
||||||
|
|
||||||
|
|
|
@ -217,7 +217,7 @@ void Functions::CreateFunctions()
|
||||||
Add(fun_who);
|
Add(fun_who);
|
||||||
Add(fun_vim);
|
Add(fun_vim);
|
||||||
|
|
||||||
plugin.Call(WINIX_CREATE_FUNCTIONS);
|
plugin.Call((Session*)0, WINIX_CREATE_FUNCTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@ int main(int argv, char ** argc)
|
||||||
app.Start();
|
app.Start();
|
||||||
|
|
||||||
app.Lock();
|
app.Lock();
|
||||||
plugin.Call(WINIX_CLOSE);
|
plugin.Call((Session*)0, WINIX_CLOSE);
|
||||||
app.Close();
|
app.Close();
|
||||||
// now all sessions are cleared
|
// now all sessions are cleared
|
||||||
app.Unlock();
|
app.Unlock();
|
||||||
|
|
|
@ -67,7 +67,7 @@ void Notify::Init()
|
||||||
notify_template_activate_account = AddTemplate(L"notify_confirm_account.txt");
|
notify_template_activate_account = AddTemplate(L"notify_confirm_account.txt");
|
||||||
notify_template_reset_password = AddTemplate(L"notify_reset_password.txt");
|
notify_template_reset_password = AddTemplate(L"notify_reset_password.txt");
|
||||||
|
|
||||||
plugin.Call(WINIX_NOTIFY_ADD_TEMPLATE);
|
plugin.Call((Session*)0, WINIX_NOTIFY_ADD_TEMPLATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ void CreateFunctions()
|
||||||
ezc_functions.Insert("notify_item_link", notify_item_link);
|
ezc_functions.Insert("notify_item_link", notify_item_link);
|
||||||
ezc_functions.Insert("notify_dir_link", notify_dir_link);
|
ezc_functions.Insert("notify_dir_link", notify_dir_link);
|
||||||
|
|
||||||
plugin.Call(WINIX_NOTIFY_TEMPLATES_CREATEFUNCTIONS, &ezc_functions);
|
plugin.Call((Session*)0, WINIX_NOTIFY_TEMPLATES_CREATEFUNCTIONS, &ezc_functions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ StatsSession * stats_session = 0;
|
||||||
void SessionCreated(PluginInfo & info)
|
void SessionCreated(PluginInfo & info)
|
||||||
{
|
{
|
||||||
StatsSession * d = new StatsSession();
|
StatsSession * d = new StatsSession();
|
||||||
info.cur->session->plugin_data.Assign(d);
|
info.session->plugin_data.Assign(d);
|
||||||
|
|
||||||
if( !info.cur->request->IsParam(nostat_param) )
|
if( !info.cur->request->IsParam(nostat_param) )
|
||||||
{
|
{
|
||||||
|
@ -141,7 +141,7 @@ void RemoveSession(PluginInfo & info)
|
||||||
{
|
{
|
||||||
// temporarily for debug
|
// temporarily for debug
|
||||||
// sometimes the pointer is null here
|
// sometimes the pointer is null here
|
||||||
log << log1 << "Stats: why the info.plugin_data_base is zero? !!!!, ses_id: " << info.cur->session->id << logend;
|
log << log1 << "Stats: why the info.plugin_data_base is zero? !!!!, ses_id: " << info.session->id << logend;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ using namespace Stats;
|
||||||
plugin.Assign(WINIX_TEMPLATES_CREATEFUNCTIONS, CreateFunctions);
|
plugin.Assign(WINIX_TEMPLATES_CREATEFUNCTIONS, CreateFunctions);
|
||||||
plugin.Assign(WINIX_CONTENT_MAKE, ContentMake);
|
plugin.Assign(WINIX_CONTENT_MAKE, ContentMake);
|
||||||
plugin.Assign(WINIX_SESSION_CREATED, SessionCreated);
|
plugin.Assign(WINIX_SESSION_CREATED, SessionCreated);
|
||||||
plugin.Assign(WINIX_SESSION_REMOVE, RemoveSession);
|
plugin.Assign(WINIX_PLUGIN_SESSION_DATA_REMOVE, RemoveSession);
|
||||||
plugin.Assign(WINIX_CLOSE, Close);
|
plugin.Assign(WINIX_CLOSE, Close);
|
||||||
plugin.Assign(WINIX_FILE_REMOVED, RemoveFile);
|
plugin.Assign(WINIX_FILE_REMOVED, RemoveFile);
|
||||||
plugin.Assign(WINIX_DIR_PREPARE_TO_REMOVE, RemoveDir);
|
plugin.Assign(WINIX_DIR_PREPARE_TO_REMOVE, RemoveDir);
|
||||||
|
|
|
@ -117,7 +117,7 @@ void CreateSession(PluginInfo & info)
|
||||||
SessionData * p = new SessionData();
|
SessionData * p = new SessionData();
|
||||||
|
|
||||||
p->fun_rm = &info.functions->fun_rm;
|
p->fun_rm = &info.functions->fun_rm;
|
||||||
info.cur->session->plugin_data.Assign(p);
|
info.session->plugin_data.Assign(p);
|
||||||
log << log4 << "Ticket: created ticket plugin data: " << (void*)p << logend;
|
log << log4 << "Ticket: created ticket plugin data: " << (void*)p << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ using namespace Ticket;
|
||||||
plugin.Assign(WINIX_FILE_REMOVED, RemoveTicket);
|
plugin.Assign(WINIX_FILE_REMOVED, RemoveTicket);
|
||||||
plugin.Assign(WINIX_NOTIFY_ADD_TEMPLATE, AddNotifyTemplate);
|
plugin.Assign(WINIX_NOTIFY_ADD_TEMPLATE, AddNotifyTemplate);
|
||||||
plugin.Assign(WINIX_SESSION_CREATED, CreateSession);
|
plugin.Assign(WINIX_SESSION_CREATED, CreateSession);
|
||||||
plugin.Assign(WINIX_SESSION_REMOVE, RemoveSession);
|
plugin.Assign(WINIX_PLUGIN_SESSION_DATA_REMOVE, RemoveSession);
|
||||||
plugin.Assign(WINIX_END_REQUEST, EndRequest);
|
plugin.Assign(WINIX_END_REQUEST, EndRequest);
|
||||||
|
|
||||||
tdb.SetConn(info.db->GetConn());
|
tdb.SetConn(info.db->GetConn());
|
||||||
|
|
|
@ -581,7 +581,7 @@ void Templates::CreateFunctions()
|
||||||
ezc_functions.Insert("content", content);
|
ezc_functions.Insert("content", content);
|
||||||
|
|
||||||
|
|
||||||
plugin.Call(WINIX_TEMPLATES_CREATEFUNCTIONS, &ezc_functions);
|
plugin.Call((Session*)0, WINIX_TEMPLATES_CREATEFUNCTIONS, &ezc_functions);
|
||||||
log << log3 << "Templates: there are " << ezc_functions.Size() << " ezc functions" << logend;
|
log << log3 << "Templates: there are " << ezc_functions.Size() << " ezc functions" << logend;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,7 +755,7 @@ using namespace TemplatesFunctions;
|
||||||
ReadIndexTemplates();
|
ReadIndexTemplates();
|
||||||
ReadChangeTemplates();
|
ReadChangeTemplates();
|
||||||
|
|
||||||
plugin.Call(WINIX_ADD_TEMPLATE);
|
plugin.Call((Session*)0, WINIX_ADD_TEMPLATE);
|
||||||
|
|
||||||
SetHtmlFilter();
|
SetHtmlFilter();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue