diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-02-12 14:40:51 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-02-12 14:40:51 +0300 |
commit | 6c8fc71eafb0f0bb069dba703c805a5247c917c7 (patch) | |
tree | efca07d7ff100a183b56eb1bb5d31602444408b3 | |
parent | 54480f21f115b40e76806210a61bdde00d3842f7 (diff) | |
download | rspamd-6c8fc71eafb0f0bb069dba703c805a5247c917c7.tar.gz rspamd-6c8fc71eafb0f0bb069dba703c805a5247c917c7.zip |
* Add log function to perl API
* Prepare for more detailed work on rspamd perl API
-rw-r--r-- | perl/rspamd.pm | 24 | ||||
-rw-r--r-- | perl/rspamd.xs | 18 | ||||
-rw-r--r-- | src/main.c | 20 | ||||
-rw-r--r-- | src/main.h | 2 |
4 files changed, 62 insertions, 2 deletions
diff --git a/perl/rspamd.pm b/perl/rspamd.pm index d3b2fac0e..6048f1a3f 100644 --- a/perl/rspamd.pm +++ b/perl/rspamd.pm @@ -7,11 +7,35 @@ use warnings; require Exporter; our @ISA = qw(Exporter); +our @EXPORT = qw( + module_init + module_reload + LOG_ERROR + LOG_WARNING + LOG_MESSAGE + LOG_INFO + LOG_DEBUG +); our $VERSION = '0.0.1'; require XSLoader; XSLoader::load('rspamd', $VERSION); + +sub module_init { + my ($cfg) = @_; +} + +sub module_reload { + my ($cfg) = @_; +} + +use constant LOG_ERROR => 1 << 3; +use constant LOG_WARNING => 1 << 4; +use constant LOG_MESSAGE => 1 << 5; +use constant LOG_INFO => 1 << 6; +use constant LOG_DEBUG => 1 << 7; + 1; __END__ diff --git a/perl/rspamd.xs b/perl/rspamd.xs index 4dfc9e665..c7e1ae776 100644 --- a/perl/rspamd.xs +++ b/perl/rspamd.xs @@ -464,7 +464,7 @@ OUTPUT: RETVAL void -rspamd_task_get_module_param (r, modulename, paramname) +rspamd_config_get_module_param (r, modulename, paramname) CODE: struct config_file *r; char *module, *param, *value; @@ -483,3 +483,19 @@ rspamd_task_get_module_param (r, modulename, paramname) sv_setpv(TARG, value); ST(0) = TARG; + +MODULE = rspamd PACKAGE = rspamd_log PREFIX = rspamd_log_ +PROTOTYPES: DISABLE + +void +rspamd_log_log (level, str) + CODE: + int level; + char *str; + + level = (int)SvIV (ST(0)); + str = (char *)SvPV_nolen (ST(1)); + + g_log (G_LOG_DOMAIN, level, "%s", str); + XSRETURN_EMPTY; + diff --git a/src/main.c b/src/main.c index f315367d7..e33d6e8dd 100644 --- a/src/main.c +++ b/src/main.c @@ -25,6 +25,8 @@ /* 2 seconds to fork new process in place of dead one */ #define SOFT_FORK_TIME 2 +/* Perl module init function */ +#define MODULE_INIT_FUNC "module_init" struct config_file *cfg; @@ -85,10 +87,28 @@ static void init_filters (struct config_file *cfg) { struct perl_module *module; + char *init_func, *class; + size_t funclen; + dSP; LIST_FOREACH (module, &cfg->perl_modules, next) { if (module->path) { require_pv (module->path); + ENTER; + SAVETMPS; + + PUSHMARK (SP); + XPUSHs (sv_2mortal (newSVpv (class, 0))); + XPUSHs (sv_2mortal (newSViv (PTR2IV (cfg)))); + PUTBACK; + /* Call module init function */ + funclen = strlen (module->path) + sizeof ("::") + sizeof (MODULE_INIT_FUNC) - 1; + init_func = g_malloc (funclen); + snptintf (init_func, funclen, "%s::%s", module->path, MODULE_INIT_FUNC); + call_method (init_func, G_DISCARD); + + FREETMPS; + LEAVE; } } } diff --git a/src/main.h b/src/main.h index 10f9ef215..fb64ffed4 100644 --- a/src/main.h +++ b/src/main.h @@ -43,7 +43,7 @@ #define DEFAULT_METRIC "default" /* Logging in postfix style */ -#define msg_err g_error +#define msg_err g_critical #define msg_warn g_warning #define msg_info g_message #define msg_debug g_debug |