aboutsummaryrefslogtreecommitdiffstats
path: root/perl
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2008-08-20 17:09:13 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2008-08-20 17:09:13 +0400
commite90352d20a0d5f615c906b7719f95599cb2aaeac (patch)
tree61c2a5a7efc21fb03b4ba9a9779af8e76e641702 /perl
parent86fd197a95f72d09e5cccbc059829ff5f6b03b87 (diff)
downloadrspamd-e90352d20a0d5f615c906b7719f95599cb2aaeac.tar.gz
rspamd-e90352d20a0d5f615c906b7719f95599cb2aaeac.zip
* Rewrite perl module for new XS, now perl filters got only object of rspamd module that provides access to every part of message
* Add memcached access api for perl * Reorganize Makefile, add .PHONY targets * Fix memcached module as now we cannot write or read several keys in async mode
Diffstat (limited to 'perl')
-rw-r--r--perl/rspamd.xs127
1 files changed, 123 insertions, 4 deletions
diff --git a/perl/rspamd.xs b/perl/rspamd.xs
index ada7a5997..681e40308 100644
--- a/perl/rspamd.xs
+++ b/perl/rspamd.xs
@@ -6,12 +6,13 @@
#include <sys/types.h>
#include <unistd.h>
+#include <EXTERN.h>
+#include <perl.h>
+#include <XSUB.h>
+
#include "../config.h"
#include "../main.h"
-
-#include "EXTERN.h"
-#include "perl.h"
-#include "XSUB.h"
+#include "../perl.h"
#define perl_set_session(r) \
r = INT2PTR(struct worker_task *, SvIV((SV *) SvRV(ST(0))))
@@ -98,3 +99,121 @@ get_part (r, num)
OUTPUT:
RETVAL
+void
+read_memcached_key (r, key, datalen, callback)
+ CODE:
+ struct worker_task *r;
+ char *key;
+ unsigned int datalen;
+ SV *callback;
+ STRLEN keylen;
+ struct _param {
+ SV *callback;
+ struct worker_task *task;
+ } *callback_data;
+ memcached_param_t param;
+
+ perl_set_session (r);
+ key = (char *) SvPV (ST(1), keylen);
+ datalen = (unsigned int) SvIV (ST(2));
+ callback = SvRV(ST(3));
+
+ r->memc_ctx->callback = perl_call_memcached_callback;
+ callback_data = malloc (sizeof (struct _param));
+ if (callback_data == NULL) {
+ XSRETURN_UNDEF;
+ }
+ callback_data->callback = callback;
+ callback_data->task = r;
+ r->memc_ctx->callback_data = (void *)callback_data;
+
+ r->memc_busy = 1;
+
+ strlcpy (param.key, key, sizeof (param.key));
+ param.buf = malloc (datalen);
+ if (param.buf != NULL) {
+ param.bufsize = datalen;
+ }
+ param.bufpos = 0;
+ param.expire = 0;
+
+ memc_get (r->memc_ctx, &param);
+ XSRETURN_EMPTY;
+
+void
+write_memcached_key (r, key, data, expire, callback)
+ CODE:
+ struct worker_task *r;
+ char *key, *data;
+ SV *callback;
+ STRLEN keylen, datalen;
+ int expire;
+ struct _param {
+ SV *callback;
+ struct worker_task *task;
+ } *callback_data;
+ memcached_param_t param;
+
+ perl_set_session (r);
+ key = (char *) SvPV (ST(1), keylen);
+ data = (char *) SvPV (ST(2), datalen);
+ expire = (int) SvIV (ST(3));
+ callback = SvRV(ST(4));
+
+ r->memc_ctx->callback = perl_call_memcached_callback;
+ callback_data = malloc (sizeof (struct _param));
+ if (callback_data == NULL) {
+ XSRETURN_UNDEF;
+ }
+ callback_data->callback = callback;
+ callback_data->task = r;
+ r->memc_ctx->callback_data = (void *)callback_data;
+
+ r->memc_busy = 1;
+
+ strlcpy (param.key, key, sizeof (param.key));
+ param.buf = data;
+ param.bufsize = datalen;
+ param.bufpos = 0;
+ param.expire = expire;
+
+ memc_set (r->memc_ctx, &param, expire);
+ XSRETURN_EMPTY;
+
+void
+delete_memcached_key (r, key, callback)
+ CODE:
+ struct worker_task *r;
+ char *key;
+ SV *callback;
+ STRLEN keylen;
+ struct _param {
+ SV *callback;
+ struct worker_task *task;
+ } *callback_data;
+ memcached_param_t param;
+
+ perl_set_session (r);
+ key = (char *) SvPV (ST(1), keylen);
+ callback = SvRV(ST(2));
+
+ r->memc_ctx->callback = perl_call_memcached_callback;
+ callback_data = malloc (sizeof (struct _param));
+ if (callback_data == NULL) {
+ XSRETURN_UNDEF;
+ }
+ callback_data->callback = callback;
+ callback_data->task = r;
+ r->memc_ctx->callback_data = (void *)callback_data;
+
+ r->memc_busy = 1;
+
+ strlcpy (param.key, key, sizeof (param.key));
+ param.buf = NULL;
+ param.bufsize = 0;
+ param.bufpos = 0;
+ param.expire = 0;
+
+ memc_delete (r->memc_ctx, &param);
+ XSRETURN_EMPTY;
+