From eb737947eb2afe98f9dac1121fa37d1b746c5657 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 8 Oct 2015 13:15:15 +0100 Subject: [PATCH] Reorganize includes to reduce namespace pollution. --- config.h.in | 168 +------------------------ contrib/aho-corasick/acism.c | 1 + contrib/cdb/cdb.h | 2 + src/CMakeLists.txt | 2 +- src/client/rspamc.c | 6 +- src/client/rspamdclient.c | 2 +- src/client/rspamdclient.h | 1 + src/controller.c | 5 +- src/http_proxy.c | 1 + src/libmime/filter.c | 12 +- src/libmime/message.h | 1 + src/libmime/smtp_proto.c | 1 + src/libmime/smtp_utils.c | 3 +- src/libserver/buffer.c | 1 + src/libserver/cfg_rcl.c | 11 ++ src/libserver/cfg_utils.c | 2 + src/libserver/dynamic_cfg.c | 1 + src/libserver/fuzzy_backend.c | 1 + src/libserver/proxy.c | 1 + src/libserver/proxy.h | 1 + src/libserver/roll_history.c | 1 + src/libserver/spf.h | 1 + src/libserver/symbols_cache.c | 2 + src/libserver/symbols_cache.h | 2 +- src/libserver/task.c | 1 + src/libserver/task.h | 2 + src/libserver/worker_util.c | 4 + src/libstat/backends/mmaped_file.c | 2 +- src/libstat/backends/sqlite3_backend.c | 1 + src/libstat/classifiers/bayes.c | 1 + src/libutil/addr.c | 11 ++ src/libutil/addr.h | 15 +++ src/libutil/aio_event.c | 2 + src/libutil/http.c | 2 +- src/libutil/logger.c | 12 +- src/libutil/map.c | 1 + src/libutil/map.h | 2 + src/libutil/mem_pool.c | 5 + src/libutil/printf.c | 6 +- src/libutil/rrd.c | 2 + src/libutil/sqlite_utils.c | 1 + src/libutil/str_util.c | 2 +- src/libutil/unix-std.h | 88 +++++++++++++ src/libutil/util.c | 27 +++- src/libutil/util.h | 5 + src/lua/lua_buffer.c | 2 + src/lua/lua_cfg_file.c | 3 +- src/lua/lua_http.c | 1 + src/lua/lua_rsa.c | 1 + src/lua/lua_tcp.c | 1 + src/lua/lua_util.c | 1 + src/lua_worker.c | 1 + src/plugins/fuzzy_check.c | 6 +- src/plugins/regexp.c | 1 - src/plugins/spf.c | 1 + src/plugins/surbl.c | 5 +- src/plugins/surbl.h | 1 - src/rspamadm/pw.c | 1 + src/rspamadm/rspamadm.c | 5 + src/rspamd.c | 35 +++++- src/smtp_proxy.c | 1 + test/rspamd_async_test.c | 4 +- test/rspamd_cryptobox_test.c | 1 + test/rspamd_http_test.c | 6 + test/rspamd_lua_test.c | 5 + test/rspamd_mem_pool_test.c | 6 + test/rspamd_shingles_test.c | 2 +- test/rspamd_test_suite.c | 2 - test/rspamd_upstream_test.c | 2 +- 69 files changed, 298 insertions(+), 217 deletions(-) create mode 100644 src/libutil/unix-std.h diff --git a/config.h.in b/config.h.in index da476a758..693a9380e 100644 --- a/config.h.in +++ b/config.h.in @@ -281,53 +281,6 @@ #include #endif -/* queue */ -#ifdef HAVE_COMPATIBLE_QUEUE_H -#ifdef HAVE_SYS_QUEUE_H -#include -#endif -#else -#include "queue.h" -#endif - -/* sys/socket */ -#ifdef HAVE_SYS_SOCKET_H -#include -#endif - -/* sys/file.h */ -#ifdef HAVE_SYS_FILE_H -#include -#endif - -/* sys/uio.h */ -#ifdef HAVE_SYS_UIO_H -#include -#endif - -/* sys/mman */ -#ifdef HAVE_SYS_MMAN_H -#include -#endif - -/* netinet issues */ -#ifdef HAVE_NETINET_IN_H -#include -#endif -#ifdef HAVE_ARPA_INET_H -#include -#endif - -/* unix sockets */ -#ifdef HAVE_SYS_UN_H -#include -#endif - -/* netdb */ -#ifdef HAVE_NETDB_H -#include -#endif - /* stdlib */ #ifdef HAVE_STDLIB_H #include @@ -343,124 +296,17 @@ #include #endif -/* timedb */ -#ifdef HAVE_SYS_TIMEB_H -#include -#endif - -#ifdef HAVE_UNISTD_H -#include -#endif - -/* sysexits */ -#ifdef HAVE_SYSEXITS_H -#include -#endif - -/* unistd */ -#ifdef HAVE_UNISTD_H -#include +#ifdef HAVE_STDLIB_H +#include #endif - /* string */ #ifdef HAVE_STRING_H #include #endif -/* strings */ -#ifdef HAVE_STRINGS_H -#include -#endif - -/* fcntl */ -#ifdef HAVE_FCNTL_H -#include -#endif - -/* Linux specific falloc.h */ -#ifdef HAVE_LINUX_FALLOC_H -#include -#endif - -/* poll */ -#ifdef HAVE_POLL_H -#include -#endif - -/* sys/stat */ -#ifdef HAVE_SYS_STAT_H -#include -#endif - -/* sys/wait */ -#ifdef HAVE_SYS_WAIT_H -#include -#endif - -/* sys/resource.h */ -#ifdef HAVE_SYS_RESOURCE_H -#include -#endif - -/* math */ -#ifdef HAVE_MATH_H -#include -#endif - -/* libutil */ -#ifdef HAVE_LIBUTIL_H -#include -#endif - -/* pwd and grp */ -#ifdef HAVE_PWD_H -#include -#endif - -#ifdef HAVE_GRP_H -#include -#endif - -#ifdef HAVE_GLOB_H -#include -#endif - -/* syslog */ -#ifdef HAVE_SYSLOG_H -#include -#endif - -#ifdef HAVE_LIBGEN_H -#include -#define HAVE_DIRNAME 1 -#endif - -#ifdef HAVE_SEARCH_H -#include -#endif - -#ifdef WITH_GPERF_TOOLS -#include -#endif - -#ifdef HAVE_SCHED_YIELD -#include -#endif - -#ifdef HAVE_DIRENT_H -#include -#endif - #include -#include -#ifdef HAVE_SIGINFO_H -# include -#endif -#include -#if _EVENT_NUMERIC_VERSION > 0x02000000 -# include -#endif + #include @@ -478,14 +324,6 @@ typedef off_t goffset; #endif -#ifndef BUILD_STATIC -#include -#endif - -#ifndef NO_GMIME -#include -#endif - #ifndef ALIGN #if defined(_MSC_VER) # define ALIGN(x) __declspec(align(x)) diff --git a/contrib/aho-corasick/acism.c b/contrib/aho-corasick/acism.c index 64e1eb956..111704805 100644 --- a/contrib/aho-corasick/acism.c +++ b/contrib/aho-corasick/acism.c @@ -18,6 +18,7 @@ */ #include "_acism.h" +#include "unix-std.h" #define BACK ((SYMBOL)0) #define ROOT ((STATE) 0) diff --git a/contrib/cdb/cdb.h b/contrib/cdb/cdb.h index 03da9ac41..959c24f1f 100644 --- a/contrib/cdb/cdb.h +++ b/contrib/cdb/cdb.h @@ -9,6 +9,8 @@ #define TINYCDB_VERSION 0.77 #include "config.h" +#include "unix-std.h" +#include /* * OpenBSD fix diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2561fa0ff..0490186df 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -85,7 +85,7 @@ SET(PLUGINSSRC plugins/surbl.c plugins/chartable.c plugins/fuzzy_check.c plugins/spf.c - plugins/dkim_check.c) + plugins/dkim_check.c libutil/unix-std.h) SET(MODULES_LIST surbl regexp chartable fuzzy_check spf dkim) SET(WORKERS_LIST normal controller smtp_proxy fuzzy lua http_proxy) diff --git a/src/client/rspamc.c b/src/client/rspamc.c index 1d9252147..9be97cba0 100644 --- a/src/client/rspamc.c +++ b/src/client/rspamc.c @@ -27,6 +27,11 @@ #include "http.h" #include "rspamdclient.h" #include "utlist.h" +#include "unix-std.h" + +#ifdef HAVE_SYS_WAIT_H +#include +#endif #define DEFAULT_PORT 11333 #define DEFAULT_CONTROL_PORT 11334 @@ -1345,7 +1350,6 @@ main (gint argc, gchar **argv, gchar **env) event_base_loop (ev_base, 0); g_hash_table_destroy (kwattrs); - g_mime_shutdown (); /* Wait for children processes */ cur = g_list_first (children); diff --git a/src/client/rspamdclient.c b/src/client/rspamdclient.c index 272fe581b..58ea0ad0e 100644 --- a/src/client/rspamdclient.c +++ b/src/client/rspamdclient.c @@ -24,7 +24,7 @@ #include "rspamdclient.h" #include "util.h" #include "http.h" -#include "keypairs_cache.h" +#include "unix-std.h" #ifdef HAVE_FETCH_H #include diff --git a/src/client/rspamdclient.h b/src/client/rspamdclient.h index 2a63b5a7f..85b51514b 100644 --- a/src/client/rspamdclient.h +++ b/src/client/rspamdclient.h @@ -26,6 +26,7 @@ #include "config.h" #include "ucl.h" +#include struct rspamd_client_connection; struct rspamd_http_message; diff --git a/src/controller.c b/src/controller.c index 871037b32..6d14342d7 100644 --- a/src/controller.c +++ b/src/controller.c @@ -29,12 +29,11 @@ #include "libstat/stat_api.h" #include "rspamd.h" #include "libserver/worker_util.h" -#include "utlist.h" - -#include "blake2.h" #include "cryptobox.h" #include "ottery.h" #include "libutil/rrd.h" +#include "unix-std.h" +#include /* 60 seconds for worker's IO */ #define DEFAULT_WORKER_IO_TIMEOUT 60000 diff --git a/src/http_proxy.c b/src/http_proxy.c index 6570e01cc..572d78578 100644 --- a/src/http_proxy.c +++ b/src/http_proxy.c @@ -35,6 +35,7 @@ #include "libserver/worker_util.h" #include "keypairs_cache.h" #include "ottery.h" +#include "unix-std.h" /* Rotate keys each minute by default */ #define DEFAULT_ROTATION_TIME 60.0 diff --git a/src/libmime/filter.c b/src/libmime/filter.c index ed50efafe..ab8833a8a 100644 --- a/src/libmime/filter.c +++ b/src/libmime/filter.c @@ -27,15 +27,9 @@ #include "filter.h" #include "rspamd.h" #include "message.h" -#include "cfg_file.h" -#include "util.h" -#include "expression.h" -#include "libstat/stat_api.h" -#include "utlist.h" - -#ifdef WITH_LUA -# include "lua/lua_common.h" -#endif +#include "lua/lua_common.h" +#include + #define COMMON_PART_FACTOR 95 diff --git a/src/libmime/message.h b/src/libmime/message.h index b509b23cd..e98001448 100644 --- a/src/libmime/message.h +++ b/src/libmime/message.h @@ -7,6 +7,7 @@ #define RSPAMD_MESSAGE_H #include "config.h" +#include struct rspamd_task; struct controller_session; diff --git a/src/libmime/smtp_proto.c b/src/libmime/smtp_proto.c index 05d5c43d5..b6a14bdef 100644 --- a/src/libmime/smtp_proto.c +++ b/src/libmime/smtp_proto.c @@ -29,6 +29,7 @@ #include "smtp.h" #include "smtp_proto.h" #include "smtp_utils.h" +#include "unix-std.h" gchar * make_smtp_error (rspamd_mempool_t *pool, diff --git a/src/libmime/smtp_utils.c b/src/libmime/smtp_utils.c index df50abc65..32b23bfd7 100644 --- a/src/libmime/smtp_utils.c +++ b/src/libmime/smtp_utils.c @@ -23,9 +23,8 @@ #include "config.h" #include "rspamd.h" -#include "filter.h" #include "smtp.h" -#include "smtp_proto.h" +#include "unix-std.h" void free_smtp_session (gpointer arg) diff --git a/src/libserver/buffer.c b/src/libserver/buffer.c index 0875de300..4b8e3a3e5 100644 --- a/src/libserver/buffer.c +++ b/src/libserver/buffer.c @@ -25,6 +25,7 @@ #include "config.h" #include "buffer.h" #include "rspamd.h" +#include "unix-std.h" #ifdef HAVE_SYS_SENDFILE_H #include #endif diff --git a/src/libserver/cfg_rcl.c b/src/libserver/cfg_rcl.c index f50b37010..57674aae3 100644 --- a/src/libserver/cfg_rcl.c +++ b/src/libserver/cfg_rcl.c @@ -31,6 +31,15 @@ #include "expression.h" #include "composites.h" #include "libserver/worker_util.h" +#include "unix-std.h" + +#ifdef HAVE_SYSLOG_H +#include +#endif + +#ifdef HAVE_GLOB_H +#include +#endif struct rspamd_rcl_default_handler_data { struct rspamd_rcl_struct_parser pd; @@ -103,6 +112,7 @@ rspamd_rcl_logging_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, } else if (g_ascii_strcasecmp (log_type, "syslog") == 0) { /* Need to get facility */ +#ifdef HAVE_SYSLOG_H cfg->log_facility = LOG_DAEMON; cfg->log_type = RSPAMD_LOG_SYSLOG; val = ucl_object_find_key (obj, "facility"); @@ -168,6 +178,7 @@ rspamd_rcl_logging_handler (rspamd_mempool_t *pool, const ucl_object_t *obj, return FALSE; } } +#endif } else if (g_ascii_strcasecmp (log_type, "stderr") == 0 || g_ascii_strcasecmp (log_type, "console") == 0) { diff --git a/src/libserver/cfg_utils.c b/src/libserver/cfg_utils.c index 95c984b9c..5e3bf1561 100644 --- a/src/libserver/cfg_utils.c +++ b/src/libserver/cfg_utils.c @@ -34,6 +34,8 @@ #include "dynamic_cfg.h" #include "utlist.h" #include "stat_api.h" +#include "unix-std.h" +#include #define DEFAULT_SCORE 10.0 diff --git a/src/libserver/dynamic_cfg.c b/src/libserver/dynamic_cfg.c index eaa658b8b..cbb7913a4 100644 --- a/src/libserver/dynamic_cfg.c +++ b/src/libserver/dynamic_cfg.c @@ -26,6 +26,7 @@ #include "map.h" #include "filter.h" #include "dynamic_cfg.h" +#include "unix-std.h" struct config_json_buf { GString *buf; diff --git a/src/libserver/fuzzy_backend.c b/src/libserver/fuzzy_backend.c index af6eb193d..41363ae13 100644 --- a/src/libserver/fuzzy_backend.c +++ b/src/libserver/fuzzy_backend.c @@ -24,6 +24,7 @@ #include "config.h" #include "rspamd.h" #include "fuzzy_backend.h" +#include "unix-std.h" #include diff --git a/src/libserver/proxy.c b/src/libserver/proxy.c index 09171eeb9..2eff2b08e 100644 --- a/src/libserver/proxy.c +++ b/src/libserver/proxy.c @@ -24,6 +24,7 @@ #include "config.h" #include "rspamd.h" #include "proxy.h" +#include "unix-std.h" static void rspamd_proxy_backend_handler (gint fd, gshort what, gpointer data); static void rspamd_proxy_client_handler (gint fd, gshort what, gpointer data); diff --git a/src/libserver/proxy.h b/src/libserver/proxy.h index 784a78dbc..a372f30e0 100644 --- a/src/libserver/proxy.h +++ b/src/libserver/proxy.h @@ -27,6 +27,7 @@ #include "config.h" #include "buffer.h" +#include /** * @file proxy.h diff --git a/src/libserver/roll_history.c b/src/libserver/roll_history.c index 74c7c8214..6c48fc224 100644 --- a/src/libserver/roll_history.c +++ b/src/libserver/roll_history.c @@ -26,6 +26,7 @@ #include "config.h" #include "rspamd.h" #include "roll_history.h" +#include "unix-std.h" static const gchar rspamd_history_magic[] = {'r', 's', 'h', '1'}; diff --git a/src/libserver/spf.h b/src/libserver/spf.h index 473eff086..cdb7a0434 100644 --- a/src/libserver/spf.h +++ b/src/libserver/spf.h @@ -3,6 +3,7 @@ #include "config.h" #include "ref.h" +#include "addr.h" struct rspamd_task; struct spf_resolved; diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c index eaa4dce03..5e72eb97c 100644 --- a/src/libserver/symbols_cache.c +++ b/src/libserver/symbols_cache.c @@ -29,6 +29,8 @@ #include "symbols_cache.h" #include "cfg_file.h" #include "lua/lua_common.h" +#include "unix-std.h" +#include #define msg_err_cache(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \ cache->static_pool->tag.tagname, cache->cfg->checksum, \ diff --git a/src/libserver/symbols_cache.h b/src/libserver/symbols_cache.h index f6fffcc08..95f292243 100644 --- a/src/libserver/symbols_cache.h +++ b/src/libserver/symbols_cache.h @@ -28,7 +28,7 @@ #include "config.h" #include "ucl.h" #include -#define MAX_SYMBOL 128 +#include struct rspamd_task; struct rspamd_config; diff --git a/src/libserver/task.c b/src/libserver/task.c index 6dd00b8bf..eaf845949 100644 --- a/src/libserver/task.c +++ b/src/libserver/task.c @@ -29,6 +29,7 @@ #include "lua/lua_common.h" #include "composites.h" #include "stat_api.h" +#include "unix-std.h" static GQuark rspamd_task_quark (void) diff --git a/src/libserver/task.h b/src/libserver/task.h index 02f6f9ea0..ee57c0f93 100644 --- a/src/libserver/task.h +++ b/src/libserver/task.h @@ -30,6 +30,8 @@ #include "mem_pool.h" #include "dns.h" +#include + enum rspamd_command { CMD_CHECK, CMD_SYMBOLS, diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c index ddd72acb9..71656116a 100644 --- a/src/libserver/worker_util.c +++ b/src/libserver/worker_util.c @@ -26,6 +26,10 @@ #include "message.h" #include "lua/lua_common.h" #include "worker_util.h" +#include "unix-std.h" +#ifdef WITH_GPERF_TOOLS +#include +#endif /** * Return worker's control structure by its type diff --git a/src/libstat/backends/mmaped_file.c b/src/libstat/backends/mmaped_file.c index 41d6900ce..2daf6e6cb 100644 --- a/src/libstat/backends/mmaped_file.c +++ b/src/libstat/backends/mmaped_file.c @@ -24,7 +24,7 @@ #include "config.h" #include "stat_internal.h" -#include "rspamd.h" +#include "unix-std.h" #define CHAIN_LENGTH 128 diff --git a/src/libstat/backends/sqlite3_backend.c b/src/libstat/backends/sqlite3_backend.c index 26b9c56b4..a978f5753 100644 --- a/src/libstat/backends/sqlite3_backend.c +++ b/src/libstat/backends/sqlite3_backend.c @@ -29,6 +29,7 @@ #include "libstat/stat_internal.h" #include "libmime/message.h" #include "lua/lua_common.h" +#include "unix-std.h" #define SQLITE3_BACKEND_TYPE "sqlite3" #define SQLITE3_SCHEMA_VERSION "1" diff --git a/src/libstat/classifiers/bayes.c b/src/libstat/classifiers/bayes.c index 67c2e3116..b0b2be4f3 100644 --- a/src/libstat/classifiers/bayes.c +++ b/src/libstat/classifiers/bayes.c @@ -30,6 +30,7 @@ #include "filter.h" #include "cfg_file.h" #include "stat_internal.h" +#include "math.h" static inline GQuark bayes_error_quark (void) diff --git a/src/libutil/addr.c b/src/libutil/addr.c index 4a48ab7e8..1c7f4dbdf 100644 --- a/src/libutil/addr.c +++ b/src/libutil/addr.c @@ -26,6 +26,17 @@ #include "util.h" #include "logger.h" +#include "unix-std.h" +/* pwd and grp */ +#ifdef HAVE_PWD_H +#include +#endif + +#ifdef HAVE_GRP_H +#include +#endif + + enum { RSPAMD_IPV6_UNDEFINED = 0, RSPAMD_IPV6_SUPPORTED, diff --git a/src/libutil/addr.h b/src/libutil/addr.h index a13c14b53..affd87158 100644 --- a/src/libutil/addr.h +++ b/src/libutil/addr.h @@ -24,6 +24,21 @@ #define ADDR_H_ #include "config.h" + +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_NETINET_IN_H +#include +#endif +#ifdef HAVE_ARPA_INET_H +#include +#endif +/* unix sockets */ +#ifdef HAVE_SYS_UN_H +#include +#endif + #include "mem_pool.h" /** diff --git a/src/libutil/aio_event.c b/src/libutil/aio_event.c index 0686bbd0d..0c3a6f4fb 100644 --- a/src/libutil/aio_event.c +++ b/src/libutil/aio_event.c @@ -22,8 +22,10 @@ */ #include "config.h" +#include #include "aio_event.h" #include "rspamd.h" +#include "unix-std.h" #ifdef HAVE_SYS_EVENTFD_H #include diff --git a/src/libutil/http.c b/src/libutil/http.c index fe7ac2d53..f363969b4 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -32,7 +32,7 @@ #include "ottery.h" #include "keypair_private.h" #include "cryptobox.h" -#include +#include "unix-std.h" #define ENCRYPTED_VERSION " HTTP/1.0" diff --git a/src/libutil/logger.c b/src/libutil/logger.c index 3367829a6..b83aa5cd6 100644 --- a/src/libutil/logger.c +++ b/src/libutil/logger.c @@ -29,6 +29,11 @@ #include "rspamd.h" #include "map.h" #include "xxhash.h" +#include "unix-std.h" + +#ifdef HAVE_SYSLOG_H +#include +#endif /* How much message should be repeated before it is count to be repeated one */ #define REPEATS_MIN 3 @@ -174,9 +179,11 @@ rspamd_log_open_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) rspamd_log->enabled = TRUE; return 0; case RSPAMD_LOG_SYSLOG: +#ifdef HAVE_SYSLOG_H openlog ("rspamd", LOG_NDELAY | LOG_PID, rspamd_log->cfg->log_facility); rspamd_log->enabled = TRUE; +#endif return 0; case RSPAMD_LOG_FILE: rspamd_log->fd = open (rspamd_log->cfg->log_file, @@ -212,7 +219,9 @@ rspamd_log_close_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid) /* Do nothing special */ break; case RSPAMD_LOG_SYSLOG: +#ifdef HAVE_SYSLOG_H closelog (); +#endif break; case RSPAMD_LOG_FILE: if (rspamd_log->enabled) { @@ -576,7 +585,7 @@ syslog_log_function (const gchar *log_domain, gpointer arg) { rspamd_logger_t *rspamd_log = arg; - +#ifdef HAVE_SYSLOG_H struct { GLogLevelFlags glib_level; gint syslog_level; @@ -607,6 +616,7 @@ syslog_log_function (const gchar *log_domain, module != NULL ? module : "", function != NULL ? function : "", message); +#endif } /** diff --git a/src/libutil/map.c b/src/libutil/map.c index 28faf13c4..6c813a133 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -32,6 +32,7 @@ #include "util.h" #include "mem_pool.h" #include "blake2.h" +#include "unix-std.h" static const gchar *hash_fill = "1"; diff --git a/src/libutil/map.h b/src/libutil/map.h index 64421ec1b..95c7de27b 100644 --- a/src/libutil/map.h +++ b/src/libutil/map.h @@ -2,6 +2,8 @@ #define RSPAMD_MAP_H #include "config.h" +#include + #include "mem_pool.h" #include "radix.h" diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c index 849e70c03..e87a1578b 100644 --- a/src/libutil/mem_pool.c +++ b/src/libutil/mem_pool.c @@ -28,6 +28,11 @@ #include "logger.h" #include "utlist.h" #include "ottery.h" +#include "unix-std.h" + +#ifdef HAVE_SCHED_YIELD +#include +#endif /* Sleep time for spin lock in nanoseconds */ #define MUTEX_SLEEP_TIME 10000000L diff --git a/src/libutil/printf.c b/src/libutil/printf.c index 3813524a0..67a2f3d98 100644 --- a/src/libutil/printf.c +++ b/src/libutil/printf.c @@ -25,7 +25,7 @@ #include "printf.h" #include "fstring.h" -#include "rspamd.h" +#include /** * From FreeBSD libutil code @@ -449,7 +449,6 @@ rspamd_vprintf_common (rspamd_printf_append_func func, if (*fmt == '*') { d = (gint)va_arg (args, gint); if (G_UNLIKELY (d < 0)) { - msg_err ("critical error: fraction width is less than 0"); return 0; } frac_width = (guint)d; @@ -466,7 +465,6 @@ rspamd_vprintf_common (rspamd_printf_append_func func, case '*': d = (gint)va_arg (args, gint); if (G_UNLIKELY (d < 0)) { - msg_err ("critical error: size is less than 0"); return 0; } slen = (glong)d; @@ -715,7 +713,7 @@ rspamd_vprintf_common (rspamd_printf_append_func func, continue; case 'N': - c = LF; + c = '\n'; RSPAMD_PRINTF_APPEND (&c, 1); continue; diff --git a/src/libutil/rrd.c b/src/libutil/rrd.c index b7bd75d08..c5793a590 100644 --- a/src/libutil/rrd.c +++ b/src/libutil/rrd.c @@ -26,6 +26,8 @@ #include "rrd.h" #include "util.h" #include "logger.h" +#include "unix-std.h" +#include #define msg_err_rrd(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \ "rrd", file->id, \ diff --git a/src/libutil/sqlite_utils.c b/src/libutil/sqlite_utils.c index 980d07abc..0458a0a02 100644 --- a/src/libutil/sqlite_utils.c +++ b/src/libutil/sqlite_utils.c @@ -25,6 +25,7 @@ #include "config.h" #include "libutil/logger.h" #include "libutil/sqlite_utils.h" +#include "unix-std.h" static GQuark diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index 96a26e1c1..9031305b0 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -25,8 +25,8 @@ #include "config.h" #include "util.h" -#include "mem_pool.h" #include "xxhash.h" +#include static const guchar lc_map[256] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, diff --git a/src/libutil/unix-std.h b/src/libutil/unix-std.h new file mode 100644 index 000000000..988669c4b --- /dev/null +++ b/src/libutil/unix-std.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2015, Vsevolod Stakhov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY AUTHOR ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef RSPAMD_UNIX_STD_H_H +#define RSPAMD_UNIX_STD_H_H + +#include "config.h" + +/* + * Default unix system includes + */ + +/* sys/file.h */ +#ifdef HAVE_SYS_FILE_H +#include +#endif + +/* sys/uio.h */ +#ifdef HAVE_SYS_UIO_H +#include +#endif + +/* sys/mman */ +#ifdef HAVE_SYS_MMAN_H +#include +#endif + + +/* timedb */ +#ifdef HAVE_SYS_TIMEB_H +#include +#endif + +#ifdef HAVE_UNISTD_H +#include +#endif + +/* sysexits */ +#ifdef HAVE_SYSEXITS_H +#include +#endif + +/* strings */ +#ifdef HAVE_STRINGS_H +#include +#endif + +/* fcntl */ +#ifdef HAVE_FCNTL_H +#include +#endif + +#ifdef HAVE_SYS_STAT_H +#include +#endif + + +#ifdef HAVE_DIRENT_H +#include +#endif + +#include + +#ifdef HAVE_LIBGEN_H +#include +#endif + +#endif diff --git a/src/libutil/util.c b/src/libutil/util.c index daf427ef3..dae26a5c0 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -27,8 +27,7 @@ #include "util.h" #include "cfg_file.h" #include "rspamd.h" -#include "filter.h" -#include "message.h" +#include "unix-std.h" #include "xxhash.h" #include "ottery.h" @@ -49,10 +48,32 @@ #ifdef HAVE_LOCALE_H #include #endif - +/* libutil */ +#ifdef HAVE_LIBUTIL_H +#include +#endif #ifdef __APPLE__ #include #endif +#ifdef WITH_GPERF_TOOLS +#include +#endif +/* poll */ +#ifdef HAVE_POLL_H +#include +#endif + +#ifdef HAVE_SIGINFO_H +#include +#endif +/* sys/wait */ +#ifdef HAVE_SYS_WAIT_H +#include +#endif +/* sys/resource.h */ +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif #include "blake2.h" diff --git a/src/libutil/util.h b/src/libutil/util.h index a78c4dfda..e563718f8 100644 --- a/src/libutil/util.h +++ b/src/libutil/util.h @@ -8,6 +8,11 @@ #include "addr.h" #include "str_util.h" +#ifdef HAVE_NETDB_H +#include +#endif +#include + struct rspamd_config; struct rspamd_main; struct workq; diff --git a/src/lua/lua_buffer.c b/src/lua/lua_buffer.c index 021b13a0d..d5f4c7848 100644 --- a/src/lua/lua_buffer.c +++ b/src/lua/lua_buffer.c @@ -23,6 +23,8 @@ #include "lua_common.h" #include "buffer.h" +#include "unix-std.h" +#include /* Public prototypes */ struct rspamd_io_dispatcher_s * lua_check_io_dispatcher (lua_State * L); diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c index bc9bdb3ac..0a63164f5 100644 --- a/src/lua/lua_cfg_file.c +++ b/src/lua/lua_cfg_file.c @@ -23,10 +23,9 @@ */ #include "lua_common.h" -#include "symbols_cache.h" #include "expression.h" -#include "filter.h" #include "composites.h" +#include "unix-std.h" #ifdef HAVE_SYS_UTSNAME_H #include #endif diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c index bbea1ebce..6e0417a82 100644 --- a/src/lua/lua_http.c +++ b/src/lua/lua_http.c @@ -26,6 +26,7 @@ #include "dns.h" #include "http.h" #include "utlist.h" +#include "unix-std.h" /*** * @module rspamd_http diff --git a/src/lua/lua_rsa.c b/src/lua/lua_rsa.c index a85d0db71..b4b84d896 100644 --- a/src/lua/lua_rsa.c +++ b/src/lua/lua_rsa.c @@ -29,6 +29,7 @@ */ #include "lua_common.h" +#include "unix-std.h" #ifdef HAVE_OPENSSL #include diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c index 030f3109b..afc1fd5d9 100644 --- a/src/lua/lua_tcp.c +++ b/src/lua/lua_tcp.c @@ -26,6 +26,7 @@ #include "buffer.h" #include "dns.h" #include "utlist.h" +#include "unix-std.h" static void lua_tcp_handler (int fd, short what, gpointer ud); /*** diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c index 3a7d00211..73099621f 100644 --- a/src/lua/lua_util.c +++ b/src/lua/lua_util.c @@ -27,6 +27,7 @@ #include "html.h" #include "cfg_rcl.h" #include "tokenizers/tokenizers.h" +#include /*** * @module rspamd_util diff --git a/src/lua_worker.c b/src/lua_worker.c index c378ffc0b..b2a3ffc19 100644 --- a/src/lua_worker.c +++ b/src/lua_worker.c @@ -33,6 +33,7 @@ #include "message.h" #include "map.h" #include "dns.h" +#include "unix-std.h" #include "lua/lua_common.h" diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 6ca18aaf8..e7c932c99 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -46,13 +46,11 @@ #include "libserver/worker_util.h" #include "fuzzy_storage.h" #include "utlist.h" -#include "rspamd.h" #include "blake2.h" #include "ottery.h" -#include "cryptobox.h" -#include "keypairs_cache.h" #include "keypair_private.h" -#include "http.h" +#include "unix-std.h" +#include #define DEFAULT_SYMBOL "R_FUZZY_HASH" #define DEFAULT_UPSTREAM_ERROR_TIME 10 diff --git a/src/plugins/regexp.c b/src/plugins/regexp.c index 2fd267aa0..819bc762e 100644 --- a/src/plugins/regexp.c +++ b/src/plugins/regexp.c @@ -33,7 +33,6 @@ #include "mime_expressions.h" #include "libutil/map.h" #include "lua/lua_common.h" -#include "rspamd.h" struct regexp_module_item { struct rspamd_expression *expr; diff --git a/src/plugins/spf.c b/src/plugins/spf.c index f19d2b50f..8780d8aa7 100644 --- a/src/plugins/spf.c +++ b/src/plugins/spf.c @@ -38,6 +38,7 @@ #include "libutil/hash.h" #include "libutil/map.h" #include "rspamd.h" +#include "addr.h" #define DEFAULT_SYMBOL_FAIL "R_SPF_FAIL" #define DEFAULT_SYMBOL_SOFTFAIL "R_SPF_SOFTFAIL" diff --git a/src/plugins/surbl.c b/src/plugins/surbl.c index 7ce58ab1d..baf0706d8 100644 --- a/src/plugins/surbl.c +++ b/src/plugins/surbl.c @@ -43,14 +43,11 @@ #include "config.h" #include "libmime/message.h" -#include "libutil/hash.h" #include "libutil/map.h" #include "rspamd.h" #include "surbl.h" -#include "regexp.h" -#include "acism.h" - #include "utlist.h" +#include "unix-std.h" static struct surbl_ctx *surbl_module_ctx = NULL; diff --git a/src/plugins/surbl.h b/src/plugins/surbl.h index 9eab93000..320423698 100644 --- a/src/plugins/surbl.h +++ b/src/plugins/surbl.h @@ -3,7 +3,6 @@ #include "config.h" #include "acism.h" -#include "rspamd.h" #define DEFAULT_REDIRECTOR_PORT 8080 #define DEFAULT_SURBL_WEIGHT 10 diff --git a/src/rspamadm/pw.c b/src/rspamadm/pw.c index f72db4fa3..e090cd424 100644 --- a/src/rspamadm/pw.c +++ b/src/rspamadm/pw.c @@ -28,6 +28,7 @@ #include "cryptobox.h" #include "rspamd.h" #include "rspamadm.h" +#include "unix-std.h" static void rspamadm_pw (gint argc, gchar **argv); static const char *rspamadm_pw_help (gboolean full_help); diff --git a/src/rspamadm/rspamadm.c b/src/rspamadm/rspamadm.c index 80c180102..19dbea4a3 100644 --- a/src/rspamadm/rspamadm.c +++ b/src/rspamadm/rspamadm.c @@ -26,6 +26,11 @@ #include "rspamadm.h" #include "rspamd.h" #include "ottery.h" +#include "unix-std.h" + +#ifdef HAVE_LIBUTIL_H +#include +#endif static gboolean verbose = FALSE; static gboolean list_commands = FALSE; diff --git a/src/rspamd.c b/src/rspamd.c index 4faa2d36c..743c34ced 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -26,15 +26,42 @@ #include "rspamd.h" #include "libutil/map.h" #include "fuzzy_storage.h" -#include "libserver/symbols_cache.h" #include "lua/lua_common.h" #include "libserver/worker_util.h" #include "ottery.h" #include "xxhash.h" #include "utlist.h" -#include "libstat/stat_api.h" -#include "cryptobox.h" -#include "regexp.h" +#include "unix-std.h" +/* sysexits */ +#ifdef HAVE_SYSEXITS_H +#include +#endif +/* pwd and grp */ +#ifdef HAVE_PWD_H +#include +#endif +#ifdef HAVE_GRP_H +#include +#endif + +#include +#ifdef HAVE_SIGINFO_H +#include +#endif +/* sys/resource.h */ +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif +#ifdef HAVE_SYS_WAIT_H +#include +#endif +#ifdef HAVE_LIBUTIL_H +#include +#endif +#ifdef WITH_GPERF_TOOLS +#include +#endif + #ifdef HAVE_OPENSSL #include #include diff --git a/src/smtp_proxy.c b/src/smtp_proxy.c index 43119afa2..e93ef69ad 100644 --- a/src/smtp_proxy.c +++ b/src/smtp_proxy.c @@ -27,6 +27,7 @@ #include "rspamd.h" #include "smtp.h" #include "libserver/worker_util.h" +#include "unix-std.h" /* * SMTP proxy is a simple smtp proxy worker for dns resolving and diff --git a/test/rspamd_async_test.c b/test/rspamd_async_test.c index 71eec712a..fcd76333f 100644 --- a/test/rspamd_async_test.c +++ b/test/rspamd_async_test.c @@ -22,11 +22,9 @@ */ #include "config.h" -#include "tests.h" #include "rspamd.h" #include "aio_event.h" -#include "mem_pool.h" - +#include "unix-std.h" extern struct event_base *base; diff --git a/test/rspamd_cryptobox_test.c b/test/rspamd_cryptobox_test.c index c7ad2921c..d01d99ee3 100644 --- a/test/rspamd_cryptobox_test.c +++ b/test/rspamd_cryptobox_test.c @@ -29,6 +29,7 @@ #include "fstring.h" #include "ottery.h" #include "cryptobox.h" +#include "unix-std.h" static const int mapping_size = 64 * 8192 + 1; static const int max_seg = 32; diff --git a/test/rspamd_http_test.c b/test/rspamd_http_test.c index 429ae5be9..81b598a45 100644 --- a/test/rspamd_http_test.c +++ b/test/rspamd_http_test.c @@ -28,6 +28,12 @@ #include "tests.h" #include "ottery.h" #include "cryptobox.h" +#include "unix-std.h" +#include + +#ifdef HAVE_SYS_WAIT_H +#include +#endif static const int file_blocks = 1; static const int pconns = 100; diff --git a/test/rspamd_lua_test.c b/test/rspamd_lua_test.c index caeb9814e..8b1b09383 100644 --- a/test/rspamd_lua_test.c +++ b/test/rspamd_lua_test.c @@ -25,6 +25,11 @@ #include "rspamd.h" #include "util.h" #include "lua/lua_common.h" +#include "unix-std.h" + +#ifdef HAVE_GLOB_H +#include +#endif static const char *lua_src = BUILDROOT "/test/lua/tests.lua"; diff --git a/test/rspamd_mem_pool_test.c b/test/rspamd_mem_pool_test.c index fe5ba56b8..e8813f574 100644 --- a/test/rspamd_mem_pool_test.c +++ b/test/rspamd_mem_pool_test.c @@ -1,6 +1,12 @@ #include "config.h" #include "mem_pool.h" #include "tests.h" +#include "unix-std.h" +#include + +#ifdef HAVE_SYS_WAIT_H +#include +#endif #define TEST_BUF "test bufffer" #define TEST2_BUF "test bufffertest bufffer" diff --git a/test/rspamd_shingles_test.c b/test/rspamd_shingles_test.c index 3a1dd8ba2..2b33ad684 100644 --- a/test/rspamd_shingles_test.c +++ b/test/rspamd_shingles_test.c @@ -24,8 +24,8 @@ #include "config.h" #include "rspamd.h" #include "shingles.h" -#include "fstring.h" #include "ottery.h" +#include static void generate_random_string (char *begin, size_t len) diff --git a/test/rspamd_test_suite.c b/test/rspamd_test_suite.c index e10ebd889..97d0565b8 100644 --- a/test/rspamd_test_suite.c +++ b/test/rspamd_test_suite.c @@ -1,7 +1,5 @@ #include "config.h" #include "rspamd.h" -#include "cfg_file.h" -#include "regexp.h" #include "libstat/stat_api.h" #include "tests.h" diff --git a/test/rspamd_upstream_test.c b/test/rspamd_upstream_test.c index 9e04c4dda..e2f2c17ee 100644 --- a/test/rspamd_upstream_test.c +++ b/test/rspamd_upstream_test.c @@ -25,8 +25,8 @@ #include "config.h" #include "rspamd.h" -#include "upstream.h" #include "ottery.h" +#include const char *test_upstream_list = "microsoft.com:443:1,google.com:80:2,kernel.org:443:3"; const char *new_upstream_list = "freebsd.org:80"; -- 2.39.5