/* <@LICENSE>
- * Copyright 2004 Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
4115 named type definition in parentheses
4127 conditional expression is constant
4514 unreferenced inline function removed
+ 4996 deprecated "unsafe" functions (bug 4855)
*/
#pragma warning( disable : 4115 4127 4514 )
+#if (_MSC_VER >= 1400) /* VC8+ */
+#pragma warning( disable : 4996 )
+#endif
+
#endif
#include <winsock.h>
#else
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
+/* some platforms (Cygwin) don't implement getaddrinfo */
+#ifdef EAI_AGAIN
+#define SPAMC_HAS_ADDRINFO 1
+#endif
#endif
-#ifdef _WIN32
+#if (defined(_WIN32) || !defined(_SYSEXITS_H))
/* FIXME: This stuff has to go somewhere else */
#define EX_OK 0
#define SPAMC_RAW_MODE 0
#define SPAMC_BSMTP_MODE 1
-#define SPAMC_USE_SSL (1<<27)
-#define SPAMC_SAFE_FALLBACK (1<<28)
-#define SPAMC_CHECK_ONLY (1<<29)
+#define SPAMC_USE_INET6 (1<<31)
+#define SPAMC_USE_INET4 (1<<30)
+
+#define SPAMC_CHECK_ONLY (1<<29)
+#define SPAMC_SAFE_FALLBACK (1<<28)
+#define SPAMC_USE_SSL (1<<27)
/* Jan 30, 2003 ym: added reporting options */
-#define SPAMC_REPORT (1<<26)
-#define SPAMC_REPORT_IFSPAM (1<<25)
+#define SPAMC_REPORT (1<<26)
+#define SPAMC_REPORT_IFSPAM (1<<25)
/* Feb 1 2003 jm: might as well fix bug 191 as well */
-#define SPAMC_SYMBOLS (1<<24)
+#define SPAMC_SYMBOLS (1<<24)
/* 2003/04/16 SJF: randomize hostname order (quasi load balancing) */
#define SPAMC_RANDOMIZE_HOSTS (1<<23)
/* log to stderr */
-#define SPAMC_LOG_TO_STDERR (1<<22)
+#define SPAMC_LOG_TO_STDERR (1<<22)
+
+/* Nov 24, 2004 NP: added learning support */
+#define SPAMC_LEARN (1<<21)
+
+/* May 5, 2005 NP: added list reporting support */
+#define SPAMC_REPORT_MSG (1<<20)
+
+/* Oct 21, 2005 sidney: added ping test */
+#define SPAMC_PING (1<<19)
+
+/* Jan 1, 2007 sidney: added SSL protocol versions */
+/* no flags means use default of SSL_v23 */
+/* Set both flags to specify TSL_v1 */
+#define SPAMC_TLSV1 (1<<18)
+#define SPAMC_SSLV3 (1<<17)
+
+/* Nov 30, 2006 jm: add -z, zlib support */
+#define SPAMC_USE_ZLIB (1<<16)
+
+/* Jan 16, 2007 jm: get markup headers from spamd */
+#define SPAMC_HEADERS (1<<15)
+
+/* December 5, 2007 duncf: send log messages to callback */
+#define SPAMC_LOG_TO_CALLBACK (1<<14)
+
+/* December 6, 2011 Sebastian Wiesinger <sebastian@karotte.org>:
+ * Turn EX_UNAVAILABLE into EX_TEMPFAIL - bug 6717
+ * */
+#define SPAMC_UNAVAIL_TEMPFAIL (1<<13)
+
+#define SPAMC_MESSAGE_CLASS_SPAM 1
+#define SPAMC_MESSAGE_CLASS_HAM 2
+
+#define SPAMC_SET_LOCAL 1
+#define SPAMC_SET_REMOTE 2
+
+#define SPAMC_REMOVE_LOCAL 4
+#define SPAMC_REMOVE_REMOTE 8
+
+#define SPAMC_MAX_MESSAGE_LEN (256 * 1024 * 1024) /* see bug 4928 */
/* Aug 14, 2002 bj: A struct for storing a message-in-progress */
typedef enum
/* Set before passing the struct on! */
unsigned int max_len; /* messages larger than this will return EX_TOOBIG */
int timeout; /* timeout for read() system calls */
+ int connect_timeout; /* Sep 8, 2008 mrgus: timeout for opening sockets */
/* Filled in by message_read */
message_type_t type;
char *raw;
- unsigned int raw_len; /* Raw message buffer */
+ int raw_len; /* Raw message buffer */
+ /* note: do not make "raw_len" in particular unsigned! see bug 4593 */
char *pre;
int pre_len; /* Pre-message data (e.g. SMTP commands) */
char *msg;
- unsigned int msg_len; /* The message */
+ int msg_len; /* The message */
char *post;
int post_len; /* Post-message data (e.g. SMTP commands) */
int content_length;
int is_spam; /* EX_ISSPAM if the message is spam, EX_NOTSPAM
if not */
float score, threshold; /* score and threshold */
+ char *outbuf; /* Buffer for output from spamd */
char *out;
int out_len; /* Output from spamd. Either the filtered
message, or the check-only response. Or else,
unsigned short port; /* for TCP sockets */
+#ifdef SPAMC_HAS_ADDRINFO
+ struct addrinfo *hosts[TRANSPORT_MAX_HOSTS];
+#else
struct in_addr hosts[TRANSPORT_MAX_HOSTS];
+#endif
int nhosts;
int flags;
+
+ /* added in SpamAssassin 3.2.0 */
+ int connect_retries;
+ int retry_sleep;
+
+ /* Added for filterloop */
+ int filter_retries;
+ int filter_retry_sleep;
};
+/* Initialise and setup transport-specific context for the connection
+ * to spamd. Note that this may leak a small amount of string data for
+ * the remote hostname (bug 5531) if called repeatedly; use
+ * transport_cleanup() to clean this up. */
extern void transport_init(struct transport *tp);
extern int transport_setup(struct transport *tp, int flags);
int message_filter(struct transport *tp, const char *username,
int flags, struct message *m);
+/* Process the message through the spamd tell command, making as many
+ * connection attempts as are implied by the transport structure. To make
+ * this do failover, more than one host is defined, but if there is only
+ * one there, no failover is done.
+ */
+int message_tell(struct transport *tp, const char *username, int flags,
+ struct message *m, int msg_class,
+ unsigned int tellflags, unsigned int *didtellflags);
+
/* Dump the message. If there is any data in the message (typically, m->type
* will be MESSAGE_ERROR) it will be message_writed. Then, fd_in will be piped
* to fd_out intol EOF. This is particularly useful if you get back an
* EX_TOOBIG. */
-void message_dump(int in_fd, int out_fd, struct message *m);
+void message_dump(int in_fd, int out_fd, struct message *m, int flags);
/* Do a message_read->message_filter->message_write sequence, handling errors
* appropriately with dump_message or appropriate CHECK_ONLY output. Returns
int max_size, int in_fd, int out_fd,
const int check_only, const int safe_fallback);
+void register_spamc_header_callback(const struct message *m, void (*func)(struct message *m, int flags, char *buf, int len));
+void register_spamd_header_callback(const struct message *m, void (*func)(struct message *m, int flags, const char *buf, int len));
+
+void register_libspamc_log_callback(void (*function)(int flags, int level, char *msg, va_list args));
+
void libspamc_log(int flags, int level, char *msg, ...);
+/* Cleanup the resources allocated for storing details of the transport.
+ * Added in SpamAssassin 3.3.0. */
+void transport_cleanup(struct transport *tp);
+
+/* define a preprocessor symbol so that calling code can tell if the
+ * transport_cleanup() API function is available. */
+#define SPAMC_HAS_TRANSPORT_CLEANUP
+
#endif