From 7a387e1e1dcfd0c5e208df79e09aa2d851a00328 Mon Sep 17 00:00:00 2001 From: chris mikkelson Date: Thu, 2 Apr 2009 21:06:05 -0500 Subject: [PATCH] Clean up module return code handling; renamed SSM_MSG to more descriptive SSM_RESPONSE, and cleaned up macros, adding SSM_PASSED to avoid the explicit (ret & 0x0F) comparisons. --- module.c | 12 ++++++------ smtpsink.h | 13 ++++++++----- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/module.c b/module.c index 94eea33..f3ed34f 100644 --- a/module.c +++ b/module.c @@ -78,7 +78,7 @@ module_connect(struct conn *c) { for (i = 0; i < nmod; i++) { if (modlist[i]->ssm_connect) { ret = modlist[i]->ssm_connect(c); - if ((ret & 0x0F) != SSM_PASS) return ret; + if (!SSM_PASSED(ret)) return ret; } } return SSM_ACCEPT; @@ -92,7 +92,7 @@ module_helo(struct conn *c, char *cmd, int len, int argoff) for (i = 0; i < nmod; i++) { if (modlist[i]->ssm_helo) { ret = modlist[i]->ssm_helo(c,cmd,len,argoff); - if ((ret & 0x0F) != SSM_PASS) return ret; + if (!SSM_PASSED(ret)) return ret; } } return SSM_ACCEPT; @@ -106,7 +106,7 @@ module_mail(struct conn *c, char *cmd, int len, int argoff) for (i = 0; i < nmod; i++) { if (modlist[i]->ssm_mail) { ret = modlist[i]->ssm_mail(c,cmd,len,argoff); - if ((ret & 0x0F) != SSM_PASS) return ret; + if (!SSM_PASSED(ret)) return ret; } } return SSM_ACCEPT; @@ -119,7 +119,7 @@ module_rcpt(struct conn *c, char *cmd, int len, int argoff) for (i = 0; i < nmod; i++) { if (modlist[i]->ssm_rcpt) { ret = modlist[i]->ssm_rcpt(c,cmd,len,argoff); - if ((ret & 0x0F) != SSM_PASS) return ret; + if (!SSM_PASSED(ret)) return ret; } } return SSM_ACCEPT; @@ -132,7 +132,7 @@ module_data(struct conn *c, char *cmd, int len, int argoff) for (i = 0; i < nmod; i++) { if (modlist[i]->ssm_enddata) { ret = modlist[i]->ssm_data(c, cmd, len, argoff); - if ((ret & 0x0F) != SSM_PASS) return ret; + if (!SSM_PASSED(ret)) return ret; } } return SSM_ACCEPT; @@ -157,7 +157,7 @@ module_enddata(struct conn *c) for (i = 0; i < nmod; i++) { if (modlist[i]->ssm_enddata) { ret = modlist[i]->ssm_enddata(c); - if ((ret & 0x0F) != SSM_PASS) return ret; + if (!SSM_PASSED(ret)) return ret; } } return SSM_ACCEPT; diff --git a/smtpsink.h b/smtpsink.h index 75076ae..56d6f84 100644 --- a/smtpsink.h +++ b/smtpsink.h @@ -39,15 +39,18 @@ int respond(struct conn *, const char *, ...); /* SSM_PASS: move on to next module */ /* SSM_ACCEPT: stop processing, accept command */ /* SSM_REJECT: stop processing, reject command */ -/* SSM_MSG | SSM_ACCEPT: stop processing, accept command, module responded */ -/* SSM_MSG | SSM_REJECT: stop processing, reject command, module responded */ +/* SSM_RESPONSE | SSM_ACCEPT: stop processing, accept command, module responded */ +/* SSM_RESPONSE | SSM_REJECT: stop processing, reject command, module responded */ #define SSM_PASS 0 #define SSM_ACCEPT 1 #define SSM_REJECT 2 -#define SSM_MSG (1 << 8) +#define SSM_RESPONSE (1 << 8) -#define SSM_ACCEPTED(x) ((x & 0x0F) == SSM_ACCEPT) -#define SSM_RESPONDED(x) (x & 0x100) +#define SSM_ACTION(x) ((x) & 0x0F) +#define SSM_PASSED(x) (SSM_ACTION(x) == SSM_PASS) +#define SSM_ACCEPTED(x) (SSM_ACTION(x) == SSM_ACCEPT) +#define SSM_REJECTED(x) (SSM_ACTION(x) == SSM_REJECT) +#define SSM_RESPONDED(x) ((x) & SSM_RESPONSE) struct smtpsink_module { unsigned ssm_module_index; -- 2.50.1