aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-08-21 11:46:57 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-08-21 11:46:57 +0300
commita1718144344d2743713164adc1790ec1ac399d8c (patch)
treecd8b86e6b13f2877151eddcbf7fbb2f69260f0ca /src
parente2f591b6cd344420023daa910c7435298fe376c9 (diff)
downloadmailfromd-a1718144344d2743713164adc1790ec1ac399d8c.tar.gz
mailfromd-a1718144344d2743713164adc1790ec1ac399d8c.tar.bz2
Rename mfd -> src
Diffstat (limited to 'src')
-rw-r--r--src/.gitignore15
-rw-r--r--src/Makefile.am174
-rw-r--r--src/bitmask.h84
-rw-r--r--src/builtin/.gitignore34
-rw-r--r--src/builtin/Makefile.am92
-rw-r--r--src/builtin/body.bi61
-rw-r--r--src/builtin/builtin.c65
-rw-r--r--src/builtin/builtin.def21
-rw-r--r--src/builtin/callout.bi39
-rw-r--r--src/builtin/ctype.bi47
-rw-r--r--src/builtin/curhdr.bi212
-rw-r--r--src/builtin/db.bi800
-rw-r--r--src/builtin/dns.bi392
-rw-r--r--src/builtin/email.bi54
-rw-r--r--src/builtin/geoip.bi59
-rw-r--r--src/builtin/gethostname.bi138
-rw-r--r--src/builtin/getopt.bi152
-rw-r--r--src/builtin/getpw.bi77
-rw-r--r--src/builtin/gettext.bi42
-rw-r--r--src/builtin/header.bi80
-rw-r--r--src/builtin/init.m463
-rw-r--r--src/builtin/io.bi759
-rw-r--r--src/builtin/ipaddr.bi102
-rw-r--r--src/builtin/macro.bi49
-rw-r--r--src/builtin/mail.bi313
-rw-r--r--src/builtin/mbox.bi251
-rw-r--r--src/builtin/mmq.bi28
-rw-r--r--src/builtin/msg.bi469
-rw-r--r--src/builtin/msg.h44
-rw-r--r--src/builtin/mudebug.bi27
-rw-r--r--src/builtin/other.bi125
-rw-r--r--src/builtin/progress.bi30
-rw-r--r--src/builtin/qrnt.bi30
-rw-r--r--src/builtin/rate.bi46
-rw-r--r--src/builtin/rcpt.bi43
-rw-r--r--src/builtin/sa.bi532
-rw-r--r--src/builtin/sieve.bi181
-rw-r--r--src/builtin/snarf.m4661
-rw-r--r--src/builtin/spf.bi73
-rw-r--r--src/builtin/sprintf.bi420
-rw-r--r--src/builtin/string.bi218
-rw-r--r--src/builtin/system.bi119
-rw-r--r--src/builtin/vars.bi80
-rw-r--r--src/callout.c628
-rw-r--r--src/callout.h66
-rw-r--r--src/calloutd.c182
-rw-r--r--src/dbgmod.awk10
-rw-r--r--src/deprecation.c439
-rw-r--r--src/drivers.c2622
-rw-r--r--src/drv.awk63
-rw-r--r--src/engine.c830
-rw-r--r--src/gram.y4234
-rw-r--r--src/lex.l1288
-rw-r--r--src/mailfromd.h972
-rw-r--r--src/main.c1383
-rw-r--r--src/mf-status.mfi99
-rw-r--r--src/mfstat.awk55
-rw-r--r--src/opcode.awk97
-rw-r--r--src/opcodes94
-rw-r--r--src/optab.opc56
-rw-r--r--src/optab.oph6
-rw-r--r--src/pmtool.c469
-rw-r--r--src/pp.c483
-rw-r--r--src/pragma.c222
-rw-r--r--src/prog.c2696
-rw-r--r--src/prog.h95
-rw-r--r--src/savsrv.c499
-rw-r--r--src/spf.c1283
-rw-r--r--src/spf.h53
-rw-r--r--src/srvcfg.c870
-rw-r--r--src/srvcfg.h28
-rw-r--r--src/stack.c119
-rw-r--r--src/status.mfh3
-rw-r--r--src/status.mfi33
-rw-r--r--src/symbols.c1034
75 files changed, 28312 insertions, 0 deletions
diff --git a/src/.gitignore b/src/.gitignore
new file mode 100644
index 00000000..e07df217
--- /dev/null
+++ b/src/.gitignore
@@ -0,0 +1,15 @@
+gram.c
+gram.h
+gram.output
+lex.c
+calloutd
+mailfromd
+mf-status.c
+callout-dbgmod.h
+mfd-dbgmod.h
+node-tab.c
+node-type.h
+optab.c
+optab.h
+pmtool
+status.mf
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 00000000..fc65ecae
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,174 @@
+# This file is part of Mailfromd.
+# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Sergey Poznyakoff
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+sbin_PROGRAMS = mailfromd calloutd
+bin_PROGRAMS = pmtool
+SUBDIRS = builtin
+incdir=$(pkgdatadir)/$(VERSION)/include
+inc_DATA = status.mf status.mfh
+
+noinst_LIBRARIES = libcallout.a
+libcallout_a_SOURCES = \
+ callout.c\
+ callout.h\
+ savsrv.c\
+ srvcfg.c
+
+mailfromd_SOURCES = \
+ deprecation.c\
+ engine.c\
+ gram.y\
+ lex.l\
+ main.c\
+ mf-status.c\
+ optab.c\
+ optab.h\
+ pp.c\
+ pragma.c\
+ prog.c\
+ prog.h\
+ spf.c\
+ stack.c\
+ symbols.c
+
+mailfromd_LDADD = \
+ ./libcallout.a\
+ builtin/libbuiltin.a\
+ ../lib/libpmdb.a\
+ ../lib/libmf.a\
+ ../lib/libdbm.a\
+ ../gnu/libgnu.a\
+ $(MAILUTILS_LIBS)\
+ $(MILTER)\
+ $(GEOIP_LIBS)
+
+noinst_HEADERS = \
+ bitmask.h\
+ callout-dbgmod.h\
+ mailfromd.h\
+ spf.h\
+ drivers.c\
+ mfd-dbgmod.h\
+ srvcfg.h
+
+calloutd_SOURCES = \
+ calloutd.c
+
+calloutd_LDADD = \
+ ./libcallout.a\
+ ../lib/libpmdb.a\
+ ../lib/libmf.a\
+ ../lib/libdbm.a\
+ ../gnu/libgnu.a\
+ $(MAILUTILS_LIBS)\
+ $(MILTER)
+
+pmtool_SOURCES = \
+ pmtool.c
+
+pmtool_LDADD = \
+ ../lib/libpmdb.a\
+ ../lib/libmf.a\
+ ../lib/libdbm.a\
+ ../gnu/libgnu.a\
+ $(MAILUTILS_LIBS)
+
+EXTRA_DIST = \
+ dbgmod.awk\
+ drv.awk\
+ gram.h\
+ mf-status.mfi\
+ mfstat.awk\
+ node-tab.c\
+ node-type.h\
+ opcode.awk\
+ opcodes\
+ optab.opc\
+ optab.oph\
+ status.mf\
+ status.mfh\
+ status.mfi
+
+BUILT_SOURCES=\
+ callout-dbgmod.h\
+ mf-status.c\
+ mfd-dbgmod.h\
+ node-tab.c\
+ node-type.h\
+ optab.c\
+ optab.h
+
+AM_CPPFLAGS=-DSYSCONFDIR=\"$(sysconfdir)\"\
+ -DDEFAULT_STATE_DIR=\"$(DEFAULT_STATE_DIR)\"\
+ -DDEFAULT_SOCKET=\"$(DEFAULT_SOCKET)\"\
+ -DDEFAULT_VERSION_INCLUDE_DIR=\"$(incdir)\"\
+ -DDEFAULT_INCLUDE_DIR=\"$(pkgdatadir)/include\"\
+ -DDEFAULT_PREPROCESSOR="\"$(DEFAULT_PREPROCESSOR)\""\
+ -DLOCALEDIR=\"$(localedir)\"
+
+INCLUDES = \
+ $(MAILUTILS_INCLUDES)\
+ $(MU_COMMON_INCLUDES)\
+ -I$(top_srcdir)/lib\
+ -I$(top_srcdir)/gnu\
+ -I../gnu\
+ -I$(top_srcdir)/src/builtin\
+ $(MILTER_INCLUDES)
+
+node-type.h: drivers.c
+ $(AM_V_GEN) $(AWK) -v MODE=types -f $(top_srcdir)/src/drv.awk drivers.c > node-type.h
+
+node-tab.c: drivers.c
+ $(AM_V_GEN) $(AWK) -f $(top_srcdir)/src/drv.awk drivers.c > node-tab.c
+
+lex.c: gram.h
+status.mf: status.mfi mailfromd.h Makefile.am
+
+SUFFIXES = .mfi .mf .opc .oph
+
+.mfi.c:
+ $(AM_V_GEN) $(AWK) -f $(top_srcdir)/src/mfstat.awk \
+ $(top_srcdir)/src/mailfromd.h $< > $@
+
+.mfi.mf:
+ $(AM_V_GEN) $(AWK) -f $(top_srcdir)/src/mfstat.awk \
+ $(top_srcdir)/src/mailfromd.h $< > $@
+
+
+.opc.c:
+ $(AM_V_GEN) $(AWK) -f $(top_srcdir)/src/opcode.awk \
+ $(top_srcdir)/src/opcodes $< > $@
+
+.oph.h:
+ $(AM_V_GEN) $(AWK) -f $(top_srcdir)/src/opcode.awk \
+ $(top_srcdir)/src/opcodes $< > $@
+
+optab.c optab.h: opcodes
+
+mfd-dbgmod.h: Makefile.am
+ $(AM_V_GEN) sed -n 's/.*debug *(MF_SOURCE_\([^,]*\),.*/\1/p' \
+ $(mailfromd_SOURCES) $(libcallout_a_SOURCES) | sort | uniq | \
+ awk -f $(top_srcdir)/src/dbgmod.awk > mfd-dbgmod.h
+
+callout-dbgmod.h: Makefile.am
+ $(AM_V_GEN) sed -n 's/.*debug *(MF_SOURCE_\([^,]*\),.*/\1/p' \
+ $(libcallout_a_SOURCES) | sort | uniq | awk -f \
+ $(top_srcdir)/src/dbgmod.awk > callout-dbgmod.h
+
+M4=m4
+
+AM_YFLAGS=-dtv
+AM_LFLAGS=-dvp
diff --git a/src/bitmask.h b/src/bitmask.h
new file mode 100644
index 00000000..846180e6
--- /dev/null
+++ b/src/bitmask.h
@@ -0,0 +1,84 @@
+/* This file is part of Mailfromd.
+ Copyright (C) 2009, 2010 Sergey Poznyakoff
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdlib.h>
+
+/* FIXME: Ensure that sizeof(bitmask_bits_t)<=sizeof(void*) */
+typedef unsigned bitmask_bits_t;
+
+struct bitmask
+{
+ size_t bm_nset; /* Number of bits set */
+ size_t bm_size; /* Number of elements in bm_bits */
+ bitmask_bits_t *bm_bits;
+};
+
+#define NBMBITS (sizeof(bitmask_bits_t) * 8)
+
+#define BIT_WORD(n) ((n) / NBMBITS)
+#define BIT_MASK(n) ((bitmask_bits_t)1 << ((n) % NBMBITS))
+
+#define bitmask_zero(bm) \
+ do { \
+ memset((bm)->bm_bits, 0, \
+ (bm)->bm_size * sizeof(bitmask_bits_t)); \
+ (bm)->bm_nset = 0; \
+ } while (0)
+
+#define bitmask_init(bm) memset(bm, 0, sizeof((bm)[0]))
+#define bitmask_nset(bm) ((bm)->bm_nset)
+#define bitmask_max(bm) ((bm)->bm_nset * NBMBITS)
+
+#define __bitmask_expand(bm,n) \
+ do { \
+ size_t __n = n; \
+ (bm)->bm_bits = xrealloc((bm)->bm_bits, \
+ (__n) * sizeof(bitmask_bits_t)); \
+ memset((bm)->bm_bits + (bm)->bm_size, 0, \
+ ((__n) - (bm)->bm_size) * sizeof(bitmask_bits_t)); \
+ (bm)->bm_size = __n; \
+ } while (0)
+
+#define bitmask_set(bm,n) \
+ do { \
+ unsigned num = BIT_WORD(n); \
+ if (num >= (bm)->bm_size) \
+ __bitmask_expand(bm, num+1); \
+ (bm)->bm_bits[num] |= BIT_MASK(n); \
+ (bm)->bm_nset++; \
+ } while (0)
+
+#define bitmask_isset(bm,n) \
+ ((BIT_WORD(n) < (bm)->bm_size) \
+ && (bm)->bm_bits[BIT_WORD(n)] & BIT_MASK(n))
+
+#define bitmask_clr(bm,n) \
+ do { \
+ unsigned num = BIT_WORD(n); \
+ if (num < (bm)->bm_size) { \
+ (bm)->bm_bits[num] &= ~BIT_MASK(n); \
+ (bm)->bm_nset--; \
+ } \
+ } while (0)
+
+#define bitmask_merge(d,s) \
+ do { \
+ int __i; \
+ if ((s)->bm_size > (d)->bm_size) \
+ __bitmask_expand(d, (s)->bm_size); \
+ for (__i = 0; __i < (s)->bm_size; __i++) \
+ (d)->bm_bits[__i] |= (s)->bm_bits[__i]; \
+ } while (0)
diff --git a/src/builtin/.gitignore b/src/builtin/.gitignore
new file mode 100644
index 00000000..6944a066
--- /dev/null
+++ b/src/builtin/.gitignore
@@ -0,0 +1,34 @@
+builtin.h
+body.c
+callout.c
+ctype.c
+curhdr.c
+db.c
+dns.c
+email.c
+geoip.c
+gethostname.c
+getopt.c
+getpw.c
+gettext.c
+header.c
+io.c
+ipaddr.c
+macro.c
+mail.c
+mbox.c
+mmq.c
+msg.c
+mudebug.c
+other.c
+progress.c
+qrnt.c
+rate.c
+rcpt.c
+sa.c
+sieve.c
+spf.c
+sprintf.c
+string.c
+system.c
+vars.c
diff --git a/src/builtin/Makefile.am b/src/builtin/Makefile.am
new file mode 100644
index 00000000..297b389a
--- /dev/null
+++ b/src/builtin/Makefile.am
@@ -0,0 +1,92 @@
+# This file is part of Mailfromd.
+# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Sergey Poznyakoff
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+noinst_LIBRARIES = libbuiltin.a
+noinst_HEADERS = builtin.h msg.h
+
+BI_FILES=\
+ body.bi\
+ callout.bi\
+ ctype.bi\
+ curhdr.bi\
+ db.bi\
+ dns.bi\
+ email.bi\
+ geoip.bi\
+ gethostname.bi\
+ getopt.bi\
+ getpw.bi\
+ gettext.bi\
+ header.bi\
+ io.bi\
+ ipaddr.bi\
+ macro.bi\
+ mail.bi\
+ mbox.bi\
+ mmq.bi\
+ msg.bi\
+ mudebug.bi\
+ progress.bi\
+ rate.bi\
+ rcpt.bi\
+ sa.bi\
+ sieve.bi\
+ spf.bi\
+ sprintf.bi\
+ string.bi\
+ system.bi\
+ other.bi\
+ vars.bi\
+ qrnt.bi
+
+libbuiltin_a_SOURCES = builtin.c $(BI_FILES:.bi=.c)
+
+EXTRA_DIST = \
+ $(BI_FILES)\
+ builtin.def\
+ builtin.h\
+ init.m4\
+ snarf.m4
+
+BUILT_SOURCES=\
+ $(BI_FILES:.bi=.c)\
+ builtin.h
+
+INCLUDES = \
+ $(MAILUTILS_INCLUDES)\
+ $(MU_COMMON_INCLUDES)\
+ -I$(top_srcdir)/lib\
+ -I$(top_srcdir)/gnu\
+ -I../gnu\
+ $(MILTER_INCLUDES)\
+ -I$(top_srcdir)/src
+
+builtin.h: Makefile.am
+
+$(BI_FILES:.bi=.c): snarf.m4 init.m4
+
+SUFFIXES = .bi .c .def .h .mfi .mf
+
+M4=m4
+
+.bi.c:
+ $(AM_V_GEN)$(M4) --prefix -s -DSOURCE="$<" $(top_srcdir)/src/builtin/snarf.m4 $< > $@-t && \
+ sed '1{/#line/d;}' $@-t > $@ && \
+ rm $@-t
+
+.def.h:
+ $(AM_V_GEN) $(M4) --prefix $(top_srcdir)/src/builtin/init.m4 $(BI_FILES) $< > $@
+
diff --git a/src/builtin/body.bi b/src/builtin/body.bi
new file mode 100644
index 00000000..4518fade
--- /dev/null
+++ b/src/builtin/body.bi
@@ -0,0 +1,61 @@
+/* This file is part of Mailfromd. -*- c -*-
+ Copyright (C) 2008, 2010 Sergey Poznyakoff
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "msg.h"
+
+MF_STATE(body)
+MF_DEFUN(body_string, STRING, POINTER text, NUMBER length)
+{
+ size_t off;
+ char *s = MF_ALLOC_HEAP(off, length + 1);
+ memcpy(s, text, length);
+ s[length] = 0;
+ MF_RETURN(off);
+}
+END
+
+/* number current_message() */
+MF_STATE(eom)
+MF_CAPTURE
+MF_DEFUN(current_message, NUMBER)
+{
+ mu_stream_t mstr = env_get_stream(env);
+ mu_message_t msg;
+ int rc;
+
+ rc = bi_get_current_message(env);
+ if (rc < 0) {
+ rc = mf_stream_to_message(mstr, &msg);
+ MF_ASSERT(rc == 0,
+ mfe_failure,
+ "mu_stream_to_message: %s",
+ mu_strerror(rc));
+ rc = bi_message_register(env, NULL, msg, 1);
+ MF_ASSERT(rc >= 0,
+ mfe_failure,
+ _("no more message slots available"));
+ }
+ MF_RETURN(rc);
+}
+END
+
+MF_DEFUN(replbody, VOID, STRING text)
+{
+ env_msgmod(env, body_repl, "BODY", text, 0);
+}
+END
+
+MF_INIT
diff --git a/src/builtin/builtin.c b/src/builtin/builtin.c
new file mode 100644
index 00000000..48cae27d
--- /dev/null
+++ b/src/builtin/builtin.c
@@ -0,0 +1,65 @@
+/* This file is part of Mailfromd.
+ Copyright (C) 2010 Sergey Poznyakoff
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/error.h>
+#include <gettext.h>
+
+#define DEFINE_BUILTIN_MODULE
+#include "builtin.h"
+
+void
+builtin_setup ()
+{
+ struct builtin_module *mod;
+ for (mod = builtin_module; mod->name; mod++)
+ if (mod->init)
+ mod->init();
+}
+
+void
+builtin_set_module_trace(const char *name, size_t len, int val)
+{
+ struct builtin_module *mod;
+
+ for (mod = builtin_module; mod->name; mod++)
+ if (strlen (mod->name) == len
+ && memcmp(mod->name, name, len) == 0) {
+ mod->trace = val;
+ return;
+ }
+
+ mu_error(gettext("no such module: %*.*s"), len, len, name);
+}
+
+void
+builtin_set_all_module_trace(int val)
+{
+ struct builtin_module *mod;
+
+ for (mod = builtin_module; mod->name; mod++)
+ mod->trace = val;
+}
+
+int
+builtin_module_trace(unsigned idx)
+{
+ return idx < BUILTIN_IDX_MAX && builtin_module[idx].trace;
+}
diff --git a/src/builtin/builtin.def b/src/builtin/builtin.def
new file mode 100644
index 00000000..366d2648
--- /dev/null
+++ b/src/builtin/builtin.def
@@ -0,0 +1,21 @@
+MF_BEGIN_OUTPUT
+
+struct builtin_module {
+ char *name;
+ void (*init)(void);
+ int trace;
+};
+
+MF_DEFINES
+
+#ifdef DEFINE_BUILTIN_MODULE
+MF_BUILTIN_DECLS
+MF_BUILTIN_MODULES
+#endif
+
+extern int provide_callout;
+
+void builtin_setup(void);
+void builtin_set_module_trace(const char *name, size_t len, int val);
+void builtin_set_all_module_trace(int val);
+int builtin_module_trace(unsigned idx);
diff --git a/src/builtin/callout.bi b/src/builtin/callout.bi
new file mode 100644
index 00000000..43facfc0
--- /dev/null
+++ b/src/builtin/callout.bi
@@ -0,0 +1,39 @@
+/* This file is part of Mailfromd. -*- c -*-
+ Copyright (C) 2006, 2007, 2008, 2009, 2010 Sergey Poznyakoff
+
+ This program is free software; you c