aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-07-03 17:22:19 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-07-03 17:22:19 +0300
commita113a190cc7b5339e9d07904cd1cf8c2820a0e53 (patch)
treeb3fd118e67726f3cf16942acca65614bf1d36d3a
parent14e0558e6051671d9ebc8083467e021dfd81780a (diff)
downloadmailfromd-a113a190cc7b5339e9d07904cd1cf8c2820a0e53.tar.gz
mailfromd-a113a190cc7b5339e9d07904cd1cf8c2820a0e53.tar.bz2
Move MMQ from milter context to program evaluation environment.
* src/engine.c: (message_data): Remove mmq. Use env_msgmod functions to access it. All uses updated. (ctx_msgmod): Removed. (priv_store_msgmod_closure): Removed. (mlfi_eom): Use env_msgmod_count to check the size of the message modification queue and env_msgmod_apply to apply it. * src/mailfromd.h (env_msgmod): Rename to env_msgmod_append. (env_clear_msgmod): Rename to env_msgmod_clear. (env_msgmod_apply): New proto. * src/prog.c (ENVF_MSGMOD): Remove. (eval_environ) <flags,mmq>: Remove. (instr_result): Use env_msgmod_count to chech for mmq size. (env_clear_msgmod): Rewrite and rename to env_msgmod_clear. (env_msgmod): Rewrite and rename to env_msgmod_append. (env_msgmod_count): New function. (destroy_environment): Destroy env->mmq
-rw-r--r--src/builtin/body.bi4
-rw-r--r--src/builtin/dkim.bi2
-rw-r--r--src/builtin/from.bi2
-rw-r--r--src/builtin/header.bi10
-rw-r--r--src/builtin/mmq.bi2
-rw-r--r--src/builtin/qrnt.bi2
-rw-r--r--src/builtin/rcpt.bi4
-rw-r--r--src/engine.c58
-rw-r--r--src/mailfromd.h10
-rw-r--r--src/prog.c66
10 files changed, 78 insertions, 82 deletions
diff --git a/src/builtin/body.bi b/src/builtin/body.bi
index 09616f8b..cd3655aa 100644
--- a/src/builtin/body.bi
+++ b/src/builtin/body.bi
@@ -47,13 +47,13 @@ END
MF_DEFUN(replbody, VOID, STRING text)
{
- env_msgmod(env, body_repl, "BODY", text, 0);
+ env_msgmod_append(env, body_repl, "BODY", text, 0);
}
END
MF_DEFUN(replbody_fd, VOID, NUMBER fd)
{
- env_msgmod(env, body_repl_fd, "BODYFD", NULL, _bi_io_fd(env, fd, 0));
+ env_msgmod_append(env, body_repl_fd, "BODYFD", NULL, _bi_io_fd(env, fd, 0));
}
END
diff --git a/src/builtin/dkim.bi b/src/builtin/dkim.bi
index b30c4b97..870a5689 100644
--- a/src/builtin/dkim.bi
+++ b/src/builtin/dkim.bi
@@ -87,7 +87,7 @@ STRING canon_h, STRING canon_b, STRING headers)
locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(header_add),
sighdr, p);
- env_msgmod(env, header_add, sighdr, p, 1);
+ env_msgmod_append(env, header_add, sighdr, p, 1);
free(sighdr);
}
END
diff --git a/src/builtin/from.bi b/src/builtin/from.bi
index 1faeb056..112567e5 100644
--- a/src/builtin/from.bi
+++ b/src/builtin/from.bi
@@ -27,7 +27,7 @@ MF_DEFUN(set_from, VOID, STRING addr, OPTIONAL, STRING args)
locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(set_from),
addr);
- env_msgmod(env, set_from, addr, MF_OPTVAL(args, NULL), 0);
+ env_msgmod_append(env, set_from, addr, MF_OPTVAL(args, NULL), 0);
}
END
diff --git a/src/builtin/header.bi b/src/builtin/header.bi
index 053592c7..588bdf8e 100644
--- a/src/builtin/header.bi
+++ b/src/builtin/header.bi
@@ -29,14 +29,14 @@ MF_DEFUN(header_add, VOID, STRING name, STRING value, OPTIONAL, NUMBER idx)
msgmod_opcode_str(header_insert),
idx,
name, value);
- env_msgmod(env, header_insert, name, value, idx);
+ env_msgmod_append(env, header_insert, name, value, idx);
} else {
trace("%s%s:%u: %s \"%s: %s\"",
mailfromd_msgid(env_get_context(env)),
locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(header_add),
name, value);
- env_msgmod(env, header_add, name, value, 1);
+ env_msgmod_append(env, header_add, name, value, 1);
}
}
END
@@ -53,7 +53,7 @@ MF_DEFUN(header_insert, VOID, STRING name, STRING value, NUMBER idx)
msgmod_opcode_str(header_insert),
idx,
name, value);
- env_msgmod(env, header_insert, name, value, idx);
+ env_msgmod_append(env, header_insert, name, value, idx);
}
END
@@ -68,7 +68,7 @@ MF_DEFUN(header_delete, VOID, STRING name, OPTIONAL, NUMBER idx)
locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(header_delete),
name, MF_OPTVAL(idx, 1));
- env_msgmod(env, header_delete, name, NULL, MF_OPTVAL(idx, 1));
+ env_msgmod_append(env, header_delete, name, NULL, MF_OPTVAL(idx, 1));
}
END
@@ -83,7 +83,7 @@ MF_DEFUN(header_replace, VOID, STRING name, STRING value, OPTIONAL, NUMBER idx)
locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(header_replace),
name, value, MF_OPTVAL(idx, 1));
- env_msgmod(env, header_replace, name, value, MF_OPTVAL(idx, 1));
+ env_msgmod_append(env, header_replace, name, value, MF_OPTVAL(idx, 1));
}
END
diff --git a/src/builtin/mmq.bi b/src/builtin/mmq.bi
index e6ff9d6f..e7822cca 100644
--- a/src/builtin/mmq.bi
+++ b/src/builtin/mmq.bi
@@ -23,7 +23,7 @@ MF_BUILTIN_MODULE
MF_DEFUN(mmq_purge, VOID)
{
- env_clear_msgmod(env);
+ env_msgmod_clear(env);
}
END
diff --git a/src/builtin/qrnt.bi b/src/builtin/qrnt.bi
index 88e62e90..10fb22ee 100644
--- a/src/builtin/qrnt.bi
+++ b/src/builtin/qrnt.bi
@@ -27,7 +27,7 @@ MF_DEFUN(quarantine, VOID, STRING reason)
locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(quarantine),
reason);
- env_msgmod(env, quarantine, reason, NULL, 0);
+ env_msgmod_append(env, quarantine, reason, NULL, 0);
}
END
diff --git a/src/builtin/rcpt.bi b/src/builtin/rcpt.bi
index 7f87455d..e5df6d3c 100644
--- a/src/builtin/rcpt.bi
+++ b/src/builtin/rcpt.bi
@@ -27,7 +27,7 @@ MF_DEFUN(rcpt_add, VOID, STRING addr)
locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(rcpt_add),
addr);
- env_msgmod(env, rcpt_add, addr, NULL, 0);
+ env_msgmod_append(env, rcpt_add, addr, NULL, 0);
}
END
@@ -42,7 +42,7 @@ MF_DEFUN(rcpt_delete, VOID, STRING addr)
locus.beg.mu_file, locus.beg.mu_line,
msgmod_opcode_str(rcpt_delete),
addr);
- env_msgmod(env, rcpt_delete, addr, NULL, 0);
+ env_msgmod_append(env, rcpt_delete, addr, NULL, 0);
}
END
diff --git a/src/engine.c b/src/engine.c
index 9dc736a5..a0bed5fa 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -42,13 +42,11 @@
static const char *ctx_getsym(void *data, const char *str);
static int ctx_setreply(void *data, char *code, char *xcode, char *message);
-static void ctx_msgmod(void *data, struct msgmod_closure *cmd);
/* Per-message data */
struct message_data {
eval_environ_t env; /* Evaluation environment */
- mu_list_t mmq; /* Message Modification Queue */
char *helostr; /* Domain name obtained in HELO phase */
char msgid[64]; /* Message ID */
};
@@ -59,7 +57,6 @@ test_message_data_init(eval_environ_t env)
{
test_message_data = mu_alloc(sizeof(*test_message_data));
test_message_data->env = env;
- test_message_data->mmq = NULL;
test_message_data->helostr = NULL;
test_message_data->msgid[0] = 0;
}
@@ -85,10 +82,9 @@ priv_get(SMFICTX *ctx)
md->env = create_environment(ctx,
ctx_getsym,
ctx_setreply,
- ctx_msgmod,
+ NULL,
ctx);
clear_rcpt_count(md->env);
- md->mmq = NULL;
md->helostr = NULL;
md->msgid[0] = 0;
gacopyz_setpriv(ctx, md);
@@ -126,40 +122,6 @@ mailfromd_msgid(SMFICTX *ctx)
return md->msgid;
}
-void
-destroy_msgmod_closure(void *item)
-{
- struct msgmod_closure *cmd = item;
- free(cmd->name);
- free(cmd->value);
-}
-
-int
-priv_store_msgmod_closure(SMFICTX *ctx, struct msgmod_closure *cmd)
-{
- struct message_data *md = priv_get(ctx);
- if (!md)
- return 1;
-
- if (!cmd) {
- mu_debug(MF_SOURCE_ENGINE, MU_DEBUG_TRACE5,
- ("clearing msgmod list"));
- mu_list_destroy(&md->mmq);
- return 0;
- }
-
- if (!md->mmq) {
- mu_list_create(&md->mmq);
- mu_list_set_destroy_item(md->mmq, destroy_msgmod_closure);
- }
- mu_debug(MF_SOURCE_ENGINE, MU_DEBUG_TRACE5,
- ("adding msgmod_closure: %s \"%s\" %s %u",
- msgmod_opcode_str(cmd->opcode),
- SP(cmd->name), SP(cmd->value), cmd->idx));
- mu_list_append(md->mmq, cmd);
- return 0;
-}
-
/* Run-time execution */
@@ -183,12 +145,6 @@ ctx_setreply(void *data, char *code, char *xcode, char *message)
return 0;
}
-static void
-ctx_msgmod(void *data, struct msgmod_closure *cmd)
-{
- priv_store_msgmod_closure(data, cmd);
-}
-
/* Message capturing functions */
static int capture_enabled;
@@ -260,7 +216,6 @@ filter_cleanup(SMFICTX *ctx)
xeval(md->env, smtp_state_end);
free(md->helostr);
destroy_environment(md->env);
- mu_list_destroy(&md->mmq);
free(md);
gacopyz_setpriv(ctx, NULL);
}
@@ -657,7 +612,6 @@ run_msgmod(void *item, void *data)
return 0;
}
-
sfsistat
mlfi_eom(SMFICTX *ctx)
{
@@ -672,15 +626,16 @@ mlfi_eom(SMFICTX *ctx)
env_make_frame(md->env);
status = mlfi_eval(ctx, smtp_state_eom);
env_leave_frame(md->env, 0);
- if ((status == SMFIS_ACCEPT || status == SMFIS_CONTINUE) && md->mmq) {
+ if ((status == SMFIS_ACCEPT || status == SMFIS_CONTINUE)
+ && env_msgmod_count(md->env) > 0) {
mu_debug(MF_SOURCE_ENGINE, MU_DEBUG_TRACE6,
("flushing message modification queue"));
- mu_list_foreach(md->mmq, run_msgmod, ctx);
+ env_msgmod_apply(md->env, run_msgmod, ctx);
}
mf_proctitle_format("%sfinished", md->msgid);
clear_rcpt_count(md->env);
- mu_list_destroy(&md->mmq);
+ env_msgmod_clear(md->env);
return status;
}
@@ -692,8 +647,7 @@ mlfi_abort(SMFICTX *ctx)
mu_debug(MF_SOURCE_ENGINE, MU_DEBUG_TRACE7, ("Abort"));
mf_proctitle_format("%saborting", md->msgid);
- mu_list_destroy(&md->mmq);
- md->mmq = NULL;
+ env_msgmod_clear(md->env);
md->msgid[0] = 0;
/* Note: the value of helostr is not discarded: RFC 2822,
section 4.1.1.5 states that RSET issued immediately
diff --git a/src/mailfromd.h b/src/mailfromd.h
index 520ea52a..401e67e3 100644
--- a/src/mailfromd.h
+++ b/src/mailfromd.h
@@ -815,9 +815,13 @@ int env_capture_start(eval_environ_t env);
int env_capture_write(eval_environ_t env, const char *buf, size_t size);
int env_capture_write_args(eval_environ_t env, ...);
void env_final_gc(eval_environ_t env);
-void env_msgmod(eval_environ_t env, enum msgmod_opcode opcode,
- const char *name, const char *value, unsigned idx);
-void env_clear_msgmod(eval_environ_t env);
+
+void env_msgmod_append(eval_environ_t env, enum msgmod_opcode opcode,
+ const char *name, const char *value, unsigned idx);
+void env_msgmod_clear(eval_environ_t env);
+size_t env_msgmod_count(eval_environ_t env);
+void env_msgmod_apply(eval_environ_t env, mu_list_action_t fun, void *data);
+
void capture_on(void);
const char *env_get_macro(eval_environ_t env, const char *symbol);
diff --git a/src/prog.c b/src/prog.c
index 56f9cdf0..5cdefe0e 100644
--- a/src/prog.c
+++ b/src/prog.c
@@ -225,8 +225,6 @@ disable_prog_trace(const char *modlist)
See comment to env_fixup_autos, below. */
#define MAX_AUTO_PTR 128
-#define ENVF_MSGMOD 0x01 /* message modification instruction has been used */
-
struct exception_context {
prog_counter_t pc;
prog_counter_t tos;
@@ -277,8 +275,6 @@ struct eval_environ {
int (*setreply)(void *data, char *code, char *xcode, char *message);
void (*msgmod)(void *data, struct msgmod_closure *c);
- int flags;
-
/* Regular expression matching */
regmatch_t *matches; /* Match map */
size_t matchcount; /* Number of used entries in matches */
@@ -292,7 +288,10 @@ struct eval_environ {
its end before writing. */
mu_header_t header; /* Headers from stream, converted to a MU
object. */
-
+
+ /* Message modification queue */
+ mu_list_t mmq;
+
/* Non-local exits */
struct exception_context *defcatch_ctx;
struct exception_context *catch_ctx;
@@ -1726,7 +1725,7 @@ instr_result(eval_environ_t env)
if (xcode[0] == 0)
xcode = NULL;
- if (status == SMFIS_ACCEPT && (env->flags & ENVF_MSGMOD))
+ if (status == SMFIS_ACCEPT && env_msgmod_count(env))
runtime_warning(env, _("`accept' causes previous message "
"modification commands to be ignored; "
"call mmq_purge() prior to `accept', "
@@ -1764,7 +1763,7 @@ instr_header(eval_environ_t env)
msgmod_opcode_str(opcode),
name, SP(value));
- env_msgmod(env, opcode, name, value, 1);
+ env_msgmod_append(env, opcode, name, value, 1);
}
void
@@ -2623,19 +2622,30 @@ env_get_header(eval_environ_t env, mu_header_t *hdr)
*hdr = env->header;
return 0;
}
+
+/* MMQ */
void
-env_clear_msgmod(eval_environ_t env)
+env_msgmod_clear(eval_environ_t env)
{
if (PROG_TRACE_ENGINE)
prog_trace(env, "Clearing message modification queue");
- env->msgmod(env->data, NULL);
- env->flags &= ~ENVF_MSGMOD;
+ if (env->msgmod)
+ env->msgmod(env->data, NULL);
+ mu_list_clear(env->mmq);
}
void
-env_msgmod(eval_environ_t env, enum msgmod_opcode opcode,
- const char *name, const char *value, unsigned idx)
+destroy_msgmod_closure(void *item)
+{
+ struct msgmod_closure *cmd = item;
+ free(cmd->name);
+ free(cmd->value);
+}
+
+void
+env_msgmod_append(eval_environ_t env, enum msgmod_opcode opcode,
+ const char *name, const char *value, unsigned idx)
{
struct msgmod_closure *cp = mu_alloc(sizeof *cp);
@@ -2648,8 +2658,35 @@ env_msgmod(eval_environ_t env, enum msgmod_opcode opcode,
cp->name = name ? mu_strdup(name) : NULL;
cp->value = value ? mu_strdup(value) : NULL;
cp->idx = idx;
- env->msgmod(env->data, cp);
- env->flags |= ENVF_MSGMOD;
+
+ if (!env->mmq) {
+ mu_list_create(&env->mmq);
+ mu_list_set_destroy_item(env->mmq, destroy_msgmod_closure);
+ }
+ mu_debug(MF_SOURCE_ENGINE, MU_DEBUG_TRACE5,
+ ("adding msgmod_closure: %s \"%s\" %s %u",
+ msgmod_opcode_str(cp->opcode),
+ SP(cp->name), SP(cp->value), cp->idx));
+ if (env->msgmod)
+ env->msgmod(env->data, cp);
+ mu_list_append(env->mmq, cp);
+}
+
+size_t
+env_msgmod_count(eval_environ_t env)
+{
+ size_t n;
+ if (!env->mmq)
+ n = 0;
+ else
+ mu_list_count(env->mmq, &n);
+ return n;
+}
+
+void
+env_msgmod_apply(eval_environ_t env, mu_list_action_t fun, void *data)
+{
+ mu_list_foreach(env->mmq, fun, data);
}
@@ -2802,6 +2839,7 @@ destroy_environment(eval_environ_t env)
mu_stream_destroy(&env->stream);
mu_header_destroy(&env->header);
mu_list_destroy(&env->cleanup_list);
+ mu_list_destroy(&env->mmq);
env_builtin_priv_destroy(env);
free(env);
}

Return to:

Send suggestions and report system problems to the System administrator.