]>
diplodocus.org Git - mdeliver/blob - libspamc.h
be3d0fd90bbad18a415fe0fa0d1fdb97d45a4642
2 * Copyright 2004 Apache Software Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #include <sys/types.h>
25 /* ignore MSVC++ warnings that are annoying and hard to remove:
26 4115 named type definition in parentheses
27 4127 conditional expression is constant
28 4514 unreferenced inline function removed
30 #pragma warning( disable : 4115 4127 4514 )
35 #include <sys/socket.h>
36 #include <netinet/in.h>
40 /* FIXME: This stuff has to go somewhere else */
48 #define EX_UNAVAILABLE 69
49 #define EX_SOFTWARE 70
52 #define EX_CANTCREAT 73
54 #define EX_TEMPFAIL 75
55 #define EX_PROTOCOL 76
59 #define STDIN_FILENO 0
60 #define STDOUT_FILENO 1
62 /* FIXME: This doesn't belong here either */
63 #define LOG_EMERG 0 /* system is unusable */
64 #define LOG_ALERT 1 /* action must be taken immediately */
65 #define LOG_CRIT 2 /* critical conditions */
66 #define LOG_ERR 3 /* error conditions */
67 #define LOG_WARNING 4 /* warning conditions */
68 #define LOG_NOTICE 5 /* normal but significant condition */
69 #define LOG_INFO 6 /* informational */
70 #define LOG_DEBUG 7 /* debug-level messages */
78 /* Aug 14, 2002 bj: Bitflags instead of lots of bool parameters */
79 #define SPAMC_MODE_MASK 1
80 #define SPAMC_RAW_MODE 0
81 #define SPAMC_BSMTP_MODE 1
83 #define SPAMC_USE_SSL (1<<27)
84 #define SPAMC_SAFE_FALLBACK (1<<28)
85 #define SPAMC_CHECK_ONLY (1<<29)
87 /* Jan 30, 2003 ym: added reporting options */
88 #define SPAMC_REPORT (1<<26)
89 #define SPAMC_REPORT_IFSPAM (1<<25)
91 /* Feb 1 2003 jm: might as well fix bug 191 as well */
92 #define SPAMC_SYMBOLS (1<<24)
94 /* 2003/04/16 SJF: randomize hostname order (quasi load balancing) */
95 #define SPAMC_RANDOMIZE_HOSTS (1<<23)
98 #define SPAMC_LOG_TO_STDERR (1<<22)
100 /* Nov 24, 2004 NP: added learning support */
101 #define SPAMC_LEARN (1<<21)
103 /* May 5, 2005 NP: added list reporting support */
104 #define SPAMC_REPORT_MSG (1<<20)
107 #define SPAMC_MESSAGE_CLASS_SPAM 1
108 #define SPAMC_MESSAGE_CLASS_HAM 2
110 #define SPAMC_SET_LOCAL 1
111 #define SPAMC_SET_REMOTE 2
113 #define SPAMC_REMOVE_LOCAL 4
114 #define SPAMC_REMOVE_REMOTE 8
116 /* Aug 14, 2002 bj: A struct for storing a message-in-progress */
126 struct libspamc_private_message
;
130 /* Set before passing the struct on! */
131 unsigned int max_len
; /* messages larger than this will return EX_TOOBIG */
132 int timeout
; /* timeout for read() system calls */
134 /* Filled in by message_read */
137 unsigned int raw_len
; /* Raw message buffer */
139 int pre_len
; /* Pre-message data (e.g. SMTP commands) */
141 unsigned int msg_len
; /* The message */
143 int post_len
; /* Post-message data (e.g. SMTP commands) */
146 /* Filled in by filter_message */
147 int is_spam
; /* EX_ISSPAM if the message is spam, EX_NOTSPAM
149 float score
, threshold
; /* score and threshold */
150 char *outbuf
; /* Buffer for output from spamd */
152 int out_len
; /* Output from spamd. Either the filtered
153 message, or the check-only response. Or else,
154 a pointer to msg above. */
156 /* these members added in SpamAssassin version 2.60: */
157 struct libspamc_private_message
*priv
;
160 /*------------------------------------------------------------------------
161 * TRANSPORT (2004/04/16 - SJF)
163 * The code to connect with the daemon has gotten more complicated: support
164 * for SSL, fallback to multiple hosts, and using UNIX domain sockets. The
165 * code has gotten ugly with way too many parameters being passed all around.
167 * So we've created this object to hold all the info required to connect with
168 * the remote site, including a self-contained list of all the IP addresses
169 * in the event this is using TCP sockets. These multiple IPs can be obtained
170 * only from DNS returning more than one A record for a single name, and
171 * this allows for fallback.
173 * We also allow a kind of quasi-load balancing, where we take the list of
174 * A records from DNS and randomize them before starting out - this lets
175 * us spread the load out among multiple servers if desired. The idea for
176 * load balancing goes to Jeremy Zawodny.
178 * By putting all our data here, we remove "fallback" from being a special
179 * case. We may find ourselves with several IP addresses, but if the user
180 * disables fallback, we set the IP address count to one. Now the connect
181 * code just loops over that same address.
183 #define TRANSPORT_LOCALHOST 0x01 /* TCP to localhost only */
184 #define TRANSPORT_TCP 0x02 /* standard TCP socket */
185 #define TRANSPORT_UNIX 0x03 /* UNIX domain socket */
187 #define TRANSPORT_MAX_HOSTS 256 /* max hosts we can failover between */
193 const char *socketpath
; /* for UNIX dommain socket */
194 const char *hostname
; /* for TCP sockets */
196 unsigned short port
; /* for TCP sockets */
198 struct in_addr hosts
[TRANSPORT_MAX_HOSTS
];
203 extern void transport_init(struct transport
*tp
);
204 extern int transport_setup(struct transport
*tp
, int flags
);
206 /* Aug 14, 2002 bj: New interface functions */
208 /* Read in a message from the fd, with the mode specified in the flags.
209 * Returns EX_OK on success, EX_otherwise on failure. On failure, m may be
210 * either MESSAGE_NONE or MESSAGE_ERROR. */
211 int message_read(int in_fd
, int flags
, struct message
*m
);
213 /* Write out a message to the fd, as specified by m->type. Note that
214 * MESSAGE_NONE messages have nothing to write. Also note that if you ran the
215 * message through message_filter with SPAMC_CHECK_ONLY, it will only output
216 * the "score/threshold" line. */
217 long message_write(int out_fd
, struct message
*m
);
219 /* Process the message through the spamd filter, making as many connection
220 * attempts as are implied by the transport structure. To make this do
221 * failover, more than one host is defined, but if there is only one there,
222 * no failover is done.
224 int message_filter(struct transport
*tp
, const char *username
,
225 int flags
, struct message
*m
);
227 /* Process the message through the spamd tell command, making as many
228 * connection attempts as are implied by the transport structure. To make
229 * this do failover, more than one host is defined, but if there is only
230 * one there, no failover is done.
232 int message_tell(struct transport
*tp
, const char *username
, int flags
,
233 struct message
*m
, int msg_class
,
234 unsigned int tellflags
, unsigned int *didtellflags
);
236 /* Dump the message. If there is any data in the message (typically, m->type
237 * will be MESSAGE_ERROR) it will be message_writed. Then, fd_in will be piped
238 * to fd_out intol EOF. This is particularly useful if you get back an
240 void message_dump(int in_fd
, int out_fd
, struct message
*m
);
242 /* Do a message_read->message_filter->message_write sequence, handling errors
243 * appropriately with dump_message or appropriate CHECK_ONLY output. Returns
244 * EX_OK or EX_ISSPAM/EX_NOTSPAM on success, some error EX on error. */
245 int message_process(struct transport
*trans
, char *username
, int max_size
,
246 int in_fd
, int out_fd
, const int flags
);
248 /* Cleanup the resources we allocated for storing the message. Call after
249 * you're done processing. */
250 void message_cleanup(struct message
*m
);
252 /* Aug 14, 2002 bj: This is now legacy, don't use it. */
253 int process_message(struct transport
*tp
, char *username
,
254 int max_size
, int in_fd
, int out_fd
,
255 const int check_only
, const int safe_fallback
);
258 void libspamc_log(int flags
, int level
, char *msg
, ...);