Reformatted code
This commit is contained in:
40
gomilter.go
40
gomilter.go
@@ -24,14 +24,14 @@ package gomilter
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
"encoding/binary"
|
||||
"reflect"
|
||||
"os"
|
||||
"strings"
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type sockaddr_in struct {
|
||||
@@ -193,7 +193,6 @@ func GobDecode(buf []byte, data interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// ********* Filter Callback functions *********
|
||||
// These are registered with Milter
|
||||
// They are only called if they get registered but need to be defined anyway
|
||||
@@ -286,7 +285,7 @@ func Go_xxfi_body(ctx *C.SMFICTX, bodyp *C.uchar, bodylen C.size_t) C.sfsistat {
|
||||
// Our bit slice is backed by the original body. No copy is made here
|
||||
// Be aware that converting the byte slice to string will make a copy
|
||||
var b []byte
|
||||
b = (*[1<<30]byte)(unsafe.Pointer(bodyp))[0:bodylen]
|
||||
b = (*[1 << 30]byte)(unsafe.Pointer(bodyp))[0:bodylen]
|
||||
// Call our application's callback
|
||||
m := milter.(checkForBody)
|
||||
code := m.Body(ctx2int(ctx), b)
|
||||
@@ -438,7 +437,7 @@ func GetPriv(ctx uintptr, privatedata interface{}) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func SetReply (ctx uintptr, rcode, xcode, message string) int {
|
||||
func SetReply(ctx uintptr, rcode, xcode, message string) int {
|
||||
type CtxPtr *C.struct_smfi_str
|
||||
crcode := C.CString(rcode)
|
||||
defer C.free(unsafe.Pointer(crcode))
|
||||
@@ -450,7 +449,7 @@ func SetReply (ctx uintptr, rcode, xcode, message string) int {
|
||||
return int(C.smfi_setreply(int2ctx(ctx), crcode, cxcode, cmessage))
|
||||
}
|
||||
|
||||
func SetMLReply (ctx uintptr, rcode, xcode string, message ...string) int {
|
||||
func SetMLReply(ctx uintptr, rcode, xcode string, message ...string) int {
|
||||
/* Allows up to 32 lines of message
|
||||
*/
|
||||
|
||||
@@ -468,7 +467,7 @@ func SetMLReply (ctx uintptr, rcode, xcode string, message ...string) int {
|
||||
defer C.free(argv)
|
||||
// Assign each line to its address offset
|
||||
for i := 0; i < len(message); i++ {
|
||||
linePtr := (**C.char)(unsafe.Pointer(uintptr(argv) + uintptr(i) * ptrSize))
|
||||
linePtr := (**C.char)(unsafe.Pointer(uintptr(argv) + uintptr(i)*ptrSize))
|
||||
line := C.CString(message[i])
|
||||
defer C.free(unsafe.Pointer(line))
|
||||
*linePtr = line
|
||||
@@ -491,7 +490,7 @@ func AddHeader(ctx uintptr, headerf, headerv string) int {
|
||||
defer C.free(unsafe.Pointer(cheaderv))
|
||||
|
||||
// Call smfi_addheader
|
||||
return int(C.smfi_addheader(int2ctx(ctx), cheaderf, cheaderv));
|
||||
return int(C.smfi_addheader(int2ctx(ctx), cheaderf, cheaderv))
|
||||
}
|
||||
|
||||
func ChgHeader(ctx uintptr, headerf string, hdridx int, headerv string) int {
|
||||
@@ -504,7 +503,7 @@ func ChgHeader(ctx uintptr, headerf string, hdridx int, headerv string) int {
|
||||
defer C.free(unsafe.Pointer(cheaderv))
|
||||
|
||||
// Call smfi_chgheader
|
||||
return int(C.smfi_chgheader(int2ctx(ctx), cheaderf, C.int(hdridx), cheaderv));
|
||||
return int(C.smfi_chgheader(int2ctx(ctx), cheaderf, C.int(hdridx), cheaderv))
|
||||
}
|
||||
|
||||
func InsHeader(ctx uintptr, hdridx int, headerf, headerv string) int {
|
||||
@@ -517,10 +516,9 @@ func InsHeader(ctx uintptr, hdridx int, headerf, headerv string) int {
|
||||
defer C.free(unsafe.Pointer(cheaderv))
|
||||
|
||||
// Call smfi_insheader
|
||||
return int(C.smfi_insheader(int2ctx(ctx), C.int(hdridx), cheaderf, cheaderv));
|
||||
return int(C.smfi_insheader(int2ctx(ctx), C.int(hdridx), cheaderf, cheaderv))
|
||||
}
|
||||
|
||||
|
||||
func ChgFrom(ctx uintptr, mail, args string) int {
|
||||
/* Change the envelope sender address. SMFIF_CHGFROM
|
||||
*/
|
||||
@@ -595,12 +593,10 @@ func progress(ctx uintptr) int {
|
||||
|
||||
// ********* Run the milter *********
|
||||
|
||||
|
||||
|
||||
func Run(amilter Milter) int {
|
||||
milter = amilter
|
||||
if milter.GetDebug() {
|
||||
LoggerPrintf ("Debugging enabled")
|
||||
LoggerPrintf("Debugging enabled")
|
||||
}
|
||||
|
||||
// Declare an empty smfiDesc structure
|
||||
@@ -774,10 +770,10 @@ func Run(amilter Milter) int {
|
||||
return int(result)
|
||||
}
|
||||
|
||||
var LoggerPrintln func(...interface {})
|
||||
var LoggerPrintf func(string, ...interface {})
|
||||
var LoggerPrintln func(...interface{})
|
||||
var LoggerPrintf func(string, ...interface{})
|
||||
|
||||
func init() {
|
||||
LoggerPrintln = func(i ...interface {}) { fmt.Println(i...) }
|
||||
LoggerPrintf = func(i string, j ...interface {}) { fmt.Printf(i, j...) }
|
||||
LoggerPrintln = func(i ...interface{}) { fmt.Println(i...) }
|
||||
LoggerPrintf = func(i string, j ...interface{}) { fmt.Printf(i, j...) }
|
||||
}
|
||||
|
||||
@@ -15,13 +15,10 @@ Sample Milter
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
"."
|
||||
"fmt"
|
||||
|
||||
)
|
||||
|
||||
|
||||
type Mymilter struct {
|
||||
gomilter.MilterRaw // Embed the basic functionality. No callbacks yet
|
||||
}
|
||||
@@ -43,7 +40,7 @@ func main() {
|
||||
mymilter := new(Mymilter)
|
||||
mymilter.FilterName = "TestFilter"
|
||||
mymilter.Debug = true
|
||||
mymilter.Flags = gomilter.AddHdrs|gomilter.AddRcpt
|
||||
mymilter.Flags = gomilter.AddHdrs | gomilter.AddRcpt
|
||||
|
||||
// Start Milter
|
||||
gomilter.Run(mymilter)
|
||||
|
||||
@@ -7,10 +7,8 @@ Copyright (c) 2015 Leon Baker
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
m "github.com/leonrbaker/gomilter"
|
||||
"fmt"
|
||||
|
||||
m "github.com/leonrbaker/gomilter"
|
||||
)
|
||||
|
||||
type Mymilter struct {
|
||||
@@ -86,7 +84,7 @@ func (milter *Mymilter) Eom(ctx uintptr) (sfsistat int8) {
|
||||
fmt.Println("t:", t)
|
||||
|
||||
m.AddHeader(ctx, "LEONUX-Mailer",
|
||||
"test server;\n\ttest1=\"foobar\"")
|
||||
"test server;\n\ttest1=\"foobar\"")
|
||||
|
||||
newBody := []byte("This is a new body")
|
||||
m.ReplaceBody(ctx, newBody)
|
||||
@@ -107,7 +105,7 @@ func main() {
|
||||
mymilter := new(Mymilter)
|
||||
mymilter.FilterName = "TestFilter"
|
||||
mymilter.Debug = true
|
||||
mymilter.Flags = m.ADDHDRS|m.ADDRCPT|m.CHGFROM|m.CHGBODY
|
||||
mymilter.Flags = m.ADDHDRS | m.ADDRCPT | m.CHGFROM | m.CHGBODY
|
||||
mymilter.Socket = "unix:/var/milterattachcheck/socket"
|
||||
|
||||
// Start Milter
|
||||
|
||||
Reference in New Issue
Block a user