added: plugin mechanism
files: core/plugin.h core/plugin.cpp core/pluginmsg.h added: directory 'main' with main.cpp (moved from 'core' directory) changed: the way of building nearly everything is in cmslu.so only main() is in cmslu and is dynamically linked with cmslu.so git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@516 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -12,7 +12,7 @@ all: $(o)
|
||||
|
||||
|
||||
depend:
|
||||
makedepend $(DEPMACROS) -Y. -f- *.cpp > Makefile.dep
|
||||
makedepend -Y. -f- *.cpp > Makefile.dep
|
||||
echo -n "o = " > Makefile.o.dep
|
||||
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
||||
|
||||
|
@@ -4,7 +4,9 @@ acceptbaseparser.o: acceptbaseparser.h
|
||||
compress.o: compress.h log.h
|
||||
config.o: config.h ../confparser/confparser.h log.h data.h dirs.h item.h
|
||||
config.o: dircontainer.h users.h user.h ugcontainer.h groups.h group.h
|
||||
config.o: functions.h function.h lastcontainer.h mounts.h mount.h
|
||||
config.o: functions.h function.h lastcontainer.h mounts.h mount.h plugin.h
|
||||
config.o: request.h requesttypes.h session.h done.h error.h thread.h
|
||||
config.o: compress.h acceptencodingparser.h acceptbaseparser.h pluginmsg.h
|
||||
data.o: data.h dirs.h item.h dircontainer.h users.h user.h ugcontainer.h
|
||||
data.o: log.h groups.h group.h functions.h function.h lastcontainer.h
|
||||
data.o: mounts.h mount.h
|
||||
@@ -20,28 +22,17 @@ done.o: done.h
|
||||
error.o: error.h log.h
|
||||
function.o: function.h item.h
|
||||
functioncodeparser.o: functioncodeparser.h item.h function.h log.h
|
||||
functionparser.o: functionparser.h requesttypes.h ../app/content.h log.h
|
||||
functionparser.o: item.h error.h data.h dirs.h dircontainer.h users.h user.h
|
||||
functionparser.o: ugcontainer.h groups.h group.h functions.h function.h
|
||||
functionparser.o: lastcontainer.h mounts.h mount.h db.h thread.h request.h
|
||||
functionparser.o: session.h done.h compress.h acceptencodingparser.h
|
||||
functionparser.o: acceptbaseparser.h
|
||||
functionparser.o: functionparser.h requesttypes.h log.h item.h error.h data.h
|
||||
functionparser.o: dirs.h dircontainer.h users.h user.h ugcontainer.h groups.h
|
||||
functionparser.o: group.h functions.h function.h lastcontainer.h mounts.h
|
||||
functionparser.o: mount.h db.h thread.h request.h session.h done.h compress.h
|
||||
functionparser.o: acceptencodingparser.h acceptbaseparser.h
|
||||
functions.o: functions.h function.h item.h
|
||||
groups.o: groups.h group.h ugcontainer.h log.h db.h item.h user.h thread.h
|
||||
groups.o: error.h dircontainer.h
|
||||
httpsimpleparser.o: httpsimpleparser.h
|
||||
lastcontainer.o: lastcontainer.h log.h
|
||||
log.o: log.h
|
||||
main.o: requestcontroller.h ../content/content.h ../core/item.h
|
||||
main.o: ../templates/templates.h ../../ezc/src/ezc.h
|
||||
main.o: ../templates/patterncacher.h ../app/templates.h ../core/thread.h
|
||||
main.o: sessionmanager.h sessioncontainer.h session.h done.h item.h error.h
|
||||
main.o: log.h user.h functionparser.h requesttypes.h ../app/content.h data.h
|
||||
main.o: dirs.h dircontainer.h users.h ugcontainer.h groups.h group.h
|
||||
main.o: functions.h function.h lastcontainer.h mounts.h mount.h request.h
|
||||
main.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h db.h
|
||||
main.o: config.h ../confparser/confparser.h notify.h
|
||||
main.o: ../templatesnotify/templatesnotify.h ../core/mount.h
|
||||
misc.o: misc.h item.h log.h
|
||||
mount.o: mount.h
|
||||
mountparser.o: mountparser.h mount.h item.h error.h log.h data.h dirs.h
|
||||
@@ -53,27 +44,31 @@ mounts.o: lastcontainer.h request.h requesttypes.h session.h done.h error.h
|
||||
mounts.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
|
||||
mounts.o: mountparser.h
|
||||
notify.o: log.h notify.h ../templatesnotify/templatesnotify.h ../core/mount.h
|
||||
notify.o: ../../ezc/src/ezc.h data.h dirs.h item.h dircontainer.h users.h
|
||||
notify.o: user.h ugcontainer.h groups.h group.h functions.h function.h
|
||||
notify.o: lastcontainer.h mounts.h mount.h misc.h request.h requesttypes.h
|
||||
notify.o: session.h done.h error.h thread.h compress.h acceptencodingparser.h
|
||||
notify.o: acceptbaseparser.h
|
||||
notify.o: data.h dirs.h item.h dircontainer.h users.h user.h ugcontainer.h
|
||||
notify.o: groups.h group.h functions.h function.h lastcontainer.h mounts.h
|
||||
notify.o: mount.h misc.h request.h requesttypes.h session.h done.h error.h
|
||||
notify.o: thread.h compress.h acceptencodingparser.h acceptbaseparser.h
|
||||
plugin.o: plugin.h request.h requesttypes.h session.h done.h item.h error.h
|
||||
plugin.o: log.h user.h function.h thread.h compress.h acceptencodingparser.h
|
||||
plugin.o: acceptbaseparser.h data.h dirs.h dircontainer.h users.h
|
||||
plugin.o: ugcontainer.h groups.h group.h functions.h lastcontainer.h mounts.h
|
||||
plugin.o: mount.h pluginmsg.h
|
||||
request.o: request.h requesttypes.h session.h done.h item.h error.h log.h
|
||||
request.o: user.h function.h thread.h compress.h acceptencodingparser.h
|
||||
request.o: acceptbaseparser.h getparser.h httpsimpleparser.h postparser.h
|
||||
request.o: cookieparser.h data.h dirs.h dircontainer.h users.h ugcontainer.h
|
||||
request.o: groups.h group.h functions.h lastcontainer.h mounts.h mount.h
|
||||
request.o: plugin.h pluginmsg.h
|
||||
requestcontroller.o: requestcontroller.h ../content/content.h ../core/item.h
|
||||
requestcontroller.o: ../templates/templates.h ../../ezc/src/ezc.h
|
||||
requestcontroller.o: ../templates/patterncacher.h ../app/templates.h
|
||||
requestcontroller.o: ../templates/templates.h ../templates/patterncacher.h
|
||||
requestcontroller.o: ../core/thread.h sessionmanager.h sessioncontainer.h
|
||||
requestcontroller.o: session.h done.h item.h error.h log.h user.h
|
||||
requestcontroller.o: functionparser.h requesttypes.h ../app/content.h data.h
|
||||
requestcontroller.o: dirs.h dircontainer.h users.h ugcontainer.h groups.h
|
||||
requestcontroller.o: group.h functions.h function.h lastcontainer.h mounts.h
|
||||
requestcontroller.o: mount.h request.h thread.h compress.h
|
||||
requestcontroller.o: acceptencodingparser.h acceptbaseparser.h postparser.h
|
||||
requestcontroller.o: httpsimpleparser.h cookieparser.h notify.h
|
||||
requestcontroller.o: functionparser.h requesttypes.h data.h dirs.h
|
||||
requestcontroller.o: dircontainer.h users.h ugcontainer.h groups.h group.h
|
||||
requestcontroller.o: functions.h function.h lastcontainer.h mounts.h mount.h
|
||||
requestcontroller.o: request.h thread.h compress.h acceptencodingparser.h
|
||||
requestcontroller.o: acceptbaseparser.h postparser.h httpsimpleparser.h
|
||||
requestcontroller.o: cookieparser.h notify.h
|
||||
requestcontroller.o: ../templatesnotify/templatesnotify.h ../core/mount.h
|
||||
session.o: session.h done.h item.h error.h log.h user.h
|
||||
sessioncontainer.o: sessioncontainer.h session.h done.h item.h error.h log.h
|
||||
|
@@ -1 +1 @@
|
||||
o = acceptbaseparser.o compress.o config.o data.o db.o db_itemcolumns.o dircontainer.o dirs.o done.o error.o function.o functioncodeparser.o functionparser.o functions.o groups.o httpsimpleparser.o lastcontainer.o log.o main.o misc.o mount.o mountparser.o mounts.o notify.o request.o requestcontroller.o session.o sessioncontainer.o sessionmanager.o users.o
|
||||
o = acceptbaseparser.o compress.o config.o data.o db.o db_itemcolumns.o dircontainer.o dirs.o done.o error.o function.o functioncodeparser.o functionparser.o functions.o groups.o httpsimpleparser.o lastcontainer.o log.o misc.o mount.o mountparser.o mounts.o notify.o plugin.o request.o requestcontroller.o session.o sessioncontainer.o sessionmanager.o users.o
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "data.h"
|
||||
#include "plugin.h"
|
||||
|
||||
|
||||
Config::Config()
|
||||
@@ -119,6 +120,9 @@ void Config::AssignValues()
|
||||
|
||||
data.session_max_iddle = Int("session_max_iddle");
|
||||
data.compression = Bool("compression");
|
||||
|
||||
std::string p = Text("plugin");
|
||||
data.plugin_file.push_back(p);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -86,6 +86,9 @@ public:
|
||||
int session_max_iddle;
|
||||
|
||||
bool compression;
|
||||
|
||||
// plugins
|
||||
std::vector<std::string> plugin_file;
|
||||
|
||||
// end config members
|
||||
// -----------------------------------------------------------------
|
||||
|
@@ -12,9 +12,6 @@
|
||||
|
||||
#include "requesttypes.h"
|
||||
|
||||
#ifdef APPFUNCTIONS
|
||||
#include "../app/content.h"
|
||||
#endif
|
||||
|
||||
class FunctionParser
|
||||
{
|
||||
|
124
core/main.cpp
124
core/main.cpp
@@ -1,124 +0,0 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2009, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <signal.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "requestcontroller.h"
|
||||
#include "data.h"
|
||||
#include "log.h"
|
||||
#include "request.h"
|
||||
#include "db.h"
|
||||
#include "config.h"
|
||||
#include "notify.h"
|
||||
|
||||
|
||||
// singletons
|
||||
// first 'data' then 'log' then 'request'
|
||||
Data data;
|
||||
Log log;
|
||||
Log nlog; // notify log (used by another thread)
|
||||
Request request;
|
||||
Db db;
|
||||
Config config;
|
||||
RequestController req_controller;
|
||||
Notify notify;
|
||||
|
||||
|
||||
|
||||
void signal_term(int)
|
||||
{
|
||||
log << log1 << "cmslu stopped" << logend;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void signal_hup(int)
|
||||
{
|
||||
log << log1 << "SIGHUP received" << logend;
|
||||
data.signal_hup = true;
|
||||
config.ReadConfig(false); /* errors not to stdout */
|
||||
}
|
||||
|
||||
|
||||
|
||||
void print_syntax()
|
||||
{
|
||||
std::cout << "Syntax:" << std::endl;
|
||||
std::cout << " cmslu.fcgi config_file" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main(int argv, char ** argc)
|
||||
{
|
||||
std::srand(std::time(0));
|
||||
|
||||
if( argv != 2 )
|
||||
{
|
||||
print_syntax();
|
||||
return 1;
|
||||
}
|
||||
|
||||
data.config_file = argc[1];
|
||||
|
||||
|
||||
|
||||
if( !config.ReadConfig(true) ) /* errors to stdout */
|
||||
return 2;
|
||||
|
||||
|
||||
// closing descriptors only at the beginning
|
||||
// !! temporary we do not close standard output for errors
|
||||
// client postgresql uses it for reporting warnings (I don't know why)
|
||||
//close(2);
|
||||
|
||||
if( !data.log_stdout )
|
||||
{
|
||||
close(1);
|
||||
data.stdout_is_closed = true;
|
||||
}
|
||||
|
||||
|
||||
log.Init(data.log_level, data.log_file, data.log_stdout);
|
||||
nlog.Init(data.log_level, data.log_notify_file, false);
|
||||
db.Init(data.db_database, data.db_user, data.db_pass);
|
||||
request.Init();
|
||||
|
||||
if( !req_controller.Init() )
|
||||
return 1;
|
||||
|
||||
if( !notify.Init(data.templates) )
|
||||
return 2;
|
||||
|
||||
signal(SIGTERM, signal_term);
|
||||
signal(SIGINT, signal_term);
|
||||
signal(SIGHUP, signal_hup);
|
||||
|
||||
|
||||
while( true )
|
||||
{
|
||||
//log << log2 << "checking for table consistency:" << logend;
|
||||
// !! zrobic wyjatek dla root
|
||||
//db.CheckAllUrlSubject();
|
||||
|
||||
log << log1 << "cmslu started" << logend;
|
||||
|
||||
req_controller.Loop();
|
||||
|
||||
if( data.signal_hup )
|
||||
data.signal_hup = false;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
127
core/plugin.cpp
Executable file
127
core/plugin.cpp
Executable file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2009, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include "plugin.h"
|
||||
#include "pluginmsg.h"
|
||||
|
||||
|
||||
|
||||
|
||||
void Plugin::UnloadPlugins()
|
||||
{
|
||||
size_t i;
|
||||
|
||||
slots.clear();
|
||||
|
||||
for(i=0 ; i<plugins.size() ; ++i)
|
||||
dlclose(plugins[i]);
|
||||
|
||||
plugins.clear();
|
||||
}
|
||||
|
||||
|
||||
Plugin::Plugin()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Plugin::~Plugin()
|
||||
{
|
||||
UnloadPlugins();
|
||||
}
|
||||
|
||||
|
||||
void Plugin::LoadPlugins(const std::vector<std::string> & plugins)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for(i=0 ; i<plugins.size() ; ++i)
|
||||
{
|
||||
LoadPlugin(plugins[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Plugin::LoadPlugin(const std::string & filename)
|
||||
{
|
||||
LoadPlugin(filename.c_str());
|
||||
}
|
||||
|
||||
|
||||
void Plugin::LoadPlugin(const char * filename)
|
||||
{
|
||||
void * p = dlopen(filename, RTLD_NOW | RTLD_LOCAL);
|
||||
|
||||
if( !p )
|
||||
{
|
||||
log << log1 << "Pl: cannot load a plugin: " << filename << logend;
|
||||
|
||||
/*
|
||||
const char * t = dlerror();
|
||||
if( t )
|
||||
log << log1 << t << logend;
|
||||
*/
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Fun fun = (Fun)dlfunc(p, "Init");
|
||||
|
||||
if( !fun )
|
||||
{
|
||||
log << log1 << "Pl: cannot load a plugin: " << filename << " (there is no Init() function)" << logend;
|
||||
dlclose(p);
|
||||
return;
|
||||
}
|
||||
|
||||
arg.Clear();
|
||||
|
||||
if( fun(&arg) )
|
||||
{
|
||||
log << log1 << "Pl: plugin loaded: " << filename << logend;
|
||||
plugins.push_back(p);
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Pl: plugin Init() returned false (" << filename << ") " << logend;
|
||||
dlclose(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Arg * Plugin::Call(int message, void * a, void * a2, void * a3)
|
||||
{
|
||||
Slots::iterator i = slots.lower_bound(message);
|
||||
arg.Clear();
|
||||
arg.app = a;
|
||||
arg.app2 = a2;
|
||||
arg.app3 = a3;
|
||||
|
||||
for( ; i!=slots.end() && i->first==message ; ++i )
|
||||
{
|
||||
if( i->second(&arg) )
|
||||
arg.ret_true++;
|
||||
else
|
||||
arg.ret_false++;
|
||||
}
|
||||
|
||||
return &arg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Plugin::Assign(int message, Fun fun)
|
||||
{
|
||||
slots.insert( std::make_pair(message, fun) );
|
||||
}
|
91
core/plugin.h
Executable file
91
core/plugin.h
Executable file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2009, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef headerfilecmsluplugin
|
||||
#define headerfilecmsluplugin
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "request.h"
|
||||
#include "data.h"
|
||||
#include "pluginmsg.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
|
||||
class Plugin;
|
||||
|
||||
|
||||
// plugin arguments
|
||||
struct Arg
|
||||
{
|
||||
void * app; // used for some purposes
|
||||
void * app2; // used for some purposes
|
||||
void * app3; // used for some purposes
|
||||
|
||||
int ret_true; // how many plugins returned true
|
||||
int ret_false; // how many plugins returned false
|
||||
|
||||
|
||||
void Clear()
|
||||
{
|
||||
app = 0;
|
||||
app2 = 0;
|
||||
app3 = 0;
|
||||
ret_true = 0;
|
||||
ret_false = 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class Plugin
|
||||
{
|
||||
public:
|
||||
|
||||
typedef bool (*Fun)(Arg *);
|
||||
|
||||
|
||||
|
||||
Plugin();
|
||||
~Plugin();
|
||||
void LoadPlugin(const char * filename);
|
||||
void LoadPlugin(const std::string & filename);
|
||||
void LoadPlugins(const std::vector<std::string> & plugins);
|
||||
|
||||
void UnloadPlugins();
|
||||
|
||||
Arg * Call(int message, void * a=0, void * a2=0, void * a3=0);
|
||||
|
||||
|
||||
void Assign(int message, Fun);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
typedef std::vector<void*> Plugins;
|
||||
Plugins plugins;
|
||||
|
||||
typedef std::multimap<int, Fun> Slots;
|
||||
Slots slots;
|
||||
|
||||
|
||||
Arg arg;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
extern Plugin plugin;
|
||||
|
||||
#endif
|
||||
|
30
core/pluginmsg.h
Executable file
30
core/pluginmsg.h
Executable file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is a part of CMSLU -- Content Management System like Unix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2008-2009, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef headerfilecmslupluginmsg
|
||||
#define headerfilecmslupluginmsg
|
||||
|
||||
|
||||
#define CMSLU_TEMPLATES_CREATEFUNCTIONS 999
|
||||
#define CMSLU_REQUEST_CLEAR 1000
|
||||
|
||||
#define CMSLU_CONTENT_MAKE 2000
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
@@ -13,6 +13,10 @@
|
||||
#include "cookieparser.h"
|
||||
#include "log.h"
|
||||
#include "data.h"
|
||||
#include "plugin.h"
|
||||
|
||||
|
||||
|
||||
|
||||
Request::Request() : char_empty(0)
|
||||
{
|
||||
@@ -81,6 +85,8 @@ void Request::Clear()
|
||||
notify_code = 0;
|
||||
|
||||
browser_msie = false;
|
||||
|
||||
plugin.Call(CMSLU_REQUEST_CLEAR);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user