diff options
author | Eric Faurot <eric@cvs.openbsd.org> | 2012-09-29 11:02:42 +0000 |
---|---|---|
committer | Eric Faurot <eric@cvs.openbsd.org> | 2012-09-29 11:02:42 +0000 |
commit | a04c24417a0667efd952447cfbf483991d813507 (patch) | |
tree | 38b361ce7b0504948f07376be0e682afd46a143e | |
parent | ac830bdb508972563ddd6f986c3d186aeb75d360 (diff) |
some mfa_session cleanups.
- move mfa_session() prototype to smtpd.h
- make mfa session use a tree
- make static functions static
- merge mfa_session_init() into mfa_session()
ok chl@
-rw-r--r-- | usr.sbin/smtpd/mfa.c | 3 | ||||
-rw-r--r-- | usr.sbin/smtpd/mfa_session.c | 100 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 9 |
3 files changed, 29 insertions, 83 deletions
diff --git a/usr.sbin/smtpd/mfa.c b/usr.sbin/smtpd/mfa.c index 98caa1580c9..efaed0af2f6 100644 --- a/usr.sbin/smtpd/mfa.c +++ b/usr.sbin/smtpd/mfa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mfa.c,v 1.70 2012/09/27 17:58:56 chl Exp $ */ +/* $OpenBSD: mfa.c,v 1.71 2012/09/29 11:02:41 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -52,7 +52,6 @@ static void mfa_test_close(struct envelope *); static void mfa_test_rset(struct envelope *); static int mfa_strip_source_route(char *, size_t); static int mfa_fork_filter(struct filter *); -void mfa_session(struct submit_status *, enum session_state); static void mfa_imsg(struct imsgev *iev, struct imsg *imsg) diff --git a/usr.sbin/smtpd/mfa_session.c b/usr.sbin/smtpd/mfa_session.c index 986bba6a512..7d2e81dea01 100644 --- a/usr.sbin/smtpd/mfa_session.c +++ b/usr.sbin/smtpd/mfa_session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mfa_session.c,v 1.9 2012/09/11 12:47:36 eric Exp $ */ +/* $OpenBSD: mfa_session.c,v 1.10 2012/09/29 11:02:41 eric Exp $ */ /* * Copyright (c) 2011 Gilles Chehade <gilles@openbsd.org> @@ -39,54 +39,36 @@ #include "smtpd.h" #include "log.h" -void mfa_session(struct submit_status *, enum session_state); -struct mfa_session *mfa_session_init(struct submit_status *, enum session_state); -struct mfa_session *mfa_session_find(uint64_t); -struct mfa_session *mfa_session_xfind(uint64_t); -int mfa_session_proceed(struct mfa_session *); -void mfa_session_pickup(struct mfa_session *); -void mfa_session_fail(struct mfa_session *); -void mfa_session_destroy(struct mfa_session *); -void mfa_session_done(struct mfa_session *); +static int mfa_session_proceed(struct mfa_session *); +static void mfa_session_pickup(struct mfa_session *); +static void mfa_session_fail(struct mfa_session *); +static void mfa_session_destroy(struct mfa_session *); +static void mfa_session_done(struct mfa_session *); +static void mfa_session_imsg(int, short, void *); -void mfa_session_imsg(int, short, void *); +struct tree sessions; void mfa_session(struct submit_status *ss, enum session_state state) { struct mfa_session *ms; - ms = mfa_session_init(ss, state); - if (ms->filter == NULL) { - mfa_session_done(ms); - return; - } - if (! mfa_session_proceed(ms)) - mfa_session_fail(ms); -} - -struct mfa_session * -mfa_session_init(struct submit_status *ss, enum session_state state) -{ - struct mfa_session *ms; - - ms = calloc(1, sizeof(*ms)); - if (ms == NULL) - fatal("mfa_session_init: calloc"); - + ms = xcalloc(1, sizeof(*ms), "mfa_session"); ms->id = generate_uid(); ms->ss = *ss; ms->ss.code = 250; ms->state = state; ms->filter = TAILQ_FIRST(env->sc_filters); - SPLAY_INSERT(mfatree, &env->mfa_sessions, ms); + tree_xset(&sessions, ms->id, ms); - return ms; + if (ms->filter == NULL) + mfa_session_done(ms); + else if (!mfa_session_proceed(ms)) + mfa_session_fail(ms); } - -int +static int mfa_session_proceed(struct mfa_session *ms) { struct filter_msg fm; @@ -162,7 +144,7 @@ mfa_session_proceed(struct mfa_session *ms) return 1; } -void +static void mfa_session_pickup(struct mfa_session *ms) { if (ms->fm.code == STATUS_REJECT) { @@ -177,7 +159,7 @@ mfa_session_pickup(struct mfa_session *ms) mfa_session_proceed(ms); } -void +static void mfa_session_done(struct mfa_session *ms) { enum imsg_type imsg_type; @@ -233,42 +215,21 @@ mfa_session_done(struct mfa_session *ms) mfa_session_destroy(ms); } -struct mfa_session * -mfa_session_find(uint64_t id) -{ - struct mfa_session key; - - key.id = id; - return SPLAY_FIND(mfatree, &env->mfa_sessions, &key); -} - -struct mfa_session * -mfa_session_xfind(uint64_t id) -{ - struct mfa_session *ms; - - ms = mfa_session_find(id); - if (ms == NULL) - fatalx("mfa_session_xfind: mfa session missing"); - - return ms; -} - -void +static void mfa_session_fail(struct mfa_session *ms) { ms->ss.code = 530; mfa_session_done(ms); } -void +static void mfa_session_destroy(struct mfa_session *ms) { - SPLAY_REMOVE(mfatree, &env->mfa_sessions, ms); + tree_xpop(&sessions, ms->id); free(ms); } -void +static void mfa_session_imsg(int fd, short event, void *p) { struct filter *filter = p; @@ -321,7 +282,7 @@ mfa_session_imsg(int fd, short event, void *p) case FILTER_QUIT: case FILTER_CLOSE: case FILTER_RSET: - ms = mfa_session_xfind(fm.id); + ms = tree_xget(&sessions, fm.id); /* overwrite filter code */ ms->fm.code = fm.code; @@ -341,20 +302,3 @@ mfa_session_imsg(int fd, short event, void *p) mfa_session_imsg, filter); event_add(&filter->ev, NULL); } - -int -mfa_session_cmp(struct mfa_session *s1, struct mfa_session *s2) -{ - /* - * do not return uint64_t's - */ - if (s1->id < s2->id) - return -1; - - if (s1->id > s2->id) - return 1; - - return 0; -} - -SPLAY_GENERATE(mfatree, mfa_session, nodes, mfa_session_cmp); diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 737ca5c633c..6e186fdc569 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.374 2012/09/29 10:35:01 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.375 2012/09/29 11:02:41 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org> @@ -971,8 +971,11 @@ pid_t mda(void); /* mfa.c */ pid_t mfa(void); -int mfa_session_cmp(struct mfa_session *, struct mfa_session *); -SPLAY_PROTOTYPE(mfatree, mfa_session, nodes, mfa_session_cmp); + + +/* mfa_session.c */ +void mfa_session(struct submit_status *, enum session_state); + /* mta.c */ pid_t mta(void); |