From beb8b9d195a4e5e8c58f1860fb69043da5b841d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Mun=CC=83oz?= Date: Wed, 13 Sep 2017 16:58:05 -0700 Subject: [PATCH 1/2] Add support for the Data() callback --- README.md | 1 + filter.c | 4 ++++ filter.h | 11 ++++++----- gomilter.go | 25 +++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 29b422a..83b9174 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Milter callbacks are added by implementing methods for the struct with matching * Helo * EnvFrom * EnvRcpt +* Data * Header * Eoh * Body diff --git a/filter.c b/filter.c index 717dc15..e4f0ad7 100644 --- a/filter.c +++ b/filter.c @@ -32,6 +32,10 @@ void setHeader(struct smfiDesc *smfilter) { smfilter->xxfi_header = &Go_xxfi_header; } +void setData(struct smfiDesc *smfilter) { + smfilter->xxfi_data = &Go_xxfi_data; +} + void setEoh(struct smfiDesc *smfilter) { smfilter->xxfi_eoh = &Go_xxfi_eoh; } diff --git a/filter.h b/filter.h index 4be37f2..168d007 100644 --- a/filter.h +++ b/filter.h @@ -5,16 +5,17 @@ This projected is licensed under the terms of the MIT License. // Set Callback functions in smfiDesc struct extern void makesmfilter(struct smfiDesc *smfilter); +extern void setAbort(struct smfiDesc *smfilter); +extern void setBody(struct smfiDesc *smfilter); +extern void setClose(struct smfiDesc *smfilter); extern void setConnect(struct smfiDesc *smfilter); -extern void setHelo(struct smfiDesc *smfilter); +extern void setData(struct smfiDesc *smfilter); extern void setEnvFrom(struct smfiDesc *smfilter); extern void setEnvRcpt(struct smfiDesc *smfilter); -extern void setHeader(struct smfiDesc *smfilter); extern void setEoh(struct smfiDesc *smfilter); -extern void setBody(struct smfiDesc *smfilter); extern void setEom(struct smfiDesc *smfilter); -extern void setAbort(struct smfiDesc *smfilter); -extern void setClose(struct smfiDesc *smfilter); +extern void setHeader(struct smfiDesc *smfilter); +extern void setHelo(struct smfiDesc *smfilter); // Utility functions for things that we can't do in Go diff --git a/gomilter.go b/gomilter.go index 68e0d2d..f31c0dd 100644 --- a/gomilter.go +++ b/gomilter.go @@ -129,6 +129,10 @@ type checkForHeader interface { Header(ctx uintptr, headerf, headerv string) (sfsistat int8) } +type checkForData interface { + Data(ctx uintptr) (sfsistat int8) +} + type checkForEoh interface { Eoh(ctx uintptr) (sfsistat int8) } @@ -275,6 +279,16 @@ func Go_xxfi_envrcpt(ctx *C.SMFICTX, argv **C.char) C.sfsistat { return C.sfsistat(code) } +//export Go_xxfi_data +func Go_xxfi_data(ctx *C.SMFICTX) C.sfsistat { + m := milter.(checkForData) + code := m.Data(ctx2int(ctx)) + if milter.GetDebug() { + logger.Printf("Data callback returned: %d\n", code) + } + return C.sfsistat(code) +} + //export Go_xxfi_header func Go_xxfi_header(ctx *C.SMFICTX, headerf, headerv *C.char) C.sfsistat { m := milter.(checkForHeader) @@ -669,6 +683,17 @@ func Run(amilter Milter) int { logger.Println("Helo callback not implemented") } } + // Check if Data method was implemented + if _, ok := milter.(checkForData); ok { + if milter.GetDebug() { + logger.Println("Data callback implemented") + } + C.setData(&smfilter) + } else { + if milter.GetDebug() { + logger.Println("Data callback not implemented") + } + } // Check if EnvFrom method was implemented if _, ok := milter.(checkForEnvFrom); ok { if milter.GetDebug() { From e33ed3e0a18baac092576f860806347721624fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Mun=CC=83oz?= Date: Fri, 15 Sep 2017 16:02:12 -0700 Subject: [PATCH 2/2] Add constants used to setup the milter flags --- gomilter.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gomilter.go b/gomilter.go index f31c0dd..1992057 100644 --- a/gomilter.go +++ b/gomilter.go @@ -70,6 +70,21 @@ const ( SETSYMLIST = 0x00000100 // 100000000 ) +// What the MTA can send/filter wants in protocol +const ( + SMFIP_NOCONNECT = 0x00000001 // MTA should not send connect info + SMFIP_NOHELO = 0x00000002 // MTA should not send HELO info + SMFIP_NOMAIL = 0x00000004 // MTA should not send MAIL info + SMFIP_NORCPT = 0x00000008 // MTA should not send RCPT info + SMFIP_NOBODY = 0x00000010 // MTA should not send body + SMFIP_NOHDRS = 0x00000020 // MTA should not send headers + SMFIP_NOEOH = 0x00000040 // MTA should not send EOH + SMFIP_NR_HDR = 0x00000080 // No reply for headers + SMFIP_NOHREPL = SMFIP_NR_HDR // No reply for headers + SMFIP_NOUNKNOWN = 0x00000100 // MTA should not send unknown commands + SMFIP_NODATA = 0x00000200 // MTA should not send DATA +) + // Interface that must be implemented in order to use gomilter type Milter interface { GetFilterName() string