forked from leonrbaker/gomilter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfilter.c
220 lines (197 loc) · 8.72 KB
/
filter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
Copyright (c) 2015 Leon Baker
This projected is licensed under the terms of the MIT License.
*/
#include "libmilter/mfapi.h"
#include "_cgo_export.h"
//#include <stdio.h> // Testing with fprint remove!!!!
// Set Callback functions in smfiDesc struct
void setConnect(struct smfiDesc *smfilter) {
smfilter->xxfi_connect = &Go_xxfi_connect;
}
void setHelo(struct smfiDesc *smfilter) {
smfilter->xxfi_helo = &Go_xxfi_helo;
}
void setEnvFrom(struct smfiDesc *smfilter) {
smfilter->xxfi_envfrom = &Go_xxfi_envfrom;
}
void setEnvRcpt(struct smfiDesc *smfilter) {
smfilter->xxfi_envrcpt = &Go_xxfi_envrcpt;
}
void setHeader(struct smfiDesc *smfilter) {
smfilter->xxfi_header = &Go_xxfi_header;
}
void setEoh(struct smfiDesc *smfilter) {
smfilter->xxfi_eoh = &Go_xxfi_eoh;
}
void setBody(struct smfiDesc *smfilter) {
smfilter->xxfi_body = &Go_xxfi_body;
}
void setEom(struct smfiDesc *smfilter) {
smfilter->xxfi_eom = &Go_xxfi_eom;
}
void setAbort(struct smfiDesc *smfilter) {
smfilter->xxfi_abort = &Go_xxfi_abort;
}
void setClose(struct smfiDesc *smfilter) {
smfilter->xxfi_close = &Go_xxfi_close;
}
// Utility functions for things that we can't do as easily in Go
// Return the length of a null terminated pointer array
int argv_len(char **argv) {
int argc = 0;
while (*argv++ != NULL)
++argc;
return argc;
}
// Wrapper for setmlreply
// Not very elegant way of calling the variadic setmlreply function
int wrap_setmlreply(SMFICTX *ctx, char *rcode, char *xcode, int msgc, char **msgv) {
switch(msgc) {
case 1:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], NULL);
case 2:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], NULL);
case 3:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
NULL);
case 4:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], NULL);
case 5:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], NULL);
case 6:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], NULL);
case 7:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], NULL);
case 8:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], NULL);
case 9:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], NULL);
case 10:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
NULL);
case 11:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], NULL);
case 12:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], NULL);
case 13:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], NULL);
case 14:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], NULL);
case 15:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], NULL);
case 16:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], NULL);
case 17:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
NULL);
case 18:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], NULL);
case 19:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], NULL);
case 20:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], msgv[19], NULL);
case 21:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], msgv[19], msgv[20], NULL);
case 22:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], msgv[19], msgv[20], msgv[21], NULL);
case 23:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], msgv[19], msgv[20], msgv[21], msgv[22], NULL);
case 24:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], msgv[19], msgv[20], msgv[21], msgv[22], msgv[23],
NULL);
case 25:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], msgv[19], msgv[20], msgv[21], msgv[22], msgv[23],
msgv[24], NULL);
case 26:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], msgv[19], msgv[20], msgv[21], msgv[22], msgv[23],
msgv[24], msgv[25], NULL);
case 27:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], msgv[19], msgv[20], msgv[21], msgv[22], msgv[23],
msgv[24], msgv[25], msgv[26], NULL);
case 28:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], msgv[19], msgv[20], msgv[21], msgv[22], msgv[23],
msgv[24], msgv[25], msgv[26], msgv[27], NULL);
case 29:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], msgv[19], msgv[20], msgv[21], msgv[22], msgv[23],
msgv[24], msgv[25], msgv[26], msgv[27], msgv[28], NULL);
case 30:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], msgv[19], msgv[20], msgv[21], msgv[22], msgv[23],
msgv[24], msgv[25], msgv[26], msgv[27], msgv[28], msgv[29], NULL);
case 31:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], msgv[19], msgv[20], msgv[21], msgv[22], msgv[23],
msgv[24], msgv[25], msgv[26], msgv[27], msgv[28], msgv[29], msgv[30],
NULL);
case 32:
return smfi_setmlreply(ctx, rcode, xcode, msgv[0], msgv[1], msgv[2],
msgv[3], msgv[4], msgv[5], msgv[6], msgv[7], msgv[8], msgv[9],
msgv[10], msgv[11], msgv[12], msgv[13], msgv[14], msgv[15], msgv[16],
msgv[17], msgv[18], msgv[19], msgv[20], msgv[21], msgv[22], msgv[23],
msgv[24], msgv[25], msgv[26], msgv[27], msgv[28], msgv[29], msgv[30],
msgv[31], NULL);
default: return -1;
}
}