diff --git a/backend/src/c/bav/Makefile b/backend/src/c/bav/Makefile
index 4fbfa4a01..431de69b2 100644
--- a/backend/src/c/bav/Makefile
+++ b/backend/src/c/bav/Makefile
@@ -9,7 +9,6 @@
# #
####################################################################################################################################################################################################################################################################
#
-
CFLAGS = -I. -I../lib -pthread
LDFLAGS = -L. -L../lib -pthread
LIBS = -lagn
diff --git a/backend/src/c/bav/bav.c b/backend/src/c/bav/bav.c
index 196cb7c5a..cd6383ee2 100644
--- a/backend/src/c/bav/bav.c
+++ b/backend/src/c/bav/bav.c
@@ -402,7 +402,7 @@ find_locals (void) /*{{{*/
void *cfg;
rc = true;
- if (cfg = systemconfig_alloc (NULL)) {
+ if (cfg = systemconfig_alloc ()) {
const char *value;
char *copy;
diff --git a/backend/src/c/lib/Makefile b/backend/src/c/lib/Makefile
index 43a9c7f4c..42b32bf74 100644
--- a/backend/src/c/lib/Makefile
+++ b/backend/src/c/lib/Makefile
@@ -9,7 +9,6 @@
# #
####################################################################################################################################################################################################################################################################
#
-
CFLAGS = -I.
LDFLAGS = -L.
LIBS := -lagn -lparson
diff --git a/backend/src/c/lib/agn.h b/backend/src/c/lib/agn.h
index 9b2b0ad0c..ac47ab648 100644
--- a/backend/src/c/lib/agn.h
+++ b/backend/src/c/lib/agn.h
@@ -262,6 +262,7 @@ typedef unsigned long logmask_t;
/**
* All informations required for logging
*/
+typedef struct idc idc_t;
typedef struct { /*{{{*/
int logfd; /**< file desc. to copy output to */
int slprio; /**< syslog priority */
@@ -275,7 +276,7 @@ typedef struct { /*{{{*/
long lastday; /**< dito for the day */
int diff; /**< TZ drift */
FILE *lfp; /**< filepointer to output file */
- void *idc; /**< ID chain */
+ idc_t *idc; /**< ID chain */
bool_t slactive; /**< syslog is active */
buffer_t *obuf; /**< output buffer */
buffer_t *collect; /**< to collect all messages */
@@ -478,7 +479,7 @@ extern bool_t log_collect (log_t *l, int level);
extern void log_uncollect (log_t *l);
extern bool_t log_idset (log_t *l, const char *what);
extern void log_idclr (log_t *l);
-extern bool_t log_idpush (log_t *l, const char *what, const char *separator);
+extern bool_t log_idpush (log_t *l, const char *what);
extern void log_idpop (log_t *l);
extern void log_suspend_pop (log_t *l);
extern void log_suspend_push (log_t *l, unsigned long mask, bool_t set);
@@ -562,7 +563,7 @@ extern bool_t purl_set_anchor (purl_t *p, const byte_t *anchor);
extern const byte_t *purl_build (purl_t *p, const char *extra_encode, int *rlen, bool_t (*callback) (void *, buffer_t *, const byte_t *, int), void *priv);
extern void *systemconfig_free (void *lc);
-extern void *systemconfig_alloc (const char *fname);
+extern void *systemconfig_alloc (void);
extern const char *systemconfig_find (void *lc, const char *key);
extern bool_t systemconfig_get (void *lc, int idx, const char **key, const char **value);
diff --git a/backend/src/c/lib/buffer.c b/backend/src/c/lib/buffer.c
index 4fdd2d8e6..248f1a79b 100644
--- a/backend/src/c/lib/buffer.c
+++ b/backend/src/c/lib/buffer.c
@@ -730,19 +730,28 @@ pool_flush (pool_t *p) /*{{{*/
buffer_t *
pool_request (pool_t *p, int nsize) /*{{{*/
{
- buffer_t *b;
+ if (p -> root) {
+ buffer_t *b, *prev;
- if (b = p -> root) {
- p -> root = p -> root -> link;
+ for (b = p -> root, prev = NULL; b && b -> link; ) {
+ if ((b -> size < nsize) || ((b -> size >= nsize) && (b -> link -> size < nsize)))
+ break;
+ prev = b;
+ b = b -> link;
+ }
+ if (prev)
+ prev -> link = b -> link;
+ else
+ p -> root = b -> link;
b -> link = NULL;
buffer_clear (b);
- buffer_size (b, nsize);
- } else {
- b = buffer_alloc (nsize);
+ if (b -> size < nsize) {
+ if (! buffer_size (b, nsize))
+ buffer_clear (b);
+ }
+ return b;
}
- if (b && (! b -> valid))
- buffer_clear (b);
- return b;
+ return buffer_alloc (nsize);
}/*}}}*/
buffer_t *
pool_release (pool_t *p, buffer_t *b) /*{{{*/
diff --git a/backend/src/c/lib/log.c b/backend/src/c/lib/log.c
index 04a644b87..1ee1230f2 100644
--- a/backend/src/c/lib/log.c
+++ b/backend/src/c/lib/log.c
@@ -28,51 +28,48 @@
/** Stack for IDs.
* This stack is used to keep track of logging IDs.
*/
-typedef struct idc { /*{{{*/
- char *str; /**< concated ID string */
- struct idc *next; /**< next element in stack */
+struct idc { /*{{{*/
+ char *str; /**< concated ID string */
+ idc_t *next; /**< next element in stack */
/*}}}*/
-} idc_t;
+};
+/** Frees an ID.
+ * @param i the ID to free
+ * @return NULL
+ */
+static idc_t *
+idc_free (idc_t *i) /*{{{*/
+{
+ if (i) {
+ if (i -> str)
+ free (i -> str);
+ free (i);
+ }
+ return NULL;
+}/*}}}*/
/** Alloced ID.
* @param prefix the already stacked IDs
* @param str the new ID
- * @param separator
* @return the new head of the stack on success, NULL otherwise
*/
static idc_t *
-idc_alloc (idc_t *prefix, const char *str, const char *separator) /*{{{*/
+idc_alloc (idc_t *prefix, const char *str) /*{{{*/
{
idc_t *i;
if (i = (idc_t *) malloc (sizeof (idc_t))) {
if (prefix) {
- if (i -> str = malloc (strlen (prefix -> str) + strlen (str) + (separator ? strlen (separator) : 0) + 1))
- sprintf (i -> str, "%s%s%s", prefix -> str, (separator ? separator : ""), str);
+ if (i -> str = malloc (strlen (prefix -> str) + strlen (str) + 3))
+ sprintf (i -> str, "%s->%s", prefix -> str, str);
} else
i -> str = strdup (str);
if (i -> str)
i -> next = NULL;
- else {
- free (i);
- i = NULL;
- }
+ else
+ i = idc_free (i);
}
return i;
}/*}}}*/
-/** Frees an ID.
- * @param i the ID to free
- * @return NULL
- */
-static idc_t *
-idc_free (idc_t *i) /*{{{*/
-{
- if (i) {
- if (i -> str)
- free (i -> str);
- free (i);
- }
- return NULL;
-}/*}}}*/
/** Frees stack.
* @param i the ID to start from
* @return NULL
@@ -267,7 +264,7 @@ log_free (log_t *l) /*{{{*/
if (l -> lfp)
fclose (l -> lfp);
if (l -> idc)
- idc_free_all ((idc_t *) l -> idc);
+ idc_free_all (l -> idc);
if (l -> obuf)
buffer_free (l -> obuf);
if (l -> collect)
@@ -353,7 +350,7 @@ log_path_set (log_t *l, const char *logpath) /*{{{*/
return (logpath && (! l -> logpath)) ? false : true;
}/*}}}*/
/** Sets default logging path.
- * Sets the default logging path creating from enviroment variable
+ * Sets the default logging path creating from environment variable
* @param l the logger
* @return true on success, false otherwise
*/
@@ -460,7 +457,7 @@ bool_t
log_idset (log_t *l, const char *what) /*{{{*/
{
log_idclr (l);
- l -> idc = idc_alloc (NULL, what, NULL);
+ l -> idc = idc_alloc (NULL, what);
return l -> idc ? true : false;
}/*}}}*/
/** Clears logging IDs.
@@ -471,24 +468,23 @@ void
log_idclr (log_t *l) /*{{{*/
{
if (l -> idc)
- l -> idc = idc_free_all ((idc_t *) l -> idc);
+ l -> idc = idc_free_all (l -> idc);
}/*}}}*/
/** Push new logging ID.
* The new logging id what is pushed on top of the ID stack.
* If there is already one on the stack, the new ID is created using
- * the stack value, concaternated by separator and new ID
+ * the stack value.
* @param l the logger
* @param what the new ID
- * @param separator the separator for concaternation
* @return true on success, false otherwise
*/
bool_t
-log_idpush (log_t *l, const char *what, const char *separator) /*{{{*/
+log_idpush (log_t *l, const char *what) /*{{{*/
{
idc_t *tmp;
- if (tmp = idc_alloc ((separator ? (idc_t *) l -> idc : NULL), what, separator)) {
- tmp -> next = (idc_t *) l -> idc;
+ if (tmp = idc_alloc (l -> idc, what)) {
+ tmp -> next = l -> idc;
l -> idc = tmp;
}
return tmp ? true : false;
@@ -502,7 +498,7 @@ log_idpop (log_t *l) /*{{{*/
{
idc_t *tmp;
- if (tmp = (idc_t *) l -> idc) {
+ if (tmp = l -> idc) {
l -> idc = tmp -> next;
idc_free (tmp);
}
@@ -684,7 +680,7 @@ log_mout (log_t *l, int level, logmask_t mask, const char *what, const char *fmt
bool_t
log_vidout (log_t *l, int level, logmask_t mask, const char *fmt, va_list par) /*{{{*/
{
- return log_vmout (l, level, mask, (l -> idc ? ((idc_t *) l -> idc) -> str : NULL), fmt, par);
+ return log_vmout (l, level, mask, (l -> idc ? l -> idc -> str : NULL), fmt, par);
}/*}}}*/
/** Write to logfile.
* Same as log_vidout except that parameter are passed directly
@@ -747,7 +743,7 @@ log_slout (log_t *l, int level, logmask_t mask, int priority, const char *what,
bool_t
log_vout (log_t *l, int level, const char *fmt, va_list par) /*{{{*/
{
- return log_vmout (l, level, 0, (l -> idc ? ((idc_t *) l -> idc) -> str : NULL), fmt, par);
+ return log_vmout (l, level, 0, l -> idc ? l -> idc -> str : NULL, fmt, par);
}/*}}}*/
/** Write to logfile.
* Same as log_vout except that parameter are passed directly
diff --git a/backend/src/c/lib/systemconfig.c b/backend/src/c/lib/systemconfig.c
index 0689b8f2a..a9f2ff1d8 100644
--- a/backend/src/c/lib/systemconfig.c
+++ b/backend/src/c/lib/systemconfig.c
@@ -445,7 +445,7 @@ systemconfig_free (void *lc) /*{{{*/
return NULL;
}/*}}}*/
void *
-systemconfig_alloc (const char *fname) /*{{{*/
+systemconfig_alloc (void) /*{{{*/
{
config_t *c;
@@ -473,18 +473,18 @@ systemconfig_alloc (const char *fname) /*{{{*/
ok = false;
}
} else {
- if (! fname) {
- fname = getenv (PATH_CONFIG_ENV);
- if (! fname) {
- fname = PATH_CONFIG;
+ const char *filename;
+
+ filename = getenv (PATH_CONFIG_ENV);
+ if (! filename) {
+ filename = PATH_CONFIG;
# ifdef PATH_LEGACY
- if (access (fname, R_OK) == -1) {
- fname = PATH_LEGACY;
- }
-# endif
+ if ((access (filename, R_OK) == -1) && (access (PATH_LEGACY, R_OK) != -1)) {
+ filename = PATH_LEGACY;
}
+# endif
}
- if (! (c -> filename = strdup (fname))) {
+ if (! (c -> filename = strdup (filename))) {
ok = false;
} else {
ok = config_check (c);
diff --git a/backend/src/c/lib/timeout.c b/backend/src/c/lib/timeout.c
index 679b39448..c33f18777 100644
--- a/backend/src/c/lib/timeout.c
+++ b/backend/src/c/lib/timeout.c
@@ -47,8 +47,9 @@ timeout_init (void) /*{{{*/
timeout_release ();
timeout -> seconds = 0;
timeout -> start = 0;
+ return true;
}
- return timeout ? true : false;
+ return false;
}/*}}}*/
void
timeout_release (void) /*{{{*/
diff --git a/backend/src/c/lib/xml.c b/backend/src/c/lib/xml.c
index d1846bff7..c4bd6f64e 100644
--- a/backend/src/c/lib/xml.c
+++ b/backend/src/c/lib/xml.c
@@ -203,29 +203,6 @@ xsubstr (const xchar_t *s, int start, int end) /*{{{*/
rc = NULL;
return rc;
}/*}}}*/
-bool_t
-xmlbuf_equal (xmlbuf_t *b1, xmlbuf_t *b2) /*{{{*/
-{
- if ((! b1) && (! b2))
- return true;
- if (b1 && b2 && (b1 -> length == b2 -> length) &&
- ((! b1 -> length) || (! memcmp (b1 -> buffer, b2 -> buffer, b1 -> length))))
- return true;
- return false;
-}/*}}}*/
-char *
-xmlbuf_to_string (xmlbuf_t *b) /*{{{*/
-{
- return buffer_copystring ((buffer_t *) b);
-}/*}}}*/
-long
-xmlbuf_to_long (xmlbuf_t *b) /*{{{*/
-{
- const char *s = b ? buffer_string (b) : NULL;
-
- return s ? strtol (s, NULL, 0) : -1;
-}/*}}}*/
-
static inline unsigned long
mkcp (const xchar_t *s, int *len) /*{{{*/
{
diff --git a/backend/src/c/lib/xml.h b/backend/src/c/lib/xml.h
index 0f527c0f1..bd050e733 100644
--- a/backend/src/c/lib/xml.h
+++ b/backend/src/c/lib/xml.h
@@ -18,7 +18,6 @@
* XML data
*/
typedef byte_t xchar_t;
-typedef buffer_t xmlbuf_t;
typedef struct { /*{{{*/
int csize;
cache_t *lower,
@@ -40,67 +39,6 @@ extern int xstrnlen (const xchar_t *s, int slen);
extern int xstrcmp (const xchar_t *s1, const char *s2);
extern int xstrncmp (const xchar_t *s1, const char *s2, size_t n);
extern xchar_t *xsubstr (const xchar_t *s, int start, int end);
-extern bool_t xmlbuf_equal (xmlbuf_t *b1, xmlbuf_t *b2);
-extern char *xmlbuf_to_string (xmlbuf_t *b);
-extern long xmlbuf_to_long (xmlbuf_t *b);
-
-static inline xmlbuf_t *
-xmlbuf_alloc (int nsize) /*{{{*/
-{
- return (xmlbuf_t *) buffer_alloc (nsize);
-}/*}}}*/
-static inline xmlbuf_t *
-xmlbuf_free (xmlbuf_t *b) /*{{{*/
-{
- return (xmlbuf_t *) buffer_free ((buffer_t *) b);
-}/*}}}*/
-static inline void
-xmlbuf_clear (xmlbuf_t *b) /*{{{*/
-{
- buffer_clear ((buffer_t *) b);
-}/*}}}*/
-static inline int
-xmlbuf_length (xmlbuf_t *b) /*{{{*/
-{
- return buffer_length ((buffer_t *) b);
-}/*}}}*/
-static inline const xchar_t *
-xmlbuf_content (xmlbuf_t *b) /*{{{*/
-{
- return (const xchar_t *) buffer_content ((buffer_t *) b);
-}/*}}}*/
-static inline bool_t
-xmlbuf_add (xmlbuf_t *b, const xchar_t *data, int dlen) /*{{{*/
-{
- return buffer_append ((buffer_t *) b, (const byte_t *) data, dlen);
-}/*}}}*/
-static inline bool_t
-xmlbuf_set (xmlbuf_t *b, const xchar_t *data, int dlen) /*{{{*/
-{
- xmlbuf_clear (b);
- return xmlbuf_add (b, data, dlen);
-}/*}}}*/
-static inline const char *
-xmlbuf_string (xmlbuf_t *b) /*{{{*/
-{
- return buffer_string ((buffer_t *) b);
-}/*}}}*/
-static inline char *
-xmlbuf_copystring (xmlbuf_t *b) /*{{{*/
-{
- return buffer_copystring ((buffer_t *) b);
-}/*}}}*/
-static inline xmlbuf_t *
-pool_xrequest (pool_t *p, int nsize) /*{{{*/
-{
- return (xmlbuf_t *) pool_request (p, nsize);
-}/*}}}*/
-static inline xmlbuf_t *
-pool_xrelease (pool_t *p, xmlbuf_t *b) /*{{{*/
-{
- return (xmlbuf_t *) pool_release (p, (buffer_t *) b);
-}/*}}}*/
-
extern const xchar_t *xtolower (const xchar_t *s, int *slen, int *olen);
extern const xchar_t *xtoupper (const xchar_t *s, int *slen, int *olen);
extern const xchar_t *xtotitle (const xchar_t *s, int *slen, int *olen);
diff --git a/backend/src/c/tools/Makefile b/backend/src/c/tools/Makefile
index eaec57265..4c02453a1 100644
--- a/backend/src/c/tools/Makefile
+++ b/backend/src/c/tools/Makefile
@@ -9,7 +9,6 @@
# #
####################################################################################################################################################################################################################################################################
#
-
CFLAGS = -I../lib
LDFLAGS = -L../lib
LIBS = -lagn
diff --git a/backend/src/c/tools/cquery.c b/backend/src/c/tools/cquery.c
index fbbcf2804..666e7db15 100644
--- a/backend/src/c/tools/cquery.c
+++ b/backend/src/c/tools/cquery.c
@@ -13,25 +13,20 @@
static void
usage (const char *pgm) /*{{{*/
{
- fprintf (stderr, "Usage: %s [-c ] [-d|+]\n", pgm);
+ fprintf (stderr, "Usage: %s [-d|+]\n", pgm);
}/*}}}*/
int
main (int argc, char **argv) /*{{{*/
{
int rc;
int n;
- const char *config;
bool_t dump;
void *cfg;
const char *key, *value;
- config = NULL;
dump = false;
- while ((n = getopt (argc, argv, "c:d?h")) != -1)
+ while ((n = getopt (argc, argv, "d?h")) != -1)
switch (n) {
- case 'c':
- config = optarg;
- break;
case 'd':
dump = true;
break;
@@ -40,8 +35,8 @@ main (int argc, char **argv) /*{{{*/
default:
return usage (argv[0]), (n != '?') && (n != 'h');
}
- if (! (cfg = systemconfig_alloc (config)))
- return fprintf (stderr, "Failed to setup config %s.\n", config ? config : "from default"), 1;
+ if (! (cfg = systemconfig_alloc ()))
+ return fprintf (stderr, "Failed to setup config.\n"), 1;
rc = 0;
if (dump) {
if (optind == argc) {
diff --git a/backend/src/c/tools/qctrl.c b/backend/src/c/tools/qctrl.c
index b13cdb674..c2348e4b6 100644
--- a/backend/src/c/tools/qctrl.c
+++ b/backend/src/c/tools/qctrl.c
@@ -160,7 +160,7 @@ main (int argc, char **argv) /*{{{*/
bool_t fst;
log_out (lg, LV_DEBUG, "Initializing command %s", cmdtab[n].cmd);
- log_idpush (lg, cmdtab[n].cmd, NULL);
+ log_idpush (lg, cmdtab[n].cmd);
data = (*cmdtab[n].finit) (lg, force, args, alen);
log_idpop (lg);
if (data) {
@@ -178,7 +178,7 @@ main (int argc, char **argv) /*{{{*/
csig_block (csig);
log_mark (lg, LV_INFO, 180);
log_out (lg, LV_DEBUG, "Executing command %s", cmdtab[n].cmd);
- log_idpush (lg, cmdtab[n].cmd, NULL);
+ log_idpush (lg, cmdtab[n].cmd);
fst = (*cmdtab[n].fexec) (data);
log_idpop (lg);
if (! fst) {
@@ -210,7 +210,7 @@ main (int argc, char **argv) /*{{{*/
csig_free (csig);
}
log_out (lg, LV_DEBUG, "Deinitialize command %s", cmdtab[n].cmd);
- log_idpush (lg, cmdtab[n].cmd, NULL);
+ log_idpush (lg, cmdtab[n].cmd);
fst = (*cmdtab[n].fdeinit) (data);
log_idpop (lg);
if (! fst)
diff --git a/backend/src/c/xmlback/Makefile b/backend/src/c/xmlback/Makefile
index 039d4cc10..9286ffcf5 100644
--- a/backend/src/c/xmlback/Makefile
+++ b/backend/src/c/xmlback/Makefile
@@ -9,8 +9,7 @@
# #
####################################################################################################################################################################################################################################################################
#
-
-CFLAGS = '-DEMM_VERSION="OpenEMM 22.10.000.122"' -I. -I../lib -Iinclude
+CFLAGS = '-DEMM_VERSION="OpenEMM 23.04.000.199"' -I. -I../lib -Iinclude
LDFLAGS = -L. -L../lib -Llib
LIBS = -lagn -lslang -lopendkim -lbsd -lresolv -llua -lmpack -lssl -lcrypto -lxml2 -lz -lm
SRCS = entity.c xmlback.c parse.c create.c replace.c modify.c protect.c convert.c append.c \
@@ -42,8 +41,8 @@ lib include:
[ -d $@ ] || mkdir $@
lib/libslang.a: slang-1.4.9.tar.gz slang-1.4.9.patch
tar xaf slang-1.4.9.tar.gz && ( cd slang-1.4.9; patch -p1 < ../slang-1.4.9.patch; ./configure; make; mv src/objs/libslang.a ../lib; mv src/slang.h ../include; cd ..; rm -rf slang-1.4.9 )
-lib/liblua.a: lua-5.3.5.tar.gz
- tar xaf lua-5.3.5.tar.gz && ( cd lua-5.3.5; make linux; mv src/liblua.a ../lib; mv src/lauxlib.h src/lua.h src/luaconf.h src/lualib.h ../include; cd ..; rm -rf lua-5.3.5 )
+lib/liblua.a: lua-5.4.4.tar.gz
+ tar xaf lua-5.4.4.tar.gz && ( cd lua-5.4.4; make linux; mv src/liblua.a ../lib; mv src/lauxlib.h src/lua.h src/luaconf.h src/lualib.h ../include; cd ..; rm -rf lua-5.4.4 )
lib/libssl.a lib/libcrypto.a: openssl-1.0.1j.tar.gz
tar xzf openssl-1.0.1j.tar.gz && ( cd openssl-1.0.1j; ./config no-shared no-dso --prefix=`dirname \`pwd\`` --openssldir=/home/openemm//etc/openssl; make; mv libcrypto.a libssl.a ../lib; rm -rf ../include/openssl; mkdir ../include/openssl; cp include/openssl/*.h ../include/openssl; cd ..; rm -rf rm -rf openssl-1.0.1j )
lib/libz.a: zlib-1.2.3.tar.gz
diff --git a/backend/src/c/xmlback/alua.c b/backend/src/c/xmlback/alua.c
index c47e699b5..f3206f453 100644
--- a/backend/src/c/xmlback/alua.c
+++ b/backend/src/c/xmlback/alua.c
@@ -12,6 +12,7 @@
# include
# include
# include
+# define _GNU_SOURCE /* required to get extended fnmatch flag values */
# include
# include
# include
@@ -797,50 +798,69 @@ alua_type (lua_State *lua) /*{{{*/
lua_pushstring (lua, str);
return 1;
}/*}}}*/
+static int
+alua_dofile (lua_State *lua) /*{{{*/
+{
+ return 0;
+}/*}}}*/
+static int
+alua_loadfile (lua_State *lua) /*{{{*/
+{
+ lua_pushnil (lua);
+ lua_pushstring (lua, "not implemented");
+ return 2;
+}/*}}}*/
static struct { /*{{{*/
const char *libname;
lua_CFunction libfunc;
+ bool_t sandbox;
/*}}}*/
} alua_libtab[] = { /*{{{*/
- { "", luaopen_base },
- { LUA_STRLIBNAME, luaopen_string },
+ { "", luaopen_base, true },
+ { LUA_STRLIBNAME, luaopen_string, true },
# ifdef LUA_UTF8LIBNAME
- { LUA_UTF8LIBNAME, luaopen_utf8 },
+ { LUA_UTF8LIBNAME, luaopen_utf8, true },
# endif /* LUA_UTF8LIBNAME */
- { LUA_TABLIBNAME, luaopen_table },
- { LUA_MATHLIBNAME, luaopen_math },
- { LUA_COLIBNAME, luaopen_coroutine }
+ { LUA_TABLIBNAME, luaopen_table, true },
+ { LUA_MATHLIBNAME, luaopen_math, true },
+ { LUA_COLIBNAME, luaopen_coroutine, true }
/*}}}*/
};
static struct { /*{{{*/
const char *modname;
const char *funcname;
lua_CFunction func;
+ bool_t sandbox;
/*}}}*/
} alua_functab[] = { /*{{{*/
- { NULL, "type", alua_type }
+ { NULL, "type", alua_type, true },
+ { NULL, "dofile", alua_dofile, true },
+ { NULL, "loadfile", alua_loadfile, true }
/*}}}*/
};
# define FTSIZE (sizeof (alua_functab) / sizeof (alua_functab[0]))
void
-alua_setup_libraries (lua_State *lua) /*{{{*/
+alua_setup_libraries (lua_State *lua, bool_t sandbox) /*{{{*/
{
int n;
const char *modname;
for (n = 0; n < sizeof (alua_libtab) / sizeof (alua_libtab[0]); ++n) {
+ if ((! sandbox) || alua_libtab[n].sandbox) {
# if LUA_VERSION_NUM >= 502
- luaL_requiref (lua, alua_libtab[n].libname, alua_libtab[n].libfunc, 1);
- lua_pop (lua, 1);
+ luaL_requiref (lua, alua_libtab[n].libname, alua_libtab[n].libfunc, 1);
+ lua_pop (lua, 1);
# else
- lua_pushcfunction (lua, alua_libtab[n].libfunc);
- lua_pushstring (lua, alua_libtab[n].libname);
- lua_call (lua, 1, 0);
-# endif
+ lua_pushcfunction (lua, alua_libtab[n].libfunc);
+ lua_pushstring (lua, alua_libtab[n].libname);
+ lua_call (lua, 1, 0);
+# endif
+ }
}
alua_date_setup (lua);
- alua_env_setup (lua);
+ if (! sandbox)
+ alua_env_setup (lua);
alua_null_setup (lua);
modname = NULL;
for (n = 0; n <= FTSIZE; ++n) {
@@ -860,7 +880,7 @@ alua_setup_libraries (lua_State *lua) /*{{{*/
}
}
}
- if (n < FTSIZE) {
+ if ((n < FTSIZE) && ((! sandbox) || alua_functab[n].sandbox)) {
lua_pushcfunction (lua, alua_functab[n].func);
if (modname)
lua_setfield (lua, -2, alua_functab[n].funcname);
@@ -905,13 +925,13 @@ alua_panic (lua_State *lua) /*{{{*/
return 0;
}/*}}}*/
lua_State *
-alua_alloc (void) /*{{{*/
+alua_alloc (bool_t sandbox) /*{{{*/
{
lua_State *lua;
if (lua = lua_newstate (alua_allocator, NULL)) {
lua_atpanic (lua, alua_panic);
- alua_setup_libraries (lua);
+ alua_setup_libraries (lua, sandbox);
}
return lua;
}/*}}}*/
@@ -951,12 +971,44 @@ alua_load (lua_State *lua, const char *name, const void *code, size_t clen) /*{{
rd.clen = clen;
rd.sent = 0;
# if LUA_VERSION_NUM >= 502
- if ((lua_load (lua, alua_reader, & rd, name, NULL) == 0) && (lua_pcall (lua, 0, 0, 0) == 0))
+ if ((lua_load (lua, alua_reader, & rd, name, NULL) == 0) && (lua_pcall (lua, 0, 0, 0) == LUA_OK))
# else
- if ((lua_load (lua, alua_reader, & rd, name) == 0) && (lua_pcall (lua, 0, 0, 0) == 0))
+ if ((lua_load (lua, alua_reader, & rd, name) == 0) && (lua_pcall (lua, 0, 0, 0) == LUA_OK))
# endif
rc = true;
else
rc = false;
return rc;
}/*}}}*/
+typedef struct { /*{{{*/
+ lua_State *lua;
+ int nargs;
+ int nresults;
+ int msgh;
+ int rc;
+ /*}}}*/
+} pcall_t;
+static void
+pcall_wrapper (void *pp) /*{{{*/
+{
+ pcall_t *pc = (pcall_t *) pp;
+
+ pc -> rc = lua_pcall (pc -> lua, pc -> nargs, pc -> nresults, pc -> msgh);
+}/*}}}*/
+int
+alua_pcall (lua_State *lua, int nargs, int nresults, int msgh, int timeout) /*{{{*/
+{
+ if (timeout > 0) {
+ pcall_t pc;
+
+ pc.lua = lua;
+ pc.nargs = nargs;
+ pc.nresults = nresults;
+ pc.msgh = msgh;
+ pc.rc = -1;
+ if (timeout_exec (timeout, pcall_wrapper, & pc))
+ return pc.rc;
+ return -1;
+ } else
+ return lua_pcall (lua, nargs, nresults, msgh);
+}/*}}}*/
diff --git a/backend/src/c/xmlback/alua.h b/backend/src/c/xmlback/alua.h
index 17e3f79ef..03b7ab25f 100644
--- a/backend/src/c/xmlback/alua.h
+++ b/backend/src/c/xmlback/alua.h
@@ -40,9 +40,10 @@ extern int alua_isdate (lua_State *lua, int idx);
extern int alua_isnull (lua_State *lua, int idx);
extern void alua_pushnull (lua_State *lua);
-extern void alua_setup_libraries (lua_State *lua);
+extern void alua_setup_libraries (lua_State *lua, bool_t sandbox);
extern void alua_setup_function (lua_State *lua, const char *modname, const char *funcname, lua_CFunction func, void *closure);
-extern lua_State *alua_alloc (void);
+extern lua_State *alua_alloc (bool_t sandbox);
extern void alua_free (lua_State *lua);
extern bool_t alua_load (lua_State *lua, const char *name, const void *code, size_t clen);
+extern int alua_pcall (lua_State *lua, int nargs, int nresults, int msgh, int timeout);
# endif /* __ALUA_H */
diff --git a/backend/src/c/xmlback/block.c b/backend/src/c/xmlback/block.c
index 878513370..9042f7106 100644
--- a/backend/src/c/xmlback/block.c
+++ b/backend/src/c/xmlback/block.c
@@ -9,8 +9,48 @@
* *
********************************************************************************************************************************************************************************************************************************************************************/
# include
+# include
+# include
# include "xmlback.h"
+static const xmlChar *
+tagsearch (const xmlChar *haystack, int haystack_size, const xmlChar *needle, int needle_size, int *match_size) /*{{{*/
+{
+ const xmlChar *match = NULL;
+ int match_index = 0;
+ int clen;
+
+ while (haystack_size > 0) {
+ clen = xmlCharLength (*haystack);
+ if ((clen <= haystack_size) && (clen <= needle_size - match_index)) {
+ if ((clen == 1) && isspace (*haystack) && match && (xmlCharLength (needle[match_index]) == 1) && isspace (needle[match_index])) {
+ ++haystack;
+ --haystack_size;
+ ++match_index;
+ while ((haystack_size > 0) && (xmlCharLength (*haystack) == 1) && isspace (*haystack))
+ ++haystack, --haystack_size;
+ while ((match_index < needle_size) && (xmlCharLength (needle[match_index]) == 1) && isspace (needle[match_index]))
+ ++match_index;
+ continue;
+ }
+ if (match && memcmp (haystack, needle + match_index, clen))
+ match_index = 0;
+ if (! memcmp (haystack, needle + match_index, clen)) {
+ if (! match_index)
+ match = haystack;
+ match_index += clen;
+ if (match_index == needle_size) {
+ *match_size = haystack - match + clen;
+ return match;
+ }
+ }
+ } else
+ match_index = 0;
+ haystack += clen;
+ haystack_size -= clen;
+ }
+ return NULL;
+}/*}}}*/
block_t *
block_alloc (void) /*{{{*/
{
@@ -42,7 +82,6 @@ block_alloc (void) /*{{{*/
b -> bcontent = NULL;
b -> bout = NULL;
DO_ZERO (b, tagpos);
- b -> sorted = NULL;
b -> revalidation.source = NULL;
b -> revalidation.target = NULL;
b -> inuse = false;
@@ -78,8 +117,6 @@ block_free (block_t *b) /*{{{*/
if (b -> bout)
buffer_free (b -> bout);
DO_FREE (b, tagpos);
- if (b -> sorted)
- free (b -> sorted);
if (b -> revalidation.source)
buffer_free (b -> revalidation.source);
if (b -> revalidation.target)
@@ -88,6 +125,14 @@ block_free (block_t *b) /*{{{*/
}
return NULL;
}/*}}}*/
+void
+block_swap_inout (block_t *b) /*{{{*/
+{
+ xmlBufferPtr temp = b -> in;
+
+ b -> in = b -> out;
+ b -> out = temp;
+}/*}}}*/
bool_t
block_setup_charset (block_t *b) /*{{{*/
{
@@ -117,10 +162,27 @@ block_setup_charset (block_t *b) /*{{{*/
void
block_setup_tagpositions (block_t *b, blockmail_t *blockmail) /*{{{*/
{
- int n;
+ int n;
+ int position;
+ const xmlChar *content = b -> content ? xmlBufferContent (b -> content) : NULL;
+ int length = b -> content ? xmlBufferLength (b -> content) : 0;
- for (n = 0; n < b -> tagpos_count; ++n)
- tagpos_setup_tag (b -> tagpos[n], blockmail);
+ for (n = 0, position = 0; n < b -> tagpos_count; ++n) {
+ tagpos_t *tp = b -> tagpos[n];
+
+ if (content && tp -> name) {
+ int match_size;
+ const xmlChar *hit = tagsearch (content + position, length - position, xmlBufferContent (tp -> name), xmlBufferLength (tp -> name), & match_size);
+
+ if (hit) {
+ tp -> start = hit - content;
+ tp -> end = position = tp -> start + match_size;
+ } else {
+ tp -> start = tp -> end = position = length;
+ }
+ }
+ tagpos_setup_tag (tp, blockmail);
+ }
}/*}}}*/
void
block_find_method (block_t *b) /*{{{*/
diff --git a/backend/src/c/xmlback/blockmail.c b/backend/src/c/xmlback/blockmail.c
index 7abce49f0..70701ac5b 100644
--- a/backend/src/c/xmlback/blockmail.c
+++ b/backend/src/c/xmlback/blockmail.c
@@ -103,6 +103,7 @@ blockmail_alloc (const char *fname, bool_t syncfile, log_t *lg) /*{{{*/
b -> active = false;
b -> reason = REASON_UNSPEC;
b -> reason_detail = 0;
+ b -> reason_custom = NULL;
b -> head = NULL;
b -> body = NULL;
b -> rblocks = NULL;
@@ -139,7 +140,9 @@ blockmail_alloc (const char *fname, bool_t syncfile, log_t *lg) /*{{{*/
b -> auto_url = NULL;
b -> auto_url_is_dynamic = false;
b -> auto_url_prefix = NULL;
+ b -> gui = false;
b -> anon = false;
+ b -> anon_preserve_links = false;
b -> selector = NULL;
b -> convert_to_entities = false;
b -> onepixel_url = NULL;
@@ -177,6 +180,8 @@ blockmail_alloc (const char *fname, bool_t syncfile, log_t *lg) /*{{{*/
b -> mtbuf[0] = NULL;
b -> mtbuf[1] = NULL;
+ b -> use_new_url_modification = false;
+
DO_ZERO (b, url);
DO_ZERO (b, link_resolve);
@@ -243,6 +248,8 @@ blockmail_free (blockmail_t *b) /*{{{*/
tracker_free (b -> tracker);
if (b -> counter)
counter_free_all (b -> counter);
+ if (b -> reason_custom)
+ free (b -> reason_custom);
if (b -> head)
buffer_free (b -> head);
if (b -> body)
@@ -423,7 +430,7 @@ blockmail_unsync (blockmail_t *b) /*{{{*/
}
}/*}}}*/
bool_t
-blockmail_insync (blockmail_t *b, int cid, const char *mediatype, int subtype, int chunks, int bcccount) /*{{{*/
+blockmail_insync (blockmail_t *b, receiver_t *rec, int bcccount) /*{{{*/
{
bool_t rc;
@@ -435,6 +442,7 @@ blockmail_insync (blockmail_t *b, int cid, const char *mediatype, int subtype, i
char *size, *mtyp, *temp;
int styp;
int ncid;
+ int chunks;
long bytes;
while (inp = fgets (buf, sizeof (buf) - 1, b -> syfp)) {
@@ -466,9 +474,9 @@ blockmail_insync (blockmail_t *b, int cid, const char *mediatype, int subtype, i
}
}
}
- if (mtyp && (cid == ncid) && (! strcmp (mtyp, mediatype)) && (styp == subtype)) {
+ if (mtyp && (rec -> customer_id == ncid) && (! strcmp (mtyp, rec -> mid)) && (styp == rec -> mailtype)) {
if ((bytes > 0) && b -> mailtrack)
- mailtrack_add (b -> mailtrack, cid);
+ mailtrack_add (b -> mailtrack, rec);
rc = true;
break;
}
@@ -479,7 +487,7 @@ blockmail_insync (blockmail_t *b, int cid, const char *mediatype, int subtype, i
return rc;
}/*}}}*/
bool_t
-blockmail_tosync (blockmail_t *b, int cid, const char *mediatype, int subtype, int chunks, long size, int bcccount) /*{{{*/
+blockmail_tosync (blockmail_t *b, receiver_t *rec, int bcccount) /*{{{*/
{
bool_t rc;
@@ -494,17 +502,17 @@ blockmail_tosync (blockmail_t *b, int cid, const char *mediatype, int subtype, i
} else
pos = -1;
if (rc) {
- if ((fprintf (b -> syfp, "%d;%ld;%s;%d;%d\n", cid, size, mediatype, subtype, chunks) == -1) ||
+ if ((fprintf (b -> syfp, "%d;%ld;%s;%d;%d\n", rec -> customer_id, rec -> size, rec -> mid, rec -> mailtype, rec -> chunks) == -1) ||
(fflush (b -> syfp) == -1))
rc = false;
if (rc && (pos != -1) && (fseek (b -> syfp, pos, SEEK_SET) == -1))
rc = false;
}
}
- if (rc && cid) {
- rc = blockmail_count (b, mediatype, subtype, chunks, size, bcccount);
+ if (rc && rec -> customer_id) {
+ rc = blockmail_count (b, rec -> mid, rec -> mailtype, rec -> chunks, rec -> size, bcccount);
if (b -> active && b -> mailtrack)
- mailtrack_add (b -> mailtrack, cid);
+ mailtrack_add (b -> mailtrack, rec);
}
return rc;
}/*}}}*/
@@ -760,9 +768,10 @@ blockmail_setup_auto_url_prefix (blockmail_t *b, const char *nprefix) /*{{{*/
b -> auto_url_prefix = nprefix && *nprefix ? strdup (nprefix) : NULL;
}/*}}}*/
void
-blockmail_setup_anon (blockmail_t *b, bool_t anon) /*{{{*/
+blockmail_setup_anon (blockmail_t *b, bool_t anon, bool_t anon_preserve_links) /*{{{*/
{
b -> anon = anon;
+ b -> anon_preserve_links = anon_preserve_links;
}/*}}}*/
void
blockmail_setup_selector (blockmail_t *b, const char *selector) /*{{{*/
diff --git a/backend/src/c/xmlback/create.c b/backend/src/c/xmlback/create.c
index 5f15bfb88..c0626467a 100644
--- a/backend/src/c/xmlback/create.c
+++ b/backend/src/c/xmlback/create.c
@@ -111,17 +111,18 @@ fixer (fix_t *fix, int attcount, blockmail_t *blockmail, receiver_t *rec, bool_t
static bool_t
create_mail (blockmail_t *blockmail, receiver_t *rec) /*{{{*/
{
- int n, m;
- bool_t st;
- int attcount;
- links_t *links;
- postfix_t *postfixes;
- buffer_t *dest;
+ int n, m;
+ bool_t st;
+ int attcount;
+ links_t *links;
+ postfix_t *postfixes;
+ buffer_t *dest;
mailtypedefinition_t *mtyp;
- blockspec_t *bspec;
- block_t *block;
- rblock_t *rbprev, *rbhead;
- bool_t changed;
+ blockspec_t *bspec;
+ block_t *block;
+ block_t *header;
+ rblock_t *rbprev, *rbhead;
+ bool_t changed;
mtyp = (rec -> mailtype >= 0) && (rec -> mailtype < blockmail -> mailtypedefinition_count) ? blockmail -> mailtypedefinition[rec -> mailtype] : NULL;
if (! mtyp) {
@@ -140,6 +141,7 @@ create_mail (blockmail_t *blockmail, receiver_t *rec) /*{{{*/
* 1. Stage: check for usful blocks, count attachments and
* create the content part */
links = mtyp -> offline ? links_alloc () : NULL;
+ header = NULL;
for (n = 0; st && (n < mtyp -> blockspec_count); ++n) {
bspec = mtyp -> blockspec[n];
block = bspec -> block;
@@ -178,7 +180,7 @@ create_mail (blockmail_t *blockmail, receiver_t *rec) /*{{{*/
attcount++;
if (! block -> binary) {
if (st) {
- log_idpush (blockmail -> lg, "replace_tags", "->");
+ log_idpush (blockmail -> lg, "replace_tags");
st = replace_tags (blockmail, rec, block,
0, true,
(block -> tid != TID_EMail_Head ? NULL : replace_head),
@@ -187,29 +189,19 @@ create_mail (blockmail_t *blockmail, receiver_t *rec) /*{{{*/
log_idpop (blockmail -> lg);
if (! st)
log_out (blockmail -> lg, LV_ERROR, "Unable to replace tags in block %d for %d", block -> nr, rec -> customer_id);
+ else if (block -> tid == TID_EMail_Head) {
+ if (block -> nr == 0) {
+ header = block;
+ }
+ }
}
- if (st) {
- log_idpush (blockmail -> lg, "modify_output", "->");
+ if (st && (block -> tid != TID_EMail_Head)) {
+ log_idpush (blockmail -> lg, "modify_output");
st = modify_output (blockmail, rec, block, bspec, links);
log_idpop (blockmail -> lg);
if (! st)
log_out (blockmail -> lg, LV_ERROR, "Unable to modify output in block %d for %d", block -> nr, rec -> customer_id);
}
- if (st) {
- if ((! blockmail -> raw) && (! block -> precoded)) {
- log_idpush (blockmail -> lg, "convert_charset", "->");
- st = convert_charset (blockmail, block);
- log_idpop (blockmail -> lg);
- if (! st)
- log_out (blockmail -> lg, LV_ERROR, "Unable to convert chararcter set in block %d for %d", block -> nr, rec -> customer_id);
- } else {
- xmlBufferPtr temp;
-
- temp = block -> out;
- block -> out = block -> in;
- block -> in = temp;
- }
- }
}
}
if (changed && rec -> rvdata -> cur)
@@ -217,9 +209,39 @@ create_mail (blockmail_t *blockmail, receiver_t *rec) /*{{{*/
}
if (links)
links_free (links);
+
+ /*
+ * 2.1. Stage finalize header */
+ if (st && header) {
+ log_idpush (blockmail -> lg, "modify_header");
+ st = modify_header (blockmail, header);
+ log_idpop (blockmail -> lg);
+ if (! st)
+ log_out (blockmail -> lg, LV_ERROR, "Unable to modify header for %d", rec -> customer_id);
+ }
+
+ /*
+ * 2.2. Stage: finalize blocks */
+ for (n = 0; st && (n < mtyp -> blockspec_count); ++n) {
+ bspec = mtyp -> blockspec[n];
+ block = bspec -> block;
+ if (block -> inuse && (! block -> binary)) {
+ if (st) {
+ if ((! blockmail -> raw) && (! block -> precoded)) {
+ log_idpush (blockmail -> lg, "convert_charset");
+ st = convert_charset (blockmail, block);
+ log_idpop (blockmail -> lg);
+ if (! st)
+ log_out (blockmail -> lg, LV_ERROR, "Unable to convert chararcter set in block %d for %d", block -> nr, rec -> customer_id);
+ } else {
+ block_swap_inout (block);
+ }
+ }
+ }
+ }
/*
- * 2. Stage: determinate the required postfixes */
+ * 3. Stage: determinate the required postfixes */
postfixes = NULL;
for (n = 0; st && (n < mtyp -> blockspec_count); ++n) {
bspec = mtyp -> blockspec[n];
@@ -253,7 +275,7 @@ create_mail (blockmail_t *blockmail, receiver_t *rec) /*{{{*/
}
/*
- * 3. Stage: create the output */
+ * 4. Stage: create the output */
rbprev = NULL;
rbhead = NULL;
for (n = 0; st && (n <= mtyp -> blockspec_count); ++n) {
@@ -371,6 +393,10 @@ create_output (blockmail_t *blockmail, receiver_t *rec) /*{{{*/
blockmail -> active = true;
blockmail -> reason = REASON_UNSPEC;
blockmail -> reason_detail = 0;
+ if (blockmail -> reason_custom) {
+ free (blockmail -> reason_custom);
+ blockmail -> reason_custom = NULL;
+ }
blockmail -> head -> length = 0;
blockmail -> body -> length = 0;
if (blockmail -> raw && blockmail -> rblocks)
diff --git a/backend/src/c/xmlback/eval.c b/backend/src/c/xmlback/eval.c
index f7a76e6e8..e51330d86 100644
--- a/backend/src/c/xmlback/eval.c
+++ b/backend/src/c/xmlback/eval.c
@@ -1318,18 +1318,19 @@ do_init (blockmail_t *blockmail) /*{{{*/
s = NULL;
if (! parse_error) {
parse_error = buffer_alloc (512);
+ SLang_Error_Hook = record_error;
+ if ((SLang_init_slang () == -1) ||
+ (SLang_init_slmath () == -1) ||
+ (SLang_init_slassoc () == -1) ||
+ (SLang_init_array () == -1) ||
+ (SLdate_setup (& sd) == -1) ||
+ (SLadd_intrin_fun_table (functab, (char *) "__XMLBACK__") == -1))
+ return NULL;
} else {
parse_error -> length = 0;
}
ctx_set (blockmail);
- SLang_Error_Hook = record_error;
- if ((SLang_init_slang () != -1) &&
- (SLang_init_slmath () != -1) &&
- (SLang_init_slassoc () != -1) &&
- (SLang_init_array () != -1) &&
- (SLdate_setup (& sd) != -1) &&
- (SLadd_intrin_fun_table (functab, (char *) "__XMLBACK__") != -1) &&
- (s = (slang_t *) malloc (sizeof (slang_t)))) {
+ if (s = (slang_t *) malloc (sizeof (slang_t))) {
char *rcfile;
s -> blockmail = blockmail;
diff --git a/backend/src/c/xmlback/generate.c b/backend/src/c/xmlback/generate.c
index c120228a1..1ba1f0f1c 100644
--- a/backend/src/c/xmlback/generate.c
+++ b/backend/src/c/xmlback/generate.c
@@ -1539,21 +1539,30 @@ generate_owrite (void *data, blockmail_t *blockmail, receiver_t *rec) /*{{{*/
}
if (! blockmail -> active) {
char dsn[32];
- char scratch[128];
+ char *custom;
const char *reason;
snprintf (dsn, sizeof (dsn) - 1, "1.%d.%d", blockmail -> reason, blockmail -> reason_detail);
+ custom = NULL;
switch (blockmail -> reason) {
case REASON_UNSPEC: reason = "skip=unspec reason"; break;
case REASON_NO_MEDIA: reason = "skip=no media"; break;
case REASON_EMPTY_DOCUMENT: reason = "skip=no document"; break;
case REASON_UNMATCHED_MEDIA: reason = "skip=unmatched media"; break;
+ case REASON_CUSTOM:
default:
- snprintf (scratch, sizeof (scratch) - 1, "skip=reason %d", blockmail -> reason);
- reason = scratch;
+ if ((blockmail -> reason == REASON_CUSTOM) && blockmail -> reason_custom) {
+ if (custom = malloc (strlen (blockmail -> reason_custom) + 6))
+ sprintf (custom, "skip=%s", blockmail -> reason_custom);
+ } else if (custom = malloc (32)) {
+ sprintf (custom, "skip=reason %d", blockmail -> reason);
+ }
+ reason = custom;
break;
}
- st = write_bounce_log (g, blockmail, rec, dsn, reason);
+ st = write_bounce_log (g, blockmail, rec, dsn, reason ? reason : "skip=not specified");
+ if (custom)
+ free (custom);
} else if (! rec -> media) {
st = write_bounce_log (g, blockmail, rec, "1.0.0", "skip=missing media");
} else if (rec -> media -> type == Mediatype_EMail) {
diff --git a/backend/src/c/xmlback/link_resolve.c b/backend/src/c/xmlback/link_resolve.c
index cfb3a473b..1e66db8dd 100644
--- a/backend/src/c/xmlback/link_resolve.c
+++ b/backend/src/c/xmlback/link_resolve.c
@@ -374,7 +374,7 @@ to_target (hashtag_t *h, buffer_t *input1, xmlBufferPtr input2, buffer_t *target
if (block && block -> translate) {
xmlBufferPtr out = xmlBufferCreate ();
- xmlBufferPtr buf;
+ xmlBufferPtr buf = NULL;
if (input1) {
buf = xmlBufferCreateSize (input1 -> length);
@@ -388,7 +388,7 @@ to_target (hashtag_t *h, buffer_t *input1, xmlBufferPtr input2, buffer_t *target
done = true;
}
xmlBufferFree (out);
- if (input1)
+ if (buf)
xmlBufferFree (buf);
}
if (! done)
diff --git a/backend/src/c/xmlback/lua-5.3.5.tar.gz b/backend/src/c/xmlback/lua-5.3.5.tar.gz
deleted file mode 100644
index 90c002729..000000000
Binary files a/backend/src/c/xmlback/lua-5.3.5.tar.gz and /dev/null differ
diff --git a/backend/src/c/xmlback/lua-5.4.4.tar.gz b/backend/src/c/xmlback/lua-5.4.4.tar.gz
new file mode 100644
index 000000000..f33e45812
Binary files /dev/null and b/backend/src/c/xmlback/lua-5.4.4.tar.gz differ
diff --git a/backend/src/c/xmlback/luatc.c b/backend/src/c/xmlback/luatc.c
index 26b476de4..8e2f8b554 100644
--- a/backend/src/c/xmlback/luatc.c
+++ b/backend/src/c/xmlback/luatc.c
@@ -290,7 +290,7 @@ do_unittest (iflua_t *il, bool_t quiet, int benchmark) /*{{{*/
return rc;
}/*}}}*/
static bool_t
-validate (const char *fname, codeblock_t *cb, bool_t quiet, bool_t postproc, bool_t unittest, int benchmark) /*{{{*/
+validate (const char *fname, codeblock_t *cb, bool_t quiet, bool_t unittest, int benchmark) /*{{{*/
{
bool_t rc;
log_t *lg;
@@ -324,18 +324,19 @@ validate (const char *fname, codeblock_t *cb, bool_t quiet, bool_t postproc, boo
blockmail -> company_token = strdup ("abc123");
blockmail -> mailinglist_id = 3;
blockmail -> mailinglist_name = xmlBufferCreate ();
- xmlBufferCat (blockmail -> mailinglist_name, (const xmlChar *) "Mailinglist");
+ xmlBufferCCat (blockmail -> mailinglist_name, "Mailinglist");
blockmail -> mailing_id = 4;
blockmail -> mailing_name = xmlBufferCreate ();
- xmlBufferCat (blockmail -> mailing_name, (const xmlChar *) "Mailing");
+ xmlBufferCCat (blockmail -> mailing_name, "Mailing");
blockmail -> maildrop_status_id = 5;
blockmail -> status_field = 'W';
blockmail -> senddate = tf_parse_date ("2010-03-20 12:34:56");
- blockmail -> total_subscribers = 6;
- blockmail -> blocknr = 7;
blockmail -> secret_key = xmlBufferCreate ();
xmlBufferCCat (blockmail -> secret_key, "This is secret");
- blockmail -> secret_timestamp = 8;
+ blockmail -> secret_timestamp = 6;
+ blockmail -> total_subscribers = 7;
+ blockmail -> domain = strdup ("exsample.com");
+ blockmail -> blocknr = 8;
string_map_addsi (blockmail -> smap, "licence_id", blockmail -> licence_id);
string_map_addsi (blockmail -> smap, "owner_id", blockmail -> owner_id);
string_map_addsi (blockmail -> smap, "company_id", blockmail -> company_id);
@@ -356,7 +357,7 @@ validate (const char *fname, codeblock_t *cb, bool_t quiet, bool_t postproc, boo
if (cur -> var[0] == '_')
string_map_addss (blockmail -> smap, cur -> var + 1, cur -> val);
}
- for (run = cb; run; run = run ->next) {
+ for (run = cb; run; run = run -> next) {
char id[1024];
if (run -> condition)
@@ -365,41 +366,37 @@ validate (const char *fname, codeblock_t *cb, bool_t quiet, bool_t postproc, boo
strcpy (id, fname);
rc = false;
if (r = receiver_alloc (blockmail, 0)) {
+ iflua_t *il;
+
r -> customer_id = 100;
r -> user_type = 'W';
- if (postproc) {
- fprintf (stderr, "Postprocessing not available for %s\n", id);
- } else {
- iflua_t *il;
-
- if (il = iflua_alloc (blockmail)) {
- il -> rec = r;
- alua_setup_function (il -> lua, NULL, "fileread", l_fileread, il);
- if (quiet)
- alua_setup_function (il -> lua, NULL, "print", l_silent, NULL);
- if (alua_load (il -> lua, id, run -> code, run -> length)) {
- if (unittest)
- rc = do_unittest (il, quiet, benchmark);
- else {
- rc = true;
- lua_getglobal (il -> lua, F_MAIN);
- if (lua_isfunction (il -> lua, -1)) {
- if (lua_pcall (il -> lua, 0, 0, 0) != 0) {
- fprintf (stderr, "Failed to execute function \"" F_MAIN "\"\n");
- fprintf (stderr, "*** %s\n", lua_tostring (il -> lua, -1));
- rc = false;
- }
- } else
- lua_pop (il -> lua, 1);
- }
- } else {
- fprintf (stderr, "Failed to execute code for %s\n", id);
- fprintf (stderr, "*** %s\n", lua_tostring (il -> lua, -1));
+ if (il = iflua_alloc (blockmail, false)) {
+ il -> rec = r;
+ alua_setup_function (il -> lua, NULL, "fileread", l_fileread, il);
+ if (quiet)
+ alua_setup_function (il -> lua, NULL, "print", l_silent, NULL);
+ if (alua_load (il -> lua, id, run -> code, run -> length)) {
+ if (unittest)
+ rc = do_unittest (il, quiet, benchmark);
+ else {
+ rc = true;
+ lua_getglobal (il -> lua, F_MAIN);
+ if (lua_isfunction (il -> lua, -1)) {
+ if (lua_pcall (il -> lua, 0, 0, 0) != 0) {
+ fprintf (stderr, "Failed to execute function \"" F_MAIN "\"\n");
+ fprintf (stderr, "*** %s\n", lua_tostring (il -> lua, -1));
+ rc = false;
+ }
+ } else
+ lua_pop (il -> lua, 1);
}
- iflua_free (il);
- } else
- fprintf (stderr, "Failed to setup interpreter interface for %s\n", id);
- }
+ } else {
+ fprintf (stderr, "Failed to execute code for %s\n", id);
+ fprintf (stderr, "*** %s\n", lua_tostring (il -> lua, -1));
+ }
+ iflua_free (il);
+ } else
+ fprintf (stderr, "Failed to setup interpreter interface for %s\n", id);
receiver_free (r);
} else
fprintf (stderr, "Failed to setup receiver structure for %s\n", id);
@@ -417,23 +414,18 @@ main (int argc, char **argv) /*{{{*/
{
int n;
bool_t quiet;
- bool_t postproc;
bool_t unittest;
int benchmark;
int rc;
quiet = false;
- postproc = false;
unittest = false;
benchmark = 0;
- while ((n = getopt (argc, argv, "hqpub:")) != -1)
+ while ((n = getopt (argc, argv, "hqub:")) != -1)
switch (n) {
case 'q':
quiet = true;
break;
- case 'p':
- postproc = true;
- break;
case 'u':
unittest = true;
break;
@@ -449,10 +441,6 @@ main (int argc, char **argv) /*{{{*/
fprintf (stderr, "Usage: %s [-q] [-p | -u [-b ]] \n", argv[0]);
return n != 'h';
}
- if (postproc && unittest) {
- fprintf (stderr, "Warning: unittest in postprocess mode not supported, switched off.\n");
- unittest = false;
- }
rc = 0;
for (n = optind; n < argc; ++n) {
char *buf;
@@ -462,7 +450,7 @@ main (int argc, char **argv) /*{{{*/
codeblock_t *cb;
if (cb = split_code (buf)) {
- if (! validate (argv[n], cb, quiet, postproc, unittest, benchmark))
+ if (! validate (argv[n], cb, quiet, unittest, benchmark))
rc = 1;
codeblock_free_all (cb);
} else {
diff --git a/backend/src/c/xmlback/mailtrack.c b/backend/src/c/xmlback/mailtrack.c
index 43aa43c37..601e2c440 100644
--- a/backend/src/c/xmlback/mailtrack.c
+++ b/backend/src/c/xmlback/mailtrack.c
@@ -35,8 +35,8 @@ mailtrack_free (mailtrack_t *m) /*{{{*/
return NULL;
}/*}}}*/
void
-mailtrack_add (mailtrack_t *m, int customer_id) /*{{{*/
+mailtrack_add (mailtrack_t *m, receiver_t *rec) /*{{{*/
{
- buffer_format (m -> content, "%s%d", (m -> count ? "," : ""), customer_id);
+ buffer_format (m -> content, "%s%d/%d", (m -> count ? "," : ""), rec -> customer_id, rec -> media ? rec -> media -> type : Mediatype_Unspec);
m -> count++;
}/*}}}*/
diff --git a/backend/src/c/xmlback/misc.c b/backend/src/c/xmlback/misc.c
index aa092e8e7..45827ea12 100644
--- a/backend/src/c/xmlback/misc.c
+++ b/backend/src/c/xmlback/misc.c
@@ -128,4 +128,38 @@ xml2long (xmlBufferPtr p) /*{{{*/
scratch[len] = '\0';
return strtol (scratch, NULL, 0);
}/*}}}*/
+I void
+entity_escape (xmlBufferPtr target, const xmlChar *source, int source_length) /*{{{*/
+{
+ int clen;
+
+ while (source_length > 0) {
+ clen = xmlCharLength (*source);
+ if (clen > 1) {
+ xmlBufferAdd (target, source, clen);
+ } else
+ switch (*source) {
+ default:
+ xmlBufferAdd (target, source, clen);
+ break;
+ case '&':
+ xmlBufferCCat (target, "&");
+ break;
+ case '<':
+ xmlBufferCCat (target, "<");
+ break;
+ case '>':
+ xmlBufferCCat (target, ">");
+ break;
+ case '\'':
+ xmlBufferCCat (target, "'");
+ break;
+ case '"':
+ xmlBufferCCat (target, """);
+ break;
+ }
+ source += clen;
+ source_length -= clen;
+ }
+}/*}}}*/
# endif /* __MISC_C */
diff --git a/backend/src/c/xmlback/modify.c b/backend/src/c/xmlback/modify.c
index 7ac1b0013..ff398155f 100644
--- a/backend/src/c/xmlback/modify.c
+++ b/backend/src/c/xmlback/modify.c
@@ -102,6 +102,8 @@ mkonepixellogurl (blockmail_t *blockmail, receiver_t *rec) /*{{{*/
buffer_set (blockmail -> link_maker, xmlBufferContent (blockmail -> onepixel_url), xmlBufferLength (blockmail -> onepixel_url));
buffer_appends (blockmail -> link_maker, "uid=");
buffer_appends (blockmail -> link_maker, uid);
+ if (blockmail -> gui)
+ buffer_appends (blockmail -> link_maker, "&nocount=1");
}
free (uid);
return buffer_length (blockmail -> link_maker) ? buffer_string (blockmail -> link_maker) : NULL;
@@ -195,7 +197,7 @@ typedef struct { /*{{{*/
/*}}}*/
} rplc_t;
static bool_t
-replace_anon_hashtags (void *rp, xmlbuf_t *output, const xchar_t *token, int tlen) /*{{{*/
+replace_anon_hashtags (void *rp, buffer_t *output, const xchar_t *token, int tlen) /*{{{*/
{
rplc_t *replacer = (rplc_t *) rp;
int pos;
@@ -231,8 +233,8 @@ replace_anon_hashtags (void *rp, xmlbuf_t *output, const xchar_t *token, int tle
free (param);
return true;
}/*}}}*/
-bool_t
-modify_urls (blockmail_t *blockmail, receiver_t *rec, block_t *block, protect_t *protect, bool_t ishtml, record_t *record) /*{{{*/
+static bool_t
+modify_urls_original (blockmail_t *blockmail, receiver_t *rec, block_t *block, protect_t *protect, bool_t ishtml, record_t *record) /*{{{*/
{
int n;
int len;
@@ -320,7 +322,12 @@ modify_urls (blockmail_t *blockmail, receiver_t *rec, block_t *block, protect_t
state = ST_PLAIN_START_FOUND;
break;
/* HTML */
- case 100: CCHK ('a'); break;
+ case 100:
+ if ((tolower (ch) == 'a') || (tolower (ch) == 'v'))
+ ++state;
+ else
+ state = ST_INITIAL;
+ break;
# define HCHK(ccc) do { if ((ccc) == tolower (ch)) ++state; else if ('>' == ch) state = ST_INITIAL; else state = 101; } while (0)
case 101: HCHK ('h'); break;
case 102: HCHK ('r'); break;
@@ -402,22 +409,253 @@ modify_urls (blockmail_t *blockmail, receiver_t *rec, block_t *block, protect_t
}
}
if (blockmail -> anon) {
- if ((m == blockmail -> url_count) || blockmail -> url[m] -> admin_link) {
- xmlBufferAdd (block -> out, (const xmlChar *) "#", 1);
+ if (! blockmail -> anon_preserve_links) {
+ if ((m == blockmail -> url_count) || blockmail -> url[m] -> admin_link) {
+ xmlBufferAdd (block -> out, (const xmlChar *) "#", 1);
+ lstore = end;
+ changed = true;
+ } else if (url_is_personal (cont + start, ulen)) {
+ if (! scratch)
+ scratch = purl_alloc (NULL);
+ if (scratch && purl_parsen (scratch, cont + start, ulen)) {
+ const xchar_t *rplc;
+ int rlen;
+ rplc_t replacer = { blockmail, rec };
+
+ if ((rplc = purl_build (scratch, NULL, & rlen, replace_anon_hashtags, & replacer)) && rlen)
+ xmlBufferAdd (block -> out, (const xmlChar *) rplc, rlen);
+ lstore = end;
+ changed = true;
+ }
+ }
+ }
+ } else if (m < blockmail -> url_count) {
+ mkautourl (blockmail, rec, block, blockmail -> url[m], record);
+ lstore = end;
+ changed = true;
+ } else if (match && match -> resolved) {
+ const xmlChar *url = NULL;
+ int ulength = -1;
+ buffer_t *resolve;
+
+ if (resolve = link_resolve_get (match -> resolved, blockmail, block, match, rec, record)) {
+ url = resolve -> buffer;
+ ulength = resolve -> length;
+ }
+ if (blockmail -> tracker) {
+ if (! url) {
+ url = cont + start;
+ ulength = ulen;
+ }
+ tracker_fill (blockmail -> tracker, blockmail, & url, & ulength);
+ }
+ if (url) {
+ if (ulength > 0)
+ xmlBufferAdd (block -> out, url, ulength);
lstore = end;
changed = true;
- } else if (url_is_personal (cont + start, ulen)) {
- if (! scratch)
- scratch = purl_alloc (NULL);
- if (scratch && purl_parsen (scratch, cont + start, ulen)) {
- const xchar_t *rplc;
- int rlen;
- rplc_t replacer = { blockmail, rec };
-
- if ((rplc = purl_build (scratch, NULL, & rlen, replace_anon_hashtags, & replacer)) && rlen)
- xmlBufferAdd (block -> out, (const xmlChar *) rplc, rlen);
+ }
+ }
+ state = ST_INITIAL;
+ }
+ }
+ if (changed) {
+ if (lstore < len)
+ xmlBufferAdd (block -> out, cont + lstore, len - lstore);
+ SWAP (block);
+ }
+ if (scratch)
+ purl_free (scratch);
+ return true;
+}/*}}}*/
+static bool_t
+modify_urls_updated (blockmail_t *blockmail, receiver_t *rec, block_t *block, protect_t *protect, bool_t ishtml, record_t *record) /*{{{*/
+{
+ int n;
+ int len;
+ const xmlChar *cont;
+ int lstore;
+ int state;
+ char ch, quote;
+ int start, end;
+ int mask;
+ int clen;
+ bool_t changed;
+ purl_t *scratch;
+
+ scratch = NULL;
+ xmlBufferEmpty (block -> out);
+ len = xmlBufferLength (block -> in);
+ cont = xmlBufferContent (block -> in);
+ lstore = 0;
+ state = ST_INITIAL;
+ quote = '\0';
+ if (ishtml) {
+ mask = 2;
+ } else {
+ mask = 1;
+ }
+ start = -1;
+ end = -1;
+ changed = false;
+ for (n = 0; n <= len; ) {
+ if (n < len) {
+ clen = xmlCharLength (cont[n]);
+ if (protect) {
+ if (n >= protect -> start) {
+ if (n < protect -> end)
+ n += clen;
+ else
+ protect = protect -> next;
+ continue;
+ }
+ }
+ if ((clen > 1) || isascii ((char) cont[n])) {
+ ch = clen == 1 ? (char) cont[n] : '\0';
+ switch (state) {
+ case ST_INITIAL:
+ if (ishtml) {
+ if (ch == '<') {
+ state = 100;
+ }
+ } else if (strchr ("hm", tolower (ch))) {
+ if (tolower (ch) == 'h') {
+ state = 1;
+ } else {
+ state = 31;
+ }
+ start = n;
+ }
+ break;
+# define CHK(ccc) do { if ((ccc) == ch) ++state; else state = ST_INITIAL; } while (0)
+# define CCHK(ccc) do { if ((ccc) == tolower (ch)) ++state; else state = ST_INITIAL; } while (0)
+ /* plain: http:// and https:// */
+ case 1: CCHK ('t'); break;
+ case 2: CCHK ('t'); break;
+ case 3: CCHK ('p'); break;
+ case 4:
+ ++state;
+ if (tolower (ch) == 's')
+ break;
+ /* Fall through . . . */
+ case 5: CHK (':'); break;
+ case 6: CHK ('/'); break;
+ case 7:
+ if (ch == '/')
+ state = ST_PLAIN_START_FOUND;
+ else
+ state = ST_INITIAL;
+ break;
+ /* plain: mailto: */
+ case 31: CCHK ('a'); break;
+ case 32: CCHK ('i'); break;
+ case 33: CCHK ('l'); break;
+ case 34: CCHK ('t'); break;
+ case 35: CCHK ('o'); break;
+ case 36: CHK (':'); break;
+ case 37:
+ state = ST_PLAIN_START_FOUND;
+ break;
+ /* HTML */
+# define HCHK(ccc) do { if ((ccc) == tolower (ch)) ++state; else if ('>' == ch) state = ST_INITIAL; else state = 100; } while (0)
+ case 100: HCHK ('h'); break;
+ case 101: HCHK ('r'); break;
+ case 102: HCHK ('e'); break;
+ case 103: HCHK ('f'); break;
+# undef HCHK
+ case 104: CHK ('='); break;
+ case 105:
+ if ((ch == '"') || (ch == '\'')) {
+ quote = ch;
+ state = ST_QUOTED_START_FOUND;
+ start = n + 1;
+ } else {
+ state = ST_PLAIN_START_FOUND;
+ start = n;
+ }
+ break;
+ case ST_PLAIN_START_FOUND:
+ if (isspace (ch) || (ch == '>')) {
+ end = n;
+ state = ST_END_FOUND;
+ }
+ break;
+ case ST_QUOTED_START_FOUND:
+ if (isspace (ch) || (ch == quote)) {
+ end = n;
+ state = ST_END_FOUND;
+ }
+ break;
+ default:
+ log_out (blockmail -> lg, LV_ERROR, "modify_urls: invalid state %d at position %d", state, n);
+ state = ST_INITIAL;
+ break;
+ }
+# undef CHK
+# undef CCHK
+ } else {
+ if (state == ST_PLAIN_START_FOUND) {
+ end = n;
+ state = ST_END_FOUND;
+ } else
+ state = ST_INITIAL;
+ }
+ n += clen;
+ } else {
+ if (state == ST_PLAIN_START_FOUND) {
+ end = n;
+ state = ST_END_FOUND;
+ }
+ ++n;
+ }
+ if (state == ST_END_FOUND) {
+ int ulen, m;
+ url_t *match;
+ int first_orig = -1;
+
+ ulen = end - start;
+ for (m = 0, match = NULL; m < blockmail -> url_count; ++m) {
+ if (url_match (blockmail -> url[m], cont + start, ulen)) {
+ match = blockmail -> url[m];
+ if (blockmail -> url[m] -> usage & mask)
+ break;
+ }
+ if ((first_orig == -1) && blockmail -> url[m] -> orig) {
+ first_orig = m;
+ }
+ }
+ if (lstore < start) {
+ xmlBufferAdd (block -> out, cont + lstore, start - lstore);
+ lstore = start;
+ }
+ if ((match == NULL) && (first_orig != -1)) {
+ for (m = first_orig; m < blockmail -> url_count; ++m) {
+ if (url_match_original (blockmail -> url[m], cont + start, ulen)) {
+ match = blockmail -> url[m];
+ if (blockmail -> url[m] -> usage & mask)
+ break;
+ }
+ }
+ }
+ if (blockmail -> anon) {
+ if (! blockmail -> anon_preserve_links) {
+ if ((m == blockmail -> url_count) || blockmail -> url[m] -> admin_link) {
+ xmlBufferAdd (block -> out, (const xmlChar *) "#", 1);
lstore = end;
changed = true;
+ } else if (url_is_personal (cont + start, ulen)) {
+ if (! scratch)
+ scratch = purl_alloc (NULL);
+ if (scratch && purl_parsen (scratch, cont + start, ulen)) {
+ const xchar_t *rplc;
+ int rlen;
+ rplc_t replacer = { blockmail, rec };
+
+ if ((rplc = purl_build (scratch, NULL, & rlen, replace_anon_hashtags, & replacer)) && rlen)
+ xmlBufferAdd (block -> out, (const xmlChar *) rplc, rlen);
+ lstore = end;
+ changed = true;
+ }
}
}
} else if (m < blockmail -> url_count) {
@@ -459,7 +697,11 @@ modify_urls (blockmail_t *blockmail, receiver_t *rec, block_t *block, protect_t
purl_free (scratch);
return true;
}/*}}}*/
-
+bool_t
+modify_urls (blockmail_t *blockmail, receiver_t *rec, block_t *block, protect_t *protect, bool_t ishtml, record_t *record) /*{{{*/
+{
+ return (blockmail -> use_new_url_modification ? modify_urls_updated : modify_urls_original) (blockmail, rec, block, protect, ishtml, record);
+}/*}}}*/
static inline const byte_t *
lskip (const byte_t *line, int *linelen) /*{{{*/
{
@@ -1108,19 +1350,30 @@ modify_linelength (blockmail_t *blockmail, block_t *block, blockspec_t *bspec) /
# undef DOIT_SKIP
}/*}}}*/
bool_t
+modify_header (blockmail_t *blockmail, block_t *header) /*{{{*/
+{
+ bool_t rc = (header -> tid == TID_EMail_Head) ? true : false;
+
+ if (rc && blockmail -> revalidate_mfrom) {
+ rc = revalidate_mfrom (blockmail, header);
+ }
+ return rc;
+}/*}}}*/
+bool_t
modify_output (blockmail_t *blockmail, receiver_t *rec, block_t *block, blockspec_t *bspec, links_t *links) /*{{{*/
{
bool_t rc;
rc = true;
- if (rc && (block -> tid == TID_EMail_Head) && blockmail -> revalidate_mfrom) {
- rc = revalidate_mfrom (blockmail, block);
- }
- if (rc && (block -> tid == TID_EMail_HTML) && links) {
+ if (rc &&
+ (block -> tid == TID_EMail_HTML) &&
+ links) {
rc = collect_links (blockmail, block, links);
}
- if (rc && (! blockmail -> anon) &&
+ if (rc &&
+ (! blockmail -> anon) &&
(block -> tid == TID_EMail_HTML) &&
+ bspec &&
(bspec -> opl != OPL_None)) {
rc = add_onepixellog_image (blockmail, rec, block, bspec -> opl);
}
@@ -1129,10 +1382,18 @@ modify_output (blockmail_t *blockmail, receiver_t *rec, block_t *block, blockspe
blockmail -> convert_to_entities) {
rc = convert_entities (blockmail, block);
}
- if (rc && blockmail -> vip && (block -> tid == TID_EMail_HTML) && islower (rec -> user_type) && (tolower (blockmail -> status_field) == rec -> user_type)) {
+ if (rc &&
+ blockmail -> vip &&
+ (block -> tid == TID_EMail_HTML) &&
+ islower (rec -> user_type) &&
+ (tolower (blockmail -> status_field) == rec -> user_type)) {
rc = add_vip_block (blockmail, block);
}
- if (rc && (bspec -> linelength > 0) && bspec -> linesep) {
+ if (rc &&
+ (block -> tid == TID_EMail_Text) &&
+ bspec &&
+ (bspec -> linelength > 0) &&
+ bspec -> linesep) {
rc = modify_linelength (blockmail, block, bspec);
}
return rc;
diff --git a/backend/src/c/xmlback/parse.c b/backend/src/c/xmlback/parse.c
index 7f7e2b1b7..a1b3e0bdf 100644
--- a/backend/src/c/xmlback/parse.c
+++ b/backend/src/c/xmlback/parse.c
@@ -280,7 +280,7 @@ parse_info (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base, var_t **vbas
;
else
prev = NULL;
- log_idpush (blockmail -> lg, name, "->");
+ log_idpush (blockmail -> lg, name);
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "info")) {
@@ -323,7 +323,7 @@ parse_description (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base) /*{{{
char *ptr;
st = true;
- log_idpush (blockmail -> lg, "description", "->");
+ log_idpush (blockmail -> lg, "description");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "licence")) {
@@ -391,7 +391,7 @@ parse_general (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base) /*{{{*/
xmlNodePtr node;
st = true;
- log_idpush (blockmail -> lg, "general", "->");
+ log_idpush (blockmail -> lg, "general");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "domain"))
@@ -459,7 +459,7 @@ parse_mailcreation (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base) /*{{
long val;
st = true;
- log_idpush (blockmail -> lg, "mailcreation", "->");
+ log_idpush (blockmail -> lg, "mailcreation");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "blocknr")) {
@@ -489,7 +489,7 @@ parse_trackers (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base) /*{{{*/
xmlNodePtr node;
st = true;
- log_idpush (blockmail -> lg, "trackers", "->");
+ log_idpush (blockmail -> lg, "trackers");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "tracker")) {
@@ -594,7 +594,7 @@ parse_mediatypes (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base) /*{{{*
xmlNodePtr node;
st = true;
- log_idpush (blockmail -> lg, "mediatypes", "->");
+ log_idpush (blockmail -> lg, "mediatypes");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "media")) {
@@ -624,7 +624,7 @@ parse_tagposition (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base, tagpo
xmlNodePtr node;
st = true;
- log_idpush (blockmail -> lg, "tagposition", "->");
+ log_idpush (blockmail -> lg, "tagposition");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "block")) {
@@ -655,8 +655,6 @@ parse_block (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr node, block_t *bl
if (extract_numeric_property (blockmail, & bid, node, "id") &&
extract_numeric_property (blockmail, & val, node, "nr")) {
xmlNodePtr child;
- int start, end;
- const xmlChar *content;
st = true;
block -> bid = (int) bid;
@@ -685,9 +683,6 @@ parse_block (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr node, block_t *bl
if (! extract_numeric_property (blockmail, & block -> target_id, node, "target_id")) {
block -> target_id = 0;
}
- start = 0;
- end = 0;
- content = NULL;
for (child = node -> children; st && child; child = child -> next)
if (child -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (child -> name, "content")) {
@@ -695,73 +690,36 @@ parse_block (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr node, block_t *bl
if (st = block_setup_charset (block)) {
if (block -> binary && (! (st = block_code_binary (block))))
log_out (blockmail -> lg, LV_ERROR, "Unable to decode binary part in block %d in %s", block -> nr, blockmail -> fname);
- else {
- start = 0;
- end = xmlBufferLength (block -> content);
- content = xmlBufferContent (block -> content);
- }
} else
log_out (blockmail -> lg, LV_ERROR, "Unable to setup charset in block %d in %s", block -> nr, blockmail -> fname);
} else
log_out (blockmail -> lg, LV_ERROR, "Unable to extract content of block %d in %s", block -> nr, blockmail -> fname);
} else if (! xmlstrcmp (child -> name, "tagposition")) {
- if (content) {
- xmlChar *name;
- tagpos_t *tpos;
- int len;
- const xmlChar *ptr;
- int n;
+ xmlChar *name;
+ tagpos_t *tpos;
- name = xmlGetProp (child, char2xml ("name"));
- if (name) {
- DO_EXPAND (tpos, block, tagpos);
- if (tpos) {
- xmlBufferCat (tpos -> name, name);
- if (extract_numeric_property (blockmail, & val, child, "hash"))
- tpos -> hash = val;
- else
- tpos -> hash = 0;
- if (extract_numeric_property (blockmail, & val, child, "type"))
- tpos -> type = val;
- tagpos_find_name (tpos);
- len = xmlBufferLength (tpos -> name);
- ptr = xmlBufferContent (tpos -> name);
- n = 0;
- st = false;
- while (start < end) {
- if (content[start] != ptr[n])
- n = 0;
- if (content[start] == ptr[n]) {
- ++n;
- if (n == len) {
- st = true;
- break;
- }
- }
- ++start;
- }
- if (st) {
- ++start;
- tpos -> start = start - len;
- tpos -> end = start;
- if (child -> children)
- st = parse_tagposition (blockmail, doc, child -> children, tpos);
- } else
- log_out (blockmail -> lg, LV_ERROR, "tagposition %s not found in %s", ptr, blockmail -> fname);
- if (! st)
- DO_SHRINK (block, tagpos);
- } else
- st = false;
- } else {
- log_out (blockmail -> lg, LV_ERROR, "Missing properties in element %s in %s", child -> name, blockmail -> fname);
+ name = xmlGetProp (child, char2xml ("name"));
+ if (name) {
+ DO_EXPAND (tpos, block, tagpos);
+ if (tpos) {
+ xmlBufferCat (tpos -> name, name);
+ if (extract_numeric_property (blockmail, & val, child, "hash"))
+ tpos -> hash = val;
+ else
+ tpos -> hash = 0;
+ if (extract_numeric_property (blockmail, & val, child, "type"))
+ tpos -> type = val;
+ tagpos_find_name (tpos);
+ if (child -> children)
+ st = parse_tagposition (blockmail, doc, child -> children, tpos);
+ } else
st = false;
- }
- if (name)
- xmlFree (name);
} else {
- log_out (blockmail -> lg, LV_ERROR, "Missing content for tagposition");
+ log_out (blockmail -> lg, LV_ERROR, "Missing properties in element %s in %s", child -> name, blockmail -> fname);
st = false;
}
+ if (name)
+ xmlFree (name);
} else
unknown (blockmail, child);
if (! st)
@@ -772,11 +730,6 @@ parse_block (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr node, block_t *bl
log_out (blockmail -> lg, LV_ERROR, "Unable to setup block for BlockID %d in %s", block -> bid, blockmail -> fname);
st = false;
}
- if (st && (block -> tagpos_count > 0))
- if (! (block -> sorted = (tagpos_t **) malloc (sizeof (tagpos_t *) * block -> tagpos_count))) {
- log_out (blockmail -> lg, LV_ERROR, "Failed to alloc memory for sorted tag positions");
- st = false;
- }
} else {
log_out (blockmail -> lg, LV_ERROR, "Missing number in block in %s", blockmail -> fname);
st = false;
@@ -790,7 +743,7 @@ parse_blocks (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base) /*{{{*/
xmlNodePtr node;
st = true;
- log_idpush (blockmail -> lg, "blocks", "->");
+ log_idpush (blockmail -> lg, "blocks");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "block")) {
@@ -819,7 +772,7 @@ parse_fixdata (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base, fix_t *f)
xmlNodePtr node;
st = true;
- log_idpush (blockmail -> lg, "fixdata", "->");
+ log_idpush (blockmail -> lg, "fixdata");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "fixdata")) {
@@ -861,7 +814,7 @@ parse_blockspec (blockmail_t *blockmail, blockspec_t *bspec, xmlDocPtr doc, xmlN
xmlNodePtr node;
st = true;
- log_idpush (blockmail -> lg, "blockspec", "->");
+ log_idpush (blockmail -> lg, "blockspec");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "prefix")) {
@@ -902,7 +855,7 @@ parse_type (blockmail_t *blockmail, mailtypedefinition_t *mtyp, xmlDocPtr doc, x
char *ptr;
st = true;
- log_idpush (blockmail -> lg, "type", "->");
+ log_idpush (blockmail -> lg, "type");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "blockspec")) {
@@ -957,7 +910,7 @@ parse_types (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base) /*{{{*/
xmlNodePtr node;
st = true;
- log_idpush (blockmail -> lg, "types", "->");
+ log_idpush (blockmail -> lg, "types");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "type")) {
@@ -999,7 +952,7 @@ parse_layout (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base) /*{{{*/
field_t *field;
st = true;
- log_idpush (blockmail -> lg, "layout", "->");
+ log_idpush (blockmail -> lg, "layout");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "element")) {
@@ -1064,7 +1017,7 @@ parse_tag (blockmail_t *blockmail, tag_t **tbase, xmlDocPtr doc, xmlNodePtr base
;
else
prev = NULL;
- log_idpush (blockmail -> lg, "tag", "->");
+ log_idpush (blockmail -> lg, "tag");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "tag")) {
@@ -1122,7 +1075,7 @@ parse_dyncont (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base, dyn_t *dy
xmlNodePtr node;
st = true;
- log_idpush (blockmail -> lg, "content", "->");
+ log_idpush (blockmail -> lg, "content");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "block")) {
@@ -1154,7 +1107,7 @@ parse_dynamic (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base,
st = true;
*root = NULL;
prv = NULL;
- log_idpush (blockmail -> lg, "dynamic", "->");
+ log_idpush (blockmail -> lg, "dynamic");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "dyncont")) {
@@ -1217,7 +1170,7 @@ parse_dynamics (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base) /*{{{*/
st = true;
prv = NULL;
- log_idpush (blockmail -> lg, "dynamics", "->");
+ log_idpush (blockmail -> lg, "dynamics");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "dynamic")) {
@@ -1271,7 +1224,7 @@ parse_urls (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base) /*{{{*/
xmlNodePtr node;
st = true;
- log_idpush (blockmail -> lg, "urls", "->");
+ log_idpush (blockmail -> lg, "urls");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "url")) {
@@ -1316,7 +1269,7 @@ parse_details (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base,
st = true;
cur = NULL;
- log_idpush (blockmail -> lg, "details", "->");
+ log_idpush (blockmail -> lg, "details");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "record")) {
@@ -1377,7 +1330,7 @@ parse_receivers (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base) /*{{{*/
char *ptr;
st = false;
- log_idpush (blockmail -> lg, "receivers", "->");
+ log_idpush (blockmail -> lg, "receivers");
if (rec = receiver_alloc (blockmail, blockmail -> field_count)) {
st = true;
for (node = base; node && st; node = node -> next) {
@@ -1458,17 +1411,17 @@ parse_receivers (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base) /*{{{*/
if (parse_details (blockmail, doc, node -> children, rec)) {
st = true;
rec -> dkim = blockmail -> dkim && sdkim_should_sign (blockmail -> dkim, rec) ? true : false;
- log_idpush (blockmail -> lg, "create", "->");
+ log_idpush (blockmail -> lg, "create");
st = create_output (blockmail, rec);
if (blockmail -> eval)
eval_done_match (blockmail -> eval);
log_idpop (blockmail -> lg);
if (st) {
- log_idpush (blockmail -> lg, "write", "->");
- if (! blockmail_insync (blockmail, rec -> customer_id, rec -> mid, rec -> mailtype, rec -> chunks, bcccount)) {
+ log_idpush (blockmail -> lg, "write");
+ if (! blockmail_insync (blockmail, rec, bcccount)) {
st = (*blockmail -> output -> owrite) (blockmail -> outputdata, blockmail, rec);
if (st)
- st = blockmail_tosync (blockmail, rec -> customer_id, rec -> mid, rec -> mailtype, rec -> chunks, rec -> size, bcccount);
+ st = blockmail_tosync (blockmail, rec, bcccount);
}
log_idpop (blockmail -> lg);
if (! st)
@@ -1505,7 +1458,7 @@ parse_blockmail (blockmail_t *blockmail, xmlDocPtr doc, xmlNodePtr base) /*{{{*/
xmlNodePtr node;
st = true;
- log_idpush (blockmail -> lg, "blockmail", "->");
+ log_idpush (blockmail -> lg, "blockmail");
for (node = base; node && st; node = node -> next)
if (node -> type == XML_ELEMENT_NODE) {
if (! xmlstrcmp (node -> name, "description"))
diff --git a/backend/src/c/xmlback/replace.c b/backend/src/c/xmlback/replace.c
index d138506d5..8f1ab5ab1 100644
--- a/backend/src/c/xmlback/replace.c
+++ b/backend/src/c/xmlback/replace.c
@@ -113,7 +113,11 @@ replace_tags (blockmail_t *blockmail, receiver_t *rec, block_t *block,
{
bool_t st;
record_t *record;
+ xmlBufferPtr source;
+ tagpos_t **tagpos;
+ int tagpos_count;
int sorted_size;
+ tagpos_t **sorted;
const dyn_t *dyn, *root;
int dyncount, dynused;
long start, cur, next, end, len;
@@ -129,33 +133,41 @@ replace_tags (blockmail_t *blockmail, receiver_t *rec, block_t *block,
record = rec -> rvdata -> cur;
if (! set_content (blockmail, rec, record))
st = false;
- for (n = 0, sorted_size = 0; n < block -> tagpos_count; ++n) {
- if ((block -> tagpos[n] -> type & TP_DYNAMIC) && block -> tagpos[n] -> tname &&
- (dyn = find_dynamic (blockmail, rec, block -> tagpos[n] -> tname)) &&
- dyn -> interest && (dyn -> interest_index != -1)) {
- if (record -> isnull[dyn -> interest_index])
- block -> tagpos[n] -> sort_value = 0;
- else
- block -> tagpos[n] -> sort_value = xml2long (record -> data[dyn -> interest_index]);
- block -> sorted[sorted_size++] = block -> tagpos[n];
- block -> tagpos[n] -> sort_enable = true;
- } else
- block -> tagpos[n] -> sort_enable = false;
+ source = block -> content;
+ tagpos = block -> tagpos;
+ tagpos_count = block -> tagpos_count;
+ if ((tagpos_count > 0) && (sorted = (tagpos_t **) malloc (sizeof (tagpos_t *) * tagpos_count))) {
+ for (n = 0, sorted_size = 0; n < tagpos_count; ++n) {
+ if ((tagpos[n] -> type & TP_DYNAMIC) && tagpos[n] -> tname &&
+ (dyn = find_dynamic (blockmail, rec, tagpos[n] -> tname)) &&
+ dyn -> interest && (dyn -> interest_index != -1)) {
+ if (record -> isnull[dyn -> interest_index])
+ tagpos[n] -> sort_value = 0;
+ else
+ tagpos[n] -> sort_value = xml2long (record -> data[dyn -> interest_index]);
+ sorted[sorted_size++] = tagpos[n];
+ tagpos[n] -> sort_enable = true;
+ } else
+ tagpos[n] -> sort_enable = false;
+ }
+ if (sorted_size > 1)
+ qsort (sorted, sorted_size, sizeof (sorted[0]), tp_compare);
+ } else {
+ sorted_size = 0;
+ sorted = NULL;
}
- if (sorted_size > 1)
- qsort (block -> sorted, sorted_size, sizeof (block -> sorted[0]), tp_compare);
dyncount = 0;
dynused = 0;
start = 0;
proot = NULL;
pprev = NULL;
clear_output = false;
- end = xmlBufferLength (block -> content);
- content = xmlBufferContent (block -> content);
+ end = xmlBufferLength (source);
+ content = xmlBufferContent (source);
xmlBufferEmpty (block -> in);
for (cur = start, tidx = 0, sidx = 0; cur < end; ) {
- if (tidx < block -> tagpos_count) {
- tp = block -> tagpos[tidx++];
+ if (tidx < tagpos_count) {
+ tp = tagpos[tidx++];
next = tp -> start;
} else {
tp = NULL;
@@ -172,7 +184,7 @@ replace_tags (blockmail_t *blockmail, receiver_t *rec, block_t *block,
++dyncount;
if (tp -> sort_enable) {
if (sidx < sorted_size)
- sp = block -> sorted[sidx++];
+ sp = sorted[sidx++];
else
sp = NULL;
} else
@@ -281,36 +293,7 @@ replace_tags (blockmail_t *blockmail, receiver_t *rec, block_t *block,
}
if (tag && (cont = tag_content (tag, blockmail, rec, & n)) && (n > 0)) {
if (ispdf) {
- int clen;
-
- while (n > 0) {
- clen = xmlCharLength (*cont);
- if (clen > 1) {
- xmlBufferAdd (block -> in, cont, clen);
- } else
- switch (*cont) {
- default:
- xmlBufferAdd (block -> in, cont, clen);
- break;
- case '&':
- xmlBufferCCat (block -> in, "&");
- break;
- case '<':
- xmlBufferCCat (block -> in, "<");
- break;
- case '>':
- xmlBufferCCat (block -> in, ">");
- break;
- case '\'':
- xmlBufferCCat (block -> in, "'");
- break;
- case '"':
- xmlBufferCCat (block -> in, """);
- break;
- }
- cont += clen;
- n -= clen;
- }
+ entity_escape (block -> in, cont, n);
} else if (replace) {
individual_replace (replace, block -> in, cont, n);
} else {
@@ -327,6 +310,8 @@ replace_tags (blockmail_t *blockmail, receiver_t *rec, block_t *block,
xmlBufferEmpty (block -> in);
dynused = 0;
}
+ if (sorted)
+ free (sorted);
if ((level == 0) && (dyncount > 0) && (dynused == 0)) {
/* have hit one empty text block */
if (rec -> media && rec -> media -> empty) {
diff --git a/backend/src/c/xmlback/tflua.c b/backend/src/c/xmlback/tflua.c
index e38610686..438bebb87 100644
--- a/backend/src/c/xmlback/tflua.c
+++ b/backend/src/c/xmlback/tflua.c
@@ -34,7 +34,6 @@
lua_setfield (il -> lua, -2, (nnn)); \
} while (0)
-# if 0
static void stack_dump (lua_State *lua, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
static void
stack_dump (lua_State *lua, const char *fmt, ...) /*{{{*/
@@ -59,7 +58,6 @@ stack_dump (lua_State *lua, const char *fmt, ...) /*{{{*/
}
va_end (par);
}/*}}}*/
-# endif
static void
push_record_field (lua_State *lua, char type, bool_t isnull, xmlBufferPtr data) /*{{{*/
{
@@ -132,6 +130,7 @@ fetch_value (lua_State *lua, const char *column) /*{{{*/
typedef struct { /*{{{*/
log_t *lg;
+ bool_t sandbox;
blockmail_t *blockmail;
receiver_t *rec;
int last_customer_id;
@@ -146,6 +145,31 @@ typedef struct { /*{{{*/
# define GET_IFLUA(xxx) ((iflua_t *) lua_touserdata ((xxx), lua_upvalueindex (1)))
+static void
+iflua_verror (iflua_t *il, const char *message, va_list par) /*{{{*/
+{
+ buffer_t *b;
+
+ if (message)
+ if (b = buffer_alloc (512)) {
+ buffer_vformat (b, message, par);
+ lua_pushlstring (il -> lua, (const char *) buffer_content (b), buffer_length (b));
+ buffer_free (b);
+ } else
+ lua_pushstring (il -> lua, message);
+ lua_error (il -> lua);
+}/*}}}*/
+static void iflua_error (iflua_t *il, const char *message, ...) __attribute__ ((format (printf, 2, 3)));
+static void
+iflua_error (iflua_t *il, const char *message, ...) /*{{{*/
+{
+ va_list par;
+
+ va_start (par, message);
+ iflua_verror (il, message, par);
+ va_end (par);
+}/*}}}*/
+
static inline int
iflua_convert (lua_State *lua, const xchar_t *(*func) (xconv_t *, const xchar_t *, int, int *)) /*{{{*/
{
@@ -427,19 +451,20 @@ static struct { /*{{{*/
const char *modname;
const char *funcname;
lua_CFunction func;
+ bool_t sandbox;
/*}}}*/
} iflua_functab[] = { /*{{{*/
- { LUA_STRLIBNAME, "xlower", iflua_xlower },
- { LUA_STRLIBNAME, "xupper", iflua_xupper },
- { LUA_STRLIBNAME, "xcapitalize", iflua_xcapitalize },
- { LUA_STRLIBNAME, "like", iflua_like },
- { LUA_MULTILIBNAME, "get", iflua_multi_get },
- { LUA_MULTILIBNAME, "pos", iflua_multi_pos },
- { LUA_MULTILIBNAME, "count", iflua_multi_count },
- { LUA_AGNLIBNAME, "loglevel", iflua_loglevel },
- { LUA_AGNLIBNAME, "log", iflua_log },
- { LUA_AGNLIBNAME, "makeuid", iflua_makeuid },
- { LUA_AGNLIBNAME, "strmap", iflua_strmap }
+ { LUA_STRLIBNAME, "xlower", iflua_xlower, true },
+ { LUA_STRLIBNAME, "xupper", iflua_xupper, true },
+ { LUA_STRLIBNAME, "xcapitalize", iflua_xcapitalize, true },
+ { LUA_STRLIBNAME, "like", iflua_like, true },
+ { LUA_MULTILIBNAME, "get", iflua_multi_get, true },
+ { LUA_MULTILIBNAME, "pos", iflua_multi_pos, true },
+ { LUA_MULTILIBNAME, "count", iflua_multi_count, true },
+ { LUA_AGNLIBNAME, "loglevel", iflua_loglevel, false },
+ { LUA_AGNLIBNAME, "log", iflua_log, false },
+ { LUA_AGNLIBNAME, "makeuid", iflua_makeuid, false },
+ { LUA_AGNLIBNAME, "strmap", iflua_strmap, true }
/*}}}*/
};
@@ -449,7 +474,8 @@ iflua_setup_functions (iflua_t *il) /*{{{*/
int n;
for (n = 0; n < sizeof (iflua_functab) / sizeof (iflua_functab[0]); ++n)
- alua_setup_function (il -> lua, iflua_functab[n].modname, iflua_functab[n].funcname, iflua_functab[n].func, il);
+ if ((! il -> sandbox) || iflua_functab[n].sandbox)
+ alua_setup_function (il -> lua, iflua_functab[n].modname, iflua_functab[n].funcname, iflua_functab[n].func, il);
}/*}}}*/
static void
iflua_setup_context (iflua_t *il) /*{{{*/
@@ -491,33 +517,36 @@ iflua_setup_context (iflua_t *il) /*{{{*/
} else
lua_pushnil (il -> lua);
lua_setfield (il -> lua, -2, "senddate");
+ setsfield (il -> blockmail -> auto_url_prefix, "auto_url_prefix");
+ setbfield (il -> blockmail -> gui, "gui");
setbfield (il -> blockmail -> anon, "anon");
setsfield (il -> blockmail -> selector, "selector");
- setbfield (il -> blockmail -> rdir_content_links, "rdir_content_links");
setxfield (il -> blockmail -> auto_url, "auto_url");
setxfield (il -> blockmail -> anon_url, "anon_url");
setifield (il -> blockmail -> blocknr, "blocknr");
setifield (il -> blockmail -> total_subscribers, "total_subscribers");
- setsfield (il -> blockmail -> domain ? il -> blockmail -> domain : il -> blockmail -> fqdn, "domain");
- setsfield (il -> blockmail -> nodename, "node");
- setsfield (il -> blockmail -> fqdn, "fqdn");
- lua_createtable (il -> lua, 0, 0);
- for (v = il -> blockmail -> company_info; v; v = v -> next) {
- if (v -> val)
- setsfield (v -> val, v -> var);
- else
- setnfield (v -> var);
- if ((v -> var[0] == '_') && v -> val)
- for (n = 0; n < sizeof (mapper) / sizeof (mapper[0]); ++n)
- if ((! mapper[n].value) && (! strcmp (mapper[n].key, v -> var)))
- mapper[n].value = v -> val;
+ if (! il -> sandbox) {
+ setsfield (il -> blockmail -> domain ? il -> blockmail -> domain : il -> blockmail -> fqdn, "domain");
+ setsfield (il -> blockmail -> nodename, "node");
+ setsfield (il -> blockmail -> fqdn, "fqdn");
+ lua_createtable (il -> lua, 0, 0);
+ for (v = il -> blockmail -> company_info; v; v = v -> next) {
+ if (v -> val)
+ setsfield (v -> val, v -> var);
+ else
+ setnfield (v -> var);
+ if ((v -> var[0] == '_') && v -> val)
+ for (n = 0; n < sizeof (mapper) / sizeof (mapper[0]); ++n)
+ if ((! mapper[n].value) && (! strcmp (mapper[n].key, v -> var)))
+ mapper[n].value = v -> val;
+ }
+ lua_setfield (il -> lua, -2, "info");
+ for (n = 0; n < sizeof (mapper) / sizeof (mapper[0]); ++n)
+ if (mapper[n].value)
+ setsfield (mapper[n].value, mapper[n].map);
+ else
+ setnfield (mapper[n].map);
}
- lua_setfield (il -> lua, -2, "info");
- for (n = 0; n < sizeof (mapper) / sizeof (mapper[0]); ++n)
- if (mapper[n].value)
- setsfield (mapper[n].value, mapper[n].map);
- else
- setnfield (mapper[n].map);
lua_setfield (il -> lua, LUA_REGISTRYINDEX, ID_CTX);
}/*}}}*/
static int
@@ -596,12 +625,13 @@ iflua_free (iflua_t *il) /*{{{*/
return NULL;
}/*}}}*/
static iflua_t *
-iflua_alloc (blockmail_t *blockmail) /*{{{*/
+iflua_alloc (blockmail_t *blockmail, bool_t sandbox) /*{{{*/
{
iflua_t *il;
if (il = (iflua_t *) malloc (sizeof (iflua_t))) {
il -> lg = log_alloc (NULL, LOG_LUA, NULL);
+ il -> sandbox = sandbox;
il -> blockmail = blockmail;
il -> rec = NULL;
il -> last_customer_id = -1;
@@ -609,7 +639,7 @@ iflua_alloc (blockmail_t *blockmail) /*{{{*/
il -> last_base_block = NULL;
il -> local = NULL;
il -> source = NULL;
- if (il -> lua = alua_alloc ()) {
+ if (il -> lua = alua_alloc (sandbox)) {
iflua_setup_functions (il);
iflua_setup_context (il);
iflua_setup_customer (il);
@@ -694,7 +724,7 @@ static void
iflua_lgpush (iflua_t *il, const char *lid) /*{{{*/
{
if (il && il -> lg && lid)
- log_idpush (il -> lg, lid, "->");
+ log_idpush (il -> lg, lid);
}/*}}}*/
static void
iflua_lgpop (iflua_t *il) /*{{{*/
@@ -714,7 +744,7 @@ tf_lua_alloc (const char *func, tag_t *tag, blockmail_t *blockmail) /*{{{*/
iflua_t *il;
il = NULL;
- if (tag -> value && (il = iflua_alloc (blockmail))) {
+ if (tag -> value && (il = iflua_alloc (blockmail, false))) {
iflua_set_source (il, xmlBufferContent (tag -> value), xmlBufferLength (tag -> value));
iflua_lgpush (il, func);
if (! alua_load (il -> lua, func, xmlBufferContent (tag -> value), xmlBufferLength (tag -> value))) {
@@ -778,7 +808,7 @@ tf_lua_proc (void *ilp, const char *func, tag_t *tag, blockmail_t *blockmail, re
/* Doit */
rc = lua_pcall (il -> lua, 3, 1, 0);
if (lua_gettop (il -> lua) > 0) {
- if ((rc == 0) && alua_isdate (il -> lua, -1)) {
+ if ((rc == LUA_OK) && alua_isdate (il -> lua, -1)) {
alua_date_t *date;
if (date = alua_todate (il -> lua, -1)) {
@@ -793,17 +823,17 @@ tf_lua_proc (void *ilp, const char *func, tag_t *tag, blockmail_t *blockmail, re
} else
result = lua_tostring (il -> lua, -1);
} else {
- if (rc == 0)
+ if (rc == LUA_OK)
rc = -1;
result = "no (usable) result returned";
}
- if (rc == 0) {
+ if (rc == LUA_OK) {
if (result)
xmlBufferCCat (tag -> value, result);
} else
log_out (blockmail -> lg, LV_WARNING, "Tag \"%s\" propagates error \"%s\"", tag -> cname, (result ? result : "*no message found*"));
iflua_lgpop (il);
- return rc == 0 ? true : false;
+ return rc == LUA_OK ? true : false;
}/*}}}*/
# define EV_FUNC "__evaluate"
@@ -1067,7 +1097,7 @@ ev_lua_alloc (blockmail_t *blockmail, const char *expression) /*{{{*/
{
iflua_t *il;
- if (il = iflua_alloc (blockmail)) {
+ if (il = iflua_alloc (blockmail, true)) {
char *frame;
int flen;
@@ -1131,7 +1161,7 @@ ev_lua_vevaluate (void *ilp, receiver_t *rec, va_list par) /*{{{*/
iflua_push_context (il);
iflua_push_customer (il);
lrc = lua_pcall (il -> lua, 2, 1, 0);
- if (lrc == 0) {
+ if (lrc == LUA_OK) {
rc = 0;
if (lua_gettop (il -> lua) > 0)
switch (lua_type (il -> lua, -1)) {
diff --git a/backend/src/c/xmlback/xmlback.c b/backend/src/c/xmlback/xmlback.c
index 948d4b010..78661000b 100644
--- a/backend/src/c/xmlback/xmlback.c
+++ b/backend/src/c/xmlback/xmlback.c
@@ -131,7 +131,9 @@ main (int argc, char **argv) /*{{{*/
output_t *out;
const char *outparm;
const char *auto_url_prefix;
+ bool_t gui;
bool_t anon;
+ bool_t anon_preserve_links;
const char *selector;
bool_t convert_to_entities;
bool_t force_ecs_uid;
@@ -151,7 +153,9 @@ main (int argc, char **argv) /*{{{*/
out = & output_table[1];
outparm = NULL;
auto_url_prefix = NULL;
+ gui = false;
anon = false;
+ anon_preserve_links = false;
selector = NULL;
convert_to_entities = false;
force_ecs_uid = false;
@@ -163,7 +167,8 @@ main (int argc, char **argv) /*{{{*/
xmlInitializePredefinedEntities ();
xmlInitCharEncodingHandlers ();
json_set_escape_slashes (0);
- while ((n = getopt (argc, argv, "VDpqE:lru:as:egd:t:o:L:T:h")) != -1)
+ opterr = 0;
+ while ((n = getopt (argc, argv, "VDpqE:lru:UaAs:egd:t:o:L:T:h")) != -1)
switch (n) {
case 'V':
# ifdef EMM_VERSION
@@ -188,9 +193,15 @@ main (int argc, char **argv) /*{{{*/
case 'u':
auto_url_prefix = optarg;
break;
+ case 'U':
+ gui = true;
+ break;
case 'a':
anon = true;
break;
+ case 'A':
+ anon_preserve_links = true;
+ break;
case 's':
selector = optarg;
break;
@@ -231,7 +242,6 @@ main (int argc, char **argv) /*{{{*/
pointintime = atol (optarg);
break;
case 'h':
- default:
fprintf (stderr, "Usage: %s [-h] [-V] [-L ] [-D] [-v] [-p] [-q] [-E ] [-l] [-r] [-d ] [-o