]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
* Add log function to perl API
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 12 Feb 2009 11:40:51 +0000 (14:40 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Thu, 12 Feb 2009 11:40:51 +0000 (14:40 +0300)
* Prepare for more detailed work on rspamd perl API

perl/rspamd.pm
perl/rspamd.xs
src/main.c
src/main.h

index d3b2fac0e9c97aa9de32fc7126881d9e8c6b748c..6048f1a3f016b43e6d6ccca4435b8778a7f191a7 100644 (file)
@@ -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__
 
index 4dfc9e6658ce59d878acb885a4620744dfb92a2a..c7e1ae776d760726eef16ef61a83995a08e0d073 100644 (file)
@@ -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;
+
index f315367d7bd087ee8efcfdbb3fb43f0ea9852410..e33d6e8ddd4df52c9152f626c19dd1f630accb34 100644 (file)
@@ -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;
                }
        }
 }
index 10f9ef2151b746f424470ec0b5b61c389b55355a..fb64ffed4dc5f7e5bffdf6d180f892652a282899 100644 (file)
@@ -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